Exemplo n.º 1
0
 def test_not_voted_on2(self):
     comment = reddit.client().comment(id="dzfj0ws")
     response = StemmingResponder().respond(comment)
     self.assertDictEqual(
         response, {
             'template': 'stemming',
             'not_in_voting': set(),
             'not_voted_on': {'M0295'},
             'incorrect_keyword': set()
         })
Exemplo n.º 2
0
 def test_no_vote_at_all(self):
     comment = reddit.client().comment(id="dzrpoad")
     response = StemmingResponder().respond(comment)
     self.assertIsNone(response)
Exemplo n.º 3
0
def main():
    responders = [
        VoorzitterResponder(),
        StemmingResponder(),
        EKResponder(),
        EKTKResponder(),
        TKResponder()
    ]

    for comment in reddit.client().subreddit('rmtk').stream.comments():
        try:
            comment.refresh()

            if isinstance(comment, MoreComments):
                continue
            if comment.body and ("meta" in comment.body.lower()
                                 or comment.body == '[deleted]'):
                continue

            if comment.author and comment.author.name in [
                    'AutoRMTK', 'AutoModerator'
            ]:
                continue

            responses = [
                response for response in
                [responder.respond(comment) for responder in responders]
                if response != None
            ]

            if len(responses) < 1:
                continue

            rendered_responses = [
                Template(
                    open('templates/responses/' + r['template'] +
                         '.md').read()).render(r) for r in responses
            ]

            response_text = Template(
                open('templates/response.md').read()).render(
                    rendered_responses=rendered_responses)

            debug_permalink = comment.permalink

            prev = [
                c for c in comment.replies.list()
                if c and not isinstance(c, MoreComments) and c.author
                and c.author.name == 'AutoRMTK'
            ]

            if prev:
                prev[0].edit(response_text)
            else:
                comment.reply(response_text)
        except Exception as e:
            print(e)
            print('*****')

            client = Client(os.getenv('SENTRY_URL'))
            client.captureException()

            continue
Exemplo n.º 4
0
 def test_follows_format3(self):
     comment = reddit.client().comment(id="e041767")
     response = StemmingResponder().respond(comment)
     self.assertIsNone(response)
 def comment_valid(self, comment: Comment):
     return os.getenv('AUTORMTK_ENV') == 'ci' or [None, None, None] == [r.respond(comment) for r in [StemmingResponder(), TKResponder(), EKResponder()]]