Example #1
0
def init():
    global lastline
    lastline = LastLine()
    callbacks.add('PRIVMSG', lastline.privmsgcb, lastline.precb)
    rebefore.add(10, sed_expression, handle_sed, 'USER', allowqueue=False)
    examples.add('s', 'Perform substitution on last message spoken.', 's/foo/bar/')
    return 1
Example #2
0
def init():
    global stopped
    callbacks.add("ALL", simplelogcb, presimplelogcb)
    jcallbacks.add("ALL", jabbersimplelogcb, jabberpresimplelogcb)
    outmonitor.add("simplelog", simplelogcb, presimplelogcb)
    jabbermonitor.add("simplelog", jabbersimplelogcb, jabberpresimplelogcb)
    stopped = False
    return 1
Example #3
0
def init():
    global lastline
    lastline = LastLine()
    callbacks.add('PRIVMSG', lastline.privmsgcb, lastline.precb)
    rebefore.add(10, sed_expression, handle_sed, 'USER', allowqueue=False)
    examples.add('s', 'Perform substitution on last message spoken.',
                 's/foo/bar/')
    return 1
Example #4
0
def init():
    global stopped
    callbacks.add('ALL', supylogcb, presupylogcb)
    jcallbacks.add('ALL', jabbersupylogcb, jabberpresupylogcb)
    outmonitor.add('supylog', supylogcb, presupylogcb)
    jabbermonitor.add('supylog', jabbersupylogcb, jabberpresupylogcb)
    stopped = False
    return 1
Example #5
0
def init():
    global stopped
    callbacks.add('ALL', supylogcb, presupylogcb)
    jcallbacks.add('ALL', jabbersupylogcb, jabberpresupylogcb)
    outmonitor.add('supylog', supylogcb, presupylogcb)
    jabbermonitor.add('supylog', jabbersupylogcb, jabberpresupylogcb)
    stopped = False
    return 1
Example #6
0
def init():
    """ init plugin """
    if not awaydict.data['enable']:
        rlog(0, 'away', 'away is disabled')
        return 1
    else:
        rlog(0, 'away', 'away is enabled')
    callbacks.add('PRIVMSG', doaway, awaytest)
    callbacks.add('PRIVMSG', doback, backtest)
    return 1
Example #7
0
def init():
    """ init plugin """
    # check if enabled
    if not cfg.get('enable'):
        return 1
    # if so register callbacks
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    jcallbacks.add('Message', cb_markovtalk, cb_jmarkovtalk_test, \
threaded=True)
    # learn log or url on startup
    start_new_thread(markovtrain, (markovlearn.data,))
    return 1
Example #8
0
def init():
    """ init plugin """
    # check if enabled
    if not cfg.get('enable'):
        return 1
    # if so register callbacks
    callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True)
    callbacks.add('JOIN', cb_markovjoin, threaded=True)
    jcallbacks.add('Message', cb_markovtalk, cb_jmarkovtalk_test, \
threaded=True)
    # learn log or url on startup
    start_new_thread(markovtrain, (markovlearn.data, ))
    return 1
Example #9
0
def init():
    global seen
    seen = Seen()
    callbacks.add("PRIVMSG", seen.privmsgcb)
    callbacks.add("JOIN", seen.joincb)
    callbacks.add("PART", seen.partcb)
    callbacks.add("QUIT", seen.quitcb)
    cmnds.add("seen", seen.handle_seen, ["USER", "CLOUD"])
    examples.add("seen", "show last spoken txt of <nikc>", "seen dunker")
    return 1
Example #10
0
def init():
    global seen
    seen = Seen()
    callbacks.add('PRIVMSG', seen.privmsgcb)
    callbacks.add('JOIN', seen.joincb)
    callbacks.add('PART', seen.partcb)
    callbacks.add('QUIT', seen.quitcb)
    cmnds.add('seen', seen.handle_seen, ['USER', 'CLOUD'])
    examples.add('seen', 'show last spoken txt of <nikc>', 'seen dunker')
    return 1
Example #11
0
            return
    bot.say(ievent.channel, '%s is on %s' % (ievent.nick, hostname))


def prehexjoin(bot, ievent):
    if not len(ievent.user) == 8:
        return 0
    try:
        int(ievent.user, 16)
    except ValueError:
        return 0
    if (bot.name, ievent.channel) in cfg.get('channels'):
        return 1


callbacks.add('JOIN', hexjoin, prehexjoin)


def handle_hexjoinenable(bot, ievent):
    cfg.append('channels', (bot.name, ievent.channel))
    ievent.reply('%s channel added' % ievent.channel)


