Exemple #1
0
def init():
  """ Init """
  if not got: raise RequireError("PyCrypto is required for FiSH. Please install this library if you want to use this plug")
  if cfg.enable:
    inputmorphs.add(fishin)
    outputmorphs.add(fishout)
    callbacks.add("NOTICE", dh1080_exchange)
    cmnds.add("fish", handle_fish, "OPER")
    examples.add("fish", "command that handles fish enrypting over IRC", "fish help")
  else: logging.warn("fish plugin is not enabled - use fish-cfg enable 1")
Exemple #2
0
 def __init__(self):
     self.hide = []
     modname = whichplugin()
     logging.debug("persistconfig - module name is %s" % modname)
     Config.__init__(self, 'plugs' + os.sep + modname, "config")
     self.modname = modname
     self.plugname = self.modname.split('.')[-1]
     cmndname = "%s-cfg" % self.plugname
     logging.debug('persistconfig - added command %s (%s)' % (cmndname, self.plugname))
     from tl.lib.commands import cmnds, Command
     cmnds[cmndname] = Command(self.modname, cmndname, self.cfg, ['OPER', ])
     examples.add(cmndname, "%s configuration" % self.plugname, cmndname)
     cmndnamesave = cmndname + "save"
     cmnds[cmndnamesave] = Command(self.modname, cmndnamesave, self.cfgsave, ['OPER',])
     examples.add(cmndnamesave, "save %s configuration" % self.plugname, cmndnamesave)
     cmndnamedef = cmndname + "defined"
     cmnds[cmndnamedef] = Command(self.modname, cmndnamedef, self.cfgdefined, ['OPER',])
     examples.add(cmndnamedef, "show defined config vars for %s plugin" % self.plugname, cmndnamedef)
Exemple #3
0
def handle_plugenable(bot, event):
    """ arguments" <plugname> - enable a plugin. """
    if not event.rest: event.missing("<plugname>") ; return
    if "." in event.rest: mod = event.rest
    else: mod = bot.plugs.getmodule(event.rest)
    if not mod: event.reply("can't find module for %s" % event.rest) ; return
    event.reply("reloading and enabling %s" % mod)
    plugenable(mod)
    bot.enable(mod)
    bot.plugs.reload(mod, force=True)
    update_mod(mod)
    event.done()

cmnds.add("plug-enable", handle_plugenable, ["OPER", ])
examples.add("plug-enable", "enable a plugin", "plug-enable rss")

## plug-disable command

def handle_plugdisable(bot, event):
    """ arguments: <plugname> - disable a plugin. """
    if not event.rest: event.missing("<plugin>") ; return
    mod = bot.plugs.getmodule(event.rest)
    if mod in default_plugins: event.reply("can't remove a default plugin") ; return
    if not mod: event.reply("can't find module for %s" % event.rest) ; return
    event.reply("unloading and disabling %s" % mod)
    bot.plugs.unload(mod)
    plugdisable(mod)
    bot.disable(mod)
    event.done()
Exemple #4
0
        except ValueError: pass
        return 1
    except Exception as ex: handle_exception(ievent)

## karma-get command

def handle_karmaget(bot, ievent):
    """ karma-get <item> .. show karma of item """
    if not ievent.rest: ievent.missing('<item>') ; return
    else: item = ievent.rest
    result = karma.get(item)
    if result: ievent.reply("%s has karma %s" % (item, str(result)))
    else: ievent.reply("%s has no karma yet" % item)

cmnds.add('karma-get', handle_karmaget, ['USER', 'WEB', 'ANON', 'ANONKARMA'])
examples.add('karma-get', 'karma-get <item> .. show karma of <item>', 'karma-get dunker')

## karma-del command

def handle_karmadel(bot, ievent):
    """ karma-del <item> .. delete karma item """
    if not ievent.rest: ievent.missing('<item>') ; return
    item = ievent.rest
    result = karma.delete(item)
    if result: ievent.reply("%s deleted" % item)
    else: ievent.reply("can't delete %s" % item)

cmnds.add('karma-del', handle_karmadel, ['OPER'])
examples.add('karma-del', 'karma-del <item> .. delete karma item', 'karma-del dunker')

