From 3e798b2ee0c63907583cc07163ef63afb26c102b Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Sun, 29 Sep 2019 14:24:34 +0200 Subject: Add humanized delta and content to confirmation message --- bot/cogs/reminders.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 6e91d2c06..695cd36ae 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -170,9 +170,12 @@ class Reminders(Scheduler, Cog): } ) + now = datetime.utcnow() + # Confirm to the user that it worked. await self._send_confirmation( - ctx, on_success="Your reminder has been created successfully!" + ctx, + on_success=f"Your reminder `{content}` will arrive in {humanize_delta(relativedelta(expiration, now))}!" ) loop = asyncio.get_event_loop() -- cgit v1.2.3 From aecda4ced7150d3c246220d7aee54635fe6d0082 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 30 Sep 2019 16:35:31 +0200 Subject: Add jump url --- bot/cogs/reminders.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 695cd36ae..4a470a640 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -100,9 +100,11 @@ class Reminders(Scheduler, Cog): embed.set_author( icon_url=Icons.remind_blurple, name="It has arrived!" - ) - - embed.description = f"Here's your reminder: `{reminder['content']}`" + + if "jump_url" in reminder: # keep backward compatibility + embed.description = f"Here's your reminder: `{reminder['content']}`. Jump back when you created the reminder : {jump_url}" + else: + embed.description = f"Here's your reminder: `{reminder['content']}`" if late: embed.colour = Colour.red() @@ -165,6 +167,7 @@ class Reminders(Scheduler, Cog): json={ 'author': ctx.author.id, 'channel_id': ctx.message.channel.id, + 'jump_url': ctx.message.jump_url, 'content': content, 'expiration': expiration.isoformat() } -- cgit v1.2.3 From 387bb50518e3766f543e23f8efe6821fb0527dd7 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 30 Sep 2019 18:55:53 +0200 Subject: Fix linting error Fix some liting error Correct error Fix linting (maybe) --- bot/cogs/reminders.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 4a470a640..27954d10e 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -99,10 +99,11 @@ class Reminders(Scheduler, Cog): embed.colour = Colour.blurple() embed.set_author( icon_url=Icons.remind_blurple, - name="It has arrived!" - - if "jump_url" in reminder: # keep backward compatibility - embed.description = f"Here's your reminder: `{reminder['content']}`. Jump back when you created the reminder : {jump_url}" + name="It has arrived!") + + if "jump_url" in reminder: # keep backward compatibility + embed.description = (f"Here's your reminder: `{reminder['content']}`." + f"Jump back when you created the reminder : {reminder['jump_url']}") else: embed.description = f"Here's your reminder: `{reminder['content']}`" -- cgit v1.2.3 From 72734cb0cb3ac7292009d62f5c9fd0f367aa139a Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Sun, 6 Oct 2019 13:03:22 +0200 Subject: Add line break between the reminder and the jump url --- bot/cogs/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 27954d10e..288035b56 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -102,7 +102,7 @@ class Reminders(Scheduler, Cog): name="It has arrived!") if "jump_url" in reminder: # keep backward compatibility - embed.description = (f"Here's your reminder: `{reminder['content']}`." + embed.description = (f"Here's your reminder: `{reminder['content']}`.\n" f"Jump back when you created the reminder : {reminder['jump_url']}") else: embed.description = f"Here's your reminder: `{reminder['content']}`" -- cgit v1.2.3 From 859ca0be8acf2a1fa229ca2972fc4989abb32584 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 7 Oct 2019 12:11:32 +0200 Subject: Fix my broken English Co-Authored-By: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> --- bot/cogs/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 288035b56..1b38d0bb2 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -103,7 +103,7 @@ class Reminders(Scheduler, Cog): if "jump_url" in reminder: # keep backward compatibility embed.description = (f"Here's your reminder: `{reminder['content']}`.\n" - f"Jump back when you created the reminder : {reminder['jump_url']}") + f"Jump back to when you created the reminder : {reminder['jump_url']}") else: embed.description = f"Here's your reminder: `{reminder['content']}`" -- cgit v1.2.3 From 5a8feefd6fe28b9f0030e6c221c982905848a74a Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 7 Oct 2019 12:17:55 +0200 Subject: Turn the jump URL into a clickable link --- bot/cogs/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 1b38d0bb2..16c431448 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -103,7 +103,7 @@ class Reminders(Scheduler, Cog): if "jump_url" in reminder: # keep backward compatibility embed.description = (f"Here's your reminder: `{reminder['content']}`.\n" - f"Jump back to when you created the reminder : {reminder['jump_url']}") + f"[Jump back to when you created the reminder]({reminder['jump_url']})") else: embed.description = f"Here's your reminder: `{reminder['content']}`" -- cgit v1.2.3 From 716cb544c95fe9ed98981fd18245cedd625daa8c Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 7 Oct 2019 12:39:30 +0200 Subject: Delete “confirmation echo” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/cogs/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 16c431448..d06dbcc7f 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -179,7 +179,7 @@ class Reminders(Scheduler, Cog): # Confirm to the user that it worked. await self._send_confirmation( ctx, - on_success=f"Your reminder `{content}` will arrive in {humanize_delta(relativedelta(expiration, now))}!" + on_success=f"Your reminder will arrive in {humanize_delta(relativedelta(expiration, now))}!" ) loop = asyncio.get_event_loop() -- cgit v1.2.3 From 4f406f335d87d05c2f2287af35556ce16584991b Mon Sep 17 00:00:00 2001 From: kraktus <56031107+kraktus@users.noreply.github.com> Date: Sat, 12 Oct 2019 22:25:01 +0200 Subject: Compact `!free` output --- bot/cogs/free.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bot/cogs/free.py b/bot/cogs/free.py index 269c5c1b9..afd54671a 100644 --- a/bot/cogs/free.py +++ b/bot/cogs/free.py @@ -72,30 +72,32 @@ class Free(Cog): # Display all potentially inactive channels # in descending order of inactivity if free_channels: - embed.description += "**The following channel{0} look{1} free:**\n\n**".format( - 's' if len(free_channels) > 1 else '', - '' if len(free_channels) > 1 else 's' - ) - # Sort channels in descending order by seconds # Get position in list, inactivity, and channel object # For each channel, add to embed.description sorted_channels = sorted(free_channels, key=itemgetter(0), reverse=True) + if len(sorted_channels) > 3: # display 3 channels max + sorted_channels = sorted_channels[:3] + for i, (inactive, channel) in enumerate(sorted_channels, 1): minutes, seconds = divmod(inactive, 60) if minutes > 59: hours, minutes = divmod(minutes, 60) - embed.description += f"{i}. {channel.mention} inactive for {hours}h{minutes}m{seconds}s\n\n" + embed.description += f"{i}. {channel.mention} **{hours}h {minutes}m {seconds}s** inactive\n" else: - embed.description += f"{i}. {channel.mention} inactive for {minutes}m{seconds}s\n\n" + embed.description += f"{i}. {channel.mention} **{minutes}m {seconds}s** inactive\n" - embed.description += ("**\nThese channels aren't guaranteed to be free, " - "so use your best judgement and check for yourself.") + embed.description += ( + "Please confirm these channels " + "are free before posting" + ) else: - embed.description = ("**Doesn't look like any channels are available right now. " - "You're welcome to check for yourself to be sure. " - "If all channels are truly busy, please be patient " - "as one will likely be available soon.**") + embed.description = ( + "**Doesn't look like any channels are available right now. " + "You're welcome to check for yourself to be sure. " + "If all channels are truly busy, please be patient " + "as one will likely be available soon.**" + ) await ctx.send(embed=embed) -- cgit v1.2.3 From d26eba13ebee06013bacf07e35e8e11c2de250c1 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Sun, 13 Oct 2019 21:19:28 +0800 Subject: Show matched word and location in watchlist embed --- bot/cogs/filtering.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 265ae5160..18c2550a2 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -184,12 +184,25 @@ class Filtering(Cog): else: channel_str = f"in {msg.channel.mention}" + # Word and match stats for watch_words and watch_tokens + if filter_name in ("watch_words", "watch_tokens"): + m = triggered + match = m[0] + surroundings = m.string[max(m.start() - 10, 0): m.end() + 10] + message_content = ( + f"**Match:** '{match}'\n" + f"**Location:** '...{surroundings}...'\n" + f"\n**Original Message:**\n{msg.content}" + ) + else: # Use content of discord Message + message_content = msg.content + message = ( f"The {filter_name} {_filter['type']} was triggered " f"by **{msg.author.name}#{msg.author.discriminator}** " f"(`{msg.author.id}`) {channel_str} with [the " f"following message]({msg.jump_url}):\n\n" - f"{msg.content}" + f"{message_content}" ) log.debug(message) @@ -237,8 +250,9 @@ class Filtering(Cog): Only matches words with boundaries before and after the expression. """ for regex_pattern in WORD_WATCHLIST_PATTERNS: - if regex_pattern.search(text): - return True + match = regex_pattern.search(text) + if match: + return match # match objects always have a boolean value of True return False @@ -250,11 +264,12 @@ class Filtering(Cog): This will match the expression even if it does not have boundaries before and after. """ for regex_pattern in TOKEN_WATCHLIST_PATTERNS: - if regex_pattern.search(text): + match = regex_pattern.search(text) + if match: # Make sure it's not a URL if not URL_RE.search(text): - return True + return match # match objects always have a boolean value of True return False -- cgit v1.2.3 From 2b25644e5e7f0abaa332750ed9666d845534fc35 Mon Sep 17 00:00:00 2001 From: mathsman5133 Date: Tue, 15 Oct 2019 11:50:56 +1100 Subject: Utilise `tasks.loop` and a webhook for reddit postings --- bot/cogs/reddit.py | 223 +++++++++++++++++++---------------------------------- bot/constants.py | 2 +- config-default.yml | 2 +- 3 files changed, 80 insertions(+), 147 deletions(-) diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py index 0f575cece..58a6d3c7e 100644 --- a/bot/cogs/reddit.py +++ b/bot/cogs/reddit.py @@ -2,13 +2,14 @@ import asyncio import logging import random import textwrap -from datetime import datetime, timedelta +from datetime import datetime from typing import List -from discord import Colour, Embed, Message, TextChannel +from discord import Colour, Embed, TextChannel from discord.ext.commands import Bot, Cog, Context, group +from discord.ext.tasks import loop -from bot.constants import Channels, ERROR_REPLIES, Reddit as RedditConfig, STAFF_ROLES +from bot.constants import Channels, ERROR_REPLIES, Reddit as RedditConfig, STAFF_ROLES, Webhooks from bot.converters import Subreddit from bot.decorators import with_role from bot.pagination import LinePaginator @@ -26,15 +27,25 @@ class Reddit(Cog): def __init__(self, bot: Bot): self.bot = bot - self.reddit_channel = None + self.webhook = None # set in on_ready + bot.loop.create_task(self.init_reddit_ready()) - self.prev_lengths = {} - self.last_ids = {} + self.auto_poster_loop.start() - self.new_posts_task = None - self.top_weekly_posts_task = None + def cog_unload(self) -> None: + """Stops the loops when the cog is unloaded.""" + self.auto_poster_loop.cancel() - self.bot.loop.create_task(self.init_reddit_polling()) + async def init_reddit_ready(self) -> None: + """Sets the reddit webhook when the cog is loaded.""" + await self.bot.wait_until_ready() + if not self.webhook: + self.webhook = await self.bot.fetch_webhook(Webhooks.reddit) + + @property + def channel(self) -> TextChannel: + """Returns the #reddit channel object from the bot's cache.""" + return self.bot.get_channel(Channels.reddit) async def fetch_posts(self, route: str, *, amount: int = 25, params: dict = None) -> List[dict]: """A helper method to fetch a certain amount of Reddit posts at a given route.""" @@ -63,23 +74,18 @@ class Reddit(Cog): log.debug(f"Invalid response from: {url} - status code {response.status}, mimetype {response.content_type}") return list() # Failed to get appropriate response within allowed number of retries. - async def send_top_posts( - self, channel: TextChannel, subreddit: Subreddit, content: str = None, time: str = "all" - ) -> Message: - """Create an embed for the top posts, then send it in a given TextChannel.""" + async def get_top_posts(self, subreddit: Subreddit, time: str = "all") -> Embed: + """Returns an embed for the top posts of the given subreddit.""" # Create the new spicy embed. - embed = Embed() - embed.description = "" - - # Get the posts - async with channel.typing(): - posts = await self.fetch_posts( - route=f"{subreddit}/top", - amount=5, - params={ - "t": time - } - ) + embed = Embed(description="") + + posts = await self.fetch_posts( + route=f"{subreddit}/top", + amount=5, + params={ + "t": time + } + ) if not posts: embed.title = random.choice(ERROR_REPLIES) @@ -89,9 +95,7 @@ class Reddit(Cog): "If this problem persists, please let us know." ) - return await channel.send( - embed=embed - ) + return embed for post in posts: data = post["data"] @@ -115,103 +119,51 @@ class Reddit(Cog): ) embed.colour = Colour.blurple() + return embed - return await channel.send( - content=content, - embed=embed - ) - - async def poll_new_posts(self) -> None: - """Periodically search for new subreddit posts.""" - while True: - await asyncio.sleep(RedditConfig.request_delay) - - for subreddit in RedditConfig.subreddits: - # Make a HEAD request to the subreddit - head_response = await self.bot.http_session.head( - url=f"{self.URL}/{subreddit}/new.rss", - headers=self.HEADERS - ) - - content_length = head_response.headers["content-length"] - - # If the content is the same size as before, assume there's no new posts. - if content_length == self.prev_lengths.get(subreddit, None): - continue - - self.prev_lengths[subreddit] = content_length - - # Now we can actually fetch the new data - posts = await self.fetch_posts(f"{subreddit}/new") - new_posts = [] - - # Only show new posts if we've checked before. - if subreddit in self.last_ids: - for post in posts: - data = post["data"] - - # Convert the ID to an integer for easy comparison. - int_id = int(data["id"], 36) + @loop() + async def auto_poster_loop(self) -> None: + """Post the top 5 posts daily, and the top 5 posts weekly.""" + # once we upgrade to d.py 1.3 this can be removed and the loop can use the `time=datetime.time.min` parameter + now = datetime.utcnow() + midnight_tomorrow = now.replace(day=now.day + 1, hour=0, minute=0, second=0) + seconds_until = (midnight_tomorrow - now).total_seconds() - # If we've already seen this post, finish checking - if int_id <= self.last_ids[subreddit]: - break + await asyncio.sleep(seconds_until) - embed_data = { - "title": textwrap.shorten(data["title"], width=64, placeholder="..."), - "text": textwrap.shorten(data["selftext"], width=128, placeholder="..."), - "url": self.URL + data["permalink"], - "author": data["author"] - } - - new_posts.append(embed_data) - - self.last_ids[subreddit] = int(posts[0]["data"]["id"], 36) - - # Send all of the new posts as spicy embeds - for data in new_posts: - embed = Embed() - - embed.title = data["title"] - embed.url = data["url"] - embed.description = data["text"] - embed.set_footer(text=f"Posted by u/{data['author']} in {subreddit}") - embed.colour = Colour.blurple() - - await self.reddit_channel.send(embed=embed) + await self.bot.wait_until_ready() + if not self.webhook: + await self.bot.fetch_webhook(Webhooks.reddit) - log.trace(f"Sent {len(new_posts)} new {subreddit} posts to channel {self.reddit_channel.id}.") + if datetime.utcnow().weekday() == 0: + await self.top_weekly_posts() + # if it's a monday send the top weekly posts - async def poll_top_weekly_posts(self) -> None: - """Post a summary of the top posts every week.""" - while True: - now = datetime.utcnow() + for subreddit in RedditConfig.subreddits: + top_posts = await self.get_top_posts(subreddit=subreddit, time="day") + await self.webhook.send(username=f"{subreddit} Top Daily Posts", embed=top_posts) - # Calculate the amount of seconds until midnight next monday. - monday = now + timedelta(days=7 - now.weekday()) - monday = monday.replace(hour=0, minute=0, second=0) - until_monday = (monday - now).total_seconds() + async def top_weekly_posts(self) -> None: + """Post a summary of the top posts.""" + for subreddit in RedditConfig.subreddits: + # Send and pin the new weekly posts. + top_posts = await self.get_top_posts(subreddit=subreddit, time="week") - await asyncio.sleep(until_monday) + message = await self.webhook.send(wait=True, username=f"{subreddit} Top Weekly Posts", embed=top_posts) - for subreddit in RedditConfig.subreddits: - # Send and pin the new weekly posts. - message = await self.send_top_posts( - channel=self.reddit_channel, - subreddit=subreddit, - content=f"This week's top {subreddit} posts have arrived!", - time="week" - ) + if subreddit.lower() == "r/python": + if not self.channel: + log.warning("Failed to get #reddit channel to remove pins in the weekly loop.") + return - if subreddit.lower() == "r/python": - # Remove the oldest pins so that only 5 remain at most. - pins = await self.reddit_channel.pins() + # Remove the oldest pins so that only 5 remain at most. + pins = await self.channel.pins() - while len(pins) >= 5: - await pins[-1].unpin() - del pins[-1] + while len(pins) >= 5: + await pins[-1].unpin() + del pins[-1] - await message.pin() + await message.pin() @group(name="reddit", invoke_without_command=True) async def reddit_group(self, ctx: Context) -> None: @@ -221,32 +173,26 @@ class Reddit(Cog): @reddit_group.command(name="top") async def top_command(self, ctx: Context, subreddit: Subreddit = "r/Python") -> None: """Send the top posts of all time from a given subreddit.""" - await self.send_top_posts( - channel=ctx.channel, - subreddit=subreddit, - content=f"Here are the top {subreddit} posts of all time!", - time="all" - ) + async with ctx.typing(): + embed = await self.get_top_posts(subreddit=subreddit, time="all") + + await ctx.send(content=f"Here are the top {subreddit} posts of all time!", embed=embed) @reddit_group.command(name="daily") async def daily_command(self, ctx: Context, subreddit: Subreddit = "r/Python") -> None: """Send the top posts of today from a given subreddit.""" - await self.send_top_posts( - channel=ctx.channel, - subreddit=subreddit, - content=f"Here are today's top {subreddit} posts!", - time="day" - ) + async with ctx.typing(): + embed = await self.get_top_posts(subreddit=subreddit, time="day") + + await ctx.send(content=f"Here are today's top {subreddit} posts!", embed=embed) @reddit_group.command(name="weekly") async def weekly_command(self, ctx: Context, subreddit: Subreddit = "r/Python") -> None: """Send the top posts of this week from a given subreddit.""" - await self.send_top_posts( - channel=ctx.channel, - subreddit=subreddit, - content=f"Here are this week's top {subreddit} posts!", - time="week" - ) + async with ctx.typing(): + embed = await self.get_top_posts(subreddit=subreddit, time="week") + + await ctx.send(content=f"Here are this week's top {subreddit} posts!", embed=embed) @with_role(*STAFF_ROLES) @reddit_group.command(name="subreddits", aliases=("subs",)) @@ -264,19 +210,6 @@ class Reddit(Cog): max_lines=15 ) - async def init_reddit_polling(self) -> None: - """Initiate reddit post event loop.""" - await self.bot.wait_until_ready() - self.reddit_channel = await self.bot.fetch_channel(Channels.reddit) - - if self.reddit_channel is not None: - if self.new_posts_task is None: - self.new_posts_task = self.bot.loop.create_task(self.poll_new_posts()) - if self.top_weekly_posts_task is None: - self.top_weekly_posts_task = self.bot.loop.create_task(self.poll_top_weekly_posts()) - else: - log.warning("Couldn't locate a channel for subreddit relaying.") - def setup(bot: Bot) -> None: """Reddit cog load.""" diff --git a/bot/constants.py b/bot/constants.py index f4f45eb2c..ffe32e1ea 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -364,6 +364,7 @@ class Webhooks(metaclass=YAMLGetter): talent_pool: int big_brother: int + reddit: int class Roles(metaclass=YAMLGetter): @@ -438,7 +439,6 @@ class URLs(metaclass=YAMLGetter): class Reddit(metaclass=YAMLGetter): section = "reddit" - request_delay: int subreddits: list diff --git a/config-default.yml b/config-default.yml index ca405337e..52e0b880c 100644 --- a/config-default.yml +++ b/config-default.yml @@ -141,6 +141,7 @@ guild: webhooks: talent_pool: 569145364800602132 big_brother: 569133704568373283 + reddit: 123456789 filter: @@ -323,7 +324,6 @@ anti_spam: reddit: - request_delay: 60 subreddits: - 'r/Python' -- cgit v1.2.3 From 7120ae014ebcef984c619e859cdad5cac9073a45 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Tue, 15 Oct 2019 19:39:43 +0800 Subject: Rename `triggered` to `match` --- bot/cogs/filtering.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 18c2550a2..13b8b9678 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -154,11 +154,11 @@ class Filtering(Cog): # Does the filter only need the message content or the full message? if _filter["content_only"]: - triggered = await _filter["function"](msg.content) + match = await _filter["function"](msg.content) else: - triggered = await _filter["function"](msg) + match = await _filter["function"](msg) - if triggered: + if match: # If this is a filter (not a watchlist), we should delete the message. if _filter["type"] == "filter": try: @@ -186,11 +186,9 @@ class Filtering(Cog): # Word and match stats for watch_words and watch_tokens if filter_name in ("watch_words", "watch_tokens"): - m = triggered - match = m[0] - surroundings = m.string[max(m.start() - 10, 0): m.end() + 10] + surroundings = match.string[max(match.start() - 10, 0): match.end() + 10] message_content = ( - f"**Match:** '{match}'\n" + f"**Match:** '{match[0]}'\n" f"**Location:** '...{surroundings}...'\n" f"\n**Original Message:**\n{msg.content}" ) @@ -212,7 +210,7 @@ class Filtering(Cog): if filter_name == "filter_invites": additional_embeds = [] - for invite, data in triggered.items(): + for invite, data in match.items(): embed = discord.Embed(description=( f"**Members:**\n{data['members']}\n" f"**Active:**\n{data['active']}" -- cgit v1.2.3 From a7e1d5542d3bbd5d1df4aa179a838ff5430fcaf7 Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Sat, 19 Oct 2019 17:09:39 +0530 Subject: Add moderation channels check to cog_check --- bot/cogs/moderation/management.py | 8 ++++++-- bot/constants.py | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py index 491f6d400..b7f5db2f5 100644 --- a/bot/cogs/moderation/management.py +++ b/bot/cogs/moderation/management.py @@ -11,7 +11,7 @@ from bot import constants from bot.converters import InfractionSearchQuery from bot.pagination import LinePaginator from bot.utils import time -from bot.utils.checks import with_role_check +from bot.utils.checks import in_channel_check, with_role_check from . import utils from .infractions import Infractions from .modlog import ModLog @@ -257,7 +257,11 @@ class ModManagement(commands.Cog): # This cannot be static (must have a __func__ attribute). def cog_check(self, ctx: Context) -> bool: """Only allow moderators to invoke the commands in this cog.""" - return with_role_check(ctx, *constants.MODERATION_ROLES) + checks = [ + with_role_check(ctx, *constants.MODERATION_ROLES), + in_channel_check(ctx, *constants.MODERATION_CHANNELS) + ] + return all(checks) # This cannot be static (must have a __func__ attribute). async def cog_command_error(self, ctx: Context, error: Exception) -> None: diff --git a/bot/constants.py b/bot/constants.py index f4f45eb2c..f22668a2b 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -347,6 +347,8 @@ class Channels(metaclass=YAMLGetter): message_log: int mod_alerts: int modlog: int + mods: int + mod_spam: int off_topic_0: int off_topic_1: int off_topic_2: int @@ -500,6 +502,9 @@ PROJECT_ROOT = os.path.abspath(os.path.join(BOT_DIR, os.pardir)) MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner +# Default Channel combinations +MODERATION_CHANNELS = Channels.admins, Channels.mod_alerts, Channels.mods, Channels.mod_spam + # Bot replies NEGATIVE_REPLIES = [ -- cgit v1.2.3 From fe514ab501df2513ab2878bf565b39bb9a742750 Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Sat, 19 Oct 2019 17:23:35 +0530 Subject: Add missing channels to the config --- config-default.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config-default.yml b/config-default.yml index ca405337e..4b8185aaa 100644 --- a/config-default.yml +++ b/config-default.yml @@ -109,6 +109,8 @@ guild: message_log: &MESSAGE_LOG 467752170159079424 mod_alerts: 473092532147060736 modlog: &MODLOG 282638479504965634 + mods: 305126844661760000 + mod_spam: 620607373828030464 off_topic_0: 291284109232308226 off_topic_1: 463035241142026251 off_topic_2: 463035268514185226 -- cgit v1.2.3 From e84e760af56e9149d7c8f19279ef17a933de8f19 Mon Sep 17 00:00:00 2001 From: mathsman5133 Date: Sun, 20 Oct 2019 21:15:06 +1100 Subject: Apply suggestions from review, and add correct webhook ID. - More informative docstrings for `Reddit.channel` and `get_top_posts` - Add the `amount` parameter, defaulting to 5. - Pin a max of 12 weeks worth of top posts. --- bot/cogs/reddit.py | 24 ++++++++++++++---------- config-default.yml | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py index 58a6d3c7e..7749d237f 100644 --- a/bot/cogs/reddit.py +++ b/bot/cogs/reddit.py @@ -44,7 +44,7 @@ class Reddit(Cog): @property def channel(self) -> TextChannel: - """Returns the #reddit channel object from the bot's cache.""" + """Get the #reddit channel object from the bot's cache.""" return self.bot.get_channel(Channels.reddit) async def fetch_posts(self, route: str, *, amount: int = 25, params: dict = None) -> List[dict]: @@ -74,17 +74,21 @@ class Reddit(Cog): log.debug(f"Invalid response from: {url} - status code {response.status}, mimetype {response.content_type}") return list() # Failed to get appropriate response within allowed number of retries. - async def get_top_posts(self, subreddit: Subreddit, time: str = "all") -> Embed: - """Returns an embed for the top posts of the given subreddit.""" - # Create the new spicy embed. + async def get_top_posts(self, subreddit: Subreddit, time: str = "all", amount: int = 5) -> Embed: + """ + Get the top amount of posts for a given subreddit within a specified timeframe. + + A time of "all" will get posts from all time, "day" will get top daily posts and "week" will get the top + weekly posts. + + The amount should be between 0 and 25 as Reddit's JSON requests only provide 25 posts at most. + """ embed = Embed(description="") posts = await self.fetch_posts( route=f"{subreddit}/top", - amount=5, - params={ - "t": time - } + amount=amount, + params={"t": time} ) if not posts: @@ -156,10 +160,10 @@ class Reddit(Cog): log.warning("Failed to get #reddit channel to remove pins in the weekly loop.") return - # Remove the oldest pins so that only 5 remain at most. + # Remove the oldest pins so that only 12 remain at most. pins = await self.channel.pins() - while len(pins) >= 5: + while len(pins) >= 12: await pins[-1].unpin() del pins[-1] diff --git a/config-default.yml b/config-default.yml index 52e0b880c..c97072d57 100644 --- a/config-default.yml +++ b/config-default.yml @@ -141,7 +141,7 @@ guild: webhooks: talent_pool: 569145364800602132 big_brother: 569133704568373283 - reddit: 123456789 + reddit: 635408384794951680 filter: -- cgit v1.2.3 From 3e6e7899927f97be7c3722aad7fe6539e0357e04 Mon Sep 17 00:00:00 2001 From: kraktus <56031107+kraktus@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:42:05 +0200 Subject: Add a footer and one-line a string --- bot/cogs/free.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bot/cogs/free.py b/bot/cogs/free.py index afd54671a..f8031a32a 100644 --- a/bot/cogs/free.py +++ b/bot/cogs/free.py @@ -79,18 +79,15 @@ class Free(Cog): if len(sorted_channels) > 3: # display 3 channels max sorted_channels = sorted_channels[:3] - for i, (inactive, channel) in enumerate(sorted_channels, 1): + for (inactive, channel) in sorted_channels: minutes, seconds = divmod(inactive, 60) if minutes > 59: hours, minutes = divmod(minutes, 60) - embed.description += f"{i}. {channel.mention} **{hours}h {minutes}m {seconds}s** inactive\n" + embed.description += f"{channel.mention} **{hours}h {minutes}m {seconds}s** inactive\n" else: - embed.description += f"{i}. {channel.mention} **{minutes}m {seconds}s** inactive\n" + embed.description += f"{channel.mention} **{minutes}m {seconds}s** inactive\n" - embed.description += ( - "Please confirm these channels " - "are free before posting" - ) + embed.set_footer(text="Please confirm these channels are free before posting") else: embed.description = ( "**Doesn't look like any channels are available right now. " -- cgit v1.2.3 From d16fd998fb46702d01d409e68c4132fb07722249 Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Mon, 21 Oct 2019 19:34:03 +0530 Subject: Add #admin-spam channel to moderation channels list - Change doc string for cog_check method --- bot/cogs/moderation/management.py | 2 +- bot/constants.py | 3 ++- config-default.yml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py index b7f5db2f5..44a508436 100644 --- a/bot/cogs/moderation/management.py +++ b/bot/cogs/moderation/management.py @@ -256,7 +256,7 @@ class ModManagement(commands.Cog): # This cannot be static (must have a __func__ attribute). def cog_check(self, ctx: Context) -> bool: - """Only allow moderators to invoke the commands in this cog.""" + """Only allow moderators from moderator channels to invoke the commands in this cog.""" checks = [ with_role_check(ctx, *constants.MODERATION_ROLES), in_channel_check(ctx, *constants.MODERATION_CHANNELS) diff --git a/bot/constants.py b/bot/constants.py index f22668a2b..e4086d8e6 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -328,6 +328,7 @@ class Channels(metaclass=YAMLGetter): subsection = "channels" admins: int + admin_spam: int announcements: int big_brother_logs: int bot: int @@ -503,7 +504,7 @@ MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner # Default Channel combinations -MODERATION_CHANNELS = Channels.admins, Channels.mod_alerts, Channels.mods, Channels.mod_spam +MODERATION_CHANNELS = Channels.admins, Channels.admin_spam, Channels.mod_alerts, Channels.mods, Channels.mod_spam # Bot replies diff --git a/config-default.yml b/config-default.yml index 4b8185aaa..cd8f5600e 100644 --- a/config-default.yml +++ b/config-default.yml @@ -90,6 +90,7 @@ guild: channels: admins: &ADMINS 365960823622991872 + admin-spam: 563594791770914816 announcements: 354619224620138496 big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 -- cgit v1.2.3 From b17b6e3ab8f867b55c7040c5f24c708a8caa0494 Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Mon, 21 Oct 2019 19:39:28 +0530 Subject: Fix typo in channel name --- config-default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-default.yml b/config-default.yml index cd8f5600e..31e88c839 100644 --- a/config-default.yml +++ b/config-default.yml @@ -90,7 +90,7 @@ guild: channels: admins: &ADMINS 365960823622991872 - admin-spam: 563594791770914816 + admin_spam: 563594791770914816 announcements: 354619224620138496 big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 -- cgit v1.2.3 From 0b020642c8df1133d87ee650741026e33f7570f4 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 21 Oct 2019 17:07:39 +0200 Subject: Update send_reminder message creation It is now truly backward compatible and use a more DRY method --- bot/cogs/reminders.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index b8dafcd05..8adebb04b 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -101,13 +101,13 @@ class Reminders(Scheduler, Cog): embed.colour = Colour.blurple() embed.set_author( icon_url=Icons.remind_blurple, - name="It has arrived!") + name="It has arrived!" + ) + + embed.description = f"Here's your reminder: `{reminder['content']}`." - if "jump_url" in reminder: # keep backward compatibility - embed.description = (f"Here's your reminder: `{reminder['content']}`.\n" - f"[Jump back to when you created the reminder]({reminder['jump_url']})") - else: - embed.description = f"Here's your reminder: `{reminder['content']}`" + if reminder.get("jump_url"): # keep backward compatibility + embed.description += f"\n[Jump back to when you created the reminder]({reminder['jump_url']})" if late: embed.colour = Colour.red() -- cgit v1.2.3 From 39e52f573bdcf8fb538fff5175f241c55bd9e0b3 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 21 Oct 2019 18:44:17 +0200 Subject: Create STAFF_CHANNELS constant --- bot/constants.py | 8 ++++++++ config-default.yml | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index 4beae84e9..f341fb499 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -328,6 +328,7 @@ class Channels(metaclass=YAMLGetter): subsection = "channels" admins: int + admin_spam: int announcements: int big_brother_logs: int bot: int @@ -346,11 +347,14 @@ class Channels(metaclass=YAMLGetter): helpers: int message_log: int meta: int + mod_spam: int + mods: int mod_alerts: int modlog: int off_topic_0: int off_topic_1: int off_topic_2: int + organisation: int python: int reddit: int talent_pool: int @@ -392,6 +396,7 @@ class Guild(metaclass=YAMLGetter): id: int ignored: List[int] + staff_channels: List[int] class Keys(metaclass=YAMLGetter): @@ -507,6 +512,9 @@ PROJECT_ROOT = os.path.abspath(os.path.join(BOT_DIR, os.pardir)) MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner +# Roles combinations +STAFF_CHANNELS = Guild.staff_channels + # Bot replies NEGATIVE_REPLIES = [ diff --git a/config-default.yml b/config-default.yml index 197743296..23dcbd44c 100644 --- a/config-default.yml +++ b/config-default.yml @@ -90,11 +90,12 @@ guild: channels: admins: &ADMINS 365960823622991872 + admin_spam: &ADMIN_SPAM 563594791770914816 announcements: 354619224620138496 big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 checkpoint_test: 422077681434099723 - defcon: 464469101889454091 + defcon: &DEFCON 464469101889454091 devlog: &DEVLOG 622895325144940554 devtest: &DEVTEST 414574275865870337 help_0: 303906576991780866 @@ -105,14 +106,17 @@ guild: help_5: 454941769734422538 help_6: 587375753306570782 help_7: 587375768556797982 - helpers: 385474242440986624 + helpers: &HELPERS 385474242440986624 message_log: &MESSAGE_LOG 467752170159079424 meta: 429409067623251969 + mod_spam: &MOD_SPAM 620607373828030464 + mods: &MODS 305126844661760000 mod_alerts: 473092532147060736 modlog: &MODLOG 282638479504965634 off_topic_0: 291284109232308226 off_topic_1: 463035241142026251 off_topic_2: 463035268514185226 + organisation: &ORGANISATION 551789653284356126 python: 267624335836053506 reddit: 458224812528238616 staff_lounge: &STAFF_LOUNGE 464905259261755392 @@ -121,6 +125,7 @@ guild: user_event_a: &USER_EVENT_A 592000283102674944 verification: 352442727016693763 + staff_channels: [*ADMINS, *ADMIN_SPAM, *MOD_SPAM, *MODS, *HELPERS, *ORGANISATION, *DEFCON] ignored: [*ADMINS, *MESSAGE_LOG, *MODLOG] roles: -- cgit v1.2.3 From 2bff275f39347c0c1fb06be38b3119fe7f23e273 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Mon, 21 Oct 2019 18:45:25 +0200 Subject: Show total infraction count only in staff channels --- bot/cogs/moderation/infractions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py index f2ae7b95d..997ffe524 100644 --- a/bot/cogs/moderation/infractions.py +++ b/bot/cogs/moderation/infractions.py @@ -12,7 +12,7 @@ from discord.ext.commands import Context, command from bot import constants from bot.api import ResponseCodeError -from bot.constants import Colours, Event +from bot.constants import Colours, Event, STAFF_CHANNELS from bot.decorators import respect_role_hierarchy from bot.utils import time from bot.utils.checks import with_role_check @@ -465,6 +465,8 @@ class Infractions(Scheduler, commands.Cog): if infraction["actor"] == self.bot.user.id: end_msg = f" (reason: {infraction['reason']})" + elif ctx.channel.id not in STAFF_CHANNELS: + end_msg = '' else: infractions = await self.bot.api_client.get( "bot/infractions", -- cgit v1.2.3 From 1dc08b8622b4d99bc7c480da5f91f774fdfd0787 Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Tue, 22 Oct 2019 21:53:39 +0530 Subject: Modify in_channel_check to accept list of channels - Update test cases for in_channel_check --- bot/utils/checks.py | 6 +++--- tests/utils/test_checks.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bot/utils/checks.py b/bot/utils/checks.py index ad892e512..db56c347c 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -38,9 +38,9 @@ def without_role_check(ctx: Context, *role_ids: int) -> bool: return check -def in_channel_check(ctx: Context, channel_id: int) -> bool: - """Checks if the command was executed inside of the specified channel.""" - check = ctx.channel.id == channel_id +def in_channel_check(ctx: Context, *channel_ids: int) -> bool: + """Checks if the command was executed inside the list of specified channels.""" + check = ctx.channel.id in channel_ids log.trace(f"{ctx.author} tried to call the '{ctx.command.name}' command. " f"The result of the in_channel check was {check}.") return check diff --git a/tests/utils/test_checks.py b/tests/utils/test_checks.py index 7121acebd..ef1144ac9 100644 --- a/tests/utils/test_checks.py +++ b/tests/utils/test_checks.py @@ -57,10 +57,10 @@ def test_without_role_check_without_unwanted_role(context): def test_in_channel_check_for_correct_channel(context): - context.channel.id = 42 - assert checks.in_channel_check(context, context.channel.id) + context.channel.id = [42] + assert checks.in_channel_check(context, *context.channel.id) def test_in_channel_check_for_incorrect_channel(context): - context.channel.id = 42 - assert not checks.in_channel_check(context, context.channel.id + 10) + context.channel.id = [42 + 10] + assert not checks.in_channel_check(context, *context.channel.id) -- cgit v1.2.3 From a11596de969a53853151ad8a5ca2d6564227e0ab Mon Sep 17 00:00:00 2001 From: Atul Mishra Date: Tue, 22 Oct 2019 22:37:22 +0530 Subject: Add test cases for in_channel_check --- tests/bot/utils/test_checks.py | 8 ++++++++ tests/utils/test_checks.py | 0 2 files changed, 8 insertions(+) delete mode 100644 tests/utils/test_checks.py diff --git a/tests/bot/utils/test_checks.py b/tests/bot/utils/test_checks.py index 22dc93073..19b758336 100644 --- a/tests/bot/utils/test_checks.py +++ b/tests/bot/utils/test_checks.py @@ -41,3 +41,11 @@ class ChecksTests(unittest.TestCase): role_id = 42 self.ctx.author.roles.append(MockRole(role_id=role_id)) self.assertTrue(checks.without_role_check(self.ctx, role_id + 10)) + + def test_in_channel_check_for_correct_channel(self): + self.ctx.channel.id = 42 + self.assertTrue(checks.in_channel_check(self.ctx, *[42])) + + def test_in_channel_check_for_incorrect_channel(self): + self.ctx.channel.id = 42 + 10 + self.assertFalse(checks.in_channel_check(self.ctx, *[42])) diff --git a/tests/utils/test_checks.py b/tests/utils/test_checks.py deleted file mode 100644 index e69de29bb..000000000 -- cgit v1.2.3 From 27cf5788d7f960e6bfb68891874cdfdaa5584ba1 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Wed, 23 Oct 2019 10:15:47 +0200 Subject: Substract one to now calculation Avoid aving `Your reminder will arrive in 59 minutes and 59 seconds!` instead of `Your reminder will arrive in 1 hour!` --- bot/cogs/reminders.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index 8adebb04b..81990704b 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -2,7 +2,7 @@ import asyncio import logging import random import textwrap -from datetime import datetime +from datetime import datetime, timedelta from operator import itemgetter from typing import Optional @@ -176,7 +176,7 @@ class Reminders(Scheduler, Cog): } ) - now = datetime.utcnow() + now = datetime.utcnow() - timedelta(seconds=1) # Confirm to the user that it worked. await self._send_confirmation( -- cgit v1.2.3 From fae86078206eb5726c606636aaa6a0ba315f5b73 Mon Sep 17 00:00:00 2001 From: Akarys42 Date: Wed, 23 Oct 2019 11:04:26 +0200 Subject: Use standart filter conditions even if DEBUG_MODE is on. The old method filtered only in #dev-test but this channel no longer exists --- bot/cogs/filtering.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 1d1d74e74..fda58b83a 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -9,7 +9,7 @@ from discord.ext.commands import Bot, Cog from bot.cogs.moderation import ModLog from bot.constants import ( - Channels, Colours, DEBUG_MODE, + Channels, Colours, Filter, Icons, URLs ) @@ -136,10 +136,6 @@ class Filtering(Cog): and not msg.author.bot # Author not a bot ) - # If we're running the bot locally, ignore role whitelist and only listen to #dev-test - if DEBUG_MODE: - filter_message = not msg.author.bot and msg.channel.id == Channels.devtest - # If none of the above, we can start filtering. if filter_message: for filter_name, _filter in self.filters.items(): -- cgit v1.2.3 From 28985df9fd98ae2d22b9606f80f63a96040424cf Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 24 Oct 2019 10:45:14 +0800 Subject: Prepend emoji indicative of success of !eval --- bot/cogs/snekbox.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py index 81185cf3e..7316f9583 100644 --- a/bot/cogs/snekbox.py +++ b/bot/cogs/snekbox.py @@ -115,6 +115,16 @@ class Snekbox(Cog): return msg, error + @staticmethod + def get_status_emoji(results: dict) -> str: + """Return an emoji corresponding to the status code or lack of output in result.""" + if not results["stdout"].strip(): # No output + return ":warning:" + elif results["returncode"] == 0: # No error + return ":white_check_mark:" + else: # Exception + return ":x:" + async def format_output(self, output: str) -> Tuple[str, Optional[str]]: """ Format the output and return a tuple of the formatted output and a URL to the full output. @@ -204,7 +214,8 @@ class Snekbox(Cog): else: output, paste_link = await self.format_output(results["stdout"]) - msg = f"{ctx.author.mention} {msg}.\n\n```py\n{output}\n```" + icon = self.get_status_emoji(results) + msg = f"{ctx.author.mention} {icon} {msg}.\n\n```py\n{output}\n```" if paste_link: msg = f"{msg}\nFull output: {paste_link}" -- cgit v1.2.3 From 7ad9b1b96cba59818943ada569ddbba1d092069b Mon Sep 17 00:00:00 2001 From: kosayoda Date: Thu, 24 Oct 2019 15:22:40 +0800 Subject: Fix incorrect type hint for return value --- bot/cogs/filtering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 13b8b9678..ec387ac40 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -241,7 +241,7 @@ class Filtering(Cog): break # We don't want multiple filters to trigger @staticmethod - async def _has_watchlist_words(text: str) -> bool: + async def _has_watchlist_words(text: str) -> Union[bool, re.Match]: """ Returns True if the text contains one of the regular expressions from the word_watchlist in our filter config. @@ -255,7 +255,7 @@ class Filtering(Cog): return False @staticmethod - async def _has_watchlist_tokens(text: str) -> bool: + async def _has_watchlist_tokens(text: str) -> Union[bool, re.Match]: """ Returns True if the text contains one of the regular expressions from the token_watchlist in our filter config. -- cgit v1.2.3 From 8ba85a74b77822ff89e1d18cd3f98a68439f0bbf Mon Sep 17 00:00:00 2001 From: kraktus <56031107+kraktus@users.noreply.github.com> Date: Thu, 24 Oct 2019 12:39:41 +0200 Subject: Requested changes --- bot/cogs/free.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/cogs/free.py b/bot/cogs/free.py index f8031a32a..e1554a4b4 100644 --- a/bot/cogs/free.py +++ b/bot/cogs/free.py @@ -76,10 +76,8 @@ class Free(Cog): # Get position in list, inactivity, and channel object # For each channel, add to embed.description sorted_channels = sorted(free_channels, key=itemgetter(0), reverse=True) - if len(sorted_channels) > 3: # display 3 channels max - sorted_channels = sorted_channels[:3] - for (inactive, channel) in sorted_channels: + for (inactive, channel) in sorted_channels[:3]: minutes, seconds = divmod(inactive, 60) if minutes > 59: hours, minutes = divmod(minutes, 60) -- cgit v1.2.3 From efdd666f0972c4e5468aee3477b5150d176f6d25 Mon Sep 17 00:00:00 2001 From: kraktus <56031107+kraktus@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:06:12 +0200 Subject: Remove bold tag when no channel is available --- bot/cogs/free.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/free.py b/bot/cogs/free.py index e1554a4b4..82285656b 100644 --- a/bot/cogs/free.py +++ b/bot/cogs/free.py @@ -88,10 +88,10 @@ class Free(Cog): embed.set_footer(text="Please confirm these channels are free before posting") else: embed.description = ( - "**Doesn't look like any channels are available right now. " + "Doesn't look like any channels are available right now. " "You're welcome to check for yourself to be sure. " "If all channels are truly busy, please be patient " - "as one will likely be available soon.**" + "as one will likely be available soon." ) await ctx.send(embed=embed) -- cgit v1.2.3