Beispiel #1
0
def handle_settodo(bot, ievent):
    """ todo-set <name> <txt> .. add a todo to another user's todo list"""
    try:
        who = ievent.args[0]
        what = ' '.join(ievent.args[1:])
    except IndexError: ievent.missing('<nick> <what>') ;return
    if not what: ievent.missing('<nick> <what>') ; return
    userhost = getwho(bot, who)
    if not userhost: ievent.reply("can't find userhost for %s" % who) ; return
    whouser = getusers().getname(userhost)
    if not whouser: ievent.reply("can't find user for %s" % userhost) ; return
    name = getusers().getname(ievent.userhost)
    if not getusers().permitted(userhost, name, 'todo'): ievent.reply("%s doesn't permit todo sharing for %s " % (who, name)) ; return
    what = "%s: %s" % (ievent.nick, what)
    ttime = strtotime(what)
    nr = 0
    if not ttime  == None:
        ievent.reply('time detected ' + time.ctime(ttime))
        what = striptime(what)
        karma = plugs.get("tl.plugs.db.karma2")
        if karma: alarmnr = alarms.add(bot.name, who, ttime, what)
        else: alarmnr = None
        nr = todo.add(whouser, what, ttime, alarmnr)
    else: nr = todo.add(whouser, what, None)
    ievent.reply('todo item %s added' % nr)
Beispiel #2
0
def get_tlid(event):
    """ make a timed event id. """
    from tl.lib.users import getusers
    user = getusers().byname(target)
    if not target: user = getusers().getuser(target)
    if not user: raise NoSuchUser(userhost)
    tlid = "/timeline/%s-%s-%s" % (event.ctime, event.token, stripname(user.data.name)) 
    tlid = normdir(tlid)
    logging.warn("tlid is %s" % tlid)
    return tlid
Beispiel #3
0
def get_uid(target=None):
    """ make a uid (userid) based on username). """
    if not target: uid = "/console/" + getpass.getuser()
    else:
        from tl.lib.users import getusers
        user = getusers().byname(target)
        if not user: user = getusers().getuser(target)
        if not user: raise NoSuchUser(target)
        name = user.data.name
        uid = "/users/" + name
    uid = normdir(uid)
    logging.warn("uid is %s" % uid)
    return uid
Beispiel #4
0
def handle_todo(bot, ievent):
    """ todo [<item>] .. show todo's or set todo item .. a time/date can be given. """
    if len(ievent.args) > 0: handle_todo2(bot, ievent) ; return
    name = getusers().getname(ievent.userhost)
    try: todoos = todo.get(name)
    except KeyError: ievent.reply('i dont have todo info for %s' % user.name) ; return
    saytodo(bot, ievent, todoos)
Beispiel #5
0
def do_opts(type="console", args=[], *argslist, **kwargs):
    from tl.version import getversion
    if not args: args = sys.argv
    if type != "console": print("TIMELINE %s" % getversion(type.upper()))
    cfg = None
    if type == "irc": target = api_opts + bot_opts + irc_opts
    elif type == "xmpp": target = api_opts + bot_opts + xmpp_opts
    elif type == "fleet": target = api_opts + fleet_opts
    elif type == "init": target = []
    elif type == "console": target = bot_opts + console_opts
    else: target = []
    opts =  make_opts(args, target, *argslist, **kwargs)
    if type == "console": ll = "error"
    else: ll = "warn" 
    if opts.datadir: setdatadir(opts.datadir)
    else: setdatadir(homedir + os.sep + ".tl")
    setloglevel(opts.loglevel or ll)
    if opts.bork: tl.utils.exception.bork = True ; logging.warn("bork mode enabled")
    if opts.nourl: tl.utils.url.enabled = False ; logging.warn("url fetching disabled")
    if opts.nocolors: tl.utils.log.docolor = False ; logging.warn("colors in logging is disabled")
    from tl.lib.users import getusers
    u = getusers()
    if opts.owner and u: u.make_owner(opts.owner)
    from tl.lib.config import getmainconfig
    maincfg = getmainconfig(opts.datadir)
    if type == "irc": cfg = makeircconfig(opts, opts.name)
    elif type == "xmpp" or type == "xmpp": cfg = makexmppconfig(opts, opts.name)
    elif type == "console": cfg = makeconsoleconfig(opts, opts.name)
    else: cfg = makedefaultconfig(opts, opts.name) 
    if opts.anon: cfg.auto_register = True ; cfg.guestasuser = True
    else: cfg.auto_register = False
    if maincfg.dbtype: logging.warn("database type is %s" % maincfg.dbtype)
    return (opts, cfg)