## karmaup RE
Exemple #5
0
def handle_overflowstart(bot, event):
    global state
    for bla in event.args:
        try: name, gid = bla.split(":")
        except: name = gid = bla
        state.data.names[gid] = name
        target = [bot.cfg.name, event.channel]
        if gid not in state.data.ids: state.data.ids[gid] = []
        if not gid in state.data.watch or not target in state.data.ids[gid]: state.data.ids[gid].append(target) ; state.data.watch.append(gid)
        else: event.reply("we are already monitoring %s in %s" % (gid, str(target)))
    state.save()
    sync()
    event.done()

cmnds.add("overflow-start", handle_overflowstart, ["OPER", ])
examples.add("overflow-start", "start monitoring a stackoverflow id into the channel", "overflow-start feedbackoverflow:625681")

## overflow-stop command

def handle_overflowstop(bot, event):
    if not event.args: event.missing("<stackoveflow id") ; return
    global state
    id = event.args[0]
    try:
        del state.data.ids[id]
        del state.data.names[id]
        state.save()
        event.done()
    except (KeyError, ValueError): event.reply("we are not monitoring %s in %s" % (id, event.channel))
    
cmnds.add("overflow-stop", handle_overflowstop, ["OPER", ])
Exemple #6
0
import logging

## admin-save command

def handle_adminsave(bot, ievent):
    """ no arguments - boot the bot .. do some initialisation. """
    ievent.reply("saving mainconfig")
    getmainconfig().save()
    ievent.reply("saving fleet bots")
    getfleet().save()
    ievent.reply("saving all plugins")
    plugs.save()
    ievent.done()

cmnds.add('admin-save', handle_adminsave, 'OPER')
examples.add('admin-save', 'initialize the bot', 'admin-boot')

## admin-boot command

def handle_adminboot(bot, ievent):
    """ no arguments - boot the bot .. do some initialisation. """
    ievent.reply("reloading all plugins")
    if 'saveperms' in ievent.rest: boot(force=True, saveperms=True, clear=True)
    else: boot(force=True, saveperms=False, clear=True)
    ievent.done()

cmnds.add('admin-boot', handle_adminboot, 'OPER')
examples.add('admin-boot', 'initialize the bot', 'admin-boot')

## admin-bootthreaded command
Exemple #7
0
def handle_geo(bot, event):
    """ arguments: <ipnr> - do a geo lookup. """
    if not event.rest: 
        event.missing("<ipnr>")
        return
    
    query = event.rest.strip()
    ip = host2ip(query)
    if not ip: event.reply("Couldn't look up the hostname") ; return
    res = querygeoipserver(ip)
    if res: event.reply("geo of %s is: " % ip, res)
    else: event.reply("no result")

cmnds.add("geo", handle_geo, ["OPER", "GEO"])
examples.add("geo", "do a geo lookup on ip nr", "geo 127.0.0.1")

## callbacks

def handle_geoPRE(bot, event):
    if "." in event.hostname and event.chan and event.chan.data.dogeo: return True 

def handle_geoJOIN(bot, event):
    event.reply("geo - doing query on %s" % event.hostname)
    try:
        result = querygeoipserver(host2ip(event.hostname))
        if result: event.reply("%s lives in %s, %s (%s)" % (event.nick, result['city'], result['country_name'], result['country_code']))
        else: event.reply("no result")
    except: handle_exception()

callbacks.add("JOIN", handle_geoJOIN, handle_geoPRE)
Exemple #8
0
    txt = re.sub('\s+', ' ', txt)
    txt = txt.replace('|', ' - ')
    return txt

## wikipedia command

resultre1 = re.compile("(<li>.*?</li>)")
resultre2 = re.compile("(<h2>.*?</h2>)")

