async def check_inbox(self): await self.bot.wait_until_ready() channel = self.bot.get_channel(740496959311446056) user = await self.bot.reddit.user.me() msgs = [ msg async for msg in user.inbox() if msg.id not in self._msg_ids ] for msg in reversed(msgs): self._msg_ids.add(msg.id) if self._skip_msgs: continue if msg.was_comment: comment = await self.bot.reddit.comment(msg.id) item = RedditItem(comment, self.bot.subreddits[0], "new") embed = await item.get_embed(embed_template=self.bot.embed) else: author = await msg.author() embed = self.bot.embed.set_author( name=f"Message by /u/{msg._data['author']}", url=author._data.get("icon_img", "") or Embed.Empty) embed.description = msg.body embed.timestamp = msg.created_utc message = await channel.send(embed=embed) if msg.was_comment: await item.add_reactions(message) self._skip_msgs = False
async def test_get_embed(self, reddit: apraw.Reddit, subreddit: Subreddit): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: assert isinstance(await item.get_embed(), discord.Embed)
async def test_get_ban_message(self, reddit: apraw.Reddit, subreddit: Subreddit, banhammer: Banhammer): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: assert isinstance( banhammer.message_builder.get_ban_message(item, 10), str)
async def test_url(self, reddit: apraw.Reddit, subreddit: Subreddit): await subreddit.load_reactions() sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: assert item.url in s.url
async def test_get_reactions(self, reddit: apraw.Reddit, subreddit: Subreddit): await subreddit.load_reactions() sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: for r in subreddit.get_reactions(item): assert isinstance(r, Reaction)
async def test_get_item_embed(self, reddit: apraw.Reddit, subreddit: Subreddit, banhammer: Banhammer): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: assert isinstance( await banhammer.message_builder.get_item_embed(item), discord.Embed)
async def test_format_reply(self, reddit: apraw.Reddit, subreddit: Subreddit, banhammer: Banhammer): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break assert item if item: assert isinstance(item.format_reply("Test reply."), str)
async def test_get_message(self, reddit: apraw.Reddit, subreddit: Subreddit): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break payload = ReactionPayload() payload.feed(item, False, "Test", "🔥", "Test reply.") assert isinstance(await payload.get_message(), str)
async def test_get_author_name(self, reddit: apraw.Reddit, subreddit: Subreddit): sub = await reddit.subreddit("banhammerdemo") item = None author = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") author = await s.author() break if item: author_name = await item.get_author_name() assert author_name.lower() == author.name.lower()
async def test_get_reaction(self, reddit: apraw.Reddit, subreddit: Subreddit): await subreddit.load_reactions() sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: emojis = [r.emoji for r in subreddit.get_reactions(item)] if emojis: reaction = subreddit.get_reaction(item, emojis[0]) assert reaction == subreddit.get_reactions(item)[0]
async def handle_reposts(self, item: RedditItem): self._comment_ids.add(item.item.id) try: submission = await item.item.submission() except Exception as e: print(f"Couldn't fetch comment's parent submission: {e}") else: submission_item = RedditItem(submission, item.subreddit, "reports") embed = await submission_item.get_embed(embed_template=self.embed) embed.add_field(name="Comment by /u/RepostSleuthBot", value=f"{item.body}\n\n[Comment.]({item.url})") msg = await self.get_channel(lc_config["reposts_channel"]).send(embed=embed) await submission_item.add_reactions(msg)
async def test_feed(self, reddit: apraw.Reddit, subreddit: Subreddit): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break payload = ReactionPayload() payload.feed(item, False, "Test", "🔥", "Test reply.") assert payload.item == item assert not payload.approved assert payload.user == "Test" assert payload.reply == "Test reply." assert payload.emoji == "🔥"
async def test_is_author_removed(self, reddit: apraw.Reddit, subreddit: Subreddit, banhammer: Banhammer): sub = await reddit.subreddit("banhammerdemo") item = None async for s in sub.new(): item = RedditItem(s, subreddit, "new") break if item: assert not await item.is_author_removed() url = "https://www.reddit.com/r/banhammerdemo/comments/c66rdl" item = await banhammer.get_item(url) if item: assert await item.is_author_removed()