🏡 index : ~doyle/dave.git

author Jordan Doyle <jordan@doyle.wf> 2017-08-01 19:36:24.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2017-08-01 19:36:24.0 +01:00:00
commit
5604c5d6f4fc2354df7e7148dc9250f69a323d39 [patch]
tree
d30eef15599088cfab044e8a2c59799e1878e821
parent
6be8841eb9d2d49ad966afe93a8d97f94c4c1538
download
5604c5d6f4fc2354df7e7148dc9250f69a323d39.tar.gz

Don't tell the user about reddit failures (why would they want to know?)



Diff

 dave/modules/reddit.py | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/dave/modules/reddit.py b/dave/modules/reddit.py
index 9e5e5a4..f011e06 100644
--- a/dave/modules/reddit.py
+++ a/dave/modules/reddit.py
@@ -23,7 +23,6 @@
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})

        if req.status_code != 200:
            bot.msg(source, responsestatus(req.status_code, "That post"))
            return

        req = req.json()
@@ -56,8 +55,7 @@
@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 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
@@ -67,11 +65,11 @@
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})

        if req.status_code != 200:
            bot.msg(source, responsestatus(req.status_code, args[0]))
            return

        if "/search.json" in req.url:
            bot.msg(source, responsestatus(404, args[0]))
            # 404'd, reddit redirected us to the search page because they couldn't find
            # the user.
            return

        req = req.json()
@@ -115,7 +113,6 @@
                  headers={'user-agent': 'irc bot (https://github.com/w4)'})

        if req.status_code != 200:
            bot.msg(source, responsestatus(req.status_code, args[0]))
            return

        req = req.json()
@@ -142,13 +139,3 @@
            " Reddit employee." if resp["is_employee"] else ""
        ]
    ))

def responsestatus(status, item):
    if status == 404:
        return "{} does not exist.".format(item)
    elif status == 403:
        return "{} is private.".format(item)
    elif status == 429:
        return "Rate-limited by reddit. Please try again in a few minutes."
    else:
        return "Reddit returned an error, response: {}".format(status)