Source code for bot.plugs.start
# bot/plugs/start.py
#
#
""" start various bots. """
# thnx to nikt none
## IMPORTS
from bot import kernel, Object, NoSuchBotType, XMPPBot, IRCBot, ConsoleBot, Bot
from bot.looper import RSS, Spider
from bot.utils import error
## basic imports
import logging
import _thread
import time
## default config
cfg = Object()
cfg.server = "localhost"
cfg.username = "monitor"
cfg.channel = "#botje"
cfg.nick = "botje"
cfg.user = "monitor@xmpp.jp"
## start command
[docs]def do_start(event):
try: what = event.args[1].upper()
except IndexError: event.reply("start what?") ; return
try: target = event.args[2]
except IndexError: target = None
thing = None
if what == "IRC": cfg.server = target or cfg.server; thing = IRCBot(cfg)
elif what == "XMPP":
cfg.user = target or cfg.user
try: cfg.username, cfg.server = cfg.user.split("@")
except ValueError: pass
thing = XMPPBot(cfg)
elif what == "RSS": thing = RSS(60.0)
elif what == "SPIDER": thing = Spider(60.0)
if not thing: event.reply("start what?") ; return
if what not in kernel.run: kernel.run[what] = thing
if what in ["IRC", "XMPP"]: _thread.start_new_thread(kernel.run[what].begin, ())
if what == "XMPP": _thread.start_new_thread(kernel.run[what].loop, ())
event.reply("started %s" % type(thing))
kernel.register("start", do_start)