Example #1
0
def init():
  """ Init """
  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")
Example #2
0
def init():
    """ Init """
    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")
Example #3
0
def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l,))
    return 1
Example #4
0
def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l, ))
    return 1
Example #5
0
def init():
    global lastline
    lastline = LastLine()
    callbacks.add('PRIVMSG', lastline.privmsgcb, lastline.precb)
    callbacks.add('CONSOLE', lastline.privmsgcb, lastline.precb)
    callbacks.add('Message', lastline.privmsgcb, lastline.precb)
    cmnds.add(sed_expression, handle_sed, 'USER', regex=True)
    examples.add('s', 'Perform substitution on last message spoken.', 's/foo/bar/')
    return 1
Example #6
0
def init():
    global lastline
    lastline = LastLine()
    callbacks.add('PRIVMSG', lastline.privmsgcb, lastline.precb)
    callbacks.add('CONSOLE', lastline.privmsgcb, lastline.precb)
    callbacks.add('Message', lastline.privmsgcb, lastline.precb)
    cmnds.add(sed_expression, handle_sed, 'USER', regex=True)
    examples.add('s', 'Perform substitution on last message spoken.',
                 's/foo/bar/')
    return 1
Example #7
0
    try:
        test_urls = re_url_match.findall(ievent.txt)
        for i in test_urls:
            if not state['urls'].has_key(bot.cfg.name):
                state['urls'][bot.cfg.name] = {}
            if not state['urls'][bot.cfg.name].has_key(ievent.channel):
                state['urls'][bot.cfg.name][ievent.channel] = []
            if not i in state['urls'][bot.cfg.name][ievent.channel]:
                state['urls'][bot.cfg.name][ievent.channel].append(i)
        state.save()
        logging.warn("added url from %s" % ievent.auth)
    except Exception, ex:
        handle_exception()


callbacks.add('CONSOLE', urlcb, urlpre, threaded=True)
callbacks.add('PRIVMSG', urlcb, urlpre, threaded=True)
callbacks.add('MESSAGE', urlcb, urlpre, threaded=True)
callbacks.add('TORNADO', urlcb, urlpre, threaded=True)

## url-search commands


def handle_urlsearch(bot, ievent):
    """ arguments: <searchtxt> - search the per channel url database for a search term. """
    if not state:
        ievent.reply('rss state not initialized')
        return
    if not ievent.rest:
        ievent.missing('<searchtxt>')
        return
Example #8
0
            for i in self.data[bot.name]['nickservtxt']:
                self.sendstring(bot, i)
                logging.warn('nickserv - sent %s' % i)
        except:
            pass


## basic init stuff

nsauth = NSAuth()
if not nsauth.data:
    nsauth = NSAuth()

## register clallback

callbacks.add('001', nsauth.handle_001, threaded=True)

## ns-add command


def handle_nsadd(bot, ievent):
    """ add a bot to the nickserv. """
    if bot.jabber: return
    if len(ievent.args) < 1:
        ievent.missing('<password> [<nickserv nick>] [<identify command>]')
        return
    if nsauth.has(bot): ievent.reply('replacing previous configuration')
    options = {}
    if len(ievent.args) >= 1: options.update({'password': ievent.args[0]})
    if len(ievent.args) >= 2: options.update({'nickserv': ievent.args[1]})
    if len(ievent.args) >= 3:
Example #9
0
    """ see if we should op a user on join """
    # don't try to op the bot
    if ievent.nick == bot.nick: return
    #if bot.state.has_key('no-op') and chan in bot.state['no-op']: return
    import time
    time.sleep(1)
    if (ievent.user and 'OPER' in ievent.user.data.perms) or (
            ievent.chan and ievent.userhost in ievent.chan.data.ops):
        bot.doop(ievent.channel.lower(), ievent.nick)
    try:
        bot.splitted.remove(ievent.nick.lower())
    except (ValueError, AttributeError):
        pass


callbacks.add('JOIN', opjoincb)

## op command


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)
Example #10
0
        chandata = ievent.chan.data.autovoice
    except KeyError:
        return
    try:
        for regex in ievent.chan.data.autovoiceblacklist:
            r = regex.replace("*", ".*?")
            if re.search(r, ievent.userhost):
                logging.warn("%s in autovoice blacklist .. not giving voice." %
                             ievent.userhost)
                return
    except:
        handle_exception()
    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')
Example #11
0
    """ catch channel chat for possible URLs. """
    if ievent.how == "background": return 0
    if cfg.data.has_key(ievent.channel) and cfg.data[ievent.channel]:
        if len(ievent.txt) >= 5:
            if (ievent.txt.find('www.') != -1) or (ievent.txt.find('http') !=
                                                   -1):
                return 1
    return 0


def catchUrls(bot, ievent):
    """ the urlinfo callback. """
    bot.saynocb(ievent.channel, getUrlInfo(ievent.txt))


callbacks.add('PRIVMSG', catchUrls, catchHasUrls, threaded=True)
callbacks.add('CONSOLE', catchUrls, catchHasUrls, threaded=True)
callbacks.add('MESSAGE', catchUrls, catchHasUrls, threaded=True)
callbacks.add('DISPATCH', catchUrls, catchHasUrls, threaded=True)
callbacks.add('TORNADO', catchUrls, catchHasUrls, threaded=True)

## urlinfo-enable command


def handle_urlinfo_enable(bot, ievent):
    """ no arguments - enable urlinfo in a channel. """
    cfg.data[ievent.channel] = True
    cfg.save()
    ievent.reply('urlinfo enabled')

Example #12
0
# jsb/plugs/core/nickcapture.py
#
#

""" nick recapture callback. """

## jsb imports

from jsb.lib.callbacks import callbacks

## callbacks

def ncaptest(bot, ievent):
    """ test if user is splitted. """
    if '*.' in ievent.txt or bot.cfg.server in ievent.txt: return 0
    ievent.bind()
    if bot.cfg.wantnick and bot.cfg.wantnick.lower() == ievent.nick.lower(): return 1
    if bot.cfg.nick.lower() == ievent.nick.lower(): return 1
    return 0

