示例#1
0
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)
示例#2
0
def handle_rssdelchannel(bot, ievent):
    """ rss-delchannel <name> [<botname>] <channel> .. delete channel \
        from rss item """
    botname = None
    try:
        (name, botname, channel) = ievent.args
    except ValueError:
        try:
            (name, channel) = ievent.args
            botname = bot.name
        except ValueError:
            try:
                name = ievent.args[0]
                botname = bot.name
                channel = ievent.channel
            except IndexError:
                ievent.missing('<name> [<botname>] [<channel>]')
                return
    rssitem = watcher.byname(name)
    if rssitem == None:
        ievent.reply("we don't have a %s rss object" % name)
        return
    if jsonstring([botname, channel]) in rssitem.watchchannels:
        rssitem.watchchannels.remove(jsonstring([botname, channel]))
        ievent.reply('%s removed from %s rss item' % (channel, name))
    elif [botname, channel] not in rssitem.watchchannels:
        rssitem.watchchannels.remove([botname, channel])
        ievent.reply('%s removed from %s rss item' % (channel, name))
    else:
        ievent.reply('we are not monitoring %s on (%s,%s)' % (name, botname, \
channel))
        return
    watcher.save()
示例#3
0
def handle_rssdelchannel(bot, ievent):
    """ rss-delchannel <name> [<botname>] <channel> .. delete channel \
        from rss item """
    botname = None
    try:
        (name, botname, channel) = ievent.args
    except ValueError:
        try:
            (name, channel) = ievent.args
            botname = bot.name
        except ValueError:
            try:
                name = ievent.args[0]
                botname = bot.name
                channel = ievent.channel
            except IndexError:
                ievent.missing('<name> [<botname>] [<channel>]')
                return
    rssitem = watcher.byname(name)
    if rssitem == None:
        ievent.reply("we don't have a %s rss object" % name)
        return
    if jsonstring([botname, channel]) in rssitem.watchchannels:
        rssitem.watchchannels.remove(jsonstring([botname, channel]))
        ievent.reply('%s removed from %s rss item' % (channel, name))
    elif [botname, channel] not in rssitem.watchchannels:
        rssitem.watchchannels.remove([botname, channel])
        ievent.reply('%s removed from %s rss item' % (channel, name))
    else:
        ievent.reply('we are not monitoring %s on (%s,%s)' % (name, botname, \
channel))
        return
    watcher.save()
示例#4
0
    def peek(self, name, *args):
        rssitem = self.byname(name)
        if not rssitem or not rssitem.running or rssitem.stoprunning:
            return
        try:
            try:
                res = self.getdata(name)
            except socket.timeout:
                rlog(10, 'rss', 'socket timeout of %s' % name)
                return
            except RssException, ex:
                rlog(10, 'rss', '%s error: %s' % (name, str(ex)))
                return
            if not res:
                return
            res2 = []
            for j in res:
                try:
                    d = j['updated'] 
                except KeyError:
                    if j not in self.results[name]:
                        self.results[name].append(j)
                        res2.append(j)
                else:
                    if not checkfordate(self.results[name], d):
                        self.results[name].append(j)
                        res2.append(j)
            if not res2:
                return
            for item in rssitem.watchchannels:
                try:
                    (botname, channel) = item
                except:
                    try:
                        (botname, channel) = loads(item)
                    except:
                        rlog(10, 'rss', '%s is not in the format \
(botname,channel)' % str(item))
                bot = fleet.byname(botname)
                if not bot:
                    continue
                if self.markup.get(jsonstring([name, channel]), 'reverse-order'):
                    res2 = res2[::-1]
                if self.markup.get(jsonstring([name, channel]), 'all-lines'):
                    for i in res2:
                        response = self.makeresponse(name, [i, ], channel)
                        bot.say(channel, "\002%s\002: %s" % \
(rssitem.name, response), fromm=rssitem.name)
                else:
                    sep =  self.markup.get(jsonstring([name, channel]), 'separator')
                    if sep:
                        response = self.makeresponse(name, res2, channel, \
sep=sep)
                    else:
                        response = self.makeresponse(name, res2, channel)
                    bot.say(channel, "\002%s\002: %s" % (rssitem.name, \
response), fromm=rssitem.name)
示例#5
0
 def makeresult(self, name, target, data):
     res = []
     for j in data:
         tmp = {}
         if not self.itemslists[jsonstring([name, target])]:
             return []
         for i in self.itemslists[jsonstring([name, target])]:
             try:
                 tmp[i] = unicode(j[i])
             except KeyError:
                 continue
         res.append(tmp)
     return res