cmnds.add('hexjoin-enable', handle_hexjoinenable, 'OPER')
examples.add('hexjoin-enable', 'enable hexjoin in the channel the command is \
given in', 'hexjoin-enable')


def handle_hexjoindisable(bot, ievent):
    try:
        cfg.remove('channels', (bot.name, ievent.channel))
Example #12
0
def greetingtest(bot, ievent):
    """ check if greeting callback should be called """
    if greetings and ievent.channel in cfg.get('enable'):
        return 1

def greetingcallback(bot, ievent):
    """ do the greeting """
    username = users.getname(ievent.userhost)
    try:
        greetingslist = greetings[username]
        if greetingslist:
            ievent.reply(random.choice(greetingslist))
    except KeyError:
        pass

callbacks.add('JOIN', greetingcallback, greetingtest)

def handle_greetingadd(bot, ievent):
    """ add greetings txt """
    if not greetings:
        ievent.reply('the greet plugin is not properly initialised')
    if not ievent.rest:
        ievent.missing('<txt>')
        return
    username = users.getname(ievent.userhost)
    greetings.add(username, ievent.rest)
    greetings.save()
    ievent.reply('greeting message added')

cmnds.add('greeting-add', handle_greetingadd, 'USER')
examples.add('greeting-add', "add greeting message", 'greeting-add yooo dudes')
Example #13
0
user database .. see %shelp for help"
                    % bot.channels[ievent.channel]["cc"],
                )
            else:
                rlog(
                    100,
                    "register",
                    "username %s already exists .. can't \
add %s"
                    % (ievent.nick, ievent.userhost),
                )
    except Exception, ex:
        rlog(100, "register", "failed to add %s (%s) .. reason: %s" % (ievent.nick, ievent.userhost, str(ex)))


callbacks.add("JOIN", anoncb, anonpre, threaded=True)
callbacks.add("Presence", anoncb, anonpre, threaded=True)
tests.add("anon-enable --chan #dunkbots").fakein(":[email protected] JOIN #dunkbots").sleep(3).add(
    "delete dunker"
).add("anon-disable --chan #dunkbots")


def handle_anonenable(bot, ievent):
    cfg.append("enable", jsonstring([bot.name, ievent.channel]))
    ievent.reply("anon enabled on (%s,%s)" % (bot.name, ievent.channel))


cmnds.add("anon-enable", handle_anonenable, "OPER")
examples.add("anon-enable", "enable anon register", "anon-enable")
tests.add("anon-enable", "anon enabled")
Example #14
0
cmnds.add('usermode-add', handle_usermodeadd, 'OPER', threaded=True)
examples.add('usermode-add', 'add a usermode', 'usermode-add I')

def handle_usermodedel(bot, ievent):
    """ delete mode from bot """
    if not ievent.args:
        ievent.missing('<mode(s)>')
        return
    modes = list(' '.join(ievent.args).replace(' ', ''))
    umodes.delmode(bot, modes)
    bot.sendraw('MODE %s -%s' % (bot.nick, ''.join(modes)))
    ievent.reply('ok')

cmnds.add('usermode-del', handle_usermodedel, 'OPER', threaded=True)
examples.add('usermode-del', 'remove a usermode', 'usermode-del I')

def handle_usermodelist(bot, ievent):
    """ list modes of bot """
    modes = umodes.getmode(bot)
    if not modes:
        ievent.reply('no modes set')
    else:
        modes.sort()
        ievent.reply('mode +%s' % ''.join(modes))

cmnds.add('usermode-list', handle_usermodelist, 'OPER')
examples.add('usermode-list', 'show user modes', 'usermode-list')

# callbacks
callbacks.add('001', umodes.handle_001)
#

""" nick recapture callback. """

__copyright__ = 'this file is in the public domain'

from gozerbot.callbacks import callbacks
from gozerbot.plughelp import plughelp

plughelp.add('nickcapture', 'nickcapture takes a nick back if a user quits')

def ncaptest(bot, ievent):

    """ test if user is splitted. """

    if '*.' in ievent.txt or bot.server in ievent.txt:
        return 0

    if bot.orignick.lower() == ievent.nick.lower():
        return 1

    return 0

def ncap(bot, ievent):

    """ recapture the nick. """

    bot.donick(bot.orignick)

callbacks.add('QUIT', ncap, ncaptest, threaded=True)
Example #16
0
from gozerbot.callbacks import callbacks
from gozerbot.plughelp import plughelp

plughelp.add('underauth', 'provide callbacks that registers the bot with the \
undernet network')

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] == u'AUTH' and
                args[-3] == u'/QUOTE' and
                args[-2] == u'PASS')
    except Exception, ex:
        return 0