def handle_wikipedia(bot, ievent):
    """ arguments: <searchtxt> ["-"<countrycode>] -  search wikipedia, you can provide an optional country code.  """
    if not ievent.rest: ievent.missing('<searchtxt>') ; return
    showall = False
    res = searchwiki(ievent.rest)
    if not res[0]: ievent.reply('no result found') ; return
    prefix = '%s ===> ' % res[1]
    result = resultre1.findall(res[0])
    if result:
        if bot.type == "sxmpp" and not ievent.groupchat: showall = True
        ievent.reply(prefix, result, dot="<br>", showall=showall)
        return
    result2 = resultre2.findall(res[0])
    if result2:
        if bot.type == "sxmpp" and not ievent.groupchat: showall = True
        ievent.reply(prefix, result2, dot="<br>", showall=showall)
        return
    else: ievent.reply("no data found on %s" % event.rest)

cmnds.add('wikipedia', handle_wikipedia, ['USER', 'GUEST'])
examples.add('wikipedia', 'search wikipedia for <what>','1) wikipedia bot 2) wikipedia -nl bot')
Exemple #9
0
#

""" gatekeeper commands. """

## tl imports

from tl.lib.commands import cmnds
from tl.lib.examples import examples

## gatekeeper-allow command

def handle_gatekeeperallow(bot, event):
    """ arguments: <userhost> - allow user on bot. """
    if not event.rest: event.missing("<userhost>") ; return
    bot.gatekeeper.allow(event.rest)
    event.done()

cmnds.add('gatekeeper-allow', handle_gatekeeperallow, 'OPER')
examples.add('gatekeeper-allow', 'add JID of remote bot that we allow to receice events from', 'gatekeeper-allow [email protected]')

## gatekeeper-deny command

def handle_gatekeeperdeny(bot, event):
    """ arguments: userhost - deny user on bot. """
    if not event.rest: event.missing("<userhost>") ; return
    bot.gatekeeper.deny(event.rest)
    event.done()

cmnds.add('gatekeeper-deny', handle_gatekeeperdeny, 'OPER')
examples.add('gatekeeper-deny', 'remove JID of remote bot', 'gatekeeper-deny [email protected]')
Exemple #10
0
# tl/plugs/core/uniq.py
#
#

""" used in a pipeline .. unique elements. """

__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
__license__ = 'BSD'

## tl imports

from tl.lib.examples import examples
from tl.lib.commands import cmnds
from tl.utils.generic import waitforqueue

## basic imports

import time

## uniq command

def handle_uniq(bot, ievent):
    """ no arguments - uniq the result list, use this command in a pipeline. """
    if not ievent.inqueue: time.sleep(0.5)
    result = list(ievent.inqueue)
    if not result: ievent.reply('no result')
    else: ievent.reply("result: ", result)

cmnds.add('uniq', handle_uniq, ['OPER', 'USER', 'GUEST'])
examples.add('uniq', 'sort out multiple elements', 'list ! uniq')
Exemple #11
0
            ievent.reply("only one character is allowed")
            return
        try: ievent.chan.data.cc = what
        except (KeyError, TypeError):
            ievent.reply("no channel %s in database" % chan)
            return
        ievent.chan.save()
        ievent.reply('control char set to %s' % what)
    except IndexError:
        try:
            cchar = ievent.getcc()
            ievent.reply('controlchar are/is %s' % cchar)
        except (KeyError, TypeError): ievent.reply("default cc is %s" % bot.cfg['defaultcc'])

cmnds.add('cc', handle_cc, 'USER')
examples.add('cc', 'set control char of channel or show control char of channel','1) cc ! 2) cc')

## cc-add command

def handle_ccadd(bot, ievent):
    """ arguments: <character> - add a control char to the channels cc list. """
    try:
        what = ievent.args[0]
        if not bot.users.allowed(ievent.userhost, 'OPER'): return
        if len(what) > 1:
            ievent.reply("only one character is allowed")
            return
        try: ievent.chan.data.cc += what
        except (KeyError, TypeError):
            ievent.reply("no channel %s in database" % ievent.channel)
            return
Exemple #12
0
def handle_forwardadd(bot, event):
    """ arguments: <bot JID> - add a new forward (xmpp account). """
    if not event.rest:
        event.missing('<bot JID>')
        return
    if "@" in event.rest:
        forward.data.outs[event.rest] = event.user.data.name
        forward.save()
        if not event.rest in event.chan.data.forwards: event.chan.data.forwards.append(event.rest)
    else: event.reply("arguments must be a JID (Jabber ID).") ; return
    if event.rest:
        event.chan.save()
        event.done()