示例#6
0
 def makeresult(self, name, target, data):
     res = []
     for j in data:
         tmp = {}
         if not self.itemslists[jsonstring([name, target])]:
             return []
         for i in self.itemslists[jsonstring([name, target])]:
             try:
                 tmp[i] = unicode(j[i])
             except KeyError:
                 continue
         res.append(tmp)
     return res
示例#7
0
def handle_gotchan(bot, ievent):
    """ got-chan <listofnrs> .. remove items from channel shoplist """
    if len(ievent.args) == 0:
        ievent.missing('<list of nrs>')
        return
    try:
        nrs = []
        for i in ievent.args:
            nrs.append(int(i))
    except ValueError:
        ievent.reply('%s is not an integer' % i)
        return
    try:
        shop = shops[jsonstring((bot.name, ievent.channel))]
    except KeyError:
        ievent.reply("nothing to shop")
        return
    if not shop:
        ievent.reply("nothing to shop")
        return
    nrs.sort()
    nrs.reverse()
    teller = 0
    for i in range(len(shop)-1, -1 , -1):
        if i in nrs:
            try:
                del shop[i]
                teller += 1
            except IndexError:
                pass
    shops.save()
    ievent.reply('%s shop item(s) deleted' % teller)
示例#8
0
 def feeds(self, botname, channel):
     """ show names/channels of running watcher """
     result = []
     for j, z in self.data.iteritems():
         if jsonstring([botname, channel]) in z.watchchannels or [botname, channel] in z.watchchannels:
             result.append(z.name)
     return result
示例#9
0
def handle_shopchan(bot, ievent):
    """ shop-chan [<item>] .. show channel shop list or add <item> """
    if len(ievent.args) != 0:
        handle_shopchan2(bot, ievent)
        return
    shop = shops[jsonstring((bot.name, ievent.channel))]
    sayshop(bot, ievent, shop)
示例#10
0
def handle_gotchan(bot, ievent):
    """ got-chan <listofnrs> .. remove items from channel shoplist """
    if len(ievent.args) == 0:
        ievent.missing('<list of nrs>')
        return
    try:
        nrs = []
        for i in ievent.args:
            nrs.append(int(i))
    except ValueError:
        ievent.reply('%s is not an integer' % i)
        return
    try:
        shop = shops[jsonstring((bot.name, ievent.channel))]
    except KeyError:
        ievent.reply("nothing to shop")
        return
    if not shop:
        ievent.reply("nothing to shop")
        return
    nrs.sort()
    nrs.reverse()
    teller = 0
    for i in range(len(shop) - 1, -1, -1):
        if i in nrs:
            try:
                del shop[i]
                teller += 1
            except IndexError:
                pass
    shops.save()
    ievent.reply('%s shop item(s) deleted' % teller)
示例#11
0
def handle_rssaddchannel(bot, ievent):
    """ rss-addchannel <name> [<botname>] <channel> .. add a channel to \
        rss item """
    try:
        (name, botname, channel) = ievent.args
    except ValueError:
        try:
            (name, channel) = ievent.args
            botname = bot.name
        except ValueError:
            try:
                name = ievent.args[0]
                botname = bot.name
                channel = ievent.channel
            except IndexError:
                ievent.missing('<name> [<botname>] <channel>')
                return
    rssitem = watcher.byname(name)
    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([botname, channel]) in rssitem.watchchannels or [botname, channel] in rssitem.watchchannels:
        ievent.reply('we are already monitoring %s on (%s,%s)' % \
(name, botname, channel))
        return
    rssitem.watchchannels.append([botname, channel])
    watcher.save()
    ievent.reply('%s added to %s rss item' % (channel, name))
示例#12
0
def handle_shopchan(bot, ievent):
    """ shop-chan [<item>] .. show channel shop list or add <item> """
    if len(ievent.args) != 0:
        handle_shopchan2(bot, ievent)
        return
    shop = shops[jsonstring((bot.name, ievent.channel))]
    sayshop(bot, ievent, shop)
