Source code for zbot.plugs.start

# zbot/plugs/start.py
#
#

""" start various bots. """

## IMPORTS

from zbot import kernel, Object
from zbot.utils import error
from zbot.drivers import get_bot

## basic imports

import logging
import _thread
import time

## service/port mapping

ports = {
         "IRC": 6667,
         "XMPP": 5222,
        }

## default config 

cfg = Object()
cfg.server = "localhost"
cfg.nick = "zbot"
cfg.username = "zbot"
cfg.user = "monitor@xmpp.jp"
cfg.channel = "#dunkbots"

## start command

[docs]def do_start(event): try: type = event.args[1].upper() ; user = event.args[2] ; cfg.user = user except IndexError: pass cfg.port = ports[type] if type == "XMPP": try: cfg.username, cfg.server = cfg.user.split("@") except ValueError: pass logging.warn("start %s %s %s %s" % (type, cfg.server, cfg.username, cfg.port)) bot = get_bot(type, cfg) logging.warn("starting %s" % bot) _thread.start_new_thread(bot.begin, ()) if type == "XMPP": _thread.start_new_thread(bot.loop, ())
kernel.cmnds.register("start", do_start)