def ncap(bot, ievent):
    """ recapture the nick. """
    bot.donick(bot.cfg.wantnick or bot.cfg.nick)

callbacks.add('QUIT', ncap, ncaptest, threaded=True)
Example #13
0
# jsb/plugs/core/nickcapture.py
#
#
""" nick recapture callback. """

## jsb imports

from jsb.lib.callbacks import callbacks

## callbacks


def ncaptest(bot, ievent):
    """ test if user is splitted. """
    if '*.' in ievent.txt or bot.cfg.server in ievent.txt: return 0
    ievent.bind()
    if bot.cfg.wantnick and bot.cfg.wantnick.lower() == ievent.nick.lower():
        return 1
    if bot.cfg.nick.lower() == ievent.nick.lower(): return 1
    return 0


def ncap(bot, ievent):
    """ recapture the nick. """
    bot.donick(bot.cfg.wantnick or bot.cfg.nick)


callbacks.add('QUIT', ncap, ncaptest, threaded=True)
Example #14
0
        logging.info("%s - cleaned %s" %  (self.name, [item.nowrunning for item in r]))
        logging.debug("%s - now running: %s" % (self.name, self.size()))
        
## show runner status

def runner_status():
    print cmndrunner.runnersizes()
    print callbackrunner.runnersizes()


## global runners

cmndrunner = defaultrunner = Runners("default", 50, BotEventRunner) 
longrunner = Runners("long", 80, LongRunner)
callbackrunner = Runners("callback", 70, BotEventRunner)
waitrunner = Runners("wait", 20, BotEventRunner)
apirunner = Runners("api", 20, BotEventRunner)
threadrunner = Runners("threads", 50, Runner)

allrunners = [cmndrunner, longrunner, callbackrunner, waitrunner, apirunner, threadrunner]

## cleanup 

def runnercleanup(bot, event):
    for runner in allrunners: runner.cleanup()

callbacks.add("TICK60", runnercleanup)

def size():
    return "cmnd: %s - callbacks: %s - wait: %s - long: %s - api: %s thread: %s" % (cmndrunner.size(), callbackrunner.size(), waitrunner.size(), longrunner.size(), apirunner.size(), threadrunner.size())
Example #15
0
        if not askbot: askbot = fleet.makebot('xmpp', 'askxmppbot')
        logging.debug("ask - %s %s %s %s" % (botname, type, userhost, channel))
        if askbot:
            for jid in channel: askbot.say(channel, "%s says: %s" % (event.userhost, txt))
        else:
            logging.warn("ask - can't find %s bot in fleet" % type)
            continue
        try:
            questions.data[event.userhost].remove([botname, type, userhost, channel])
            questions.save()
        except ValueError: pass
        done.append(channel)
        break
    if done: event.reply('answer sent to ', done)

callbacks.add('MESSAGE', askcallback, askprecondition)
callbacks.add('EXEC', askcallback, askprecondition)
callbacks.add('WEB', askcallback, askprecondition)

## ask command

def handle_ask(bot, event):
    """ 
        this command lets you ask a question that gets dispatched to jabber 
        users that have registered themselves for that particular subject. 

    """
    try: subject, question = event.rest.split(' ', 1)
    except ValueError:
        event.missing('<subject> <question>')
        return
Example #16
0
def predefine(bot, event):
    """ define precondition. """
    if event.iscommand: return False
    if len(event.txt) < 2: return False
    #if event.txt and (event.txt[0] == "?" or event.txt[-1] == "?") and not event.forwarded: return True
    if event.txt and (event.txt[0] == "?") and not event.forwarded: return True
    return False

def definecb(bot, event):
    """ define callback, is for catching ? queries. """
    event.bind(bot)
    result = []
    items = PlugPersist(event.channel)
    target = event.txt.lower()
    if target[0] == "?": target = target[1:]
    if target[-1] == "?": target = target[:-1]
    if target in items.data: result = items.data[target]
    globalitems = GlobalPersist("definedb")
    if target in globalitems.data:
        if not target in result: result.extend(globalitems.data[target])    
    if result: event.reply("%s is " % target, result, dot=", ")
    event.ready()

callbacks.add("PRIVMSG", definecb, predefine)
callbacks.add("MESSAGE", definecb, predefine)
callbacks.add("DISPATCH", definecb, predefine)
callbacks.add("CONSOLE", definecb, predefine)
callbacks.add("CMND", definecb, predefine)
callbacks.add("TORNADO", definecb, predefine)
Example #17
0
                askbot.say(channel, "%s says: %s" % (event.userhost, txt))
        else:
            logging.warn("ask - can't find %s bot in fleet" % type)
            continue
        try:
            questions.data[event.userhost].remove(
                [botname, type, userhost, channel])
            questions.save()
        except ValueError:
            pass
        done.append(channel)
        break
    if done: event.reply('answer sent to ', done)


callbacks.add('MESSAGE', askcallback, askprecondition)
callbacks.add('EXEC', askcallback, askprecondition)
callbacks.add('WEB', askcallback, askprecondition)

## ask command


def handle_ask(bot, event):
    """ 
        this command lets you ask a question that gets dispatched to jabber 
        users that have registered themselves for that particular subject. 

    """
    try:
        subject, question = event.rest.split(' ', 1)
    except ValueError:
Example #18
0
ORDER_K = 2

# Maximum generation cycles
MAXGEN = 500

markovlearn = PlugPersist('markovlearn')
markovlearn.data.l = markovlearn.data.l or []
markovwords = {}
markovwordi = []
markovchains = {}

cfg.define('loud', 0)

def dummycb(bot, event): pass

callbacks.add('START', dummycb)

def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l,))
    return 1

def size():
    """ return size of markov chains """
    return len(markovchains)
Example #19
0
import jsb.utils.name

jsb.utils.name.allowednamechars += string.printable

class InputData(PlugPersist): pass

## input callback

def input(bot, event):
    inp = event.txt
    if inp.startswith(";in "): inp = inp[4:]
    timed = strtotime(inp)
    fn = "%s,%s,%s,%s,%s" % (event.channel, timed or "", event.cbtype, event.ctime, inp[:200])
    input = InputData(fn)
    input.data = event.tojson()
    if ";in" in event.txt or not ";" in event.txt: input.save() ; event.reply("ok")

