From 9ec955812bc160a389a24fe7737e2ab8f9580d3c Mon Sep 17 00:00:00 2001 From: sco1 Date: Tue, 19 Mar 2019 13:38:49 -0400 Subject: Docstring pass for Christmas cogs --- bot/seasons/christmas/adventofcode.py | 118 +++++++++++++++------------------- 1 file changed, 51 insertions(+), 67 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index a926a6cb..2fd474db 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -25,19 +25,15 @@ COUNTDOWN_STEP = 60 * 5 def is_in_advent() -> bool: - """ - Utility function to check if we are between December 1st - and December 25th. - """ + """Utility function to check if we are between December 1st and December 25th.""" + # Run the code from the 1st to the 24th return datetime.now(EST).day in range(1, 25) and datetime.now(EST).month == 12 def time_left_to_aoc_midnight() -> Tuple[datetime, timedelta]: - """ - This calculates the amount of time left until midnight in - UTC-5 (Advent of Code maintainer timezone). - """ + """Calculates the amount of time left until midnight in UTC-5 (Advent of Code maintainer timezone).""" + # Change all time properties back to 00:00 todays_midnight = datetime.now(EST).replace(microsecond=0, second=0, @@ -52,10 +48,8 @@ def time_left_to_aoc_midnight() -> Tuple[datetime, timedelta]: async def countdown_status(bot: commands.Bot): - """ - Every `COUNTDOWN_STEP` seconds set the playing status of the bot to - the number of minutes & hours left until the next day's release. - """ + """Set the playing status of the bot to the minutes & hours left until the next day's challenge.""" + while is_in_advent(): _, time_left = time_left_to_aoc_midnight() @@ -83,11 +77,12 @@ async def countdown_status(bot: commands.Bot): async def day_countdown(bot: commands.Bot): """ - Calculate the number of seconds left until the next day of advent. Once - we have calculated this we should then sleep that number and when the time - is reached ping the advent of code role notifying them that the new task is - ready. + Calculate the number of seconds left until the next day of advent. + + Once we have calculated this we should then sleep that number and when the time is reached, ping + the Advent of Code role notifying them that the new challenge is ready. """ + while is_in_advent(): tomorrow, time_left = time_left_to_aoc_midnight() @@ -109,9 +104,8 @@ async def day_countdown(bot: commands.Bot): class AdventOfCode: - """ - Advent of Code festivities! Ho Ho Ho! - """ + """Advent of Code festivities! Ho Ho Ho.""" + def __init__(self, bot: commands.Bot): self.bot = bot @@ -136,9 +130,7 @@ class AdventOfCode: @commands.group(name="adventofcode", aliases=("aoc",), invoke_without_command=True) async def adventofcode_group(self, ctx: commands.Context): - """ - All of the Advent of Code commands - """ + """All of the Advent of Code commands.""" await ctx.invoke(self.bot.get_command("help"), "adventofcode") @@ -148,9 +140,8 @@ class AdventOfCode: brief="Notifications for new days" ) async def aoc_subscribe(self, ctx: commands.Context): - """ - Assign the role for notifications about new days being ready. - """ + """Assign the role for notifications about new days being ready.""" + role = ctx.guild.get_role(AocConfig.role_id) unsubscribe_command = f"{ctx.prefix}{ctx.command.root_parent} unsubscribe" @@ -164,9 +155,8 @@ class AdventOfCode: @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") async def aoc_unsubscribe(self, ctx: commands.Context): - """ - Remove the role for notifications about new days being ready. - """ + """Remove the role for notifications about new days being ready.""" + role = ctx.guild.get_role(AocConfig.role_id) if role in ctx.author.roles: @@ -177,9 +167,8 @@ class AdventOfCode: @adventofcode_group.command(name="countdown", aliases=("count", "c"), brief="Return time left until next day") async def aoc_countdown(self, ctx: commands.Context): - """ - Return time left until next day - """ + """Return time left until next day.""" + if not is_in_advent(): datetime_now = datetime.now(EST) december_first = datetime(datetime_now.year + 1, 12, 1, tzinfo=EST) @@ -196,17 +185,13 @@ class AdventOfCode: @adventofcode_group.command(name="about", aliases=("ab", "info"), brief="Learn about Advent of Code") async def about_aoc(self, ctx: commands.Context): - """ - Respond with an explanation of all things Advent of Code - """ + """Respond with an explanation of all things Advent of Code.""" await ctx.send("", embed=self.cached_about_aoc) @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join PyDis' private AoC leaderboard") async def join_leaderboard(self, ctx: commands.Context): - """ - DM the user the information for joining the PyDis AoC private leaderboard - """ + """DM the user the information for joining the PyDis AoC private leaderboard.""" author = ctx.message.author log.info(f"{author.name} ({author.id}) has requested the PyDis AoC leaderboard code") @@ -228,7 +213,7 @@ class AdventOfCode: ) async def aoc_leaderboard(self, ctx: commands.Context, number_of_people_to_display: int = 10): """ - Pull the top number_of_people_to_display members from the PyDis leaderboard and post an embed + Pull the top number_of_people_to_display members from the PyDis leaderboard and post an embed. For readability, number_of_people_to_display defaults to 10. A maximum value is configured in the Advent of Code section of the bot constants. number_of_people_to_display values greater than this @@ -270,7 +255,7 @@ class AdventOfCode: ) async def private_leaderboard_daily_stats(self, ctx: commands.Context): """ - Respond with a table of the daily completion statistics for the PyDis private leaderboard + Respond with a table of the daily completion statistics for the PyDis private leaderboard. Embed will display the total members and the number of users who have completed each day's puzzle """ @@ -314,7 +299,7 @@ class AdventOfCode: ) async def global_leaderboard(self, ctx: commands.Context, number_of_people_to_display: int = 10): """ - Pull the top number_of_people_to_display members from the global AoC leaderboard and post an embed + Pull the top number_of_people_to_display members from the global AoC leaderboard and post an embed. For readability, number_of_people_to_display defaults to 10. A maximum value is configured in the Advent of Code section of the bot constants. number_of_people_to_display values greater than this @@ -347,7 +332,7 @@ class AdventOfCode: async def _check_leaderboard_cache(self, ctx, global_board: bool = False): """ - Check age of current leaderboard & pull a new one if the board is too old + Check age of current leaderboard & pull a new one if the board is too old. global_board is a boolean to toggle between the global board and the Pydis private board """ @@ -404,9 +389,7 @@ class AdventOfCode: return number_of_people_to_display def _build_about_embed(self) -> discord.Embed: - """ - Build and return the informational "About AoC" embed from the resources file - """ + """Build and return the informational "About AoC" embed from the resources file.""" with self.about_aoc_filepath.open("r") as f: embed_fields = json.load(f) @@ -421,9 +404,8 @@ class AdventOfCode: return about_embed async def _boardgetter(self, global_board: bool): - """ - Invoke the proper leaderboard getter based on the global_board boolean - """ + """Invoke the proper leaderboard getter based on the global_board boolean.""" + if global_board: self.cached_global_leaderboard = await AocGlobalLeaderboard.from_url() else: @@ -431,6 +413,8 @@ class AdventOfCode: class AocMember: + """Object representing the Advent of Code user.""" + def __init__(self, name: str, aoc_id: int, stars: int, starboard: list, local_score: int, global_score: int): self.name = name self.aoc_id = aoc_id @@ -441,12 +425,14 @@ class AocMember: self.completions = self._completions_from_starboard(self.starboard) def __repr__(self): + """Generate a user-friendly representation of the AocMember & their score.""" + return f"<{self.name} ({self.aoc_id}): {self.local_score}>" @classmethod def member_from_json(cls, injson: dict) -> "AocMember": """ - Generate an AocMember from AoC's private leaderboard API JSON + Generate an AocMember from AoC's private leaderboard API JSON. injson is expected to be the dict contained in: @@ -467,7 +453,7 @@ class AocMember: @staticmethod def _starboard_from_json(injson: dict) -> list: """ - Generate starboard from AoC's private leaderboard API JSON + Generate starboard from AoC's private leaderboard API JSON. injson is expected to be the dict contained in: @@ -500,9 +486,7 @@ class AocMember: @staticmethod def _completions_from_starboard(starboard: list) -> tuple: - """ - Return days completed, as a (1 star, 2 star) tuple, from starboard - """ + """Return days completed, as a (1 star, 2 star) tuple, from starboard.""" completions = [0, 0] for day in starboard: @@ -515,6 +499,8 @@ class AocMember: class AocPrivateLeaderboard: + """Object representing the Advent of Code private leaderboard.""" + def __init__(self, members: list, owner_id: int, event_year: int): self.members = members self._owner_id = owner_id @@ -534,7 +520,7 @@ class AocPrivateLeaderboard: def calculate_daily_completion(self) -> List[tuple]: """ - Calculate member completion rates by day + Calculate member completion rates by day. Return a list of tuples for each day containing the number of users who completed each part of the challenge @@ -560,7 +546,7 @@ class AocPrivateLeaderboard: leaderboard_id: int = AocConfig.leaderboard_id, year: int = AocConfig.year ) -> "AocPrivateLeaderboard": """ - Request the API JSON from Advent of Code for leaderboard_id for the specified year's event + Request the API JSON from Advent of Code for leaderboard_id for the specified year's event. If no year is input, year defaults to the current year """ @@ -580,9 +566,7 @@ class AocPrivateLeaderboard: @classmethod def from_json(cls, injson: dict) -> "AocPrivateLeaderboard": - """ - Generate an AocPrivateLeaderboard object from AoC's private leaderboard API JSON - """ + """Generate an AocPrivateLeaderboard object from AoC's private leaderboard API JSON.""" return cls( members=cls._sorted_members(injson["members"]), owner_id=injson["owner_id"], event_year=injson["event"] @@ -590,9 +574,7 @@ class AocPrivateLeaderboard: @classmethod async def from_url(cls) -> "AocPrivateLeaderboard": - """ - Helper wrapping of AocPrivateLeaderboard.json_from_url and AocPrivateLeaderboard.from_json - """ + """Helper wrapping of AocPrivateLeaderboard.json_from_url and AocPrivateLeaderboard.from_json.""" api_json = await cls.json_from_url() return cls.from_json(api_json) @@ -600,7 +582,7 @@ class AocPrivateLeaderboard: @staticmethod def _sorted_members(injson: dict) -> list: """ - Generate a sorted list of AocMember objects from AoC's private leaderboard API JSON + Generate a sorted list of AocMember objects from AoC's private leaderboard API JSON. Output list is sorted based on the AocMember.local_score """ @@ -613,7 +595,7 @@ class AocPrivateLeaderboard: @staticmethod def build_leaderboard_embed(members_to_print: List[AocMember]) -> str: """ - Build a text table from members_to_print, a list of AocMember objects + Build a text table from members_to_print, a list of AocMember objects. Returns a string to be used as the content of the bot's leaderboard response """ @@ -638,6 +620,8 @@ class AocPrivateLeaderboard: class AocGlobalLeaderboard: + """Object representing the Advent of Code global leaderboard.""" + def __init__(self, members: List[tuple]): self.members = members self.last_updated = datetime.utcnow() @@ -654,7 +638,7 @@ class AocGlobalLeaderboard: @classmethod async def from_url(cls) -> "AocGlobalLeaderboard": """ - Generate an list of tuples for the entries on AoC's global leaderboard + Generate an list of tuples for the entries on AoC's global leaderboard. Because there is no API for this, web scraping needs to be used """ @@ -700,7 +684,7 @@ class AocGlobalLeaderboard: @staticmethod def build_leaderboard_embed(members_to_print: List[tuple]) -> str: """ - Build a text table from members_to_print, a list of tuples + Build a text table from members_to_print, a list of tuples. Returns a string to be used as the content of the bot's leaderboard response """ @@ -721,13 +705,13 @@ class AocGlobalLeaderboard: def _error_embed_helper(title: str, description: str) -> discord.Embed: - """ - Return a red-colored Embed with the given title and description - """ + """Return a red-colored Embed with the given title and description.""" return discord.Embed(title=title, description=description, colour=discord.Colour.red()) def setup(bot: commands.Bot) -> None: + """Advent of Code Cog load.""" + bot.add_cog(AdventOfCode(bot)) log.info("Cog loaded: adventofcode") -- cgit v1.2.3 From d99013ca0fc489b4774ea080fd441741aab14c97 Mon Sep 17 00:00:00 2001 From: sco1 Date: Sat, 30 Mar 2019 11:00:09 -0400 Subject: Re-add cog inheritance removed by poor merge conflict resolution --- bot/seasons/christmas/adventofcode.py | 2 +- bot/seasons/evergreen/error_handler.py | 2 +- bot/seasons/evergreen/fun.py | 2 +- bot/seasons/evergreen/uptime.py | 2 +- bot/seasons/halloween/candy_collection.py | 2 +- bot/seasons/halloween/hacktoberstats.py | 2 +- bot/seasons/halloween/halloween_facts.py | 2 +- bot/seasons/halloween/halloweenify.py | 2 +- bot/seasons/halloween/scarymovie.py | 2 +- bot/seasons/halloween/spookyavatar.py | 2 +- bot/seasons/halloween/spookygif.py | 2 +- bot/seasons/halloween/spookyreact.py | 2 +- bot/seasons/halloween/spookysound.py | 2 +- bot/seasons/halloween/timeleft.py | 2 +- bot/seasons/season.py | 2 +- bot/seasons/valentines/be_my_valentine.py | 2 +- bot/seasons/valentines/movie_generator.py | 2 +- bot/seasons/valentines/myvalenstate.py | 2 +- bot/seasons/valentines/pickuplines.py | 2 +- bot/seasons/valentines/savethedate.py | 2 +- bot/seasons/valentines/valentine_zodiac.py | 2 +- bot/seasons/valentines/whoisvalentine.py | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index f61f34b5..5d05dce6 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -103,7 +103,7 @@ async def day_countdown(bot: commands.Bot): await asyncio.sleep(120) -class AdventOfCode: +class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho.""" def __init__(self, bot: commands.Bot): diff --git a/bot/seasons/evergreen/error_handler.py b/bot/seasons/evergreen/error_handler.py index b0d05c41..26afe814 100644 --- a/bot/seasons/evergreen/error_handler.py +++ b/bot/seasons/evergreen/error_handler.py @@ -8,7 +8,7 @@ from discord.ext import commands log = logging.getLogger(__name__) -class CommandErrorHandler: +class CommandErrorHandler(commands.Cog): """A error handler for the PythonDiscord server.""" def __init__(self, bot): diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index 286d8462..05cf504e 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -8,7 +8,7 @@ from bot.constants import Emojis log = logging.getLogger(__name__) -class Fun: +class Fun(commands.Cog): """A collection of general commands for fun.""" def __init__(self, bot): diff --git a/bot/seasons/evergreen/uptime.py b/bot/seasons/evergreen/uptime.py index 4d5ac584..32c2b59d 100644 --- a/bot/seasons/evergreen/uptime.py +++ b/bot/seasons/evergreen/uptime.py @@ -9,7 +9,7 @@ from bot import start_time log = logging.getLogger(__name__) -class Uptime: +class Uptime(commands.Cog): """A cog for posting the bot's uptime.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py index 2e010cbc..70648e64 100644 --- a/bot/seasons/halloween/candy_collection.py +++ b/bot/seasons/halloween/candy_collection.py @@ -20,7 +20,7 @@ ADD_SKULL_REACTION_CHANCE = 50 # 2% ADD_SKULL_EXISTING_REACTION_CHANCE = 20 # 5% -class CandyCollection: +class CandyCollection(commands.Cog): """Candy collection game Cog.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py index ce32ad9f..42623669 100644 --- a/bot/seasons/halloween/hacktoberstats.py +++ b/bot/seasons/halloween/hacktoberstats.py @@ -13,7 +13,7 @@ from discord.ext import commands log = logging.getLogger(__name__) -class HacktoberStats: +class HacktoberStats(commands.Cog): """Hacktoberfest statistics Cog.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/halloween_facts.py b/bot/seasons/halloween/halloween_facts.py index 3ec65b87..ee90dbd3 100644 --- a/bot/seasons/halloween/halloween_facts.py +++ b/bot/seasons/halloween/halloween_facts.py @@ -25,7 +25,7 @@ PUMPKIN_ORANGE = discord.Color(0xFF7518) INTERVAL = timedelta(hours=6).total_seconds() -class HalloweenFacts: +class HalloweenFacts(commands.Cog): """A Cog for displaying interesting facts about Halloween.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/halloweenify.py b/bot/seasons/halloween/halloweenify.py index daf64ac0..ce057889 100644 --- a/bot/seasons/halloween/halloweenify.py +++ b/bot/seasons/halloween/halloweenify.py @@ -10,7 +10,7 @@ from discord.ext.commands.cooldowns import BucketType log = logging.getLogger(__name__) -class Halloweenify: +class Halloweenify(commands.Cog): """A cog to change a invokers nickname to a spooky one!""" def __init__(self, bot): diff --git a/bot/seasons/halloween/scarymovie.py b/bot/seasons/halloween/scarymovie.py index 5651c9bb..3878ef7f 100644 --- a/bot/seasons/halloween/scarymovie.py +++ b/bot/seasons/halloween/scarymovie.py @@ -13,7 +13,7 @@ TMDB_API_KEY = environ.get('TMDB_API_KEY') TMDB_TOKEN = environ.get('TMDB_TOKEN') -class ScaryMovie: +class ScaryMovie(commands.Cog): """Selects a random scary movie and embeds info into Discord chat.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/spookyavatar.py b/bot/seasons/halloween/spookyavatar.py index 042df701..15c7c431 100644 --- a/bot/seasons/halloween/spookyavatar.py +++ b/bot/seasons/halloween/spookyavatar.py @@ -12,7 +12,7 @@ from bot.utils.halloween import spookifications log = logging.getLogger(__name__) -class SpookyAvatar: +class SpookyAvatar(commands.Cog): """A cog that spookifies an avatar.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/spookygif.py b/bot/seasons/halloween/spookygif.py index ce8aef06..37d46c01 100644 --- a/bot/seasons/halloween/spookygif.py +++ b/bot/seasons/halloween/spookygif.py @@ -9,7 +9,7 @@ from bot.constants import Tokens log = logging.getLogger(__name__) -class SpookyGif: +class SpookyGif(commands.Cog): """A cog to fetch a random spooky gif from the web!""" def __init__(self, bot): diff --git a/bot/seasons/halloween/spookyreact.py b/bot/seasons/halloween/spookyreact.py index f1dbb905..9b14507a 100644 --- a/bot/seasons/halloween/spookyreact.py +++ b/bot/seasons/halloween/spookyreact.py @@ -17,7 +17,7 @@ SPOOKY_TRIGGERS = { } -class SpookyReact: +class SpookyReact(Cog): """A cog that makes the bot react to message triggers.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/spookysound.py b/bot/seasons/halloween/spookysound.py index b62a9893..7c4d8113 100644 --- a/bot/seasons/halloween/spookysound.py +++ b/bot/seasons/halloween/spookysound.py @@ -10,7 +10,7 @@ from bot.constants import Hacktoberfest log = logging.getLogger(__name__) -class SpookySound: +class SpookySound(commands.Cog): """A cog that plays a spooky sound in a voice channel on command.""" def __init__(self, bot): diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index 56a3eaed..3ea2d9ad 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -6,7 +6,7 @@ from discord.ext import commands log = logging.getLogger(__name__) -class TimeLeft: +class TimeLeft(commands.Cog): """A Cog that tells you how long left until Hacktober is over!""" def __init__(self, bot): diff --git a/bot/seasons/season.py b/bot/seasons/season.py index a64f6ca6..89ca3ca7 100644 --- a/bot/seasons/season.py +++ b/bot/seasons/season.py @@ -349,7 +349,7 @@ class SeasonBase: await bot.send_log("SeasonalBot Loaded!", f"Active Season: **{self.name_clean}**") -class SeasonManager: +class SeasonManager(commands.Cog): """A cog for managing seasons.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py index d90e73aa..55c4adb1 100644 --- a/bot/seasons/valentines/be_my_valentine.py +++ b/bot/seasons/valentines/be_my_valentine.py @@ -15,7 +15,7 @@ log = logging.getLogger(__name__) HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -class BeMyValentine: +class BeMyValentine(commands.Cog): """A cog that sends Valentines to other users!""" def __init__(self, bot): diff --git a/bot/seasons/valentines/movie_generator.py b/bot/seasons/valentines/movie_generator.py index 1b1a4a2d..a09a563f 100644 --- a/bot/seasons/valentines/movie_generator.py +++ b/bot/seasons/valentines/movie_generator.py @@ -11,7 +11,7 @@ TMDB_API_KEY = environ.get("TMDB_API_KEY") log = logging.getLogger(__name__) -class RomanceMovieFinder: +class RomanceMovieFinder(commands.Cog): """A cog that returns a random romance movie suggestion to a user.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/myvalenstate.py b/bot/seasons/valentines/myvalenstate.py index 0ea8fbab..344f52f6 100644 --- a/bot/seasons/valentines/myvalenstate.py +++ b/bot/seasons/valentines/myvalenstate.py @@ -15,7 +15,7 @@ with open(Path('bot', 'resources', 'valentines', 'valenstates.json'), 'r') as fi STATES = json.load(file) -class MyValenstate: +class MyValenstate(commands.Cog): """A Cog to find your most likely Valentine's vacation destination.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/pickuplines.py b/bot/seasons/valentines/pickuplines.py index 193eb788..ad75c93f 100644 --- a/bot/seasons/valentines/pickuplines.py +++ b/bot/seasons/valentines/pickuplines.py @@ -14,7 +14,7 @@ with open(Path('bot', 'resources', 'valentines', 'pickup_lines.json'), 'r', enco pickup_lines = load(f) -class PickupLine: +class PickupLine(commands.Cog): """A cog that gives random cheesy pickup lines.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/savethedate.py b/bot/seasons/valentines/savethedate.py index 76f418a2..281625a4 100644 --- a/bot/seasons/valentines/savethedate.py +++ b/bot/seasons/valentines/savethedate.py @@ -16,7 +16,7 @@ with open(Path('bot', 'resources', 'valentines', 'date_ideas.json'), 'r', encodi VALENTINES_DATES = load(f) -class SaveTheDate: +class SaveTheDate(commands.Cog): """A cog that gives random suggestion for a Valentine's date.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/valentine_zodiac.py b/bot/seasons/valentines/valentine_zodiac.py index 764c8ccc..1700260e 100644 --- a/bot/seasons/valentines/valentine_zodiac.py +++ b/bot/seasons/valentines/valentine_zodiac.py @@ -14,7 +14,7 @@ LETTER_EMOJI = ':love_letter:' HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"] -class ValentineZodiac: +class ValentineZodiac(commands.Cog): """A cog that returns a counter compatible zodiac sign to the given user's zodiac sign.""" def __init__(self, bot): diff --git a/bot/seasons/valentines/whoisvalentine.py b/bot/seasons/valentines/whoisvalentine.py index b7c47121..96d97e22 100644 --- a/bot/seasons/valentines/whoisvalentine.py +++ b/bot/seasons/valentines/whoisvalentine.py @@ -14,7 +14,7 @@ with open(Path("bot", "resources", "valentines", "valentine_facts.json"), "r") a FACTS = json.load(file) -class ValentineFacts: +class ValentineFacts(commands.Cog): """A Cog for displaying facts about Saint Valentine.""" def __init__(self, bot): -- cgit v1.2.3 From 1049ee3e51ca4dcc3faa6ab02f378fadf5ec231f Mon Sep 17 00:00:00 2001 From: Suhail Date: Tue, 23 Apr 2019 18:28:04 +0100 Subject: Constants cleaning --- bot/constants.py | 3 --- bot/seasons/christmas/adventofcode.py | 4 ++-- bot/seasons/halloween/candy_collection.py | 10 +++++----- bot/seasons/halloween/halloween_facts.py | 4 ++-- bot/seasons/valentines/be_my_valentine.py | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/constants.py b/bot/constants.py index d362c90e..52c76cda 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -18,7 +18,6 @@ class AdventOfCode: leaderboard_join_code = str(environ.get("AOC_JOIN_CODE", None)) leaderboard_max_displayed_members = 10 year = 2018 - channel_id = int(environ.get("AOC_CHANNEL_ID", 517745814039166986)) role_id = int(environ.get("AOC_ROLE_ID", 518565788744024082)) @@ -84,12 +83,10 @@ class Emojis: class Lovefest: - channel_id = int(environ.get("LOVEFEST_CHANNEL_ID", 542272993192050698)) role_id = int(environ.get("LOVEFEST_ROLE_ID", 542431903886606399)) class Hacktoberfest(NamedTuple): - channel_id = 498804484324196362 voice_id = 514420006474219521 diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 5d05dce6..32858673 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,7 +13,7 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Tokens +from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Tokens log = logging.getLogger(__name__) @@ -88,7 +88,7 @@ async def day_countdown(bot: commands.Bot): await asyncio.sleep(time_left.seconds) - channel = bot.get_channel(AocConfig.channel_id) + channel = bot.get_channel(Channels.seasonalbot_chat) if not channel: log.error("Could not find the AoC channel to send notification in") diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py index 70648e64..f8ab4c60 100644 --- a/bot/seasons/halloween/candy_collection.py +++ b/bot/seasons/halloween/candy_collection.py @@ -7,7 +7,7 @@ import random import discord from discord.ext import commands -from bot.constants import Hacktoberfest +from bot.constants import Channels log = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class CandyCollection(commands.Cog): if message.author.bot: return # ensure it's hacktober channel - if message.channel.id != Hacktoberfest.channel_id: + if message.channel.id != Channels.seasonalbot_chat: return # do random check for skull first as it has the lower chance @@ -65,7 +65,7 @@ class CandyCollection(commands.Cog): return # check to ensure it is in correct channel - if message.channel.id != Hacktoberfest.channel_id: + if message.channel.id != Channels.seasonalbot_chat: return # if its not a candy or skull, and it is one of 10 most recent messages, @@ -127,7 +127,7 @@ class CandyCollection(commands.Cog): ten_recent = [] recent_msg = max(message.id for message in self.bot._connection._messages - if message.channel.id == Hacktoberfest.channel_id) + if message.channel.id == Channels.seasonalbot_chat) channel = await self.hacktober_channel() ten_recent.append(recent_msg.id) @@ -159,7 +159,7 @@ class CandyCollection(commands.Cog): async def hacktober_channel(self): """Get #hacktoberbot channel from its ID.""" - return self.bot.get_channel(id=Hacktoberfest.channel_id) + return self.bot.get_channel(id=Channels.seasonalbot_chat) async def remove_reactions(self, reaction): """Remove all candy/skull reactions.""" diff --git a/bot/seasons/halloween/halloween_facts.py b/bot/seasons/halloween/halloween_facts.py index ee90dbd3..ad9aa716 100644 --- a/bot/seasons/halloween/halloween_facts.py +++ b/bot/seasons/halloween/halloween_facts.py @@ -7,7 +7,7 @@ from pathlib import Path import discord from discord.ext import commands -from bot.constants import Hacktoberfest +from bot.constants import Channels log = logging.getLogger(__name__) @@ -40,7 +40,7 @@ class HalloweenFacts(commands.Cog): async def on_ready(self): """Get event Channel object and initialize fact task loop.""" - self.channel = self.bot.get_channel(Hacktoberfest.channel_id) + self.channel = self.bot.get_channel(Channels.seasonalbot_chat) self.bot.loop.create_task(self._fact_publisher_task()) def random_fact(self): diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py index 55c4adb1..19788577 100644 --- a/bot/seasons/valentines/be_my_valentine.py +++ b/bot/seasons/valentines/be_my_valentine.py @@ -8,7 +8,7 @@ import discord from discord.ext import commands from discord.ext.commands.cooldowns import BucketType -from bot.constants import Client, Colours, Lovefest +from bot.constants import Channels, Client, Colours, Lovefest log = logging.getLogger(__name__) @@ -99,7 +99,7 @@ class BeMyValentine(commands.Cog): emoji_1, emoji_2 = self.random_emoji() lovefest_role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id) - channel = self.bot.get_channel(Lovefest.channel_id) + channel = self.bot.get_channel(Channels.seasonalbot_chat) valentine, title = self.valentine_check(valentine_type) if user is None: -- cgit v1.2.3