aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-03-10 11:28:57 -0800
committerGravatar GitHub <[email protected]>2021-03-10 11:28:57 -0800
commit6e9a71c23b2cac5e5f6f581c36d284da11702a45 (patch)
treeb9e4cea4aa0a5719c9d8552b74490e8ffbbbde83 /bot/exts
parentsuggestion by @Xithrius (diff)
parentMerge pull request #616 from python-discord/aoc-fixes (diff)
Merge branch 'master' into earth_photos
Diffstat (limited to 'bot/exts')
-rw-r--r--bot/exts/christmas/advent_of_code/_cog.py7
-rw-r--r--bot/exts/evergreen/emoji.py (renamed from bot/exts/evergreen/emoji_count.py)67
-rw-r--r--bot/exts/evergreen/pythonfacts.py33
3 files changed, 83 insertions, 24 deletions
diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py
index 466edd48..29902306 100644
--- a/bot/exts/christmas/advent_of_code/_cog.py
+++ b/bot/exts/christmas/advent_of_code/_cog.py
@@ -36,9 +36,6 @@ class AdventOfCode(commands.Cog):
self.about_aoc_filepath = Path("./bot/resources/advent_of_code/about.json")
self.cached_about_aoc = self._build_about_embed()
- self.countdown_task = None
- self.status_task = None
-
notification_coro = _helpers.new_puzzle_notification(self.bot)
self.notification_task = self.bot.loop.create_task(notification_coro)
self.notification_task.set_name("Daily AoC Notification")
@@ -173,6 +170,7 @@ class AdventOfCode(commands.Cog):
else:
await ctx.message.add_reaction(Emojis.envelope)
+ @in_month(Month.DECEMBER)
@adventofcode_group.command(
name="leaderboard",
aliases=("board", "lb"),
@@ -198,6 +196,7 @@ class AdventOfCode(commands.Cog):
await ctx.send(content=f"{header}\n\n{table}", embed=info_embed)
+ @in_month(Month.DECEMBER)
@adventofcode_group.command(
name="global",
aliases=("globalboard", "gb"),
@@ -268,7 +267,7 @@ class AdventOfCode(commands.Cog):
def cog_unload(self) -> None:
"""Cancel season-related tasks on cog unload."""
log.debug("Unloading the cog and canceling the background task.")
- self.countdown_task.cancel()
+ self.notification_task.cancel()
self.status_task.cancel()
def _build_about_embed(self) -> discord.Embed:
diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji.py
index cc43e9ab..99f71218 100644
--- a/bot/exts/evergreen/emoji_count.py
+++ b/bot/exts/evergreen/emoji.py
@@ -1,49 +1,51 @@
-import datetime
import logging
import random
+import textwrap
from collections import defaultdict
-from typing import List, Tuple
+from datetime import datetime
+from typing import List, Optional, Tuple
-import discord
+from discord import Color, Embed, Emoji
from discord.ext import commands
from bot.constants import Colours, ERROR_REPLIES
from bot.utils.pagination import LinePaginator
+from bot.utils.time import time_since
log = logging.getLogger(__name__)
-class EmojiCount(commands.Cog):
- """Command that give random emoji based on category."""
+class Emojis(commands.Cog):
+ """A collection of commands related to emojis in the server."""
def __init__(self, bot: commands.Bot):
self.bot = bot
@staticmethod
- def embed_builder(emoji: dict) -> Tuple[discord.Embed, List[str]]:
+ def embed_builder(emoji: dict) -> Tuple[Embed, List[str]]:
"""Generates an embed with the emoji names and count."""
- embed = discord.Embed(
+ embed = Embed(
color=Colours.orange,
title="Emoji Count",
- timestamp=datetime.datetime.utcnow()
+ timestamp=datetime.utcnow()
)
msg = []
if len(emoji) == 1:
for category_name, category_emojis in emoji.items():
if len(category_emojis) == 1:
- msg.append(f"There is **{len(category_emojis)}** emoji in **{category_name}** category")
+ msg.append(f"There is **{len(category_emojis)}** emoji in the **{category_name}** category.")
else:
- msg.append(f"There are **{len(category_emojis)}** emojis in **{category_name}** category")
+ msg.append(f"There are **{len(category_emojis)}** emojis in the **{category_name}** category.")
embed.set_thumbnail(url=random.choice(category_emojis).url)
else:
for category_name, category_emojis in emoji.items():
emoji_choice = random.choice(category_emojis)
if len(category_emojis) > 1:
- emoji_info = f"There are **{len(category_emojis)}** emojis in **{category_name}** category"
+ emoji_info = f"There are **{len(category_emojis)}** emojis in the **{category_name}** category."
else:
- emoji_info = f"There is **{len(category_emojis)}** emoji in **{category_name}** category"
+ emoji_info = f"There is **{len(category_emojis)}** emoji in the **{category_name}** category."
if emoji_choice.animated:
msg.append(f'<a:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}')
else:
@@ -51,9 +53,9 @@ class EmojiCount(commands.Cog):
return embed, msg
@staticmethod
- def generate_invalid_embed(emojis: list) -> Tuple[discord.Embed, List[str]]:
- """Generates error embed."""
- embed = discord.Embed(
+ def generate_invalid_embed(emojis: list) -> Tuple[Embed, List[str]]:
+ """Generates error embed for invalid emoji categories."""
+ embed = Embed(
color=Colours.soft_red,
title=random.choice(ERROR_REPLIES)
)
@@ -64,11 +66,19 @@ class EmojiCount(commands.Cog):
emoji_dict[emoji.name.split("_")[0]].append(emoji)
error_comp = ', '.join(emoji_dict)
- msg.append(f"These are the valid categories\n```{error_comp}```")
+ msg.append(f"These are the valid emoji categories:\n```{error_comp}```")
return embed, msg
- @commands.command(name="emojicount", aliases=["ec", "emojis"])
- async def emoji_count(self, ctx: commands.Context, *, category_query: str = None) -> None:
+ @commands.group(name="emoji", invoke_without_command=True)
+ async def emoji_group(self, ctx: commands.Context, emoji: Optional[Emoji]) -> None:
+ """A group of commands related to emojis."""
+ if emoji is not None:
+ await ctx.invoke(self.info_command, emoji)
+ else:
+ await ctx.send_help(ctx.command)
+
+ @emoji_group.command(name="count", aliases=("c",))
+ async def count_command(self, ctx: commands.Context, *, category_query: str = None) -> None:
"""Returns embed with emoji category and info given by the user."""
emoji_dict = defaultdict(list)
@@ -91,7 +101,24 @@ class EmojiCount(commands.Cog):
embed, msg = self.embed_builder(emoji_dict)
await LinePaginator.paginate(lines=msg, ctx=ctx, embed=embed)
+ @emoji_group.command(name="info", aliases=("i",))
+ async def info_command(self, ctx: commands.Context, emoji: Emoji) -> None:
+ """Returns relevant information about a Discord Emoji."""
+ emoji_information = Embed(
+ title=f"Emoji Information: {emoji.name}",
+ description=textwrap.dedent(f"""
+ **Name:** {emoji.name}
+ **Created:** {time_since(emoji.created_at, precision="hours")}
+ **Date:** {datetime.strftime(emoji.created_at, "%d/%m/%Y")}
+ **ID:** {emoji.id}
+ """),
+ color=Color.blurple(),
+ url=str(emoji.url),
+ ).set_thumbnail(url=emoji.url)
+
+ await ctx.send(embed=emoji_information)
+
def setup(bot: commands.Bot) -> None:
- """Emoji Count Cog load."""
- bot.add_cog(EmojiCount(bot))
+ """Add the Emojis cog into the bot."""
+ bot.add_cog(Emojis(bot))
diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py
new file mode 100644
index 00000000..457c2fd3
--- /dev/null
+++ b/bot/exts/evergreen/pythonfacts.py
@@ -0,0 +1,33 @@
+import itertools
+
+import discord
+from discord.ext import commands
+
+from bot.constants import Colours
+
+with open('bot/resources/evergreen/python_facts.txt') as file:
+ FACTS = itertools.cycle(list(file))
+
+COLORS = itertools.cycle([Colours.python_blue, Colours.python_yellow])
+
+
+class PythonFacts(commands.Cog):
+ """Sends a random fun fact about Python."""
+
+ def __init__(self, bot: commands.Bot) -> None:
+ self.bot = bot
+
+ @commands.command(name='pythonfact', aliases=['pyfact'])
+ async def get_python_fact(self, ctx: commands.Context) -> None:
+ """Sends a Random fun fact about Python."""
+ embed = discord.Embed(title='Python Facts',
+ description=next(FACTS),
+ colour=next(COLORS))
+ embed.add_field(name='Suggestions',
+ value="Suggest more facts [here!](https://github.com/python-discord/meta/discussions/93)")
+ await ctx.send(embed=embed)
+
+
+def setup(bot: commands.Bot) -> None:
+ """Load PythonFacts Cog."""
+ bot.add_cog(PythonFacts(bot))