def underauth_cb(bot, ievent):
    """
    Send the raw command to the server
    """
    # last two elements of the arguments list are PASS <id>
    bot._raw(' '.join(ievent.arguments[-2:]))


callbacks.add('NOTICE', underauth_cb, pre_underauth_cb)
Example #17
0
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        return 1


def privmsgcb(bot, ievent):
    """ callback for urlcaching """
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        url = test_url.group(1)
        if not urlcache.has_key(bot.name):
            urlcache[bot.name] = {}
        urlcache[bot.name][ievent.target] = url


callbacks.add('PRIVMSG', privmsgcb, precb)


def get_tinyurl(url):
    """ grab a tinyurl """
    postarray = [
        ('submit', 'submit'),
        ('url', url),
    ]
    postdata = urllib.urlencode(postarray)
    req = urllib2.Request(url='http://tinyurl.com/create.php', data=postdata)
    req.add_header('User-agent', useragent())
    try:
        res = urllib2.urlopen(req).readlines()
        #raise Exception("mekker")
    except urllib2.URLError, e:
def init():
    callbacks.add('PRIVMSG', bugtrackers.cb_privmsg)
Example #19
0
    except:
        return
    logs.logbot(botname, time.time(), to, txt)

jabbermonitor.add('log', jcblogsay, jprelogsay)

def prelog(bot, ievent):
    """ log pre condition """
    if ievent.channel and ievent.channel in logs.loglist:
        return 1

def logcb(bot, ievent):
    """ callback that logs ievent """
    logs.log(bot.name, time.time(), ievent)

callbacks.add('ALL', logcb, prelog)
jcallbacks.add('Message', logcb, prelog)

def handle_logon(bot, ievent):
    """ log-on .. enable logging in channel the command was given in """
    if not ievent.channel in logs.loglist:
        logs.loglist.append(ievent.channel)
        ievent.reply('logging enabled in %s' % ievent.channel)
    else:
        ievent.reply('%s already in loglist' % ievent.channel)

cmnds.add('log-on', handle_logon, 'OPER')
examples.add('log-on', 'enable logging of the channel in which the command \
was given', 'log-on')

def handle_logoff(bot, ievent):
Example #20
0
            tuple([host] + [result[x] for x in ['result', 'modified', \
'server', 'size', 'content', 'encoding', 'doctype']]))

cmnds.add('validate', handle_validate, 'USER')
examples.add('validate', 'validate an URL', 'validate http://gozerbot.org')
aliases.data['valid'] = 'validate'


def privmsgpre(bot, ievent):
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        return 1

def privmsgcb(bot, ievent):
    """ callback for urlcache """
    test_url = re_url_match.search(ievent.txt)
    url = test_url.group(1)
    if not urlcache.has_key(bot.name):
        urlcache[bot.name] = {}
    urlcache[bot.name][ievent.printto] = url
    rlog(0, 'snarf', 'cached url %s on %s (%s)' % (url, ievent.printto, \
bot.name))
    if cfg.data.has_key(bot.name) and cfg.data[bot.name]\
.has_key(ievent.printto) and cfg.data[bot.name][ievent.printto]:
        nevent = copy.copy(ievent)
        nevent.rest = url
        handle_snarf(bot, nevent, False)

callbacks.add('PRIVMSG', privmsgcb, privmsgpre, threaded=True)
jcallbacks.add('Message', privmsgcb, privmsgpre, threaded=True)
Example #21
0
def init():
    callbacks.add('ALL', traclogcb, pretraclogcb)
    outmonitor.add('traclog', traclogcb, pretraclogcb)
    return 1
Example #22
0
        return
    if ievent.args[0].lower() == bot.nick.lower():
        ievent.reply('not going to kickban myself')
        return
    userhost = getwho(bot, ievent.args[0])
    reason = len(ievent.args) > 1 and ' '.join(ievent.args[1:]) or 'Permban requested, bye'
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to kickban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        bot.sendraw('KICK %s %s :%s' % (ievent.channel, ievent.args[0], reason))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])

