.. _fbf.plugs.extra.topic: topic ~~~~~ .. automodule:: fbf.plugs.extra.topic :show-inheritance: :members: :undoc-members: CODE ---- :: # fbf/plugs/extra/topic.py # # """ manage topics. """ .. _fbf.plugs.extra.topic_fbf_imports: fbf imports -------------- :: from fbf.lib.commands import cmnds from fbf.lib.examples import examples .. _fbf.plugs.extra.topic_basic_imports: basic imports ---------------- :: import time .. _fbf.plugs.extra.topic_checktopicmode_function: checktopicmode function -------------------------- :: def checktopicmode(bot, ievent): """ callback for change in channel topic mode """ chan = ievent.channel mode = ievent.chan.data.mode if mode and 't' in mode: if chan not in bot.state['opchan']: ievent.reply("i'm not op on %s" % chan) return 0 return 1 .. _fbf.plugs.extra.topic_topic_command: topic command ---------------- :: def handle_gettopic(bot, ievent): """ arguments: [] - get topic """ try: channel = ievent.args[0] except IndexError: channel = ievent.channel result = bot.gettopic(channel) try: (what, who, when) = result ievent.reply('topic on %s is %s made by %s on %s' % (channel, what, who, time.ctime(when))) except (ValueError, TypeError): ievent.reply("can't get topic data of channel %s" % channel) cmnds.add('topic', handle_gettopic, 'USER', threaded=True) examples.add('topic', 'get topic', '1) topic 2) topic #dunkbots') .. _fbf.plugs.extra.topic_topic-set_command: topic-set command -------------------- :: def handle_topicset(bot, ievent): """ arguments: - set the topic """ if not bot.jabber and not checktopicmode(bot, ievent): return if not ievent.rest: ievent.missing('') ; return bot.settopic(ievent.channel, ievent.rest) ievent.done() cmnds.add('topic-set', handle_topicset, 'USER', allowqueue=False) examples.add('topic-set', 'set channel topic', 'topic-set Yooo') .. _fbf.plugs.extra.topic_topic-add_command: topic-add command -------------------- :: def handle_topicadd(bot, ievent): """ arguments: - add topic item """ if not bot.jabber and not checktopicmode(bot, ievent): return if not ievent.rest: ievent.missing("") ; return result = bot.gettopic(ievent.channel) if not result: ievent.reply("can't get topic data") ; return what = result[0] what += " | %s" % ievent.rest bot.settopic(ievent.channel, what) ievent.done() cmnds.add('topic-add', handle_topicadd, 'USER', threaded=True) examples.add('topic-add', 'add a topic item to the current topic.', 'topic-add mekker') .. _fbf.plugs.extra.topic_topic-del_command: topic-del command -------------------- :: def handle_topicdel(bot, ievent): """ arguments: - delete topic item """ if not bot.jabber and not checktopicmode(bot, ievent): return try: topicnr = int(ievent.args[0]) except (IndexError, ValueError): ievent.reply('i need a integer as argument') ; return if topicnr < 1: ievent.reply('topic items start at 1') ; return result = bot.gettopic(ievent.channel) if not result: ievent.reply("can't get topic data") ; return what = result[0].split(' | ') if topicnr > len(what): ievent.reply('there are only %s topic items' % len(what)) ; return del what[topicnr-1] newtopic = ' | '.join(what) bot.settopic(ievent.channel, newtopic) ievent.done() cmnds.add('topic-del', handle_topicdel, 'USER', threaded=True) examples.add('topic-del', 'topic-del .. delete topic item', 'topic-del 1') .. _fbf.plugs.extra.topic_topic-move_command: topic-move command --------------------- :: def handle_topicmove(bot, ievent): """ arguments: - move topic item """ if not bot.jabber and not checktopicmode(bot, ievent): return try: (topicfrom, topicto) = ievent.args except ValueError: ievent.missing(' ') ; return try: topicfrom = int(topicfrom) ; topicto = int(topicto) except ValueError: ievent.reply('i need two integers as arguments') ; return if topicfrom < 1 or topicto < 1: ievent.reply('topic items start at 1') ; return topicdata = bot.gettopic(ievent.channel) if not topicdata: ievent.reply("can't get topic data") ; return splitted = topicdata[0].split(' | ') if topicfrom > len(splitted) or topicto > len(splitted): ievent.reply('max item is %s' % len(splitted)) ; return tmp = splitted[topicfrom-1] del splitted[topicfrom-1] splitted.insert(topicto-1, tmp) newtopic = ' | '.join(splitted) bot.settopic(ievent.channel, newtopic) ievent.done() cmnds.add('topic-move', handle_topicmove, 'USER', threaded=True) examples.add('topic-move', 'move topic items', 'topic-move 3 1') .. _fbf.plugs.extra.topic_topic-listadd_command: topic-listadd command ------------------------ :: def handle_topiclistadd(bot, ievent): """ arguments: - add a person to a topic list """ if not bot.jabber and not checktopicmode(bot, ievent): return try: (topicnr, person) = ievent.args except ValueError: ievent.missing(' ') ; return try: topicnr = int(topicnr) except ValueError: ievent.reply('i need an integer as topicnr') ; return if topicnr < 1: ievent.reply('topic items start at 1') ; return topicdata = bot.gettopic(ievent.channel) if not topicdata: ievent.reply("can't get topic data") ; return splitted = topicdata[0].split(' | ') if topicnr > len(splitted): ievent.reply('max item is %s' % len(splitted)) ; return try: topic = splitted[topicnr-1] except IndexError: ievent.reply('no %s topic found' % str(topicnr)) ; return if topic.strip().endswith(':'): topic += " %s" % person else: topic += ",%s" % person splitted[topicnr-1] = topic newtopic = ' | '.join(splitted) bot.settopic(ievent.channel, newtopic) ievent.done() cmnds.add('topic-listadd', handle_topiclistadd, 'USER', threaded=True) examples.add('topic-listadd', 'topic-listadd .. add user to topiclist', 'topic-listadd 1 bart') .. _fbf.plugs.extra.topic_topic-listdel_command: topic-listdel command ------------------------ :: def handle_topiclistdel(bot, ievent): """ arguments: - remove person from topic list """ if not bot.jabber and not checktopicmode(bot, ievent): return try: (topicnr, person) = ievent.args except ValueError: ievent.missing(' ') ; return try: topicnr = int(topicnr) except ValueError: ievent.reply('i need an integer as topicnr') ; return if topicnr < 1: ievent.reply('topic items start at 1') ; return topicdata = bot.gettopic(ievent.channel) if not topicdata: ievent.reply("can't get topic data") ; return splitted = topicdata[0].split(' | ') if topicnr > len(splitted): ievent.reply('max item is %s' % len(splitted)) ; return try: topic = splitted[topicnr-1] except IndexError: ievent.reply('no %s topic found' % str(topicnr)) ; return if not person in topic: ievent.reply('%s is not on the list' % person) ; return l = topic.rsplit(':', 1) try: persons = l[-1].split(',') persons = [i.strip() for i in persons] persons.remove(person) except ValueError: ievent.reply('no %s in list' % person) ; return except IndexError: ievent.reply('i need a : in the topic to work properly') ; return splitted[topicnr-1] = "%s: %s" % (l[0], ','.join(persons)) newtopic = ' | '.join(splitted) bot.settopic(ievent.channel, newtopic) ievent.done() cmnds.add('topic-listdel', handle_topiclistdel, 'USER', threaded=True) examples.add('topic-listdel', 'delete user from topic list', 'topic-listdel 1 bart')