示例#13
0
def handle_anondisable(bot, ievent):
    try:
        cfg.remove('enable', jsonstring([bot.name, ievent.channel]))
        ievent.reply('anon disabled on (%s,%s)' % (bot.name, ievent.channel))
    except (KeyError, ValueError):
        ievent.reply('anon is not enabled on (%s,%s)' % (bot.name, \
ievent.channel))
示例#14
0
def handle_rssaddchannel(bot, ievent):
    """ rss-addchannel <name> [<botname>] <channel> .. add a channel to \
        rss item """
    try:
        (name, botname, channel) = ievent.args
    except ValueError:
        try:
            (name, channel) = ievent.args
            botname = bot.name
        except ValueError:
            try:
                name = ievent.args[0]
                botname = bot.name
                channel = ievent.channel
            except IndexError:
                ievent.missing('<name> [<botname>] <channel>')
                return
    rssitem = watcher.byname(name)
    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([botname, channel]) in rssitem.watchchannels or [
            botname, channel
    ] in rssitem.watchchannels:
        ievent.reply('we are already monitoring %s on (%s,%s)' % \
(name, botname, channel))
        return
    rssitem.watchchannels.append([botname, channel])
    watcher.save()
    ievent.reply('%s added to %s rss item' % (channel, name))
示例#15
0
 def feeds(self, botname, channel):
     """ show names/channels of running watcher """
     result = []
     for j, z in self.data.iteritems():
         if jsonstring([botname, channel]) in z.watchchannels or [
                 botname, channel
         ] in z.watchchannels:
             result.append(z.name)
     return result
示例#16
0
def handle_shopchan2(bot, ievent):
    """ add items to shop list """
    if not ievent.rest:
        ievent.missing('<shopitem>')
        return
    else:
        what = ievent.rest
    shops[jsonstring((bot.name, ievent.channel))] = what
    shops.save()
    ievent.reply('shop item added')
示例#17
0
def handle_shopchan2(bot, ievent):
    """ add items to shop list """
    if not ievent.rest:
        ievent.missing('<shopitem>')
        return
    else:
        what = ievent.rest
    shops[jsonstring((bot.name, ievent.channel))] = what
    shops.save()
    ievent.reply('shop item added')
示例#18
0
def handle_idle2(bot, ievent):
    """ show how idle a channel has been """
    chan = ievent.channel
    try:
        elapsed = elapsedstring(time.time()-idle.data[jsonstring((bot.name, chan))])
    except KeyError:
        ievent.reply("nobody said anything on channel %s yet" % chan)
        return
    if elapsed:
        ievent.reply("channel %s is idle for %s" % (chan, elapsed))
    else:
        ievent.reply("channel %s is not idle" % chan)
示例#19
0
    def makeresponse(self, name, res, channel, sep="\002||\002"):
        # loop over result to make a response
        result = u""
        itemslist = self.itemslists[jsonstring([name, channel])]
        if not itemslist:
            rssitem = self.byname(name)
            if not rssitem:
                return "no %s rss item" % name
            else:
                self.itemslists.extend(jsonstring([name, channel]),
                                       rssitem.itemslist)
                self.itemslists.save()
        for j in res:
            if self.markup.get(jsonstring([name, channel]), \
'skipmerge') and 'Merge branch' in j['title']:
                continue
            resultstr = u""
            for i in self.itemslists[jsonstring([name, channel])]:
                try:
                    item = unicode(j[i])
                    if not item:
                        continue
                    if item.startswith('http://'):
                        if self.markup.get(jsonstring([name, channel]), \
'tinyurl'):
                            try:
                                tinyurl = get_tinyurl(item)
                                if not tinyurl:
                                    resultstr += u"<%s> - " % item
                                else:
                                    resultstr += u"<%s> - " % tinyurl[0]
                            except Exception, ex:
                                handle_exception()
                                resultstr += u"<%s> - " % item
                        else:
                            resultstr += u"<%s> - " % item
                    else:
                        resultstr += u"%s - " % item.strip()
                except KeyError:
                    continue