callbacks.add('367', handle_367)
callbacks.add('MODE', handle_mode)
aliases.data['ban'] = 'ban-add'
aliases.data['bans'] = 'ban-list'
aliases.data['unban'] = 'ban-remove'
aliases.data['kb'] = 'ban-kickban'
aliases.data['kickban'] = 'ban-kickban'
cmnds.add('ban-add', handle_ban_add, 'OPER')
examples.add('ban-add', 'adds a host to the ban list', 'ban-add *!*@lamers.are.us')
cmnds.add('ban-list', handle_ban_list, 'OPER', threaded=True)
cmnds.add('ban-remove', handle_ban_remove, 'OPER', threaded=True)
examples.add('ban-remove', 'removes a host from the ban list', 'ban-remove 1')
cmnds.add('ban-kickban', handle_kickban_add, 'OPER')
examples.add('ban-kickban', 'kickbans the given nick', 'kickban Lam0r Get out of here')
Example #23
0
def precb(bot, ievent):
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        return 1

def privmsgcb(bot, ievent):
    """ callback for urlcaching """
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        url = test_url.group(1)
        if not urlcache.has_key(bot.name):
            urlcache[bot.name] = {}
        urlcache[bot.name][ievent.target] = url

callbacks.add('PRIVMSG', privmsgcb, precb)

def get_tinyurl(url):
    """ grab a tinyurl """
    postarray = [
        ('submit', 'submit'),
        ('url', url),
        ]
    postdata = urllib.urlencode(postarray)
    req = urllib2.Request(url='http://tinyurl.com/create.php', data=postdata)
    req.add_header('User-agent', useragent())
    try:
        res = urllib2.urlopen(req).readlines()
        #raise Exception("mekker")
    except urllib2.URLError, e:
        rlog(10, 'tinyurl', 'URLError: %s' % str(e))
Example #24
0
def urlcb(bot, ievent):
    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)  
    except Exception, ex:
        handle_exception()

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

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)
    except KeyError:
        ievent.reply('no urls known for channel %s' % ievent.channel)
Example #25
0
        for url in test_urls:
            if len(url) >= cfg.get('url-len'):
                host = url.split(':')[1].lstrip('/').split('/')[0]
                short = lnsurl(url)
                ievent.reply('%s (at %s)' % (short, host))
    except Exception,e:
        rlog(10, 'lns', 'EXCEPTION: %s' % str(e))

def handle_ln_on(bot, ievent):
    if not bot.name in state['ln-s']:
        state['ln-s'][bot.name] = {}
    if not ievent.channel.lower() in state['ln-s'][bot.name]:
        state['ln-s'][bot.name][ievent.channel.lower()] = True
    ievent.reply('ok')

def handle_ln_off(bot, ievent):
    if not bot.name in state['ln-s']:
        state['ln-s'][bot.name] = {}
    if not ievent.channel.lower() in state['ln-s'][bot.name]:
        state['ln-s'][bot.name][ievent.channel.lower()] = False
    ievent.reply('ok')

callbacks.add('PRIVMSG', lnscb)
cmnds.add('ln-on', handle_ln_on, 'USER')
examples.add('ln-on', 'enable ln in channel the command was given in', 'ln-on')
cmnds.add('ln-off', handle_ln_off, 'USER')
examples.add('ln-off', 'diable ln in channel the command was given in', \
'ln-off')
aliases.data['lns-on'] = 'ln-on'
aliases.data['lns-off'] = 'lns-off'
Example #26
0
remind = Remind(datadir + os.sep + 'plugs' + os.sep + 'remind' + os.sep + \
'remind')
if not remind.data:
    remind = Remind(datadir + os.sep + 'plugs' + os.sep + 'remind' + os.sep + \
'remind')

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)
jcallbacks.add('Message', remindcb, preremind, threaded=True)

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:
        ievent.missing('<nick> <txt>')
        return
    userhost = getwho(bot, who)
Example #27
0
def handle_idlist(bot, ievent):
    ievent.reply(str(idmanager.data))


cmnds.add('id-list', handle_idlist, 'OPER')


def handle_JOIN(bot, ievent):
    user = users.getname(ievent.userhost)
    if not user:
        user = idmanager.lookup(bot, ievent.nick.lower(), ievent.userhost)
    if not user:
        bot.sendraw('WHOIS %s' % ievent.nick)


callbacks.add('JOIN', handle_JOIN)


def handle_320_330(bot, ievent):
    text = ' '.join(ievent.arguments[2:])
    #bot.sendraw('PRIVMSG #dunkbots :%s' % str(ievent))
    # IRC protocol sucks, no generic code for identified users :-(
    # so,
    if ievent.cmnd == '320' and 'is identified to services' in text:
        # Freenode
        nick = ievent.arguments[1].lower()
        userhost = bot.userhosts[nick]
        idmanager.lookup(bot, nick, userhost)
        #bot.sendraw('PRIVMSG #dunkbots :%s is identified (320/freenode)' % nick)
    elif ievent.cmnd == '330' and 'is logged in as' in text:
        # Undernet