callbacks.add("CONSOLE", input)
cmnds.add("in", input, ["OPER", "USER"])

def look(bot, event):
    coll = PlugPersistCollection()
    fns = coll.filenames(event.rest)
    for fn in fns:
        try: cbtype, todotime, channel, ctime, txt = fn.split(",", 4)
        except ValueError as ex: print ex
        bot._raw("%s - %s" % (time.ctime(float(ctime)), txt))

cmnds.add("look", look, ["OPER", "USER"])
Example #20
0
    return False

def insult():
    s1 = ['dribbling ', 'snivelling ', 'braindead ', 'tentacled ', 'three eyed ', 'one dimensional ', 'borg loving ', 'slime sucking ', 'borg sniffing ', 'bug eyed ', 'single celled ', 'gargleblasting ', 'hallucinating ', '']
    s2 = ['', '', 'son of a ', 'clone of a ', 'excuse for a ', 'hologram of a ', 'apology for a ']
    s3 = ['', 'mutant ', 'parasitic ', 'vat-grown ', 'ferengi ', 'radiation damaged ', 'deranged ', 'space sick ', 'warp sick ', 'deviant ', 'clockwork ', 'useless ', 'superfluous ', 'stinking ' ]
    s4 = ['star goat', 'space weevil', 'toilet cleaning droid', 'bilge spore', 'nose worm', 'hyper slug', 'replicant', 'android', 'garbage droid', 'cyborg', 'pleasure droid', 'person', 'humanoid', 'bag of water', 'scumbag', 'idiot', 'douchebag', 'dumbass', 'collection of atoms']
    return random.choice(s1)+random.choice(s2)+random.choice(s3)+random.choice(s4)+"!"


## corrector-callbacks

def correctorcb(bot, event):
    event.bind(bot)

callbacks.add('PRIVMSG', correctorcb, precorrector)
callbacks.add('MESSAGE', correctorcb, precorrector)
callbacks.add('CONSOLE', correctorcb, precorrector)
callbacks.add('CONVORE', correctorcb, precorrector)

## corrector command

def handle_corrector(bot, ievent):
    insult_text = ievent.nick + ": you are are " + insult()
    if len(ievent.rest) > 0 and re.search("c-beam", ievent.rest, re.IGNORECASE) == None:
        insult_text = ievent.rest + " is a " + insult()

    if ievent.channel == "#c-base":
        bot.say(ievent.channel, insult_text)
        pass
    else:
Example #21
0
def init():
    global stopped
    stopped = False
    global loggers
    for (botname, channel) in cfg.get("channels"):
        enablelogging(botname, channel)
    callbacks.add("PRIVMSG", chatlogcb, prechatlogcb)
    callbacks.add("JOIN", chatlogcb, prechatlogcb)
    callbacks.add("PART", chatlogcb, prechatlogcb)
    callbacks.add("NOTICE", chatlogcb, prechatlogcb)
    callbacks.add("QUIT", chatlogcb, prechatlogcb)
    callbacks.add("NICK", chatlogcb, prechatlogcb)
    callbacks.add("PRESENCE", chatlogcb, prechatlogcb)
    callbacks.add("MESSAGE", chatlogcb, prechatlogcb)
    callbacks.add("CONSOLE", chatlogcb, prechatlogcb)
    first_callbacks.add("OUTPUT", chatlogcb, prechatlogcb)
    return 1
Example #22
0
def infopre(bot, ievent):
    """ see if info callback needs to be called """
    if ievent.iscmnd() and (ievent.txt and ievent.txt[-1]
                            == "?") and not ievent.woulddispatch():
        return True


def infocb(bot, ievent):
    """ implement a !infoitem callback """
    if getusers().allowed(ievent.userhost, 'USER'):
        data = info.get(ievent.execstr)
        if data: ievent.reply('%s is: ' % ievent.execstr, data)


callbacks.add('PRIVMSG', infocb, infopre)

## info-size command


def handle_infosize(bot, ievent):
    """ info-size .. show number of information items """
    ievent.reply("we have %s infoitems" % info.size())


cmnds.add('info-size', handle_infosize, ['USER', 'WEB', 'ANON'])
examples.add('info-size', 'show number of infoitems', 'info-size')

## addinfoitem RE

Example #23
0
## plugin shutdown


def shutdown():
    periodical.kill()


## make sure plugin gets autoloaded on start


def dummycb(bot, event):
    pass


callbacks.add("START", dummycb)

## geturls function


def geturls(txt):
    result = []
    if "http://" in txt or "https://" in txt:
        for item in re_url_match.findall(txt):
            logging.debug("web - raw - found url - %s" % item)
            try:
                txt = txt.replace(item, '')
            except ValueError:
                logging.error("web - invalid url - %s" % url)
            i = item
            if i.endswith('"'): i = i[:-1]
Example #24
0
    if event.iscmnd() or (bot.isgae
                          and event.userhost not in bot.cfg.followlist):
        return False
    else:
        return True


def idlecb(bot, event):
    """ idle PRIVMSG callback .. set time for channel and nick """
    ttime = time.time()
    idle.data[event.userhost] = ttime
    idle.data[event.channel] = ttime
    idle.save()


callbacks.add('PRIVMSG', idlecb, preidle)
callbacks.add('MESSAGE', idlecb, preidle)
callbacks.add('WEB', idlecb, preidle)
callbacks.add('CONSOLE', idlecb, preidle)
callbacks.add('DISPATCH', idlecb, preidle)

## commands


def handle_idle(bot, ievent):
    """ idle [<nick>] .. show how idle an channel/user has been """
    try:
        who = ievent.args[0]
    except IndexError:
        handle_idle2(bot, ievent)
        return
Example #25
0
        self.identify(bot)
        try:
            for i in self.data[bot.cfg.name]['nickservtxt']:
                self.sendstring(bot, i)
                logging.warn('nickserv - sent %s' % i)
        except: pass

## init stuff

nsauth = NSAuth()
if not nsauth.data:
    nsauth = NSAuth()

## register callback

callbacks.add('001', nsauth.handle_001, threaded=True)