cmnds.add("forward-add", handle_forwardadd, 'OPER')
examples.add("forward-add" , "add a bot JID to forward to", "forward-add tl@")

## forward-del command

def handle_forwarddel(bot, event):
    """ arguments: <bot JID> - delete a forward. """
    if not event.rest:
        event.missing('<bot JID>')
        return
    try: del forward.data.outs[event.rest]
    except KeyError: event.reply("no forward out called %s" % event.rest) ; return
    forward.save()
    if event.rest in event.chan.data.forwards: event.chan.data.forwards.remove(event.rest) ; event.chan.save()
    event.done()

cmnds.add("forward-del", handle_forwarddel, ['OPER', 'FORWARD'])
Exemple #13
0
        return
    except urllib.error.HTTPError as e: ievent.reply('unable to snarf: %s' % str(e)) ; return 
    except urllib.error.URLError as ex: ievent.reply('unable to snarf: %s' % str(ex)) ; return 
    if not url: ievent.reply('invalid url') ; return
    try: title = geturl_title(url)
    except socket.timeout: ievent.reply('%s socket timeout' % url) ; return
    except urllib.error.HTTPError as e: ievent.reply('error: %s' % e) ; return
    if title:
        host = urllib.parse.urlparse(url)[1]
        if len(host) > 20: host = host[0:20] + '...'
        ievent.reply('%s: %s' % (host, title))
    else: ievent.reply('no title found at %s' % urllib.parse.urlparse(url)[1])

cmnds.add('snarf', handle_snarf, 'USER', threaded=True)
cmnds.add('@', handle_snarf, 'USER', threaded=True)
examples.add('snarf', 'fetch the title from an URL', 'snarf http://ggzpreventie.nl')

## snarf-enable command

def handle_snarf_enable(bot, ievent):
    """ enable snarfing in channel """
    if bot.name not in cfg.data: cfg.data[bot.name] = {}
    cfg.data[bot.name][ievent.printto] = True
    cfg.save()
    ievent.reply('ok')

cmnds.add('snarf-enable', handle_snarf_enable, 'OPER')
examples.add('snarf-enable', 'enable snarfing in the channel', 'snarf-enable')

## snarf-disable command
Exemple #14
0
    else: bot.say(ievent.channel, txt, event=ievent)

## koffie command

def handle_koffie(bot, ievent):
    """ arguments: [<nick>] - get/give a coffee """
    rand = random.randint(0,len(koffie)-1)
    try:
        input = ievent.args[0]
        nick = '%s' % input
    except:
        if len('%s') >= 0: nick = ievent.nick
    do(bot, ievent, koffie[rand] + " " + nick)

cmnds.add('koffie', handle_koffie, 'USER')
examples.add('koffie', 'get a koffie quote', 'koffie')

## thee command

def handle_thee(bot, ievent):
    """ arguments: [<nick>] - get/give a thee """
    rand = random.randint(0,len(thee)-1)
    try:
        input = ievent.args[0]
        nick = '%s' % input
    except:
        if len('%s') >= 0: nick = ievent.nick
    do(bot, ievent, thee[rand] + " " + nick)

cmnds.add('thee', handle_thee, 'USER')
examples.add('thee', 'get an thee', 'thee')
Exemple #15
0
ignorenicks = []

## broadcast command

def handle_broadcast(bot, ievent):
    """ arguments: <txt> - broadcast txt to all joined channels. """
    if not ievent.rest:
         ievent.missing('<txt>')
         return
    ievent.reply('broadcasting')
    getfleet().broadcast(ievent.rest)
    partyline.say_broadcast(ievent.rest)
    ievent.reply('done')

cmnds.add('broadcast', handle_broadcast, 'OPER', threaded=True)
examples.add('broadcast', 'send a message to all channels and dcc users', 'broadcast good morning')

## jump command