Example #28
0
                throttlestate.save()
                rlog(100, 'register', 'added %s (%s)' % (ievent.nick, \
ievent.userhost))
                bot.say(
                    ievent.nick, "you have been added to the bots \
user database .. see %shelp for help" % bot.channels[ievent.channel]['cc'])
            else:
                rlog(
                    100, 'register', "username %s already exists .. can't \
add %s" % (ievent.nick, ievent.userhost))
    except Exception, ex:
        rlog(100, 'register', 'failed to add %s (%s) .. reason: %s' % \
(ievent.nick, ievent.userhost, str(ex)))


callbacks.add('JOIN', anoncb, anonpre, threaded=True)
callbacks.add('Presence', anoncb, anonpre, threaded=True)
tests.add('anon-enable --chan #dunkbots').fakein(
    ':[email protected] JOIN #dunkbots').sleep(3).add(
        'delete dunker').add('anon-disable --chan #dunkbots')


def handle_anonenable(bot, ievent):
    cfg.append('enable', jsonstring([bot.name, ievent.channel]))
    ievent.reply('anon enabled on (%s,%s)' % (bot.name, ievent.channel))


cmnds.add('anon-enable', handle_anonenable, 'OPER')
examples.add('anon-enable', 'enable anon register', 'anon-enable')
tests.add('anon-enable', 'anon enabled')
Example #29
0
        self.identify(bot)
        try:
            for i in self.data[bot.name]['nickservtxt']:
                self.sendstring(bot, i)
                rlog(10, 'nickserv', 'sent %s' % i)
        except:
            pass

# basic init stuff
nsauth = NSAuth()

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

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

def init():

    """ init the nickserv data. """

    passwd = config['nickservpass']
    if passwd:
        nsauth.add(bot, **{'password': passwd, 'nickservtxt': config['nickservtxt']})
    return 1

def handle_nsadd(bot, ievent):

    """ add a bot to the nickserv. """

    if bot.jabber:
Example #30
0
def init():
    callbacks.add('PRIVMSG', bugtrackers.cb_privmsg)
Example #31
0
def init():
    callbacks.add('PRIVMSG', throttlecb, throttlepre)
Example #32
0
cmnds.add('validate', handle_validate, 'USER')
examples.add('validate', 'validate an URL', 'validate http://gozerbot.org')
aliases.data['valid'] = 'validate'


def privmsgpre(bot, ievent):
    test_url = re_url_match.search(ievent.txt)
    if test_url:
        return 1


def privmsgcb(bot, ievent):
    """ callback for urlcache """
    test_url = re_url_match.search(ievent.txt)
    url = test_url.group(1)
    if not urlcache.has_key(bot.name):
        urlcache[bot.name] = {}
    urlcache[bot.name][ievent.printto] = url
    rlog(0, 'snarf', 'cached url %s on %s (%s)' % (url, ievent.printto, \
bot.name))
    if cfg.data.has_key(bot.name) and cfg.data[bot.name]\
.has_key(ievent.printto) and cfg.data[bot.name][ievent.printto]:
        nevent = copy.copy(ievent)
        nevent.rest = url
        handle_snarf(bot, nevent, False)


callbacks.add('PRIVMSG', privmsgcb, privmsgpre, threaded=True)
jcallbacks.add('Message', privmsgcb, privmsgpre, threaded=True)
Example #33
0
    remind = Remind(datadir + os.sep + 'plugs' + os.sep + 'remind' + os.sep + \
'remind')


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)
jcallbacks.add('Message', remindcb, preremind, threaded=True)


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:
        ievent.missing('<nick> <txt>')
        return
Example #34
0
   
cmnds.add('id-add', handle_idadd, 'OPER')

def handle_idlist(bot, ievent):
    ievent.reply(str(idmanager.data))

cmnds.add('id-list', handle_idlist, 'OPER')

def handle_JOIN(bot, ievent):
    user = users.getname(ievent.userhost)
    if not user:
        user = idmanager.lookup(bot, ievent.nick.lower(), ievent.userhost)
    if not user:
        bot.sendraw('WHOIS %s' % ievent.nick)

callbacks.add('JOIN', handle_JOIN)

def handle_320_330(bot, ievent):
    text = ' '.join(ievent.arguments[2:])
    #bot.sendraw('PRIVMSG #dunkbots :%s' % str(ievent))
    # IRC protocol sucks, no generic code for identified users :-(
    # so,
    if ievent.cmnd == '320' and 'is identified to services' in text:
        # Freenode
        nick = ievent.arguments[1].lower()
        userhost = bot.userhosts[nick]
        idmanager.lookup(bot, nick, userhost) 
        #bot.sendraw('PRIVMSG #dunkbots :%s is identified (320/freenode)' % nick)
    elif ievent.cmnd == '330' and 'is logged in as' in text:
        # Undernet
        nick = ievent.arguments[1].lower()