## ns-add command

def handle_nsadd(bot, ievent):
    """ arguments: <password> [<nickserv nick>] [<identify command>] - add a bot to the nickserv. """
    if bot.jabber: return
    if len(ievent.args) < 1:
        ievent.missing('<password> [<nickserv nick>] [<identify command>]')
        return
    if nsauth.has(bot): ievent.reply('replacing previous configuration')
    options = {}
    if len(ievent.args) >= 1: options.update({'password': ievent.args[0]})
    if len(ievent.args) >= 2: options.update({'nickserv': ievent.args[1]})
    if len(ievent.args) >= 3: options.update({'identify': ' '.join(ievent.args[2:])})
    nsauth.add(bot, **options)
Example #26
0
def handle_367(bot, ievent):
    logging.warn('kickban - 367 - %s' % str(ievent))
    channel = ievent.arguments[1].lower()
    if not bot.cfg.name in bans or not channel in bans[bot.cfg.name]:
        return  # not requested by this plugin
    b = ievent.txt.split()[0]
    target = bans[bot.cfg.name][channel]
    if b not in target: target.append(b)


def handle_mode(bot, ievent):
    logging.debug('kick-ban - mode - %s' % ievent.tojson())
    # [18 Jan 2008 13:41:29] (mode) cmnd=MODE [email protected] postfix=#eth0-test +b *!*@je.moeder.ook arguments=[u'#eth0-test', u'+b', u'*!*@je.moeder.ook'] nick=maze user=wijnand [email protected] channel=#eth0-test txt= command= args=[] rest= speed=5 options={}


callbacks.add('367', handle_367)
callbacks.add('MODE', handle_mode)

## functions


def get_bans(bot, channel):
    # :ironforge.sorcery.net 367 basla #eth0 *!*@71174af5.e1d1a3cf.net.hmsk [email protected] 1200657224
    # :ironforge.sorcery.net 367 basla #eth0 *!*@6ca5f0a3.14055a38.89.123.imsk [email protected] 1200238584
    # :ironforge.sorcery.net 368 basla #eth0 :End of Channel Ban List
    if bot.type != "irc": return []
    global bans
    channel = channel.lower()
    if not bot.cfg.name in bans:
        bans[bot.cfg.name] = {}
    bans[bot.cfg.name][channel] = []
Example #27
0
        bot.putevent(event.userhost, event.channel, event.txt, event)
        #if event.txt == 'wer ist da?':
        #    event.txt = '!ul'
        #    bot.putevent(event)
        print 'DONE'
        return True
    return False

## pr callbacks

def prcb(bot, event):
    event.bind(bot)

    return 0

callbacks.add('PRIVMSG', prcb, prepr)
callbacks.add('MESSAGE', prcb, prepr)
callbacks.add('CONSOLE', prcb, prepr)

## pr command

def handle_pr(bot, event):
    if not event.rest: event.missing("<what>") ; return
    k = event.rest.lower()
    item = PRItem(event.channel.lower() + "-" + k)
    if item.data.count: event.reply("pr of %s is %s" % (k, item.data.count))
    else: event.reply("%s doesn't have pr yet." % k)

cmnds.add('pr', handle_pr, ['USER', ])
examples.add('pr', 'show pr', 'pr jsb')
Example #28
0
        return
    ievent.reply('channel mode of %s is %s' % (chan, ievent.chan.data.mode))

cmnds.add('chan-mode', handle_channelmode, 'OPER')
examples.add('chan-mode', 'show mode of channel', '1) chan-mode 2) chan-mode #test')

## mode callback

def modecb(bot, ievent):
    """ callback to detect change of channel key. """
    if ievent.postfix.find('+k') != -1:
        key = ievent.postfix.split('+k')[1]
        ievent.chan.data.key = key
        ievent.chan.save()

callbacks.add('MODE', modecb)

## chan-addtag command

def handle_chanaddtag(bot, event):
    """ arguments: <tag> - add a tag to the channel taglist. """
    if not event.rest: event.missing("<tag>") ; return
    if not event.rest in event.chan.data.taglist:
        event.chan.data.taglist.append(event.rest)
        event.chan.save()
        event.done()
    else: event.reply("%s is already in taglist of channel %s" % (event.rest, event.channel))

cmnds.add("chan-addtag", handle_chanaddtag, 'OPER')
examples.add("chan-addtag", "add a tag to the channels taglist", "chan-addtag #jsonbot")
Example #29
0
remind = Remind('remind.data')
assert remind

## callbacks

def preremind(bot, ievent):
    """ remind precondition """
    return remind.wouldremind(ievent.userhost)

def remindcb(bot, ievent):
    """ remind callbacks """
    remind.remind(bot, ievent.userhost)

# monitor privmsg and joins
callbacks.add('PRIVMSG', remindcb, preremind, threaded=True)
callbacks.add('JOIN', remindcb, preremind, threaded=True)
callbacks.add('MESSAGE', remindcb, preremind, threaded=True)
callbacks.add('WEB', remindcb, preremind, threaded=True)

## commands

def handle_remind(bot, ievent):
    """ remind <nick> <txt> .. add a remind """
    try:
        who = ievent.args[0]
        txt = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <txt>')
        return
    if not txt:
Example #30
0
def init():
    """ called upon plugin registration. """
    global stopped
    stopped = False
    global loggers
    fleet = getfleet()
    got = False
    for (botname, channel) in cfg.get("channels"):
        if fleet.byname(botname): enablelogging(botname, channel) ; got = True 
    #if not got: return 
    callbacks.add("PRIVMSG", chatlogcb, prechatlogcb)
    callbacks.add("JOIN", chatlogcb, prechatlogcb)
    callbacks.add("PART", chatlogcb, prechatlogcb)
    callbacks.add("NOTICE", chatlogcb, prechatlogcb)
    callbacks.add("QUIT", chatlogcb, prechatlogcb)
    callbacks.add("NICK", chatlogcb, prechatlogcb)
    callbacks.add("PRESENCE", chatlogcb, prechatlogcb)
    callbacks.add("MESSAGE", chatlogcb, prechatlogcb)
    callbacks.add("CONSOLE", chatlogcb, prechatlogcb)
    first_callbacks.add("OUTPUT", chatlogcb, prechatlogcb)
    get_hooks.register("/api/log", api_log)
    return 1