示例#20
0
    def makeresponse(self, name, res, channel, sep="\002||\002"):
        # loop over result to make a response
        result = u""
        itemslist = self.itemslists[jsonstring([name, channel])]
        if not itemslist:
            rssitem = self.byname(name)
            if not rssitem:
                return "no %s rss item" % name
            else:
                self.itemslists.extend(jsonstring([name, channel]), rssitem.itemslist)
                self.itemslists.save()
        for j in res:
            if self.markup.get(jsonstring([name, channel]), \
'skipmerge') and 'Merge branch' in j['title']:
                continue
            resultstr = u""
            for i in self.itemslists[jsonstring([name, channel])]:
                try:
                    item = unicode(j[i])
                    if not item:
                        continue
                    if item.startswith('http://'):
                        if self.markup.get(jsonstring([name, channel]), \
'tinyurl'):
                            try:
                                tinyurl = get_tinyurl(item)
                                if not tinyurl:
                                    resultstr += u"<%s> - " % item
                                else:
                                    resultstr += u"<%s> - " % tinyurl[0]
                            except Exception, ex:
                                handle_exception()
                                resultstr += u"<%s> - " % item
                        else:
                            resultstr += u"<%s> - " % item
                    else:
                        resultstr += u"%s - " % item.strip()
                except KeyError:
                    continue
示例#21
0
def handle_idle2(bot, ievent):
    """ show how idle a channel has been """
    chan = ievent.channel
    try:
        elapsed = elapsedstring(time.time() -
                                idle.data[jsonstring((bot.name, chan))])
    except KeyError:
        ievent.reply("nobody said anything on channel %s yet" % chan)
        return
    if elapsed:
        ievent.reply("channel %s is idle for %s" % (chan, elapsed))
    else:
        ievent.reply("channel %s is not idle" % chan)
示例#22
0
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[jsonstring([name, target])]))
    except KeyError:
        pass
示例#23
0
def handle_rssitemslist(bot, ievent):
    """ rss-itemslist <name> .. show itemslist of rss item """
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    try:
        itemslist = watcher.itemslists[jsonstring([name, ievent.channel.lower()])]
    except KeyError:
        ievent.reply("no itemslist set for (%s, %s)" % (name, \
ievent.channel.lower()))
        return
    ievent.reply("itemslist of (%s, %s): " % (name, ievent.channel.lower()), \
itemslist, dot=True)
示例#24
0
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)
示例#25
0
def handle_markovenable(bot, ievent):
    """ enable markov in a channel .. learn the log of that channel """
    try:
        channel = ievent.args[0]
    except IndexError:
        channel = ievent.channel
    if not enabled(bot.name, channel):
        cfg.get('enable').append(jsonstring([bot.name, channel]))
    else:
        ievent.reply('%s is already enabled' % channel)
        return
    cfg.save()
    markovlearn.data.append(channel)
    markovlearn.save()
    plugins.reload('gozerplugs', 'markov')
    ievent.reply('%s enabled' % channel)
示例#26
0
def handle_rssitemslist(bot, ievent):
    """ rss-itemslist <name> .. show itemslist of rss item """
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    try:
        itemslist = watcher.itemslists[jsonstring(
            [name, ievent.channel.lower()])]
    except KeyError:
        ievent.reply("no itemslist set for (%s, %s)" % (name, \
ievent.channel.lower()))
        return
    ievent.reply("itemslist of (%s, %s): " % (name, ievent.channel.lower()), \
itemslist, dot=True)
示例#27
0
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))
示例#28
0
def handle_markovenable(bot, ievent):
    """ enable markov in a channel .. learn the log of that channel """
    try:
        channel = ievent.args[0]
    except IndexError:
        channel = ievent.channel
    if not enabled(bot.name, channel):
        cfg.get('enable').append(jsonstring([bot.name, channel]))
    else:
        ievent.reply('%s is already enabled' % channel)
        return
    cfg.save()
    markovlearn.data.append(channel)
    markovlearn.save()
    plugins.reload('gozerplugs', 'markov')
    ievent.reply('%s enabled' % channel)
示例#29
0
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[jsonstring([name, target])]))
    except KeyError:
        pass