Beispiel #6
0
def handle_listsshow(bot, ievent):
    """ show avaiable lists """
    username = getusers().getname(ievent.userhost)
    l = getlists(username)
    if not l: ievent.reply('no lists available') ; return
    else:
        result = []
        for i in l:
            if not i[2] in result: result.append(i[2])
        if result: ievent.reply("lists: ", result)
Beispiel #7
0
def handle_ignore(bot, event):
    """ arguments: <nick>|<userhost>|<JID> - ignore a user. """
    if not event.rest: event.missing("<nick>|<userhost>|<JID>") ; return
    nick = event.rest
    userhost = getwho(bot, nick)
    if not userhost: userhost = event.rest
    perms = getusers().getperms(userhost)
    if perms and "OPER" in perms: event.reply("can't ignore OPER") ; return
    if not userhost in bot.ignore: bot.ignore.append(userhost)
    event.reply("%s added to ignore list" % userhost)
Beispiel #8
0
def handle_cfgset(bot, event):
    if len(event.args) != 3: event.missing("<configname> <variable> <value>") ; return
    name, var, value = event.args
    if not var in allowset: event.reply("setting %s is not allowed" % var) ; return
    if name == "main":
        if not getusers().allowed(event.userhost, "OPER"): event.reply("you need to have OPER permissions to edit the mainconfig.") ; return
        mcfg = getmainconfig()
        try: mcfg[var] = int(value)
        except ValueError: mcfg[var] = value
        mcfg.save()
        event.done()
    else: event.reply('we current only support editing the "main" config.') ; return
Beispiel #9
0
def handle_gettodo(bot, ievent):
    """ todo-get <nick> .. get todo of another user """
    try: who = ievent.args[0]
    except IndexError: ievent.missing('<nick>') ; return
    userhost = getwho(bot, who)
    if not userhost: ievent.reply("can't find userhost for %s" % who) ; return
    users = getusers()
    whouser = users.getname(userhost)
    if not whouser: ievent.reply("can't find user for %s" % userhost) ; return
    name = users.getname(ievent.userhost)
    if not users.permitted(userhost, name, 'todo'): ievent.reply("%s doesn't permit todo sharing for %s " % (who, name)) ; return
    todoos = todo.get(whouser)
    saytodo(bot, ievent, todoos)
Beispiel #10
0
def handle_tododone(bot, ievent):
    """ todo-done <listofnrs> .. remove todo items """
    if len(ievent.args) == 0: ievent.missing('<list of nrs>') ; return
    try:
        nrs = []
        for i in ievent.args: nrs.append(int(i))
    except ValueError: ievent.reply('%s is not an integer' % i) ; return
    name = getusers().getname(ievent.userhost)
    nrdone = 0
    for i in nrs: nrdone += todo.delete(name, i)
    if nrdone == 1: ievent.reply('%s item deleted' % nrdone)
    elif nrdone == 0: ievent.reply('no items deleted')
    else: ievent.reply('%s items deleted' % nrdone)
Beispiel #11
0
def handle_setpriority(bot, ievent):
    """ todo-setprio [<channel|name>] <itemnr> <prio> .. show priority on todo item """
    try: (who, itemnr, prio) = ievent.args
    except ValueError:
        try:
            (itemnr, prio) = ievent.args
            who = getusers().getname(ievent.userhost)
        except ValueError: ievent.missing('[<channe|namel>] <itemnr> <priority>') ; return
    try:
        itemnr = int(itemnr)
        prio = int(prio)
    except ValueError: ievent.missing('[<channel|name>] <itemnr> <priority>') ; return
    who = who.lower()
    if not todo.setprio(who, itemnr, prio): ievent.reply('no todo %s found for %s' % (itemnr, who)) ; return
    ievent.reply('priority set')