Example #31
0
## copyright

__copyright__ = 'this file is in the public domain'
__author__ = '*****@*****.**'

## jsb imports

from jsb.lib.callbacks import callbacks

##  pre_underauth_cb precondition

def pre_underauth_cb(bot, ievent):
    """ 
        Only respond to the message like:
        NOTICE AUTH :*** Your ident is disabled or broken, to continue
        to connect you must type /QUOTE PASS 16188.

    """
    args = ievent.arguments
    try: return (args[0] == 'AUTH' and args[-3] == '/QUOTE' and args[-2] == 'PASS')
    except Exception, ex: return False

## underayth_cb callback

def underauth_cb(bot, ievent):
    """ Send the raw command to the server. """
    bot._raw(' '.join(ievent.arguments[-2:]))

callbacks.add('NOTICE', underauth_cb, pre_underauth_cb)
Example #32
0
            if event.nick not in i.data.whoup: i.data.whoup[event.nick] = 0
            i.data.whoup[event.nick] += 1
            if reason and reason not in i.data.whyup: i.data.whyup.append(reason)
            i.save()
        else:
            i = KarmaItem(event.channel.lower() + "-" + item)
            i.data.count -= 1
            if event.nick not in i.data.whodown: i.data.whodown[event.nick] = 0
            i.data.whodown[event.nick] -= 1
            if reason and reason not in i.data.whyup: i.data.whydown.append(reason)
            i.save()
        karma.append("%s: %s" % (item, i.data.count))
        got = item or item2
    if karma: event.reply("karma - ", karma) ; event.ready()

callbacks.add('PRIVMSG', karmacb, prekarma)
callbacks.add('MESSAGE', karmacb, prekarma)
callbacks.add('CONSOLE', karmacb, prekarma)

## karma command

def handle_karma(bot, event):
    if not event.rest: event.missing("<what>") ; return
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    if item.data.count: event.reply("karma of %s is %s" % (k, item.data.count))
    else: event.reply("%s doesn't have karma yet." % k)

cmnds.add('karma', handle_karma, ['USER', ])
examples.add('karma', 'show karma', 'karma jsb')
Example #33
0
from jsb.lib.callbacks import callbacks
from jsb.lib.examples import examples

def preautovoice(bot, ievent):
    if ievent.forwarded or ievent.relayed: return False
    return True

def cbautovoice(bot, ievent):
    """ autovoice callback """
    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)

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')

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)
Example #34
0
## callbacks


def preremind(bot, ievent):
    """ remind precondition """
    return remind.wouldremind(ievent.userhost)


def remindcb(bot, ievent):
    """ remind callbacks """
    remind.remind(bot, ievent.userhost)


# monitor privmsg and joins
callbacks.add('PRIVMSG', remindcb, preremind, threaded=True)
callbacks.add('JOIN', remindcb, preremind, threaded=True)
callbacks.add('MESSAGE', remindcb, preremind, threaded=True)
callbacks.add('WEB', remindcb, preremind, threaded=True)

## commands


def handle_remind(bot, ievent):
    """ remind <nick> <txt> .. add a remind """
    try:
        who = ievent.args[0]
        txt = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <txt>')
        return
Example #35
0
File: ask.py Project: code2u/jsb
        if not printto or userhost != printto: continue
        askbot = fleet.makebot(type)
        if not askbot: askbot = fleet.makebot('xmpp', 'askxmppbot')
        logging.debug("ask - %s %s %s %s" % (botname, type, userhost, channel))
        if askbot:
            for jid in channel: askbot.say(channel, "%s says: %s" % (event.userhost, txt))
        else: logging.warn("ask - can't find %s bot in fleet" % type) ; continue
        try:
            questions.data[event.userhost].remove([botname, type, userhost, channel])
            questions.save()
        except ValueError: pass
        done.append(channel)
        break
    if done: event.reply('answer sent to ', done)

callbacks.add('MESSAGE', askcallback, askprecondition)
callbacks.add('DISPATCH', askcallback, askprecondition)
callbacks.add('WEB', askcallback, askprecondition)
callbacks.add('CONVORE', askcallback, askprecondition)
callbacks.add('PRIVMSG', askcallback, askprecondition)

## ask command

def handle_ask(bot, event):
    """ 
        arguments: <subject> <question> - this command lets you ask a question that gets dispatched to jabber 
        users that have registered themselves for that particular subject. 

    """
    try: subject, question = event.rest.split(' ', 1)
    except ValueError:
Example #36
0
    def wrapper(*args, **kw):
        job = JobInterval(3600, 0, function, *args, **kw)
        job.group = group
        job.description = whichmodule()
        logging.warn('new interval job %d running hourly' % job.id())
        periodical.jobs.append(job)

    return wrapper

def daily(function):
    """ day decorator. """
    logging.warn('@daily(%s)' % str(function))
    daily.func_dict = function.func_dict
    group = calledfrom(sys._getframe())

    def wrapper(*args, **kw):
        job = JobInterval(86400, 0, function, *args, **kw)
        job.group =  group
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warb('new interval job %d running daily' % job.id())

    return wrapper

periodical = Periodical()

callbacks.add("TICK", periodical.looponce)

def size():
    return periodical.size()
Example #37
0
def doLookup(bot, ievent):
    logging.info("Doing lookup for fisheye changeset")
    fnd = gitHashRule.match(ievent.txt)
    for pname in cfg.data[ievent.channel]:
        project = cfg.data["projects"][pname]
        try:
            server, auth = getRpcClient(project)
            res = server.getChangeset(auth, pname, fnd.group(1))
            logging.info('response from fisheye: %s' % res)
            cs_url = "%s/changelog/%s?cs=%s" % (project["url"], pname, res["csid"])
            bot.say(ievent.channel, "%s- %s by %s: %s %s" % (pname, res["csid"][:7], res["author"], res["log"].strip()[:60], get_tinyurl(cs_url)[0]))
            return
        except:
            print "Couldn't find %s" % fnd.group(1)

