🏡 index : ~doyle/dave.git

author Jordan Doyle <jordan@doyle.wf> 2017-08-01 19:29:45.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2017-08-01 19:33:38.0 +01:00:00
commit
6be8841eb9d2d49ad966afe93a8d97f94c4c1538 [patch]
tree
0d54fb4feb7a9e38799fad0d04f2d61fb908ade9
parent
a56f474ec63603c55cde86b0b286d1a96abd18be
download
6be8841eb9d2d49ad966afe93a8d97f94c4c1538.tar.gz

If a subreddit/post/user is mentioned, don't give information about again it for 5 minutes



Diff

 dave/modules/reddit.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/dave/modules/reddit.py b/dave/modules/reddit.py
index 65fc2e0..9e5e5a4 100644
--- a/dave/modules/reddit.py
+++ a/dave/modules/reddit.py
@@ -13,6 +13,11 @@
@dave.module.dont_always_run_if_run()
def post(bot, args, sender, source):
    """Ran whenever a reddit post is sent"""
    if dave.config.redis.exists("reddit:post:mentioned:{}:{}".format(args[0], source)):
        # if this post was mentioned in the last x seconds (see the setex below),
        # don't spam info about it
        return

    if not dave.config.redis.exists("reddit:post:{}".format(args[0])):
        req = get("https://reddit.com/{}.json?limit=1".format(args[0]),
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})
@@ -30,6 +35,8 @@

    resp = req[0]["data"]["children"][0]["data"]

    dave.config.redis.setex("reddit:post:mentioned:{}:{}".format(args[0], source), 300, 1)

    bot.msg(source, assembleFormattedText(
        A.normal[
            A.bold[A.fg.lightRed["[NSFW] "]] if resp["over_18"] else "",
@@ -49,6 +56,12 @@
@dave.module.dont_always_run_if_run()
def subreddit(bot, args, sender, source):
    """Ran whenever a subreddit is mentioned"""
    if dave.config.redis.exists("reddit:subreddit:mentioned:{}:{}".format(args[0],
                                                                          source)):
        # if this subreddit was mentioned in the last x seconds (see the setex below),
        # don't spam info about it
        return

    if not dave.config.redis.exists("reddit:subreddit:{}".format(args[0])):
        req = get("https://reddit.com/r/{}/about.json".format(args[0]),
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})
@@ -70,6 +83,10 @@

    resp = req["data"]

    # don't give info about this user again in this channel for 300 seconds
    dave.config.redis.setex("reddit:subreddit:mentioned:{}:{}".format(args[0], source),
                            300, 1)

    bot.msg(source, assembleFormattedText(
        A.normal[
            A.bold[A.fg.lightRed["[NSFW] "]] if resp["over18"] else "",
@@ -88,6 +105,11 @@
@dave.module.ratelimit(1, 1)
@dave.module.dont_always_run_if_run()
def user(bot, args, sender, source):
    if dave.config.redis.exists("reddit:user:mentioned:{}:{}".format(args[0], source)):
        # if this user was mentioned in the last x seconds (see the setex below), don't
        # spam info about them
        return

    if not dave.config.redis.exists("reddit:user:{}".format(args[0])):
        req = get("https://reddit.com/u/{}/about.json".format(args[0]),
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})
@@ -104,6 +126,9 @@
        req = pickle.loads(dave.config.redis.get("reddit:user:{}".format(args[0])))

    resp = req["data"]

    # don't give info about this user again in this channel for 300 seconds
    dave.config.redis.setex("reddit:user:mentioned:{}:{}".format(args[0], source), 300, 1)

    bot.msg(source, assembleFormattedText(
        A.normal[