Source code for mini.plugs.start

# mini/plugs/start.py
#
#

""" start various bots. """

# thnx to nikt none

## IMPORTS

from mini import kernel, Object, NoSuchBotType, XMPPBot, IRCBot, ConsoleBot, Bot
from mini.looper import RSS, Spider
from mini.utils import error

## basic imports

import logging
import _thread
import time

## default config 

cfg = Object()
cfg.username = "zmon"
cfg.channel = "#dunkbots"
cfg.nick = "mini"

## 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 "irc.freenode.net" ; thing = IRCBot(cfg) elif what == "XMPP": cfg.user = target or "zmon@xmpp.jp" try: cfg.username, cfg.server = cfg.user.split("@") except ValueError: pass thing = XMPPBot(cfg) if what in ["IRC", "XMPP"]: _thread.start_new_thread(thing.begin, ()) if what == "XMPP": _thread.start_new_thread(thing.loop, ()) 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 event.reply("started %s" % thing)
kernel.register("start", do_start)