def handle_jump(bot, ievent):
    """ arguments: <server> <port> - change server. """
    if bot.jabber:
        ievent.reply('jump only works on irc bots')
        return
    if len(ievent.args) != 2:
        ievent.missing('<server> <port>')
        return
    (server, port) = ievent.args
    ievent.reply('changing to server %s' % server)
    bot.shutdown()
    bot.cfg.server = server
Exemple #16
0
def handle_urban(bot, ievent):
    """ urban <what> .. search urban for <what> """
    if len(ievent.args) > 0:
        what = " ".join(ievent.args)
    else:
        ievent.missing("<search query>")
        return
    try:
        data = geturl2(url + urllib.parse.quote_plus(what))
        if not data:
            ievent.reply("word not found: %s" % what)
            return
        data = json.loads(data)
        if data["result_type"] == "no_result":
            ievent.reply("word not found: %s" % what)
            return
        res = []
        for r in data["list"]:
            res.append(r["definition"])
        ievent.reply("result: ", res)
    except Exception as ex:
        ievent.reply(str(ex))


cmnds.add("urban", handle_urban, ["OPER", "USER", "GUEST"])
examples.add("urban", "urban <what> .. search urbandictionary for <what>", "1) urban bot 2) urban shizzle")

#### BHJTW 23-01-2012
#### BHJTW 10-03-2012
Exemple #17
0
""" send output to another user .. used in a pipeline. """

## tl imports

from tl.lib.commands import cmnds
from tl.utils.generic import getwho, waitforqueue
from tl.lib.examples import examples

## basic imports

import time

## to command

def handle_to(bot, ievent):
    """ arguments: <nick> - direct output to <nick>, use this command in a pipeline. """
    try: nick = ievent.args[0]
    except IndexError: ievent.reply('to <nick>') ; return
    if nick == 'me': nick = ievent.nick
    if not getwho(bot, nick): ievent.reply("don't know %s" % nick) ; return
    if not ievent.inqueue: time.sleep(1)
    if ievent.inqueue:
        bot.say(nick, "%s sends you this:" % ievent.nick)
        bot.say(nick, " ".join(ievent.inqueue))
        if len(ievent.inqueue) == 1: ievent.reply('1 element sent')
        else: ievent.reply('%s elements sent' % len(ievent.inqueue))
    else: ievent.reply('nothing to send')

cmnds.add('to', handle_to, ['OPER', 'USER', 'TO'])
examples.add('to', 'send pipeline output to another user', 'list ! to dunker')
Exemple #18
0
def handle_op1(bot, ievent):
    """ op [<nick>] .. op an user """
    chan = ievent.channel.lower()
    #if bot.state.has_key('no-op') and chan in bot.state['no-op']:
    #    ievent.reply('opping is disabled in %s' % ievent.channel)
    #    return
    try: nick = ievent.args[0]
    except IndexError: nick = ievent.nick
    userhost = getwho(bot, nick)
    if not userhost: userhost = ievent.userhost
    if (ievent.user and 'OPER' in ievent.user.data.perms) or (ievent.chan and userhost in ievent.chan.data.ops): bot.doop(chan, nick)
    ievent.done()

cmnds.add('op', handle_op1, 'USER', threaded=True, speed=9)
examples.add('op', 'op [<nick>] .. give ops to <nick> or op the person giving the command', '1) op 2) op dunker')

## ops-permadd command

def handle_permadd(bot, ievent):
    if not ievent.chan: ievent.reply("channel is not set in event") ; return
    try: nick = ievent.args[0]
    except IndexError: nick = ievent.nick
    userhost = getwho(bot, nick)
    if not userhost: userhost = ievent.userhost
    if not userhost in ievent.chan.data.ops:
        ievent.chan.data.ops.append(userhost)
        ievent.chan.save()
        ievent.reply("added %s to the permenent ops list" % userhost)
    else: ievent.reply("%s is already in permops list" % userhost)
Exemple #19
0
    chandata = 0
    if not ievent.chan: ievent.bind(bot, force=True)
    try: chandata = ievent.chan.data.autovoice
    except KeyError: return
    if chandata: bot.voice(ievent.channel, ievent.nick)

callbacks.add('JOIN', cbautovoice, preautovoice)

## autovoice-on command

