from tl.utils.statdict import StatDict from tl.lib.aliases import setalias ## basic imports import _thread import pickle import time import os import logging ## defines ratelimited = [] limiterlock = _thread.allocate_lock() limlock = lockdec(limiterlock) db = None ## KarmaDb class class KarmaDb(object): """ karma object """ def save(self): pass def size(self): """ return number of karma items """ global db
import _thread import types import threading import queue import re import urllib.request, urllib.parse, urllib.error from collections import deque ## defines cpy = copy.deepcopy ## locks reconnectlock = threading.RLock() reconnectlocked = lockdec(reconnectlock) lock = _thread.allocate_lock() locked = lockdec(lock) ## classes class BotBase(LazyDict): """ base class for all bots. """ 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")
from tl.utils.locking import lockdec from tl.lib.eventbase import EventBase from tl.lib.errors import BotNotSetInEvent ## basic imports import types import time import _thread import logging import re ## locks replylock = _thread.allocate_lock() replylocked = lockdec(replylock) ## classes class Message(EventBase): """ jabber message object. """ def __init__(self, nodedict={}): self.element = "message" self.jabber = True self.cmnd = "MESSAGE" self.cbtype = "MESSAGE" self.bottype = "xmpp" self.type = "normal" self.speed = 8
import os import shutil import _thread import logging import types import copy ## defines cpy = copy.deepcopy alarms = None ## locks alarmlock = _thread.allocate_lock() alarmlocked = lockdec(alarmlock) ## Alarmitem class class Alarmitem(LazyDict): """ item holding alarm data """ 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
import _thread import socket import threading import os import queue import random import logging import types import re import select import ssl ## locks outlock = _thread.allocate_lock() outlocked = lockdec(outlock) ## exceptions class Irc(BotBase): """ the irc class, provides interface to irc related stuff. """ def __init__(self, cfg=None, users=None, plugs=None, *args, **kwargs): BotBase.__init__(self, cfg, users, plugs, *args, **kwargs) BotBase.setstate(self) self.type = 'irc' self.fsock = None self.oldsock = None self.sock = None self.reconnectcount = 0
import sys import os import types import _thread import logging import uuid import _thread import getpass import copy import time ## locks savelock = _thread.allocate_lock() savelocked = lockdec(savelock) ## defines cpy = copy.deepcopy ## classes class Config(LazyDict): """ config class is a dict containing json strings. is writable to file and human editable. """
import queue import copy import sys import _thread import types import time from collections import deque ## defines cpy = copy.deepcopy ## locks loadlock = _thread.allocate_lock() locked = lockdec(loadlock) ## Plugins class class Plugins(LazyDict): """ the plugins object contains all the plugins. """ loading = LazyDict() def size(self): return len(self) def save(self): for plug in self.values(): for name in dir(plug): try:
from tl.utils.exception import handle_exception from tl.utils.trace import calledfrom, whichplugin, callstack from tl.utils.dol import Dol ## basic imports import sys import copy import _thread import logging import time ## locks lock = _thread.allocate_lock() locked = lockdec(lock) ## Callback class class Callback(object): """ class representing a callback. """ def __init__(self, modname, func, prereq, kwargs, threaded=False, speed=5): self.modname = modname self.plugname = self.modname.split('.')[-1] self.func = func # the callback function self.prereq = prereq # pre condition function self.kwargs = kwargs # kwargs to pass on to function self.threaded = copy.deepcopy(threaded) # run callback in thread self.speed = copy.deepcopy(speed) # speed to execute callback with
from tl.utils.locking import lockdec from .threads import start_new_thread from .errors import TLStop from .exit import globalshutdown ## basic imports import queue import _thread import logging import time ## locks handlerlock = _thread.allocate_lock() locked = lockdec(handlerlock) ## classes class EventHandler(object): """ events are handled in 11 queues with different priorities: queue0 is tried first queue10 last. """ def __init__(self, ordered=False): self.sortedlist = [] if ordered: self.queue = queue.PriorityQueue() else: self.queue = queue.Queue()
setalias('wq', 'quote-who') setalias('dq', 'quote-del') setalias('lq', 'quote-last') setalias('2q', 'quote-2') setalias('iq', 'quote-id') setalias('q', 'quote') setalias('sq', 'quote-search') setalias('cq', 'quote-count') setalias('q-good', 'quote-good') setalias('q-bad', 'quote-bad') ## locks quoteslock = _thread.allocate_lock() locked = lockdec(quoteslock) ## QuoteItem class class QuoteItem(object): """ object representing a quote """ def __init__(self, idnr, txt, nick=None, userhost=None, ttime=None): self.id = idnr self.txt = txt self.nick = nick self.userhost = userhost self.time = ttime ## QuetesDb class
loaded = False cmndtable = None plugins = None callbacktable = None retable = None cmndperms = None shorttable = None timestamps = None cpy = copy.deepcopy ## locks bootlock = _thread.allocate_lock() bootlocked = lockdec(bootlock) ## scandir function def scandir(d, dbenable=False): from tl.lib.plugins import plugs changed = [] try: changed = checktimestamps(d, dbenable) mods = [] if changed: logging.debug("files changed %s" % str(changed)) for plugfile in changed: if not dbenable and os.sep + 'db' in plugfile: logging.warn("db not enabled .. skipping %s" % plugfile) ; continue return changed except Exception as ex: logging.error("boot - can't read %s dir." % d) ; handle_exception()
from tl.utils.locking import lockdec from tl.lib.callbacks import callbacks from tl.lib.users import users from tl.lib.config import getmainconfig ## basic imports import _thread import os import time import logging ## locks infolock = _thread.allocate_lock() locked = lockdec(infolock) ## defines db = None ## InfoItemsDb class class InfoItemsDb(object): """ information items """ def add(self, item, description, userhost, ttime): """ add an item """ if not db: logging.error("plugin isnt initialised yet") ; return [] item = item.lower()
import types import copy import sys import time import uuid import fcntl ## defines cpy = copy.deepcopy needsaving = deque() ## locks persistlock = _thread.allocate_lock() persistlocked = lockdec(persistlock) ## cleanup function def cleanup(bot=None, event=None): global needsaving r = [] for p in needsaving: try: p.dosave() ; r.append(p) ; logging.warn("saved on retry - %s" % p.fn) except (OSError, IOError) as ex: logging.error("failed to save %s - %s" % (p, str(ex))) for p in r: try: needsaving.remove(p) except ValueError: pass return needsaving ## Persist class
from tl.lib.callbacks import callbacks import tl.lib.threads as thr ## basic imorts import datetime import sys import time import _thread import types import logging ## locks plock = _thread.allocate_lock() locked = lockdec(plock) ## defines pidcount = 0 ## JobError class class JobError(Exception): """ job error exception. """ pass ## Job class class Job(object):
from tl.utils.exception import handle_exception from tl.lib.datadir import getdatadir from tl.lib.errors import NoDbConnection, NoDbResult ## basic imports import _thread import os import time import logging import sqlite3 ## locks dblock = _thread.allocate_lock() dblocked = lockdec(dblock) ## Db class class Db(object): """ this class implements a database connection. it connects to the database on initialisation. """ def __init__(self, dbname=None, dbhost=None, dbuser=None, dbpasswd=None, dbtype=None, ddir=None, doconnect=True): self.datadir = ddir or getdatadir() self.datadir = self.datadir + os.sep + "db" + os.sep if hasattr(os, 'mkdir'): if not os.path.isdir(self.datadir): try: os.mkdir(self.datadir)
from tl.lib.aliases import setalias from tl.lib.config import getmainconfig from tl.lib.plugins import plugs from tl.db import getmaindb ## basic imports import time import _thread import os import logging ## locks todolock = _thread.allocate_lock() locked = lockdec(todolock) ## defines todo = None db = None ## TodoItem class class TodoItem: """ a todo item """ def __init__(self, name, descr, ttime=None, duration=None, warnsec=None, priority=None, num=0): self.name = name self.time = ttime