Example #35
0
        if ip:
            bot.say(ievent.channel, '%s is on %s' % (ievent.nick, ip))
            return
    bot.say(ievent.channel, '%s is on %s' % (ievent.nick, hostname))

def prehexjoin(bot , ievent):
    if not len(ievent.user) == 8:
        return 0
    try:
        int(ievent.user, 16)
    except ValueError:
        return 0
    if (bot.name, ievent.channel) in cfg.get('channels'):
        return 1

callbacks.add('JOIN', hexjoin, prehexjoin)

def handle_hexjoinenable(bot, ievent):
    cfg.append('channels', (bot.name, ievent.channel))
    ievent.reply('%s channel added' % ievent.channel)

cmnds.add('hexjoin-enable', handle_hexjoinenable, 'OPER')
examples.add('hexjoin-enable', 'enable hexjoin in the channel the command is \
given in', 'hexjoin-enable')

def handle_hexjoindisable(bot, ievent):
    try:
        cfg.remove('channels', (bot.name, ievent.channel))
        ievent.reply('%s channel removed' % ievent.channel)
    except ValueError:
        ievent.reply('%s channel is not in channels list' % ievent.channel)
Example #36
0
plughelp.add(
    'underauth', 'provide callbacks that registers the bot with the \
undernet network')


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] == u'AUTH' and args[-3] == u'/QUOTE'
                and args[-2] == u'PASS')
    except Exception, ex:
        return 0


def underauth_cb(bot, ievent):
    """
    Send the raw command to the server
    """
    # last two elements of the arguments list are PASS <id>
    bot._raw(' '.join(ievent.arguments[-2:]))


callbacks.add('NOTICE', underauth_cb, pre_underauth_cb)
Example #37
0
def cbrelayquit(bot, ievent):
    """ relay quit callback """
    time.sleep(1)
    nick = ievent.nick.lower()
    if nick in bot.splitted:
        return
    try:
        for i in bot.userchannels[nick]:
            if i in bot.state['joinedchannels']:
                relay.check(bot.name, i, "%s (%s) quit %s - %s" % \
(ievent.nick, ievent.userhost, bot.server, ievent.txt))
    except KeyError:
        rlog(10, 'relay', 'missing %s in userchannels' % nick)

callbacks.add('QUIT', cbrelayquit, nr=0, threaded=True)

def cbrelaykick(bot, ievent):
    """ relay kick callback """
    relay.check(bot.name, ievent.channel, "%s kicked %s from %s (%s) - %s" % \
(ievent.nick, ievent.arguments[1], ievent.channel, bot.server, ievent.txt))

callbacks.add('KICK', cbrelaykick, prerelay, threaded=True)