def handle_autovoiceon(bot, ievent):
    """ autovoice-on .. enable autovoice for channel the command was given in """
    try: ievent.chan.data.autovoice  = 1
    except TypeError: ievent.reply('no %s in channel database' % ievent.channel) ; return
    ievent.reply('autovoice enabled on %s' % ievent.channel)

cmnds.add('autovoice-on', handle_autovoiceon, 'OPER')
examples.add('autovoice-on', 'enable autovoice on channel in which the command is given', 'autovoice-on')

## autovoice-off command

def handle_autovoiceoff(bot, ievent):
    """ autovoice-off .. disable autovoice for the channel the command was given in """
    try:
        ievent.chan.data.autovoice = 0
        ievent.reply('autovoice disabled on %s' % ievent.channel)
    except TypeError: ievent.reply('no %s channel in database' % ievent.channel)

cmnds.add('autovoice-off', handle_autovoiceoff, 'OPER')
examples.add('autovoice-off', 'disable autovoice on channel in which the command is given', 'autovoice-off')
Exemple #20
0
# tl/plugs/core/count.py
#
#

""" count number of items in result queue. """

## tl imports

from tl.lib.commands import cmnds
from tl.utils.generic import waitforqueue
from tl.lib.examples import examples

## basic imports

import time

## count command

def handle_count(bot, ievent):
    """ no arguments - show nr of elements in result list .. use this command in a pipeline. """
    #if ievent.prev: ievent.prev.wait()
    a = ievent.inqueue
    size = len(a)
    ievent.reply(str(size))

cmnds.add('count', handle_count, ['OPER', 'USER', 'GUEST'])
examples.add('count', 'count nr of items', 'list ! count')
Exemple #21
0
        try: botname = bot.cfg.name ; (type, target) = event.args
        except ValueError:
            try: botname = bot.cfg.name ; type = bot.cfg.bottype ; target = event.args[0]
            except IndexError: event.missing('[<botname>] [<bottype>] <target>') ; return 
    origin = str((bot.cfg.name, event.channel))
    if not getfleet().byname(botname): event.reply("no %s bot in fleet." % botname) ; return
    if origin not in relay.data: relay.data[origin] = []
    try:
        if not [type, target] in relay.data[origin]:
            relay.data[origin].append([botname, type, target])
            relay.save()
    except KeyError: relay.data[origin] = [[botname, type, target], ] ; relay.save()
    event.done()

cmnds.add('relay', handle_relay, ['OPER',])
examples.add('relay', 'open a relay to another user/channel', '1) relay default-sxmpp sxmpp [email protected]')

## relay-stop command

def handle_relaystop(bot, event):
    """ arguments: [<botname>] [<bottype>] [<channel>] - stop a relay to a user. all relaying from the target will be ignored. """
    try: (botname, type, target) = event.args
    except ValueError:
        try: botname = bot.cfg.name ; (type, target) = event.args
        except (IndexError, ValueError): botname = bot.cfg.name ; type = bot.type ; target = event.channel 
    origin = str((bot.cfg.name, event.origin or event.channel))
    try:
        logging.debug('trying to remove relay (%s,%s)' % (type, target))
        relay.data[origin].remove([botname, type, target])
        relay.save()
    except (KeyError, ValueError):
Exemple #22
0
# tl/plugs/core/tail.py
#
#

""" tail bot results. """

## tl imports

from tl.utils.generic import waitforqueue
from tl.lib.commands import cmnds
from tl.lib.examples import examples

## basic imports

import time

## tail command

def handle_tail(bot, ievent):
    """ no arguments - show last <nr> elements, use this command in a pipeline. """
    try: nr = int(ievent.args[0])
    except (ValueError, IndexError): nr = 3
    if not ievent.inqueue: time.sleep(0.5)
    ievent.reply('results: ', list(ievent.inqueue)[-nr:])
    
cmnds.add('tail', handle_tail, ['OPER', 'USER', 'GUEST'])
examples.add('tail', 'show last <nr> lines of pipeline output', 'list ! tail 5')
Exemple #23
0
from tl.lib.examples import examples
from tl.lib.callbacks import callbacks, first_callbacks, last_callbacks