Beispiel #12
0
def handle_listsmerge(bot, ievent):
    """ merge 2 list """
    try: (fromlist, tolist) = ievent.args
    except ValueError: ievent.missing('<fromlist> <tolist>') ; return
    username = getusers().getname(ievent.userhost)
    res = getlist(username, fromlist)
    if not res:  ievent.reply('no %s list available or empty' % fromlist) ; return
    l = []
    for i in res: l.append(i[3])
    result = 0
    try: result = mergelist(username, tolist, l)
    except Exception as ex:
        handle_exception()
        ievent.reply('ERROR: %s' % str(ex))
        return
    ievent.reply('%s items merged' % result)
Beispiel #13
0
 def handle_close(self, bot, ievent):
     if len(ievent.args) < 3:
         ievent.missing('<bug id> <action> <message>')
         return
     try:
         status = self.close(ievent.args[0], getusers().getname(ievent.userhost), 
             ' '.join(ievent.args[2:]), ievent.args[1])
         ievent.reply('ok')
     except AssertionError as e:
         ievent.reply('error: %s' % e)
     except BugTrackerNotImplemented:
         ievent.reply('error: not implemented in this bug tracker')
     except BugTrackerNotSupported as e:
         ievent.reply('error: not supported: %s' % e)
     except BugTrackerNotFound as e:
         ievent.reply('error: not found: %s' % e)
Beispiel #14
0
def handle_todo2(bot, ievent):
    """ set todo item """
    if not ievent.rest: ievent.missing("<what>") ; return
    else: what = ievent.rest
    name = getusers().getname(ievent.userhost)
    ttime = strtotime(what)
    nr = 0
    if not ttime  == None:
        ievent.reply('time detected ' + time.ctime(ttime))
        what = striptime(what)
        alarms = plugs.get("tl.plugs.extra.alarm")
        if alarms : alarmnr = alarms.alarms.add(bot.name, ievent.nick, ttime, what)
        else: alarmnr = None
        nr = todo.add(name, what, ttime, alarmnr)
    else: nr = todo.add(name, what, None)
    ievent.reply('todo item %s added' % nr)
Beispiel #15
0
def handle_getpriority(bot, ievent):
    """ todo-getprio <[channel|name]> <itemnr> .. get priority of todo item """
    try: (who, itemnr) = ievent.args
    except ValueError:
        try:
            itemnr = ievent.args[0]
            who = getusers().getname(ievent.userhost)
        except IndexError: ievent.missing('[<channel|name>] <itemnr>') ; return
    try: itemnr = int(itemnr)
    except ValueError: ievent.missing('[<channel|name>] <itemnr>') ; return
    who = who.lower()
    todoitems = todo.get(who)
    if not todoitems: ievent.reply('no todoitems known for %s' % who) ; return
    try: prio = todoitems[itemnr].priority
    except (IndexError, KeyError): ievent.reply('no todo item %s known for %s' % (itemnr, who)) ; return
    ievent.reply('priority is %s' % prio)
Beispiel #16
0
def handle_todosettime(bot, ievent):
    """ todo-settime [<channel|name>] <itemnr> <timestring> .. set time \
        on todo item """
    ttime = strtotime(ievent.txt)
    if ttime == None: ievent.reply("can't detect time") ; return   
    txt = striptime(ievent.txt)
    try: (who, itemnr) = txt.split()
    except ValueError:
        try:
            (itemnr, ) = txt.split()
            who = getusers().getname(ievent.userhost)
        except ValueError: ievent.missing('[<channe|namel>] <itemnr> <timestring>') ; return
    try: itemnr = int(itemnr)
    except ValueError: ievent.missing('[<channel|name>] <itemnr> <timestring>') ; return
    who = who.lower()
    if not todo.settime(who, itemnr, ttime): ievent.reply('no todo %s found for %s' % (itemnr, who)) ; return
    ievent.reply('time of todo %s set to %s' % (itemnr, time.ctime(ttime)))
