From 7cb5c5517043c0006b001c15373b664b86cc6b43 Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Fri, 3 Dec 2021 17:28:15 -0500 Subject: feat: implement moving commands add exceptions and handler for commands that move locations --- bot/constants.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index f4b1cab0..854fbe55 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -23,6 +23,7 @@ __all__ = ( "Reddit", "RedisConfig", "RedirectOutput", + "PYTHON_PREFIX" "MODERATION_ROLES", "STAFF_ROLES", "WHITELISTED_CHANNELS", @@ -34,6 +35,8 @@ __all__ = ( log = logging.getLogger(__name__) +PYTHON_PREFIX = "!" + @dataclasses.dataclass class AdventOfCodeLeaderboard: id: str -- cgit v1.2.3 From 21518aed7b3cfb9c2ec4fa1722689a6c4df56372 Mon Sep 17 00:00:00 2001 From: ChrisLovering Date: Sat, 25 Dec 2021 22:23:12 +0000 Subject: Add hourly task to assign AoC completer role This task uses the cached leaderboard to see who has all 50 stars and assigns them a role to highlight them as completers. --- bot/constants.py | 1 + bot/exts/events/advent_of_code/_cog.py | 60 ++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 854fbe55..01f825a0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -291,6 +291,7 @@ class Roles(NamedTuple): helpers = int(environ.get("ROLE_HELPERS", 267630620367257601)) core_developers = 587606783669829632 everyone = int(environ.get("BOT_GUILD", 267624335836053506)) + aoc_completionist = int(environ.get("AOC_COMPLETIONIST_ROLE_ID", 916691790181056532)) class Tokens(NamedTuple): diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 52254ea1..6974d89c 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -7,12 +7,15 @@ from typing import Optional import arrow import discord from async_rediscache import RedisCache -from discord.ext import commands +from discord.ext import commands, tasks from bot.bot import Bot -from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS +from bot.constants import ( + AdventOfCode as AocConfig, Channels, Client, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS +) from bot.exts.events.advent_of_code import _helpers from bot.exts.events.advent_of_code.views.dayandstarview import AoCDropdownView +from bot.utils import members from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role from bot.utils.extensions import invoke_help_command @@ -31,6 +34,7 @@ class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho!""" # Redis Cache for linking Discord IDs to Advent of Code usernames + # RedisCache[member_id: aoc_username_string] account_links = RedisCache() def __init__(self, bot: Bot): @@ -52,6 +56,57 @@ class AdventOfCode(commands.Cog): self.status_task.set_name("AoC Status Countdown") self.status_task.add_done_callback(_helpers.background_task_callback) + self.completionist_task.start() + + @tasks.loop(minutes=10.0) + async def completionist_task(self) -> None: + """ + Give members who have completed all 50 AoC stars the completionist role. + + Runs on a schedule, as defined in the task.loop decorator. + """ + await self.bot.wait_until_guild_available() + guild = self.bot.get_guild(Client.guild) + completionist_role = guild.get_role(Roles.aoc_completionist) + if completionist_role is None: + log.warning("Could not find the AoC completionist role; cancelling completionist task.") + self.completer_task.cancel() + return + + aoc_name_to_member_id = { + aoc_name: member_id + for member_id, aoc_name in await self.account_links.items() + } + + try: + leaderboard = await _helpers.fetch_leaderboard() + except _helpers.FetchingLeaderboardFailedError: + await self.bot.send_log("Unable to fetch AoC leaderboard during role sync.") + return + + placement_leaderboard = json.loads(leaderboard["placement_leaderboard"]) + + for member_aoc_info in placement_leaderboard.values(): + if not member_aoc_info["stars"] == 50: + # Only give the role to people who have completed all 50 stars + continue + + member_id = aoc_name_to_member_id[member_aoc_info["name"]] + if not member_id: + continue + + member = members.get_or_fetch_member(guild, member_id) + if member is None: + continue + + if completionist_role in member.roles: + continue + + if await self.completionist_block_list.contains(member_id): + continue + + await members.handle_role_change(member, member.add_roles, completionist_role) + @commands.group(name="adventofcode", aliases=("aoc",)) @whitelist_override(channels=AOC_WHITELIST) async def adventofcode_group(self, ctx: commands.Context) -> None: @@ -408,6 +463,7 @@ class AdventOfCode(commands.Cog): log.debug("Unloading the cog and canceling the background task.") self.notification_task.cancel() self.status_task.cancel() + self.completionist_task.cancel() def _build_about_embed(self) -> discord.Embed: """Build and return the informational "About AoC" embed from the resources file.""" -- cgit v1.2.3 From 2c66844a3e9e59b97fba43de0d850d8cf597d9ad Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sun, 2 Jan 2022 22:23:47 +0000 Subject: Update GitHub issue closed emoji GitHub updated their issue closed emoji from red to purple, this updates the emoji to relfect that new colour. --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 01f825a0..3b426c47 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -197,7 +197,7 @@ class Emojis: # These icons are from Github's repo https://github.com/primer/octicons/ issue_open = "<:IssueOpen:852596024777506817>" - issue_closed = "<:IssueClosed:852596024739758081>" + issue_closed = "<:IssueClosed:927326162861039626>" issue_draft = "<:IssueDraft:852596025147523102>" # Not currently used by Github, but here for future. pull_request_open = "<:PROpen:852596471505223781>" pull_request_closed = "<:PRClosed:852596024732286976>" -- cgit v1.2.3 From 1fd39adbb53b14015033fcaff0cbfb4aa81c65d7 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Tue, 25 Jan 2022 12:13:07 +0300 Subject: Clean Up Constants File This commit moves the logging constants from the Client class to a new Logging class. Flake8 is renabled for constants, and the error it was disabled for was specifically ignored. All new errors were fixed. It also fixes a bug with __all__, which was trying to export a missing symbol due to a missing comma. Signed-off-by: Hassan Abouelela --- bot/constants.py | 13 ++++++++++--- bot/log.py | 8 ++++---- tox.ini | 4 +++- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 3b426c47..7e7ee749 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -12,6 +12,7 @@ __all__ = ( "Channels", "Categories", "Client", + "Logging", "Colours", "Emojis", "Icons", @@ -23,7 +24,7 @@ __all__ = ( "Reddit", "RedisConfig", "RedirectOutput", - "PYTHON_PREFIX" + "PYTHON_PREFIX", "MODERATION_ROLES", "STAFF_ROLES", "WHITELISTED_CHANNELS", @@ -37,6 +38,7 @@ log = logging.getLogger(__name__) PYTHON_PREFIX = "!" + @dataclasses.dataclass class AdventOfCodeLeaderboard: id: str @@ -130,18 +132,24 @@ class Categories(NamedTuple): media = 799054581991997460 staff = 364918151625965579 + codejam_categories_name = "Code Jam" # Name of the codejam team categories + class Client(NamedTuple): name = "Sir Lancebot" guild = int(environ.get("BOT_GUILD", 267624335836053506)) prefix = environ.get("PREFIX", ".") token = environ.get("BOT_TOKEN") debug = environ.get("BOT_DEBUG", "true").lower() == "true" - file_logs = environ.get("FILE_LOGS", "false").lower() == "true" github_bot_repo = "https://github.com/python-discord/sir-lancebot" # Override seasonal locks: 1 (January) to 12 (December) month_override = int(environ["MONTH_OVERRIDE"]) if "MONTH_OVERRIDE" in environ else None + + +class Logging(NamedTuple): + debug = Client.debug + file_logs = environ.get("FILE_LOGS", "false").lower() == "true" trace_loggers = environ.get("BOT_TRACE_LOGGERS") @@ -231,7 +239,6 @@ class Emojis: status_dnd = "<:status_dnd:470326272082313216>" status_offline = "<:status_offline:470326266537705472>" - stackoverflow_tag = "<:stack_tag:870926975307501570>" stackoverflow_views = "<:stack_eye:870926992692879371>" diff --git a/bot/log.py b/bot/log.py index 29e696e0..a87a836a 100644 --- a/bot/log.py +++ b/bot/log.py @@ -6,7 +6,7 @@ from pathlib import Path import coloredlogs -from bot.constants import Client +from bot.constants import Logging def setup() -> None: @@ -20,7 +20,7 @@ def setup() -> None: log_format = logging.Formatter(format_string) root_logger = logging.getLogger() - if Client.file_logs: + if Logging.file_logs: # Set up file logging log_file = Path("logs/sir-lancebot.log") log_file.parent.mkdir(exist_ok=True) @@ -45,7 +45,7 @@ def setup() -> None: coloredlogs.install(level=logging.TRACE, stream=sys.stdout) - root_logger.setLevel(logging.DEBUG if Client.debug else logging.INFO) + root_logger.setLevel(logging.DEBUG if Logging.debug else logging.INFO) # Silence irrelevant loggers logging.getLogger("discord").setLevel(logging.ERROR) logging.getLogger("websockets").setLevel(logging.ERROR) @@ -81,7 +81,7 @@ def _set_trace_loggers() -> None: Otherwise if the env var begins with a "*", the root logger is set to the trace level and other contents are ignored. """ - level_filter = Client.trace_loggers + level_filter = Logging.trace_loggers if level_filter: if level_filter.startswith("*"): logging.getLogger().setLevel(logging.TRACE) diff --git a/tox.ini b/tox.ini index f561fcd9..61ff9616 100644 --- a/tox.ini +++ b/tox.ini @@ -20,5 +20,7 @@ exclude= __pycache__,.cache, venv,.venv, tests, - constants.py +per-file-ignores = + # Don't require docstrings in constants + constants.py:D101 import-order-style=pycharm -- cgit v1.2.3 From 335620341046e3b7be547ac9f18d25d1fb9bec55 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Tue, 25 Jan 2022 12:15:50 +0300 Subject: Reduce AOC Logging Output The AOC cog produces a lot of large logs very frequently which have minimal value, causing the logs to be significantly harder to navigate. Signed-off-by: Hassan Abouelela --- bot/constants.py | 2 +- bot/exts/events/advent_of_code/_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 7e7ee749..d39f7361 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -55,7 +55,7 @@ class AdventOfCodeLeaderboard: def session(self) -> str: """Return either the actual `session` cookie or the fallback cookie.""" if self.use_fallback_session: - log.info(f"Returning fallback cookie for board `{self.id}`.") + log.trace(f"Returning fallback cookie for board `{self.id}`.") return AdventOfCode.fallback_session return self._session diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 15b1329d..6c004901 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -255,7 +255,7 @@ async def _fetch_leaderboard_data() -> dict[str, Any]: # Two attempts, one with the original session cookie and one with the fallback session for attempt in range(1, 3): - log.info(f"Attempting to fetch leaderboard `{leaderboard.id}` ({attempt}/2)") + log.debug(f"Attempting to fetch leaderboard `{leaderboard.id}` ({attempt}/2)") cookies = {"session": leaderboard.session} try: raw_data = await _leaderboard_request(leaderboard_url, leaderboard.id, cookies) -- cgit v1.2.3