## basic imports

import logging

## echo-callback

def echopre(bot, event):
    """ test whether we should echo. """
    if event.how != "background" and bot.type in ["tornado", "web"] and not event.forwarded and not event.cbtype == "OUTPUT": return True
    return False

def echocb(bot, event):
    """ do the echo. """
    bot.outnocb(event.channel, event.txt, event=event)

#first_callbacks.add("TORNADO", echocb, echopre)
#first_callbacks.add("DISPATCH", echocb, echopre)

## echo command

def handle_echo(bot, event):
    """ argumetnts: <txt> - echo txt to channel. """
    if event.how != "background" and not event.isremote():
        if not event.isdcc: bot.saynocb(event.channel, "%s" % event.rest, event=event)
            
cmnds.add("echo", handle_echo, ['OPER', 'USER'])
examples.add("echo", "echo input", "echo yoooo dudes")
Exemple #24
0
    try:
        what = ievent.args[0]
        if not re.search('\d*\d-\d*\d-\d\d\d\d', what): ievent.reply('i need a date in the format day-month-year') ; return
    except IndexError: ievent.missing('<date>') ; return
    name = bot.users.getname(ievent.userhost)
    try: db.execute(""" INSERT INTO birthday (name, birthday) VALUES(%s, %s) """ , (name, what))
    except:
        try: db.execute(""" UPDATE birthday SET birthday = %s WHERE name = %s """,  (what, name))
        except Exception as ex:
            handle_exception()
            ievent.reply('ERROR: %s' % str(ex))
            return
    ievent.reply('birthday set')

cmnds.add('bd-set', handle_bdset, 'USER')
examples.add('bd-set', 'bd-set <date> .. set birthday', 'bd-set 3-11-1967')

## bd-del command

def handle_bddel(bot, ievent):
    """ bd-del .. delete birthday """
    global db
    if not db: ievent.reply("plugin isnt initialised yet") ; return
    name = bot.users.getname(ievent.userhost)
    result = 0
    try: result = db.execute(""" DELETE FROM birthday WHERE name = %s """, name)
    except Exception as ex: handle_exception() ; return
    if result: ievent.reply('birthday removed')
    else: ievent.reply('no birthday known for %s' % ievent.nick)

cmnds.add('bd-del', handle_bddel, 'USER')
Exemple #25
0
    except IndexError:
        ievent.missing('<what>')
        return
    result = []
    res = []
    aliases = ievent.chan.data.aliases
    if aliases:
        for i, j in aliases.items():
            if what in i or what in j: result.append((i, j))
    if not result: ievent.reply('no %s found' % what)
    else:
        for i in result: res.append("%s => %s" % i)
        ievent.reply("aliases matching %s: " % what, res)

cmnds.add('alias-search', handle_aliassearch, 'USER')
examples.add('alias-search', 'search aliases',' alias-search web')

## alias command

def handle_aliasset(bot, ievent):
    """ arguments: <from> <to> - set alias. """
    try: (aliasfrom, aliasto) = (ievent.args[0], ' '.join(ievent.args[1:]))
    except IndexError:
        ievent.missing('<from> <to>')
        return
    if not aliasto:
        ievent.missing('<from> <to>')
        return
    if aliasfrom in cmnds:
        ievent.reply('command with same name already exists.')
        return
Exemple #26
0
        "name": ievent.args[0],
        "url": ievent.args[1].strip("/"),
        "username": ievent.args[2],
        "password": ievent.args[3],
        "channels": {},
        "serverInfo": {},
    }

    if "servers" not in cfg.data:
        cfg.data["servers"] = {}
    cfg.data["servers"][server["name"]] = server
    cfg.save()

    ievent.reply("Added confluence server %s" % server["name"])
cmnds.add("confluence-addserver", handle_add_confluence_server, ["OPER"])
examples.add("confluence-addserver", "add a confluence server", "confluence-addserver FireBreath http://confluence.firebreath.org myuser mypassword")

## confluence-delserver command