Beispiel #17
0
def handle_tomorrow(bot, ievent):
    """ todo-tomorrow .. show time related todo items for tomorrow """
    username = getusers().getname(ievent.userhost)
    if ievent.rest:
        what = ievent.rest
        ttime = strtotime(what)
        if ttime != None:
            if ttime < today() or ttime > today() + 24*60*60:
                ievent.reply("%s is not tomorrow" % time.ctime(ttime + 24*60*60))
                return
            ttime += 24*60*60
            ievent.reply('time detected ' + time.ctime(ttime))
            what = striptime(what)
        else: ttime = today() + 42*60*60
        todo.add(username, what, ttime)   
        ievent.reply('todo added')    
        return
    todoos = todo.withintime(username, today()+24*60*60, today()+2*24*60*60)
    saytodo(bot, ievent, todoos)
Beispiel #18
0
def handle_listsdel(bot, ievent):
    """ list-del <listname> ',' <listofnrs> .. remove items with indexnr from list """
    if not ievent.rest: ievent.missing('<listofnrs>') ; return
    try:
        nrs = []
        for i in ievent.rest.split(): nrs.append(int(i))
    except ValueError: ievent.reply('%s is not an integer' % i) ; return
    username = getusers().getname(ievent.userhost)
    nrs.sort()
    failed = []
    itemsdeleted = 0
    try:
        for i in nrs:
            result = delfromlist(username, i)
            if not result: failed.append(str(i))
            else: itemsdeleted += 1
    except Exception as ex:
        handle_exception()
        ievent.reply('ERROR: %s' % str(ex))
        return
    if failed: ievent.reply('failed to delete %s' % ' '.join(failed))
    ievent.reply('%s item(s) removed' % itemsdeleted)
Beispiel #19
0
def handle_lists(bot, ievent):
    """ list <listname> [',' <item>] """
    if not ievent.rest: ievent.missing("<listname> [',' <item>]") ; return
    username = getusers().getname(ievent.userhost)
    try: listname, item = ievent.rest.split(',', 1)
    except ValueError:
        l = getlist(username, ievent.rest)
        if not l: ievent.reply('no %s list available' % ievent.rest) ; return
        result = []
        for i in l: result.append("%s) %s" % (i[0], i[3]))
        ievent.reply("results: ", result)
        return
    listname = listname.strip().lower()
    item = item.strip()
    if not listname or not item: ievent.missing("<listname> [',' <item>]") ; return
    ok = 0
    try: ok = addtolist(username, listname, item)
    except Exception as ex:
        handle_exception()
        ievent.reply('ERROR: %s' % str(ex))
        return
    if ok: ievent.reply('%s added to %s list' % (item, listname))
    else: ievent.reply('add failed')
Beispiel #20
0
def handle_today(bot, ievent):
    """ todo-today .. show time related todo items for today """
    name = getusers().getname(ievent.userhost)
    todoos = todo.withintime(name, today(), today()+24*60*60)
    saytodo(bot, ievent, todoos)
Beispiel #21
0
def handle_todotime(bot, ievent):
    """ todo-time .. show time related todoos """
    name = getusers().getname(ievent.userhost)
    todoos = todo.timetodo(name)
    saytodo(bot, ievent, todoos)
Beispiel #22
0
## check for pycrypto dependancy
got = False

try:
    import Crypto.Cipher.Blowfish
    import Crypto.Cipher.AES
    got = True
except ImportError: 
    raise RequireError("PyCrypto is required for FiSH. Please install this library if you want to use this plug")

## defines

cfg = PersistConfig()
cfg.define("enable", 0)

users = getusers()

## KeyStore class

class KeyStore(Persist):
  def __init__(self, keyname):
    Persist.__init__(self, getdatadir() + os.sep + 'keys' + os.sep + 'fish' + os.sep + stripname(keyname))

## make sure we get loaded

def dummycb(bot, event): pass

callbacks.add("START", dummycb)

## plugin
Beispiel #23
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)
Beispiel #24
0
def handle_cfg(bot, event):
    if len(event.args) != 1: event.missing("<configname>") ; return
    name = event.args[0]
    if name == "main":
        if not getusers().allowed(event.userhost, "OPER"): event.reply("you need to have OPER permissions to edit the mainconfig.") ; return
        event.reply(getmainconfig().fordisplay())