示例#30
0
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[jsonstring([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))
示例#31
0
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[jsonstring([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))
示例#32
0
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))
示例#33
0
def cb_markovjoin(bot, ievent):
    """ callback to run on JOIN """
    # check if its we who are joining
    nick = ievent.nick.lower()
    if nick in bot.splitted:
        return
    if nick == bot.nick.lower():
        return
    # check if (bot.name, ievent.channel) is in onjoin list if so respond
    try:
        onjoin = cfg.get('onjoin')
    except KeyError:
        onjoin = None
    if type(onjoin) != types.ListType:
        return
    if jsonstring([bot.name, ievent.channel]) in onjoin:
        txt = getreply(bot, ievent, ievent.nick + ':')
        if txt:
            ievent.reply('%s: %s' % (ievent.nick, txt))
示例#34
0
def cb_markovjoin(bot, ievent):
    """ callback to run on JOIN """
    # check if its we who are joining
    nick = ievent.nick.lower()
    if nick in bot.splitted:
        return
    if nick == bot.nick.lower():
        return
    # check if (bot.name, ievent.channel) is in onjoin list if so respond
    try:
        onjoin = cfg.get('onjoin')
    except KeyError:
        onjoin = None
    if type(onjoin) != types.ListType:
        return
    if jsonstring([bot.name, ievent.channel]) in onjoin:
        txt = getreply(bot, ievent, ievent.nick + ':')
        if txt:
            ievent.reply('%s: %s' % (ievent.nick, txt))
示例#35
0
def handle_markovdisable(bot, ievent):
    """ disable markov in a channel """
    try:
        channel = ievent.args[0]
    except IndexError:
        channel = ievent.channel
    if enabled(bot.name, channel):
        cfg.get('enable').remove(jsonstring([bot.name, channel]))
    else:
        ievent.reply('%s is not enabled' % channel)
        return
    cfg.save()
    try:
        markovlearn.data.remove(channel)
        markovlearn.save()
    except ValueError:
        pass
    plugins.reload('gozerplugs', 'markov')
    ievent.reply('%s disabled' % channel)
示例#36
0
def handle_markovdisable(bot, ievent):
    """ disable markov in a channel """
    try:
        channel = ievent.args[0]
    except IndexError:
        channel = ievent.channel
    if enabled(bot.name, channel):
        cfg.get('enable').remove(jsonstring([bot.name, channel]))
    else:
        ievent.reply('%s is not enabled' % channel)
        return
    cfg.save()
    try:
        markovlearn.data.remove(channel)
        markovlearn.save()
    except ValueError:
        pass
    plugins.reload('gozerplugs', 'markov')
    ievent.reply('%s disabled' % channel)
示例#37
0
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))
示例#38
0
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(jsonstring([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))
示例#39
0
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(jsonstring([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))
示例#40
0
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:
        elapsed = elapsedstring(time.time() - idle.data[jsonstring((bot.name, userhost))])
    except KeyError:
        ievent.reply("i haven't seen %s" % who)
        return
    if elapsed:
        ievent.reply("%s is idle for %s" % (who, elapsed))
        return
    else:
        ievent.reply("%s is not idle" % who)
        return   
示例#41
0
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))
示例#42
0
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:
        elapsed = elapsedstring(time.time() -
                                idle.data[jsonstring((bot.name, userhost))])
    except KeyError:
        ievent.reply("i haven't seen %s" % who)
        return
    if elapsed:
        ievent.reply("%s is idle for %s" % (who, elapsed))
        return
    else:
        ievent.reply("%s is not idle" % who)
        return
示例#43
0
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
示例#44
0
def enabled(botname, channel):
    if jsonstring([botname, channel]) in cfg['enable']:
        return True
示例#45
0
def anonpre(bot, ievent):
    if 'OPER' not in cfg.get('perms') and \
jsonstring([bot.name, ievent.channel]) in cfg.get('enable'):
        return 1
示例#46
0
def enabled(botname, channel):
    if jsonstring([botname, channel]) in cfg['enable']:
        return True
示例#47
0
def handle_anonenable(bot, ievent):
    cfg.append('enable', jsonstring([bot.name, ievent.channel]))
    ievent.reply('anon enabled on (%s,%s)' % (bot.name, ievent.channel))