callbacks.add('PRIVMSG', doLookup, containsHash, threaded=True)
callbacks.add('CONSOLE', doLookup, containsHash, threaded=True)
callbacks.add('MESSAGE', doLookup, containsHash, threaded=True)
callbacks.add('DISPATCH', doLookup, containsHash, threaded=True)
callbacks.add('TORNADO', doLookup, containsHash, threaded=True)

## add_fisheye_project command

def handle_add_fisheye_project(bot, ievent):
    """ configure a new fisheye project; syntax: add_fisheye_project [project name] [url] [username] [password] """
    if len(ievent.args) != 4:
        ievent.reply("syntax: add_fisheye_project [project name] [url] [username] [password]")
        return

    project = {
        "name": ievent.args[0],
Example #38
0
})
sensorlist.save()

statussensors = PlugPersist('statussensors')
statussensors.save()

currentstatus = PlugPersist('currentstatus', False)

shared_data = {}
server = None
graphite = None
outputthread = None

## dummy callbacks to make sure plugin gets loaded on startup
def dummycb(bot, event): pass
callbacks.add("START", dummycb)

#def apiEvents():
#    return []

def statusStr(openstatus):
    if openstatus: return 'Open' 
    else: return 'Closed'

def doorStr(status):
    if str(status).lower()=='true': return 'Locked'
    elif str(status).lower()=='false': return 'Unlocked'
    else: return 'Unknown'

def apiupdate(openStatus=None, who="unknown"):
    if openStatus is None:
Example #39
0
    event.reply("geo of %s is: " % ip, querygeoipserver(ip))

cmnds.add("geo", handle_geo, ["OPER", "GEO"])

def handle_geoPRE(bot, event):
    if "." in event.hostname 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)

def handle_geoon(bot, event):
    """ enable geo lookup on JOIN. """
    event.chan.data.dogeo = True
    event.chan.save()
    event.done()

cmnds.add("geo-on", handle_geoon, ["OPER"])

def handle_geooff(bot, event):
    """ disable geo lookup on JOIN. """
    event.chan.data.dogeo = False
    event.chan.save()
    event.done()
Example #40
0
    test = getMatchRegEx(prefixList)
    fnd = test.match(ievent.txt)
    if fnd:
        ticket = fnd.group(1)
        prefix = fnd.group(2)
        logging.info("Found: %s %s" % (ticket, prefix))
        logging.info("servers: %s" % cfg.data["servers"])
        server = serversForPrefix[prefix]

        msg = getJiraIssueMessage(cfg.data["servers"][server], ticket)
        for line in msg:
            bot.say(ievent.channel, line)


callbacks.add('PRIVMSG', doLookup, containsJiraTag, threaded=True)
callbacks.add('CONSOLE', doLookup, containsJiraTag, threaded=True)
callbacks.add('MESSAGE', doLookup, containsJiraTag, threaded=True)
callbacks.add('DISPATCH', doLookup, containsJiraTag, threaded=True)
callbacks.add('TORNADO', doLookup, containsJiraTag, threaded=True)

def handle_add_jira_server(bot, ievent):
    """ configure a new jira server; syntax: add_jira_server [server name] [url] [username] [password] """
    if len(ievent.args) != 4:
        ievent.reply("syntax: add_jira_server [server name] [url] [username] [password]")
        return

    server = {
        "name": ievent.args[0],
        "url": ievent.args[1].strip("/"),
        "username": ievent.args[2],
Example #41
0
               'server':  bot.server,
               'channel': ievent.channel,
               'what':    'entrando na sala %s' % ievent.channel,
               }

  
    def size(self):
        return len(self.data.keys())

## init

seen = Seen()

## callbacks and commands register

callbacks.add('PRIVMSG', seen.privmsgcb)
callbacks.add('JOIN', seen.joincb)
callbacks.add('PART', seen.partcb)
callbacks.add('QUIT', seen.quitcb)
#callbacks.add('Presence', seen.xmppcb)
cmnds.add('seen', seen.handle_seen, ['USER', 'GUEST'])
examples.add('seen', 'show last spoken txt of <nikc>', 'seen dunker')

## shutdown

def shutdown():
    seen.save()

## size

def size():
Example #42
0
                askbot.say(channel, "%s says: %s" % (event.userhost, txt))
        else:
            logging.warn("ask - can't find %s bot in fleet" % type)
            continue
        try:
            questions.data[event.userhost].remove(
                [botname, type, userhost, channel])
            questions.save()
        except ValueError:
            pass
        done.append(channel)
        break
    if done: event.reply('answer sent to ', done)


callbacks.add('MESSAGE', askcallback, askprecondition)
callbacks.add('DISPATCH', askcallback, askprecondition)
callbacks.add('WEB', askcallback, askprecondition)
callbacks.add('PRIVMSG', askcallback, askprecondition)

## ask command


def handle_ask(bot, event):
    """ 
        arguments: <subject> <question> - this command lets you ask a question that gets dispatched to jabber 
        users that have registered themselves for that particular subject. 

    """
    try:
        subject, question = event.rest.split(' ', 1)
Example #43
0
## callbacks

def handle_367(bot, ievent):
    logging.warn('kickban - 367 - %s' % str(ievent))
    channel = ievent.arguments[1].lower()
    if not bot.cfg.name in bans or not channel in bans[bot.cfg.name]:
        return # not requested by this plugin
    b = ievent.txt.split()[0]
    target = bans[bot.cfg.name][channel]
    if b not in target: target.append(b)

def handle_mode(bot, ievent):
    logging.debug('kick-ban - mode - %s' % ievent.tojson())
    # [18 Jan 2008 13:41:29] (mode) cmnd=MODE [email protected] postfix=#eth0-test +b *!*@je.moeder.ook arguments=[u'#eth0-test', u'+b', u'*!*@je.moeder.ook'] nick=maze user=wijnand [email protected] channel=#eth0-test txt= command= args=[] rest= speed=5 options={}

callbacks.add('367', handle_367)
callbacks.add('MODE', handle_mode)

## functions