def cbrelaynick(bot, ievent):
    """ relay nick callback """
    nick = ievent.nick.lower()
    try:
        for i in bot.userchannels[nick]:
            if i in bot.state['joinedchannels']:
                relay.check(bot.name, i, "%s is now known as %s" % \
Example #38
0
jabbermonitor.add('log', jcblogsay, jprelogsay)


def prelog(bot, ievent):
    """ log pre condition """
    if ievent.channel and ievent.channel in logs.loglist:
        return 1


def logcb(bot, ievent):
    """ callback that logs ievent """
    logs.log(bot.name, time.time(), ievent)


callbacks.add('ALL', logcb, prelog)
jcallbacks.add('Message', logcb, prelog)


def handle_logon(bot, ievent):
    """ log-on .. enable logging in channel the command was given in """
    if not ievent.channel in logs.loglist:
        logs.loglist.append(ievent.channel)
        ievent.reply('logging enabled in %s' % ievent.channel)
    else:
        ievent.reply('%s already in loglist' % ievent.channel)


cmnds.add('log-on', handle_logon, 'OPER')
examples.add('log-on', 'enable logging of the channel in which the command \
was given', 'log-on')
Example #39
0
    bot.server = server
    bot.port = port
    bot.connect()

cmnds.add('jump', handle_jump, 'OPER')
examples.add('jump', 'jump <server> <port> .. switch server', 'jump localhost 6667')

def modecb(bot, ievent):

    """ callback to detect change of channel key. """

    if ievent.postfix.find('+k') != -1:
        key = ievent.postfix.split('+k')[1]
        bot.channels[ievent.channel.lower()]['key'] = key

callbacks.add('MODE', modecb)

def handle_nick(bot, ievent):

    """ nick <nickname> .. change bot's nick. """

    if bot.jabber:
        ievent.reply('nick works only on irc bots')
        return

    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nickname>')
        return
Example #40
0
from gozerbot.callbacks import callbacks
import re


def marinero_precond(bot, ievent):
    """ remind precondition """
    return re.match("^ar{3,}$", ievent.txt)


def marinero_response(bot, ievent):
    ievent.reply('marinero')


callbacks.add('PRIVMSG', marinero_response, marinero_precond)
Example #41
0
    if ievent.channel in bot.state['opchan']:
        return 1


def cbautovoice(bot, ievent):
    """ autovoice callback """
    chandata = 0
    try:
        chandata = bot.channels[ievent.channel]['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:
        bot.channels[ievent.channel]['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 \
Example #42
0
def handle_lag(bot, ievent):
    """ show lag of bot the command is given on """
    lag = lagmeters.getlag(bot.name)
    if lag == False:
        ievent.reply('no lag metered')
    else:
        ievent.reply('lag is %f seconds' % lag)


def connectedcb(bot, ievent):
    """ callback to be called when bot is connected """
    lagmeters.update_names()
    lagmeters.measure(bot.name)


def pongcb(bot, ievent):
    """ PONG callback """
    if len(ievent.arguments) == 3:
        if ievent.arguments[1].lstrip(':') == 'LAG':
            try:
                sent = float(ievent.arguments[2])
                lagmeters.recieved(bot.name, sent)
            except ValueError:
                pass


cmnds.add('lag', handle_lag, ['USER'])
examples.add('lag', 'shows the current lag', 'lag')
callbacks.add('001', connectedcb)
callbacks.add('PONG', pongcb)
Example #43
0
    if ievent.channel in bot.state["opchan"]:
        return 1


def cbautovoice(bot, ievent):
    """ autovoice callback """
    chandata = 0
    try:
        chandata = bot.channels[ievent.channel]["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:
        bot.channels[ievent.channel]["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(
Example #44
0
def preidle(bot, ievent):
    """ idle precondition aka check if it is not a command """
    if ievent.usercmnd:
        return 0
    else:
        return 1


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


callbacks.add('PRIVMSG', idlecb, preidle)
jcallbacks.add('Message', idlecb, preidle)


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
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't get userhost of %s" % who)
        return
    try:
Example #45
0
def init():
    callbacks.add('PRIVMSG', throttlecb, throttlepre)
Example #46
0
def init():
    callbacks.add('ALL', traclogcb, pretraclogcb)
    outmonitor.add('traclog', traclogcb, pretraclogcb)
    return 1
Example #47
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)
    except Exception, ex:
        handle_exception()


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


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)
    except KeyError:
Example #48
0
    if ievent.nick == bot.nick:
        return
    chan = ievent.channel.lower()
    if chan in bot.state['no-op']:
        return
    time.sleep(1)
    if cfg.get('oponsplit') or ievent.nick.lower() not in bot.splitted:
        if users.status(ievent.userhost, ievent.channel.upper()):
            if chan not in bot.state['opchan']:
                return
            bot.doop(chan, ievent.nick)
    else:
        bot.splitted.remove(ievent.nick.lower())


callbacks.add('JOIN', opjoincb, threaded=True)


def handle_op1(bot, ievent):
    """ op [<nick>] .. op an user """
    chan = ievent.channel.lower()
    if chan in bot.state['no-op']:
        ievent.reply('opping is disabled in %s' % ievent.channel)
        return
    if chan not in bot.state['opchan']:
        ievent.reply("i'm not op in %s" % ievent.channel)
        return
    try:
        nick = ievent.args[0]
    except IndexError:
        nick = ievent.nick
Example #49
0
from gozerbot.callbacks import callbacks
import re
def marinero_precond(bot, ievent):
    """ remind precondition """
    return re.match("^ar{3,}$", ievent.txt)

def marinero_response(bot, ievent):
    ievent.reply('marinero')

callbacks.add('PRIVMSG', marinero_response, marinero_precond)
Example #50
0
                short = lnsurl(url)
                ievent.reply('%s (at %s)' % (short, host))
    except Exception, e:
        rlog(10, 'lns', 'EXCEPTION: %s' % str(e))


def handle_ln_on(bot, ievent):
    if not bot.name in state['ln-s']:
        state['ln-s'][bot.name] = {}
    if not ievent.channel.lower() in state['ln-s'][bot.name]:
        state['ln-s'][bot.name][ievent.channel.lower()] = True
    ievent.reply('ok')


def handle_ln_off(bot, ievent):
    if not bot.name in state['ln-s']:
        state['ln-s'][bot.name] = {}
    if not ievent.channel.lower() in state['ln-s'][bot.name]:
        state['ln-s'][bot.name][ievent.channel.lower()] = False
    ievent.reply('ok')


callbacks.add('PRIVMSG', lnscb)
cmnds.add('ln-on', handle_ln_on, 'USER')
examples.add('ln-on', 'enable ln in channel the command was given in', 'ln-on')
cmnds.add('ln-off', handle_ln_off, 'USER')
examples.add('ln-off', 'diable ln in channel the command was given in', \
'ln-off')
aliases.data['lns-on'] = 'ln-on'
aliases.data['lns-off'] = 'lns-off'
Example #51
0
    userhost = getwho(bot, ievent.args[0])
    reason = len(ievent.args) > 1 and ' '.join(
        ievent.args[1:]) or 'Permban requested, bye'
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to kickban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        bot.sendraw('KICK %s %s :%s' %
                    (ievent.channel, ievent.args[0], reason))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])


callbacks.add('367', handle_367)
callbacks.add('MODE', handle_mode)
aliases.data['ban'] = 'ban-add'
aliases.data['bans'] = 'ban-list'
aliases.data['unban'] = 'ban-remove'
aliases.data['kb'] = 'ban-kickban'
aliases.data['kickban'] = 'ban-kickban'
cmnds.add('ban-add', handle_ban_add, 'OPER')
examples.add('ban-add', 'adds a host to the ban list',
             'ban-add *!*@lamers.are.us')
cmnds.add('ban-list', handle_ban_list, 'OPER', threaded=True)
cmnds.add('ban-remove', handle_ban_remove, 'OPER', threaded=True)
examples.add('ban-remove', 'removes a host from the ban list', 'ban-remove 1')
cmnds.add('ban-kickban', handle_kickban_add, 'OPER')
examples.add('ban-kickban', 'kickbans the given nick',
             'kickban Lam0r Get out of here')
Example #52
0
    """ kill all lag meter periodical jobs """ 
    periodical.kill()

def handle_lag(bot, ievent): 
    """ show lag of bot the command is given on """
    lag = lagmeters.getlag(bot.name)
    if lag == False:
        ievent.reply('no lag metered')
    else:
        ievent.reply('lag is %f seconds' % lag)

def connectedcb(bot, ievent):
    """ callback to be called when bot is connected """
    lagmeters.update_names()
    lagmeters.measure(bot.name)

def pongcb(bot, ievent):
    """ PONG callback """
    if len(ievent.arguments) == 3:
        if ievent.arguments[1].lstrip(':') == 'LAG':
            try:
                sent = float(ievent.arguments[2])
                lagmeters.recieved(bot.name, sent) 
            except ValueError:
                pass

cmnds.add('lag', handle_lag, ['USER'])
examples.add('lag', 'shows the current lag', 'lag')
callbacks.add('001', connectedcb)
callbacks.add('PONG', pongcb)
Example #53
0
def infopre(bot, ievent):
    """ see if info callback needs to be called """
    cc = cchar(bot, ievent)
    if ievent.origtxt and  ievent.origtxt[0] in cc and not ievent.usercmnd \
and ievent.txt:
        return 1

def infocb(bot, ievent):
    """ implement a !infoitem callback """
    if not shouldignore(ievent.userhost):
        if 'handle_question' in bot.state['allowed'] or users.allowed(ievent.userhost, 'USER'):
             data = info.get(ievent.txt)
             if data:
                ievent.reply('%s is ' % ievent.txt, data , dot=True)

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

def handle_infoupgrade(bot, ievent):
    if info.size():
         if '-f' in ievent.optionset:
             pass
         else:
             ievent.reply('there are already infoitems in the main database .. not upgrading')
             ievent.reply('use the -f option to force an upgrade')
             return
    ievent.reply('upgrading infoitems')
    nritems = upgrade()
    ievent.reply('%s items upgraded' % nritems)

cmnds.add('info-upgrade', handle_infoupgrade, 'OPER', options={'-f': ''})
Example #54
0
        try:
            for i in self.data[bot.name]['nickservtxt']:
                self.sendstring(bot, i)
                rlog(10, 'nickserv', 'sent %s' % i)
        except:
            pass


# basic init stuff
nsauth = NSAuth()

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

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


def init():
    """ init the nickserv data. """

    passwd = config['nickservpass']
    if passwd:
        nsauth.add(
            bot, **{
                'password': passwd,
                'nickservtxt': config['nickservtxt']
            })
    return 1