Пример #1
0
    print('got queue analysis results')
    for sub_id, comment_count in num_comments_idx.items():
        if sub_id not in submission_analysis:
            submission_analysis[sub_id] = {}
            submission_analysis[sub_id]['num_comments'] = 0
            submission_analysis[sub_id]['reported_comments'] = set([])
            submission_analysis[sub_id]['reported_to_mods'] = False
        submission_analysis[sub_id]['num_comments'] = max(
            comment_count, submission_analysis[sub_id]['num_comments'])
    for sub_id, reports in reports_idx.items():
        for comment_id in reports:
            submission_analysis[sub_id]['reported_comments'].add(comment_id)
    for sub_id, submission_meta in submission_analysis.items():
        political_toxicity_score = float(
            len(submission_meta['reported_comments'])
        ) / submission_meta['num_comments']
        print('political_toxicity_score for submission {} is {}'.format(
            sub_id, political_toxicity_score))
        if political_toxicity_score > TOXICITY_THRESHOLD and submission_analysis[
                sub_id]['reported_to_mods'] is False:
            toxic_submission = reddit.submission(id=sub_id)
            if toxic_submission.locked:
                print("it's already locked")
            else:
                print('submission at {} is potentially a political wasteland'.
                      format(toxic_submission.shortlink))


if __name__ == "__main__":
    reddit = authorize()
    analyze_queue(reddit)
Пример #2
0
                self.submission_analysis[sub_id] = {}
                self.submission_analysis[sub_id]['num_comments'] = 0
                self.submission_analysis[sub_id]['reported_comments'] = set([])
                self.submission_analysis[sub_id]['reported_to_mods'] = False
            self.submission_analysis[sub_id]['num_comments'] = max(comment_count,
                                                                   self.submission_analysis[sub_id]['num_comments'])
        for sub_id, reports in reports_idx.items():
            for comment_id in reports:
                self.submission_analysis[sub_id]['reported_comments'].add(comment_id)
        for sub_id, submission_meta in self.submission_analysis.items():
            political_toxicity_score = float(len(submission_meta['reported_comments'])) / submission_meta['num_comments']
            print('political_toxicity_score for submission {} is {}'.format(sub_id, political_toxicity_score))
            if political_toxicity_score > TOXICITY_THRESHOLD and self.submission_analysis[sub_id]['reported_to_mods'] is False:
                toxic_submission = self.reddit.submission(id=sub_id)
                if toxic_submission.locked or toxic_submission.removed:
                    continue
                print('submission at {} is potentially a political wasteland'.format(toxic_submission.shortlink))
                self.submission_analysis[sub_id]['reported_to_mods'] = True
                await self.bot.wait_until_ready()
                for guild in self.bot.guilds:
                    for channel in guild.channels:
                        if channel.name == 'rcoronavirus':
                            await channel.send(
                                'The submission at {} is potentially a political wasteland (score={}), '
                                'consider locking comments'.format(toxic_submission.shortlink, political_toxicity_score))


bot = commands.Bot(command_prefix='q!')
reddit_auth = authorize()
bot.add_cog(QueuebotCog(bot, reddit_auth))
bot.run(os.getenv('DISCORD'), bot=True)