def get_bans(bot, channel):
    # :ironforge.sorcery.net 367 basla #eth0 *!*@71174af5.e1d1a3cf.net.hmsk [email protected] 1200657224
    # :ironforge.sorcery.net 367 basla #eth0 *!*@6ca5f0a3.14055a38.89.123.imsk [email protected] 1200238584
    # :ironforge.sorcery.net 368 basla #eth0 :End of Channel Ban List
    if bot.type != "irc": return []
    global bans
    channel = channel.lower()
    if not bot.cfg.name in bans:
        bans[bot.cfg.name] = {}
    bans[bot.cfg.name][channel] = []
    queue368 = Queue.Queue()
Example #44
0
        return
    try:
        test_urls = re_url_match.findall(ievent.txt)
        for i in test_urls:
            if not state['urls'].has_key(bot.name):
                state['urls'][bot.name] = {}
            if not state['urls'][bot.name].has_key(ievent.channel):
                state['urls'][bot.name][ievent.channel] = []
            if not i in state['urls'][bot.name][ievent.channel]:
                state['urls'][bot.name][ievent.channel].append(i)
        state.save()
    except Exception, ex:
        handle_exception()


callbacks.add('PRIVMSG', urlcb, urlpre, threaded=True)

## url-search commands


def handle_urlsearch(bot, ievent):
    if not state:
        ievent.reply('rss state not initialized')
        return
    if not ievent.rest:
        ievent.missing('<what>')
        return
    result = []
    try:
        for i in state['urls'][bot.name][ievent.channel]:
            if ievent.rest in i:
Example #45
0
    if not state:
        return 
    try:
        test_urls = re_url_match.findall(ievent.txt)
        for i in test_urls:
            if not state['urls'].has_key(bot.name):
                state['urls'][bot.name] = {}
            if not state['urls'][bot.name].has_key(ievent.channel):
                state['urls'][bot.name][ievent.channel] = []
            if not i in state['urls'][bot.name][ievent.channel]:
                state['urls'][bot.name][ievent.channel].append(i)  
        state.save()
    except Exception, ex:
        handle_exception()

callbacks.add('PRIVMSG', urlcb, urlpre, threaded=True)

## url-search commands

def handle_urlsearch(bot, ievent):
    if not state:
        ievent.reply('rss state not initialized')
        return
    if not ievent.rest:
        ievent.missing('<what>')
        return
    result = []
    try:
        for i in state['urls'][bot.name][ievent.channel]:
            if ievent.rest in i:
                result.append(i)
Example #46
0
def precprime(bot, event):
    if event.userhost in bot.ignore: return False
    if len(event.txt) > 0 and event.txt[0] == '!': return False

    if (re.search(RE_SEIN, event.txt)):
        print "c-prime alarm"
        return True
    else:
        return False

## cprime-callbacks

def cprimecb(bot, event):
    event.bind(bot)

callbacks.add('PRIVMSG', cprimecb, precprime)
callbacks.add('MESSAGE', cprimecb, precprime)
callbacks.add('CONSOLE', cprimecb, precprime)
callbacks.add('CONVORE', cprimecb, precprime)

def getuser_old(event):
    return event.nick

def getuser(ievent):
    if ievent.channel in usermap:
        return usermap[ievent.channel]
    elif ievent.fromm and ievent.fromm in usermap:
        return usermap[ievent.fromm]
    elif ievent.nick and ievent.nick in usermap:
        return usermap[ievent.nick]
    elif ievent.ruserhost in usermap:
Example #47
0
            return False
        elif event.channel == "#c-base-bots":
            if "c-beam" in event.txt:
                return True
            else:
                return False
        else:
            return True
        return False
    return False

## cbeam callbacks

def cbeamcb(bot, event):
    event.bind(bot)
    time.sleep(1)
    if event.txt.find('help') != -1:
        event.reply('http://bit.ly/c-beam')
    else:
        event.reply(random.choice(messages))
    return 0

callbacks.add('PRIVMSG', cbeamcb, precbeam)
callbacks.add('MESSAGE', cbeamcb, precbeam)
callbacks.add('CONSOLE', cbeamcb, precbeam)

def handle_cbeam(bot, event):
    event.reply(random.choice(messages))

cmnds.add('c-beam', handle_cbeam, ['GUEST', ])
Example #48
0
        job.description = whichmodule()
        logging.warn('new interval job %d running hourly' % job.id())
        periodical.jobs.append(job)

    return wrapper


def daily(function):
    """ day decorator. """
    logging.warn('@daily(%s)' % str(function))
    daily.func_dict = function.func_dict
    group = calledfrom(sys._getframe())

    def wrapper(*args, **kw):
        job = JobInterval(86400, 0, function, *args, **kw)
        job.group = group
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warb('new interval job %d running daily' % job.id())

    return wrapper


periodical = Periodical()

callbacks.add("TICK", periodical.looponce)


def size():
    return periodical.size()
Example #49
0

## global runners

cmndrunner = defaultrunner = Runners("default", 50, BotEventRunner)
longrunner = Runners("long", 80, LongRunner)
callbackrunner = Runners("callback", 70, BotEventRunner)
waitrunner = Runners("wait", 20, BotEventRunner)
apirunner = Runners("api", 20, BotEventRunner)
threadrunner = Runners("threads", 50, Runner)

allrunners = [
    cmndrunner, longrunner, callbackrunner, waitrunner, apirunner, threadrunner
]

## cleanup


def runnercleanup(bot, event):
    for runner in allrunners:
        runner.cleanup()


callbacks.add("TICK60", runnercleanup)


def size():
    return "cmnd: %s - callbacks: %s - wait: %s - long: %s - api: %s thread: %s" % (
        cmndrunner.size(), callbackrunner.size(), waitrunner.size(),
        longrunner.size(), apirunner.size(), threadrunner.size())
Example #50
0
    if event.iscommand: return False
    if len(event.txt) < 2: return False
    if event.txt and (event.txt[0] == "?"
                      or event.txt[-1] == "?") and not event.forwarded:
        return True
    return False


