Esempio n. 1
0
 def __init__(self, botname=None, i=0, nick="", ttime=time.time(), txt="", printto=None, d={}):
     if not d: LazyDict.__init__(self)
     else:
         assert(type(d) == dict)
         LazyDict.__init__(self, d)
     if not self.botname: self.botname = botname or "default-irc"
     self.idnr = self.idnr or i
     self.nick = self.nick or nick
     self.time = self.ttime or ttime
     self.txt = self.txt or txt
     self.printto = self.printto or printto or nick or ""
Esempio n. 2
0
 def __init__(self, input={}, bot=None, parsetxt=None):
     LazyDict.__init__(self)
     if bot: self.bot = bot
     self.ctime = time.time()
     self.speed = 5
     self.nrout = 0
     self.nodispatch = True
     self.isready = threading.Event()
     self.dontbind = self.bot and self.bot.cfg and self.bot.cfg.strict or False
     if parsetxt: self.parse(parsetxt)
     if input: self.copyin(input)
     if not self.token: self.setup()
Esempio n. 3
0
 def __init__(self, filename, verbose=False, input={}, ddir=None, nolog=False, *args, **kwargs):
     assert filename
     if ddir: ddir = normdir(ddir)
     if input: LazyDict.__init__(self, input, *args, **kwargs)
     else: LazyDict.__init__(self, *args, **kwargs)
     self.filename = filename
     self.setcfile(ddir, filename)
     if not self._comments: self._comments = {}
     logging.info("%s from %s" % (self._logname, whichmodule(2)))
     self.fromfile(self._cfile)
     self.cid = get_cid(self)
     self.init()
     if self.owner: logging.info("owner is %s" % self.owner)
     if "uuid" not in self: self.setuuid()
     if not self._origdir in self._cfile: raise WrongFileName("%s not in %s" % (self._origdir, self._cfile))
Esempio n. 4
0
 def __init__(self, modname, cmnd, func, perms=[], threaded=False, wait=False, orig=None, how=None, speed=None):
     LazyDict.__init__(self)
     if not modname: raise Exception("modname is not set - %s" % cmnd)
     self.modname = cpy(modname)
     self.plugname = self.modname.split('.')[-1]
     self.cmnd = cpy(cmnd)
     self.orig = cpy(orig)
     self.func = func
     if type(perms) == bytes: perms = [perms, ]
     self.perms = cpy(perms)
     self.plugin = self.plugname
     self.threaded = cpy(threaded)
     self.wait = cpy(wait)
     self.enable = True
     self.how = how or "overwrite"
     self.regex = None
     self.speed = speed
Esempio n. 5
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)
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
     LazyDict.__init__(self, *args, **kwargs)
     self.__wait = threading.Event()