def handle_del_confluence_server(bot, ievent):
    """ remove a confluence server; syntax: del_confluence_server """
    if len(ievent.args) != 1:
        ievent.reply("syntax: del_confluence_server [server name]")
        return

    serverName = ievent.args[0]
    if "servers" not in cfg.data:
        cfg.data["servers"] = {}
    if serverName in cfg.data["servers"]:
        del cfg.data["servers"][serverName]
        cfg.save()
Exemple #27
0
def handle_shop2(bot, ievent):
    """ add items to shop list """
    if not ievent.rest:
        ievent.missing("<shopitem>")
        return
    else:
        what = ievent.rest
    if not ievent.user.state.data.shops:
        ievent.user.state.data.shops = []
    ievent.user.state.data.shops.append(what)
    ievent.user.state.save()
    ievent.reply("shop item added")


cmnds.add("shop", handle_shop, ["OPER", "USER", "GUEST"])
examples.add("shop", "show shop items or add a shop item", "1) shop 2) shop bread")

## got command


def handle_got(bot, ievent):
    """ arguments: <list of shop nrs> - remove items from shoplist """
    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)
Exemple #28
0
import os
import copy

## defines

cpy = copy.deepcopy

## fleet-avail command

def handle_fleetavail(bot, ievent):
    """ no arguments - show available fleet bots. """
    ievent.reply('available bots: ', getfleet().avail()) 

cmnds.add('fleet-avail', handle_fleetavail, 'OPER')
examples.add('fleet-avail', 'show available fleet bots', 'fleet-avail')

## fleet-connect command

def handle_fleetconnect(bot, ievent):
    """ arguments: <botname> - connect a fleet bot to it's server. """
    try: botname = ievent.args[0]
    except IndexError:
        ievent.missing('<botname>')
        return
    try:
        fleet = getfleet()
        fleetbot = fleet.byname(botname)
        if fleetbot:
            start_new_thread(fleetbot.connect, ())
            ievent.reply('%s connect thread started' % botname)
Exemple #29
0
def numeric_compare(x, y):
    try: a = int(x)
    except: return cmp(x, y)
    try: b = int(y)
    except: return cmp(x, y)
    return a - b

## sort command

def handle_sort(bot, ievent):
    """ no arguments - sort the result list, use this command in a pipeline.  """
    parser = SortOptionParser()
    args = []
    try: options, args = parser.parse_args(ievent.args)
    except SortError as e:
        ievent.reply(str(e))
        return
    if not ievent.inqueue: time.sleep(0.5)
    result = list(ievent.inqueue)
    if not result: result = args
    if options.unique: result = list(set(result))
    if options.numeric: result.sort(numeric_compare)
    else: result.sort()
    if options.ignorecase: sort(lambda a, b: cmp(a.upper(), b.upper()), result)
    if options.reverse: reverse(result)
    if result: ievent.reply("results: ", result)
    else: ievent.reply("no result")

cmnds.add('sort', handle_sort, ['OPER', 'USER', 'GUEST'])
examples.add('sort', 'sort the output of a command', 'list ! sort')
Exemple #30
0
            except: logging.warn("color - %s is not a digit" % color) ; continue
            if c < 0: d = "00"
            elif c < 9: d = "0%s" % c
            elif c > 15: d = "15"
            else: d = "%s" % c           
            if t in s: txt = txt.replace(s, "\003%s%s\003" % (d, s))
    return txt

## color-list command

def handle_colorlist(bot, event):
    """ no arguments - show list of color mappings. """
    event.reply("colors set: ", state.data.colormapping)

cmnds.add("color-list", handle_colorlist, ["OPER"])
examples.add("color-list", "show color mapping", "color-list")

## color-add command

def handle_coloradd(bot, event):
    """ arguments: <txt> <color> - add a txt/color mapping .. color must be a number between 0 and 9. """
    try: (txt, color) = event.rest.rsplit(" ", 1)
    except (TypeError, ValueError): event.missing("<txt> <color>") ; return
    try: c = int(color)
    except (ValueError, TypeError): event.reply("color must be between 0 and 9") ; return 
    if c < 0: c = 0
    if c > 15: c = 15
    state.data.colormapping[txt] = c
    state.save()
    event.reply("color of %s set to %s" % (txt, c))