def learncb(bot, event):
    """ learn callback, is for catching ? queries. """
    event.bind(bot)
    result = []
    items = PlugPersist(event.channel)
    target = event.txt.lower()
    if target[0] == "?": target = target[1:]
    if target[-1] == "?": target = target[:-1]
    if target in items.data: result = items.data[target]
    globalitems = GlobalPersist("learndb")
    if target in globalitems.data:
        if not target in result: result.extend(globalitems.data[target])
    if result: event.reply("%s is " % target, result, dot=", ")
    event.ready()


callbacks.add("PRIVMSG", learncb, prelearn)
callbacks.add("MESSAGE", learncb, prelearn)
callbacks.add("DISPATCH", learncb, prelearn)
callbacks.add("CONSOLE", learncb, prelearn)
callbacks.add("CMND", learncb, prelearn)
callbacks.add("TORNADO", learncb, prelearn)
Example #51
0
from jsb.lib.callbacks import callbacks

##  pre_underauth_cb precondition


def pre_underauth_cb(bot, ievent):
    """ 
        Only respond to the message like:
        NOTICE AUTH :*** Your ident is disabled or broken, to continue
        to connect you must type /QUOTE PASS 16188.

    """
    args = ievent.arguments
    try:
        return (args[0] == 'AUTH' and args[-3] == '/QUOTE'
                and args[-2] == 'PASS')
    except Exception, ex:
        return False


## underayth_cb callback


def underauth_cb(bot, ievent):
    """ Send the raw command to the server. """
    bot._raw(' '.join(ievent.arguments[-2:]))


callbacks.add('NOTICE', underauth_cb, pre_underauth_cb)
Example #52
0
MAXGEN = 500

markovlearn = PlugPersist('markovlearn')
markovlearn.data.l = markovlearn.data.l or []
markovwords = {}
markovwordi = []
markovchains = {}

cfg.define('loud', 0)


def dummycb(bot, event):
    pass


callbacks.add('START', dummycb)


def init():
    """ init plugin """
    if not cfg.get('enable'): return 1
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    callbacks.add('MESSAGE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('CONSOLE', cb_markovtalk, cb_markovtalk_test, threaded=True)
    start_new_thread(markovtrain, (markovlearn.data.l, ))
    return 1


def size():
    """ return size of markov chains """
Example #53
0
        if message.startswith('"'): messsage = message[1:-1]
        dest, message = message.split(" ", 1)
        dest = dest.split(",")
        finalDest = []
        for d in dest:
            if not d: continue
            d = d.strip().strip("@")
            finalDest.append(d)
            if d in cfg["aliases"].keys():
                for alias in cfg["aliases"][d]:
                    finalDest.append(alias)
        return finalDest, message

def dummycb(bot, event): pass

callbacks.add("START", dummycb)

def init_threaded():
    global server
    if server: logging.warn("irccat2 server is already running.") ; return
    if not cfg.enable: logging.warn("irccat2 is not enabled.") ; return 
    time.sleep(2)
    if "host" not in cfg or "port" not in cfg:
        cfg["host"] = "localhost"
        cfg["port"] = 54321
        cfg["botnames"] = ["default-sxmpp",]
        cfg["aliases"] = {}
    if not cfg.aliases: cfg.aliases = {}
    cfg.save()
    try:
        server = SocketServer.TCPServer((cfg["host"], int(cfg["port"])), IrcCatListener)
Example #54
0
def init():
    """ called upon plugin registration. """
    global stopped
    stopped = False
    global loggers
    for (botname, channel) in cfg.get("channels"):
        enablelogging(botname, channel)  
    callbacks.add("PRIVMSG", chatlogcb, prechatlogcb)
    callbacks.add("JOIN", chatlogcb, prechatlogcb)
    callbacks.add("PART", chatlogcb, prechatlogcb)
    callbacks.add("NOTICE", chatlogcb, prechatlogcb)
    callbacks.add("QUIT", chatlogcb, prechatlogcb)
    callbacks.add("NICK", chatlogcb, prechatlogcb)
    callbacks.add("PRESENCE", chatlogcb, prechatlogcb)
    callbacks.add("MESSAGE", chatlogcb, prechatlogcb)
    callbacks.add("CONSOLE", chatlogcb, prechatlogcb)
    callbacks.add("CONVORE", chatlogcb, prechatlogcb)
    first_callbacks.add("OUTPUT", chatlogcb, prechatlogcb)
    return 1
Example #55
0
            if reason and reason not in i.data.whyup: i.data.whyup.append(reason)
            i.save()
        else:
            i = KarmaItem(event.channel.lower() + "-" + item)
            i.data.count -= 1
            if event.nick not in i.data.whodown: i.data.whodown[event.nick] = 0
            i.data.whodown[event.nick] -= 1
            if reason and reason not in i.data.whyup: i.data.whydown.append(reason)
            i.save()
        karma.append("%s: %s" % (item, i.data.count))
        got = item or item2
    if karma: 
        if cfg.get('verbose') == '1': event.reply("karma - ", karma)
        event.ready()

callbacks.add('PRIVMSG', karmacb, prekarma)
callbacks.add('MESSAGE', karmacb, prekarma)
callbacks.add('CONSOLE', karmacb, prekarma)
callbacks.add('TORNADO', karmacb, prekarma)

## karma command

def handle_karma(bot, event):
    """ arguments: <item> - show karma of item. """
    if not event.rest: event.missing("<item>") ; return
    k = event.rest.lower()
    item = KarmaItem(event.channel.lower() + "-" + k)
    if item.data.count: event.reply("karma of %s is %s" % (k, item.data.count))
    else: event.reply("%s doesn't have karma yet." % k)

cmnds.add('karma', handle_karma, ['OPER', 'USER', 'GUEST'])
Example #56
0
idle = PlugPersist('idle.data')
if not idle.data:
    idle.data = {}

## save on shutdown


def ticksave(bot, event):
    global idle
    global changed
    if changed:
        idle.save()
        changed = False


callbacks.add("TICK60", ticksave)

## callbacks


def preidle(bot, event):
    """ idle precondition aka check if it is not a command """
    if not event.iscmnd() and event.inchan and not event.isoutput: return True


def idlecb(bot, event):
    """ idle PRIVMSG callback .. set time for channel and nick """
    ttime = time.time()
    idle.data[event.userhost] = ttime
    idle.data[event.channel] = ttime
    idle.sync()