Beispiel #1
0
 def dostart(self, botname=None, bottype=None, *args, **kwargs):
     """ create an START event and send it to callbacks. """
     e = EventBase()
     e.bot = self
     e.botname = botname or self.cfg.name
     e.bottype = bottype or self.type
     e.origin = e.botname
     e.userhost = get_bid(self)
     e.nolog = True
     e.channel = botname
     e.txt = "%s.%s - %s" % (e.botname, e.bottype, str(time.time()))
     e.cbtype = 'START'
     e.ttl = 1
     e.nick = self.cfg.nick or self.cfg.name
     self.doevent(e)
     logging.debug("%s - START event send to callbacks" % self.cfg.name)
Beispiel #2
0
 def outmonitor(self, origin, channel, txt, event=None):
     """ create an OUTPUT event with provided txt and send it to callbacks. """
     if event: e = cpy(event)
     else: e = EventBase()
     if e.status == "done":
         logging.debug("%s - outmonitor - event is done .. ignoring" % self.cfg.name)
         return
     e.bot = self
     e.origin = origin
     e.userhost = get_bid(self)
     e.auth = e.userhost
     e.channel = channel
     e.txt = txt
     e.cbtype = 'OUTPUT'
     e.nodispatch = True
     e.ttl = 1
     e.nick = self.cfg.nick or self.cfg.name
     e.bonded = True
     e.isoutput = True
     e.dontbind = True
     logging.debug("> first_callbacks > %s" % e.txt) 
     first_callbacks.check(self, e)
Beispiel #3
0
 def __init__(self, cfg=None, usersin=None, plugs=None, botname=None, nick=None, bottype=None, ordered=False, *args, **kwargs):
     logging.debug("type is %s" % str(type(self)))
     if cfg: self.cfg = cfg ; botname = botname or self.cfg.name
     if not botname: botname = "default-%s" % str(type(self)).split('.')[-1][:-2]
     if not botname: raise Exception("can't determine  botname")
     self.fleetdir = 'fleet' + os.sep + stripname(botname)
     if not self.cfg: self.cfg = Config(self.fleetdir + os.sep + 'config')
     self.cfg.name = botname or self.cfg.name
     if not self.cfg.name: raise Exception("name is not set in %s config file" % self.fleetdir)
     logging.debug("name is %s" % self.cfg.name)
     LazyDict.__init__(self)
     self.bid = get_bid(self)
     logging.warn("created bot on %s" % self.bid)
     logging.debug("created bot with config %s" % self.cfg.tojson(full=True))
     self.ecounter = 0
     self.ignore = []
     self.ids = []
     self.stats = StatDict()
     logging.warn("stats dict set to %s" % str(self.stats))
     self.aliases = getaliases()
     self.reconnectcount = 0
     self.plugs = coreplugs
     self.gatekeeper = GateKeeper(self.cfg.name)
     self.gatekeeper.allow(self.user or self.jid or self.cfg.server or self.cfg.name)
     self.starttime = time.time()
     self.type = bottype or "base"
     self.status = "init"
     self.networkname = self.cfg.networkname or self.cfg.name or ""
     from tl.lib.datadir import getdatadir
     datadir = getdatadir()
     self.datadir = datadir + os.sep + self.fleetdir
     self.maincfg = getmainconfig()
     if not self.cfg.owner:
         logging.debug("owner is not set in %s - using mainconfig" % self.cfg.cfile)
         self.cfg.owner = self.maincfg.owner
     self.users = usersin or getusers()
     logging.debug("owner is %s" % self.cfg.owner)
     self.users.make_owner(self.cfg.owner)
     self.outcache = outcache
     self.userhosts = LazyDict()
     self.nicks = LazyDict()
     self.connectok = threading.Event()
     self.reconnectcount = 0
     self.cfg.nick = nick or self.cfg.nick or 'tl'
     try:
         if not os.isdir(self.datadir): os.mkdir(self.datadir)
     except: pass
     self.setstate()
     self.outputlock = _thread.allocate_lock()
     if ordered:
         self.outqueue = queue.PriorityQueue()
         self.eventqueue = queue.PriorityQueue()
     else:
         self.outqueue = queue.Queue()
         self.eventqueue = queue.Queue()
     logging.debug("event queues is %s" % str(self.eventqueue))
     self.encoding = self.cfg.encoding or "utf-8"
     self.cmndperms = getcmndperms()
     self.outputmorphs = outputmorphs
     self.inputmorphs = inputmorphs
     tickloop.start(self)