示例#48
0
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    channel = ievent.channel
    rssitem = watcher.byname(name)
    if rssitem == None:
        ievent.reply("we don't have a %s rss item" % name)
        return
    try:
        result = watcher.getdata(name)
    except Exception, ex:
        ievent.reply('%s error: %s' % (name, str(ex)))
        return
    if watcher.markup.get(jsonstring([name, channel]), 'reverse-order'):
        result = result[::-1]
    response = None
    go = watcher.markup.get(jsonstring([name, channel]), 'all-lines')
    if go:
        for i in result:
            response = watcher.makeresponse(name, [i, ], channel)
            bot.say(channel, "\002%s\002: %s" % (rssitem.name, response), \
fromm=rssitem.name)
    else:
        response = watcher.makeresponse(name, result, ievent.channel)
        if response:
            ievent.reply("results of %s: %s" % (name, response))
        else:
            ievent.reply("can't match watcher data")
示例#49
0
def handle_anondisable(bot, ievent):
    try:
        cfg.remove("enable", jsonstring([bot.name, ievent.channel]))
        ievent.reply("anon disabled on (%s,%s)" % (bot.name, ievent.channel))
    except (KeyError, ValueError):
        ievent.reply("anon is not enabled on (%s,%s)" % (bot.name, ievent.channel))
示例#50
0
def handle_anonenable(bot, ievent):
    cfg.append("enable", jsonstring([bot.name, ievent.channel]))
    ievent.reply("anon enabled on (%s,%s)" % (bot.name, ievent.channel))
示例#51
0
def anonpre(bot, ievent):
    if "OPER" not in cfg.get("perms") and jsonstring([bot.name, ievent.channel]) in cfg.get("enable"):
        return 1
示例#52
0
    def peek(self, name, *args):
        rssitem = self.byname(name)
        if not rssitem or not rssitem.running or rssitem.stoprunning:
            return
        try:
            try:
                res = self.getdata(name)
            except socket.timeout:
                rlog(10, 'rss', 'socket timeout of %s' % name)
                return
            except RssException, ex:
                rlog(10, 'rss', '%s error: %s' % (name, str(ex)))
                return
            if not res:
                return
            res2 = []
            for j in res:
                try:
                    d = j['updated']
                except KeyError:
                    if j not in self.results[name]:
                        self.results[name].append(j)
                        res2.append(j)
                else:
                    if not checkfordate(self.results[name], d):
                        self.results[name].append(j)
                        res2.append(j)
            if not res2:
                return
            for item in rssitem.watchchannels:
                try:
                    (botname, channel) = item
                except:
                    try:
                        (botname, channel) = loads(item)
                    except:
                        rlog(
                            10, 'rss', '%s is not in the format \
(botname,channel)' % str(item))
                bot = fleet.byname(botname)
                if not bot:
                    continue
                if self.markup.get(jsonstring([name, channel]),
                                   'reverse-order'):
                    res2 = res2[::-1]
                if self.markup.get(jsonstring([name, channel]), 'all-lines'):
                    for i in res2:
                        response = self.makeresponse(name, [
                            i,
                        ], channel)
                        bot.say(channel, "\002%s\002: %s" % \
(rssitem.name, response), fromm=rssitem.name)
                else:
                    sep = self.markup.get(jsonstring([name, channel]),
                                          'separator')
                    if sep:
                        response = self.makeresponse(name, res2, channel, \
sep=sep)
                    else:
                        response = self.makeresponse(name, res2, channel)
                    bot.say(channel, "\002%s\002: %s" % (rssitem.name, \
response), fromm=rssitem.name)
示例#53
0
    try:
        name = ievent.args[0]
    except IndexError:
        ievent.missing('<name>')
        return
    channel = ievent.channel
    rssitem = watcher.byname(name)
    if rssitem == None:
        ievent.reply("we don't have a %s rss item" % name)
        return
    try:
        result = watcher.getdata(name)
    except Exception, ex:
        ievent.reply('%s error: %s' % (name, str(ex)))
        return
    if watcher.markup.get(jsonstring([name, channel]), 'reverse-order'):
        result = result[::-1]
    response = None
    go = watcher.markup.get(jsonstring([name, channel]), 'all-lines')
    if go:
        for i in result:
            response = watcher.makeresponse(name, [
                i,
            ], channel)
            bot.say(channel, "\002%s\002: %s" % (rssitem.name, response), \
fromm=rssitem.name)
    else:
        response = watcher.makeresponse(name, result, ievent.channel)
        if response:
            ievent.reply("results of %s: %s" % (name, response))
        else:
示例#54
0
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