def handle_ccdel(bot, ievent): """ remove a control char from the channels cc list. """ try: chan = ievent.args[1].lower() except IndexError: chan = ievent.channel.lower() try: what = ievent.args[0] if not users.allowed(ievent.userhost, 'OPER'): return if len(what) > 1: ievent.reply("only one character is allowed") return try: bot.channels[chan]['cc'] = \ bot.channels[chan]['cc'].replace(what, '') except KeyError: ievent.reply("no channel %s in database") return except TypeError: ievent.reply("no channel %s in database" % chan) return bot.channels.save() ievent.reply('control char %s deleted' % what) except IndexError: ievent.missing('<cc> [<channel>]')
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)
def handle_cc(bot, ievent): """ cc [<controlchar>] .. set/get control character of channel. """ try: chan = ievent.args[1].lower() except IndexError: chan = ievent.channel.lower() try: what = ievent.args[0] if not users.allowed(ievent.userhost, 'OPER'): return if len(what) > 1: ievent.reply("only one character is allowed") return try: bot.channels[chan]['cc'] = what except (KeyError, TypeError): ievent.reply("no channel %s in database" % chan) return bot.channels.save() ievent.reply('control char set to %s' % what) except IndexError: # no argument given .. show cc of channel command is given in try: cchar = bot.channels[chan]['cc'] ievent.reply('control character(s) for channel %s are/is %s' % \ (chan, cchar)) except (KeyError, TypeError): ievent.reply("default cc is %s" % config['defaultcc'])
def handle_merge(bot, ievent): """ user-merge <name> <nick> .. merge the userhost into a already \ existing user """ if len(ievent.args) != 2: ievent.missing('<name> <nick>') return name, nick = ievent.args name = name.lower() if users.gotperm(name, 'OPER') and not users.allowed(ievent.userhost, \ 'OPER'): ievent.reply("only OPER perm can merge with OPER user") return if name == 'owner' and not bot.ownercheck(ievent, "can merge with owner \ user"): return if not users.exist(name): ievent.reply("we have no user %s" % name) return userhost = getwho(bot, nick) if not userhost: ievent.reply("can't find userhost of %s" % nick) return username = users.getname(userhost) if username: ievent.reply('we already have a user with userhost %s (%s)' % \ (userhost, username)) return result = 0 try: result = users.merge(name, userhost) except Exception, ex: ievent.reply("ERROR: %s" % str(ex)) return
def handle_ccadd(bot, ievent): """ add a control char to the channels cc list. """ try: chan = ievent.args[1].lower() except IndexError: chan = ievent.channel.lower() try: what = ievent.args[0] if not users.allowed(ievent.userhost, 'OPER'): return if len(what) > 1: ievent.reply("only one character is allowed") return try: bot.channels[chan]['cc'] += what except (KeyError, TypeError): ievent.reply("no channel %s in database" % chan) return bot.channels.save() ievent.reply('control char %s added' % what) except IndexError: ievent.missing('<cc> [<channel>]')
def handle_invite(self, ievent): """ join channel if invited by OPER. """ if users.allowed(ievent.userhost, [ 'OPER', ]): self.join(ievent.txt)
def handle_rssstop(bot, ievent): """ rss-start <name> .. start a rss feed to a user """ if not ievent.rest: ievent.missing("<feed name>") return name = ievent.rest rssitem = watcher.byname(name) if bot.jabber: target = ievent.userhost else: if users.allowed(ievent.userhost, ["OPER"]) and not ievent.msg: target = ievent.channel else: target = ievent.nick if rssitem == None: ievent.reply("we don't have a %s rss feed" % name) return if not rssitem.running: ievent.reply("%s watcher is not running" % name) return if not (bot.name, target) in rssitem.watchchannels: ievent.reply("we are not monitoring %s on (%s,%s)" % (name, bot.name, target)) return rssitem.watchchannels.remove((bot.name, target)) watcher.save() ievent.reply("%s stopped" % name)
def handle_rssstart(bot, ievent): """ rss-start <name> .. start a rss feed to a user """ if not ievent.rest: ievent.missing('<feed name>') return name = ievent.rest rssitem = watcher.byname(name) if bot.jabber: if ievent.msg: target = ievent.userhost else: target = ievent.channel else: if users.allowed(ievent.userhost, ['OPER', ]) and not ievent.msg: target = ievent.channel else: target = ievent.nick if rssitem == None: ievent.reply("we don't have a %s rss object" % name) return if not rssitem.running: ievent.reply('%s watcher is not running' % name) return if jsonstring([bot.name, target]) in rssitem.watchchannels or [bot.name, target] in rssitem.watchchannels: ievent.reply('we are already monitoring %s on (%s,%s)' % \ (name, bot.name, target)) return rssitem.watchchannels.append([bot.name, target]) for item in rssitem.itemslist: watcher.itemslists.adduniq(jsonstring([name, target]), item) watcher.save() ievent.reply('%s started' % name)
def handle_ignore(bot, ievent): """ ignore nick for number of seconds. """ try: (nick, nrseconds) = ievent.args nrseconds = int(nrseconds) except ValueError: ievent.missing('<nick> <seconds>') return userhost = getwho(bot, nick) if not userhost: ievent.reply("can't get userhost of %s" % nick) return allowed = users.allowed(userhost, 'OPER', log=False) if allowed: ievent.reply("can't ignore OPER") return addignore(userhost, nrseconds) ievent.reply("ignoring %s for %s seconds" % (nick, nrseconds))
def handle_rssstop(bot, ievent): """ rss-start <name> .. start a rss feed to a user """ if not ievent.rest: ievent.missing('<feed name>') return name = ievent.rest rssitem = watcher.byname(name) if bot.jabber: target = ievent.userhost else: if users.allowed(ievent.userhost, [ 'OPER', ]) and not ievent.msg: target = ievent.channel else: target = ievent.nick if rssitem == None: ievent.reply("we don't have a %s rss feed" % name) return if not rssitem.running: ievent.reply('%s watcher is not running' % name) return if not (bot.name, target) in rssitem.watchchannels: ievent.reply('we are not monitoring %s on (%s,%s)' % \ (name, bot.name, target)) return rssitem.watchchannels.remove((bot.name, target)) watcher.save() ievent.reply('%s stopped' % name)
def handle_rssstop(bot, ievent): """ rss-start <name> .. start a rss feed to a user """ if not ievent.rest: ievent.missing('<feed name>') return name = ievent.rest rssitem = watcher.byname(name) if bot.jabber: target = ievent.userhost else: if users.allowed(ievent.userhost, ['OPER', ]) and not ievent.msg: target = ievent.channel else: target = ievent.nick if rssitem == None: ievent.reply("we don't have a %s rss feed" % name) return if not rssitem.running: ievent.reply('%s watcher is not running' % name) return try: rssitem.watchchannels.remove([bot.name, target]) except ValueError: try: rssitem.watchchannels.remove([bot.name, target]) except ValueError: ievent.reply('we are not monitoring %s on (%s,%s)' % \ (name, bot.name, target)) return watcher.save() ievent.reply('%s stopped' % name)
def auth_POST(server, request): try: input = getpostdata(request) userhost = input['userhost'] perm = input['perm'] except KeyError: rlog(0, request.host, 'auth: no port number or name provided') return dumps('no port userhost/permission provided') return dumps(users.allowed(userhost, perm))
def handle_rssmarkup(bot, ievent): try: name = ievent.args[0] except IndexError: ievent.missing("<name>") return if users.allowed(ievent.userhost, ["OPER"]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: ievent.reply(str(watcher.markup[(name, target)])) except KeyError: pass
def doaway(bot, ievent): """ away callback """ if not users.allowed(ievent.userhost, 'USER'): return # use username of user giving the command name = users.getname(ievent.userhost) if not name: return if awaydict.data.has_key((name, bot.name, ievent.channel)): return ievent.reply("ltrs %s" % ievent.nick) # add away data to entry indexed by username, botname and channel awaydict.data[(name, bot.name, ievent.channel)] = time.time() awaydict.save()
def handle_rssaddmarkup(bot, ievent): try: (name, item, value) = ievent.args except ValueError: ievent.missing("<name> <item> <value>") return if users.allowed(ievent.userhost, ["OPER"]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: watcher.markup.set((name, target), item, value) watcher.markup.save() ievent.reply("%s added to (%s,%s) markuplist" % (item, name, target)) except KeyError: ievent.reply("no (%s,%s) feed available" % (name, target))
def handle_rssadditem(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing('<name> <item>') return if bot.jabber or users.allowed(ievent.userhost, ['OPER', ]): target = ievent.channel.lower() else: target = ievent.nick.lower() if not watcher.byname(name): ievent.reply("we don't have a %s feed" % name) return watcher.itemslists.adduniq(jsonstring([name, target]), item) watcher.itemslists.save() ievent.reply('%s added to (%s,%s) itemslist' % (item, name, target))
def doback(bot, ievent): """ say hello """ if not users.allowed(ievent.userhost, 'USER'): return # reset away entry name = users.getname(ievent.userhost) if not name: return if not awaydict.data.has_key((name, bot.name, ievent.channel)): return ievent.reply("welcome back %s" % ievent.nick) try: del awaydict.data[(name, bot.name, ievent.channel)] awaydict.save() except KeyError: pass
def handle_rssmarkup(bot, ievent): try: name = ievent.args[0] except IndexError: ievent.missing('<name>') return if users.allowed(ievent.userhost, [ 'OPER', ]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: ievent.reply(str(watcher.markup[(name, target)])) except KeyError: pass
def handle_rssdelmarkup(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing("<name> <item>") return if users.allowed(ievent.userhost, ["OPER", "RSS"]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: del watcher.markup[(name, target)][item] except (KeyError, TypeError): ievent.reply("can't remove %s from %s feed's markup" % (item, name)) return watcher.markup.save() ievent.reply("%s removed from (%s,%s) markuplist" % (item, name, target))
def handle_rssdelmarkup(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing('<name> <item>') return if users.allowed(ievent.userhost, ['OPER', 'RSS']): target = ievent.channel.lower() else: target = ievent.nick.lower() try: del watcher.markup[(name, target)][item] except (KeyError, TypeError): ievent.reply("can't remove %s from %s feed's markup" % (item, name)) return watcher.markup.save() ievent.reply('%s removed from (%s,%s) markuplist' % (item, name, target))
def handle_rssaddmarkup(bot, ievent): try: (name, item, value) = ievent.args except ValueError: ievent.missing('<name> <item> <value>') return if users.allowed(ievent.userhost, [ 'OPER', ]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: watcher.markup.set((name, target), item, value) watcher.markup.save() ievent.reply('%s added to (%s,%s) markuplist' % (item, name, target)) except KeyError: ievent.reply("no (%s,%s) feed available" % (name, target))
def handle_rssadditem(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing('<name> <item>') return if bot.jabber or users.allowed(ievent.userhost, [ 'OPER', ]): target = ievent.channel.lower() else: target = ievent.nick.lower() if not watcher.byname(name): ievent.reply("we don't have a %s feed" % name) return watcher.itemslists.adduniq(jsonstring([name, target]), item) watcher.itemslists.save() ievent.reply('%s added to (%s,%s) itemslist' % (item, name, target))
def handle_rssurl(bot, ievent): """ rss-url <name> .. return url of rss item """ try: name = ievent.args[0] except IndexError: ievent.missing('<name>') return result = watcher.url(name) try: if ':' in result.split('@')[0]: if not ievent.msg: ievent.reply('run this command in a private message') return if not users.allowed(ievent.userhost, 'OPER'): ievent.reply('you need have OPER perms') return except (TypeError, ValueError): pass ievent.reply('url of %s: %s' % (name, result))
def handle_rssdelitem(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing('<name> <item>') return if users.allowed(ievent.userhost, ['OPER', 'RSS']): target = ievent.channel.lower() else: target = ievent.nick.lower() if not watcher.byname(name): ievent.reply("we don't have a %s feed" % name) return try: watcher.itemslists.remove((name, target), item) watcher.itemslists.save() except RssNoSuchItem: ievent.reply("we don't have a %s rss feed" % name) return ievent.reply('%s removed from (%s,%s) itemslist' % (item, name, target))
def handle_rssaddmarkup(bot, ievent): try: (name, item, value) = ievent.args except ValueError: ievent.missing('<name> <item> <value>') return if users.allowed(ievent.userhost, ['OPER', ]): target = ievent.channel.lower() else: target = ievent.nick.lower() try: value = int(value) except ValueError: pass try: watcher.markup.set(jsonstring([name, target]), item, value) watcher.markup.save() ievent.reply('%s added to (%s,%s) markuplist' % (item, name, target)) except KeyError: ievent.reply("no (%s,%s) feed available" % (name, target))
def handle_rssdelitem(bot, ievent): try: (name, item) = ievent.args except ValueError: ievent.missing("<name> <item>") return if users.allowed(ievent.userhost, ["OPER", "RSS"]): target = ievent.channel.lower() else: target = ievent.nick.lower() if not watcher.byname(name): ievent.reply("we don't have a %s feed" % name) return try: watcher.itemslists.remove((name, target), item) watcher.itemslists.save() except RssNoSuchItem: ievent.reply("we don't have a %s rss feed" % name) return ievent.reply("%s removed from (%s,%s) itemslist" % (item, name, target))
def handle_rssstart(bot, ievent): """ rss-start <name> .. start a rss feed to a user """ if not ievent.rest: ievent.missing('<feed name>') return name = ievent.rest rssitem = watcher.byname(name) if bot.jabber: if ievent.msg: target = ievent.userhost else: target = ievent.channel else: if users.allowed(ievent.userhost, [ 'OPER', ]) and not ievent.msg: target = ievent.channel else: target = ievent.nick if rssitem == None: ievent.reply("we don't have a %s rss object" % name) return if not rssitem.running: ievent.reply('%s watcher is not running' % name) return if jsonstring([bot.name, target]) in rssitem.watchchannels or [ bot.name, target ] in rssitem.watchchannels: ievent.reply('we are already monitoring %s on (%s,%s)' % \ (name, bot.name, target)) return rssitem.watchchannels.append([bot.name, target]) for item in rssitem.itemslist: watcher.itemslists.adduniq(jsonstring([name, target]), item) watcher.save() ievent.reply('%s started' % name)
def handle_help(bot, ievent): """ help [<cmnd>|<plugin>] .. show help on plugin/command or show basic help msg. """ try: what = ievent.args[0] except IndexError: ievent.reply('help <cmnd> or help <plugin> .. see the !list \ command for a list of available plugins or see !available command for a list \ of plugins to be reloaded') return phelp = plughelp.get(what) cmndresult = [] if phelp: ievent.reply('plugin description: %s' % phelp) perms = list(users.getperms(ievent.userhost)) for i, j in cmnds.iteritems(): if what == j.plugname: for perm in j.perms: if perm in perms: if i not in cmndresult: cmndresult.append(i) if cmndresult: cmndresult.sort() resultstr = "" for i in cmndresult: alias = aliasreverse(i) if alias: resultstr += "%s (%s) .. " % (i, alias) else: resultstr += "%s .. " % i ievent.reply('commands: %s'\ % resultstr[:-4]) else: ievent.reply('no commands available for permission %s' % \ str(perms)) result = [] for i in rebefore.relist: if what == i.plugname: if users.allowed(ievent.userhost, i.perms): result.append(i.regex) for i in reafter.relist: if what == i.plugname: if users.allowed(ievent.userhost, i.perms): result.append(i.regex) if result: resultstr = "" for i in result: resultstr += '"%s" .. ' % i ievent.reply('regular expressions: %s' % resultstr[:-4]) else: pass result = [] for i, j in callbacks.cbs.items(): for z in j: if what == z.plugname: result.append(i) if result: resultstr = "" for i in result: resultstr += "%s .. " % i ievent.reply('callbacks: %s' % resultstr[:-4]) else: pass if not cmndresult: return if what in aliases.data: ievent.reply('%s is an alias for %s' % (what, aliases.data[what])) what = aliases.data[what] try: example = examples[what] except KeyError: return ievent.reply('%s .. alias: %s .. examples: %s' % (example.descr, aliasreverse(what), example.example))
def handle_privmsg(self, ievent): """ check if PRIVMSG is command, if so dispatch. """ if ievent.nick in self.nicks401: rlog(10, self.name, "%s is available again" % ievent.nick) self.nicks401.remove(ievent.nick) if not ievent.txt: return # check if it is a dcc chat request chat = re.search(dccchatre, ievent.txt) if chat: # check if the user is known if users.allowed(ievent.userhost, 'USER'): # start connection start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) return # see if base class method would handle it if '\001' in ievent.txt: Irc.handle_privmsg(self, ievent) return # set bot and socket in ircevent ievent.bot = self ievent.sock = self.sock chan = ievent.channel.lower() # check for /msg if chan == self.nick.lower(): ievent.msg = 1 ievent.speed = 7 ievent.printto = ievent.nick ccs = ['!', '@', self.cfg['defaultcc']] # check for PRIVMSG waiting callback self.privwait.check(ievent) if ievent.isresponse: return if not self.cfg['noccinmsg']: plugins.trydispatch(self, ievent) elif ievent.txt[0] in ccs: ievent.txt = ievent.txt[1:] plugins.trydispatch(self, ievent) return ievent.printto = chan # see if we can get channel control character try: cchar = self.channels[chan]['cc'] except LookupError: cchar = self.cfg['defaultcc'] or '!' except TypeError: cchar = self.cfg['defaultcc'] or '!' # see if cchar matches, if so dispatch ievent.speed = 5 if ievent.txt[0] in cchar: ievent.cc = ievent.txt[0] ievent.txt = ievent.txt[1:] plugins.trydispatch(self, ievent) return # see if were adressed, if so dispatch txtlist = ievent.txt.split(':', 1) if txtlist[0].lower() == self.nick.lower(): if len(txtlist) < 2: return ievent.txt = txtlist[1].strip() plugins.trydispatch(self, ievent) return # habbie addressing mode txtlist = ievent.txt.split(',', 1) if txtlist[0].lower() == self.nick.lower(): if len(txtlist) < 2: return ievent.txt = txtlist[1].strip() plugins.trydispatch(self, ievent) return # check for PRIVMSG waiting callback self.privwait.check(ievent)
def handle_invite(self, ievent): """ join channel if invited by OPER. """ if users.allowed(ievent.userhost, ['OPER', ]): self.join(ievent.txt)