aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts
diff options
context:
space:
mode:
authorGravatar Dennis Pham <[email protected]>2020-10-04 21:39:11 -0400
committerGravatar GitHub <[email protected]>2020-10-04 21:39:11 -0400
commitb042dc0fcf4988db718b24a7a2d6d6cdddbc7e67 (patch)
tree2ee3cb74dacb2885f86c7fc744ffc185bf948966 /bot/exts
parentMerge branch 'master' into minesweeper-contribution (diff)
parentMerge pull request #469 from Anubhav1603/source_cmd (diff)
Merge branch 'master' into minesweeper-contribution
Diffstat (limited to 'bot/exts')
-rw-r--r--bot/exts/evergreen/bookmark.py3
-rw-r--r--bot/exts/evergreen/emoji_count.py91
-rw-r--r--bot/exts/evergreen/source.py109
-rw-r--r--bot/exts/halloween/hacktober-issue-finder.py12
-rw-r--r--bot/exts/halloween/hacktoberstats.py39
-rw-r--r--bot/exts/halloween/spookysound.py48
-rw-r--r--bot/exts/halloween/timeleft.py32
-rw-r--r--bot/exts/valentines/valentine_zodiac.py145
8 files changed, 376 insertions, 103 deletions
diff --git a/bot/exts/evergreen/bookmark.py b/bot/exts/evergreen/bookmark.py
index 73908702..5fa05d2e 100644
--- a/bot/exts/evergreen/bookmark.py
+++ b/bot/exts/evergreen/bookmark.py
@@ -5,6 +5,7 @@ import discord
from discord.ext import commands
from bot.constants import Colours, ERROR_REPLIES, Emojis, Icons
+from bot.utils.converters import WrappedMessageConverter
log = logging.getLogger(__name__)
@@ -19,7 +20,7 @@ class Bookmark(commands.Cog):
async def bookmark(
self,
ctx: commands.Context,
- target_message: discord.Message,
+ target_message: WrappedMessageConverter,
*,
title: str = "Bookmark"
) -> None:
diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py
new file mode 100644
index 00000000..ef900199
--- /dev/null
+++ b/bot/exts/evergreen/emoji_count.py
@@ -0,0 +1,91 @@
+import datetime
+import logging
+import random
+from typing import Dict, Optional
+
+import discord
+from discord.ext import commands
+
+from bot.constants import Colours, ERROR_REPLIES
+
+log = logging.getLogger(__name__)
+
+
+class EmojiCount(commands.Cog):
+ """Command that give random emoji based on category."""
+
+ def __init__(self, bot: commands.Bot):
+ self.bot = bot
+
+ def embed_builder(self, emoji: dict) -> discord.Embed:
+ """Generates an embed with the emoji names and count."""
+ embed = discord.Embed(
+ color=Colours.orange,
+ title="Emoji Count",
+ timestamp=datetime.datetime.utcnow()
+ )
+
+ if len(emoji) == 1:
+ for key, value in emoji.items():
+ embed.description = f"There are **{len(value)}** emojis in the **{key}** category"
+ embed.set_thumbnail(url=random.choice(value).url)
+ else:
+ msg = ''
+ for key, value in emoji.items():
+ emoji_choice = random.choice(value)
+ emoji_info = f'There are **{len(value)}** emojis in the **{key}** category\n'
+ msg += f'<:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}'
+ embed.description = msg
+ return embed
+
+ @staticmethod
+ def generate_invalid_embed(ctx: commands.Context) -> discord.Embed:
+ """Genrates error embed."""
+ embed = discord.Embed(
+ color=Colours.soft_red,
+ title=random.choice(ERROR_REPLIES)
+ )
+
+ emoji_dict = {}
+ for emoji in ctx.guild.emojis:
+ emoji_dict[emoji.name.split("_")[0]] = []
+
+ error_comp = ', '.join(key for key in emoji_dict.keys())
+ embed.description = f"These are the valid categories\n```{error_comp}```"
+ return embed
+
+ def emoji_list(self, ctx: commands.Context, categories: dict) -> Dict:
+ """Generates an embed with the emoji names and count."""
+ out = {category: [] for category in categories}
+
+ for emoji in ctx.guild.emojis:
+ category = emoji.name.split('_')[0]
+ if category in out:
+ out[category].append(emoji)
+ return out
+
+ @commands.command(name="emoji_count", aliases=["ec"])
+ async def ec(self, ctx: commands.Context, *, emoji: str = None) -> Optional[str]:
+ """Returns embed with emoji category and info given by the user."""
+ emoji_dict = {}
+
+ for a in ctx.guild.emojis:
+ if emoji is None:
+ log.trace("Emoji Category not provided by the user")
+ emoji_dict.update({a.name.split("_")[0]: []})
+ elif a.name.split("_")[0] in emoji:
+ log.trace("Emoji Category provided by the user")
+ emoji_dict.update({a.name.split("_")[0]: []})
+
+ emoji_dict = self.emoji_list(ctx, emoji_dict)
+
+ if len(emoji_dict) == 0:
+ embed = self.generate_invalid_embed(ctx)
+ else:
+ embed = self.embed_builder(emoji_dict)
+ await ctx.send(embed=embed)
+
+
+def setup(bot: commands.Bot) -> None:
+ """Emoji Count Cog load."""
+ bot.add_cog(EmojiCount(bot))
diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py
new file mode 100644
index 00000000..0725714f
--- /dev/null
+++ b/bot/exts/evergreen/source.py
@@ -0,0 +1,109 @@
+import inspect
+from pathlib import Path
+from typing import Optional, Tuple, Union
+
+from discord import Embed
+from discord.ext import commands
+
+from bot.constants import Source
+
+SourceType = Union[commands.Command, commands.Cog, str, commands.ExtensionNotLoaded]
+
+
+class SourceConverter(commands.Converter):
+ """Convert an argument into a help command, tag, command, or cog."""
+
+ async def convert(self, ctx: commands.Context, argument: str) -> SourceType:
+ """Convert argument into source object."""
+ cog = ctx.bot.get_cog(argument)
+ if cog:
+ return cog
+
+ cmd = ctx.bot.get_command(argument)
+ if cmd:
+ return cmd
+
+ raise commands.BadArgument(
+ f"Unable to convert `{argument}` to valid command or Cog."
+ )
+
+
+class BotSource(commands.Cog):
+ """Displays information about the bot's source code."""
+
+ def __init__(self, bot: commands.Bot):
+ self.bot = bot
+
+ @commands.command(name="source", aliases=("src",))
+ async def source_command(self, ctx: commands.Context, *, source_item: SourceConverter = None) -> None:
+ """Display information and a GitHub link to the source code of a command, tag, or cog."""
+ if not source_item:
+ embed = Embed(title="Seasonal Bot's GitHub Repository")
+ embed.add_field(name="Repository", value=f"[Go to GitHub]({Source.github})")
+ embed.set_thumbnail(url=Source.github_avatar_url)
+ await ctx.send(embed=embed)
+ return
+
+ embed = await self.build_embed(source_item)
+ await ctx.send(embed=embed)
+
+ def get_source_link(self, source_item: SourceType) -> Tuple[str, str, Optional[int]]:
+ """
+ Build GitHub link of source item, return this link, file location and first line number.
+
+ Raise BadArgument if `source_item` is a dynamically-created object (e.g. via internal eval).
+ """
+ if isinstance(source_item, commands.Command):
+ src = source_item.callback.__code__
+ filename = src.co_filename
+ else:
+ src = type(source_item)
+ try:
+ filename = inspect.getsourcefile(src)
+ except TypeError:
+ raise commands.BadArgument("Cannot get source for a dynamically-created object.")
+
+ if not isinstance(source_item, str):
+ try:
+ lines, first_line_no = inspect.getsourcelines(src)
+ except OSError:
+ raise commands.BadArgument("Cannot get source for a dynamically-created object.")
+
+ lines_extension = f"#L{first_line_no}-L{first_line_no+len(lines)-1}"
+ else:
+ first_line_no = None
+ lines_extension = ""
+
+ file_location = Path(filename).relative_to(Path.cwd()).as_posix()
+
+ url = f"{Source.github}/blob/master/{file_location}{lines_extension}"
+
+ return url, file_location, first_line_no or None
+
+ async def build_embed(self, source_object: SourceType) -> Optional[Embed]:
+ """Build embed based on source object."""
+ url, location, first_line = self.get_source_link(source_object)
+
+ if isinstance(source_object, commands.Command):
+ if source_object.cog_name == 'Help':
+ title = "Help Command"
+ description = source_object.__doc__.splitlines()[1]
+ else:
+ description = source_object.short_doc
+ title = f"Command: {source_object.qualified_name}"
+ else:
+ title = f"Cog: {source_object.qualified_name}"
+ description = source_object.description.splitlines()[0]
+
+ embed = Embed(title=title, description=description)
+ embed.set_thumbnail(url=Source.github_avatar_url)
+ embed.add_field(name="Source Code", value=f"[Go to GitHub]({url})")
+ line_text = f":{first_line}" if first_line else ""
+ embed.set_footer(text=f"{location}{line_text}")
+
+ return embed
+
+
+def setup(bot: commands.Bot) -> None:
+ """Load the BotSource cog."""
+ bot.add_cog(BotSource(bot))
diff --git a/bot/exts/halloween/hacktober-issue-finder.py b/bot/exts/halloween/hacktober-issue-finder.py
index b5ad1c4f..78acf391 100644
--- a/bot/exts/halloween/hacktober-issue-finder.py
+++ b/bot/exts/halloween/hacktober-issue-finder.py
@@ -7,13 +7,19 @@ import aiohttp
import discord
from discord.ext import commands
-from bot.constants import Month
+from bot.constants import Month, Tokens
from bot.utils.decorators import in_month
log = logging.getLogger(__name__)
URL = "https://api.github.com/search/issues?per_page=100&q=is:issue+label:hacktoberfest+language:python+state:open"
-HEADERS = {"Accept": "application / vnd.github.v3 + json"}
+
+REQUEST_HEADERS = {
+ "User-Agent": "Python Discord Hacktoberbot",
+ "Accept": "application / vnd.github.v3 + json"
+}
+if GITHUB_TOKEN := Tokens.github:
+ REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}"
class HacktoberIssues(commands.Cog):
@@ -66,7 +72,7 @@ class HacktoberIssues(commands.Cog):
url += f"&page={page}"
log.debug(f"making api request to url: {url}")
- async with session.get(url, headers=HEADERS) as response:
+ async with session.get(url, headers=REQUEST_HEADERS) as response:
if response.status != 200:
log.error(f"expected 200 status (got {response.status}) from the GitHub api.")
await ctx.send(f"ERROR: expected 200 status (got {response.status}) from the GitHub api.")
diff --git a/bot/exts/halloween/hacktoberstats.py b/bot/exts/halloween/hacktoberstats.py
index db5e37f2..ed1755e3 100644
--- a/bot/exts/halloween/hacktoberstats.py
+++ b/bot/exts/halloween/hacktoberstats.py
@@ -10,7 +10,7 @@ import aiohttp
import discord
from discord.ext import commands
-from bot.constants import Channels, Month, WHITELISTED_CHANNELS
+from bot.constants import Channels, Month, Tokens, WHITELISTED_CHANNELS
from bot.utils.decorators import in_month, override_in_channel
from bot.utils.persist import make_persistent
@@ -18,7 +18,16 @@ log = logging.getLogger(__name__)
CURRENT_YEAR = datetime.now().year # Used to construct GH API query
PRS_FOR_SHIRT = 4 # Minimum number of PRs before a shirt is awarded
-HACKTOBER_WHITELIST = WHITELISTED_CHANNELS + (Channels.hacktoberfest_2019,)
+HACKTOBER_WHITELIST = WHITELISTED_CHANNELS + (Channels.hacktoberfest_2020,)
+
+REQUEST_HEADERS = {"User-Agent": "Python Discord Hacktoberbot"}
+if GITHUB_TOKEN := Tokens.github:
+ REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}"
+
+GITHUB_NONEXISTENT_USER_MESSAGE = (
+ "The listed users cannot be searched either because the users do not exist "
+ "or you do not have permission to view the users."
+)
class HacktoberStats(commands.Cog):
@@ -29,7 +38,7 @@ class HacktoberStats(commands.Cog):
self.link_json = make_persistent(Path("bot", "resources", "halloween", "github_links.json"))
self.linked_accounts = self.load_linked_users()
- @in_month(Month.OCTOBER)
+ @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER)
@commands.group(name="hacktoberstats", aliases=("hackstats",), invoke_without_command=True)
@override_in_channel(HACKTOBER_WHITELIST)
async def hacktoberstats_group(self, ctx: commands.Context, github_username: str = None) -> None:
@@ -57,7 +66,7 @@ class HacktoberStats(commands.Cog):
await self.get_stats(ctx, github_username)
- @in_month(Month.OCTOBER)
+ @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER)
@hacktoberstats_group.command(name="link")
@override_in_channel(HACKTOBER_WHITELIST)
async def link_user(self, ctx: commands.Context, github_username: str = None) -> None:
@@ -92,7 +101,7 @@ class HacktoberStats(commands.Cog):
logging.info(f"{author_id} tried to link a GitHub account but didn't provide a username")
await ctx.send(f"{author_mention}, a GitHub username is required to link your account")
- @in_month(Month.OCTOBER)
+ @in_month(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER)
@hacktoberstats_group.command(name="unlink")
@override_in_channel(HACKTOBER_WHITELIST)
async def unlink_user(self, ctx: commands.Context) -> None:
@@ -175,11 +184,11 @@ class HacktoberStats(commands.Cog):
n = pr_stats['n_prs']
if n >= PRS_FOR_SHIRT:
- shirtstr = f"**{github_username} has earned a tshirt!**"
+ shirtstr = f"**{github_username} has earned a T-shirt or a tree!**"
elif n == PRS_FOR_SHIRT - 1:
- shirtstr = f"**{github_username} is 1 PR away from a tshirt!**"
+ shirtstr = f"**{github_username} is 1 PR away from a T-shirt or a tree!**"
else:
- shirtstr = f"**{github_username} is {PRS_FOR_SHIRT - n} PRs away from a tshirt!**"
+ shirtstr = f"**{github_username} is {PRS_FOR_SHIRT - n} PRs away from a T-shirt or a tree!**"
stats_embed = discord.Embed(
title=f"{github_username}'s Hacktoberfest",
@@ -196,7 +205,7 @@ class HacktoberStats(commands.Cog):
stats_embed.set_author(
name="Hacktoberfest",
url="https://hacktoberfest.digitalocean.com",
- icon_url="https://hacktoberfest.digitalocean.com/pretty_logo.png"
+ icon_url="https://avatars1.githubusercontent.com/u/35706162?s=200&v=4"
)
stats_embed.add_field(
name="Top 5 Repositories:",
@@ -242,16 +251,22 @@ class HacktoberStats(commands.Cog):
f"&per_page={per_page}"
)
- headers = {"user-agent": "Discord Python Hacktoberbot"}
async with aiohttp.ClientSession() as session:
- async with session.get(query_url, headers=headers) as resp:
+ async with session.get(query_url, headers=REQUEST_HEADERS) as resp:
jsonresp = await resp.json()
if "message" in jsonresp.keys():
# One of the parameters is invalid, short circuit for now
api_message = jsonresp["errors"][0]["message"]
- logging.error(f"GitHub API request for '{github_username}' failed with message: {api_message}")
+
+ # Ignore logging non-existent users or users we do not have permission to see
+ if api_message == GITHUB_NONEXISTENT_USER_MESSAGE:
+ logging.debug(f"No GitHub user found named '{github_username}'")
+ else:
+ logging.error(f"GitHub API request for '{github_username}' failed with message: {api_message}")
+
return
+
else:
if jsonresp["total_count"] == 0:
# Short circuit if there aren't any PRs
diff --git a/bot/exts/halloween/spookysound.py b/bot/exts/halloween/spookysound.py
deleted file mode 100644
index 569a9153..00000000
--- a/bot/exts/halloween/spookysound.py
+++ /dev/null
@@ -1,48 +0,0 @@
-import logging
-import random
-from pathlib import Path
-
-import discord
-from discord.ext import commands
-
-from bot.bot import SeasonalBot
-from bot.constants import Hacktoberfest
-
-log = logging.getLogger(__name__)
-
-
-class SpookySound(commands.Cog):
- """A cog that plays a spooky sound in a voice channel on command."""
-
- def __init__(self, bot: SeasonalBot):
- self.bot = bot
- self.sound_files = list(Path("bot/resources/halloween/spookysounds").glob("*.mp3"))
- self.channel = None
-
- @commands.cooldown(rate=1, per=1)
- @commands.command(brief="Play a spooky sound, restricted to once per 2 mins")
- async def spookysound(self, ctx: commands.Context) -> None:
- """
- Connect to the Hacktoberbot voice channel, play a random spooky sound, then disconnect.
-
- Cannot be used more than once in 2 minutes.
- """
- if not self.channel:
- await self.bot.wait_until_guild_available()
- self.channel = self.bot.get_channel(Hacktoberfest.voice_id)
-
- await ctx.send("Initiating spooky sound...")
- file_path = random.choice(self.sound_files)
- src = discord.FFmpegPCMAudio(str(file_path.resolve()))
- voice = await self.channel.connect()
- voice.play(src, after=lambda e: self.bot.loop.create_task(self.disconnect(voice)))
-
- @staticmethod
- async def disconnect(voice: discord.VoiceClient) -> None:
- """Helper method to disconnect a given voice client."""
- await voice.disconnect()
-
-
-def setup(bot: SeasonalBot) -> None:
- """Spooky sound Cog load."""
- bot.add_cog(SpookySound(bot))
diff --git a/bot/exts/halloween/timeleft.py b/bot/exts/halloween/timeleft.py
index 295acc89..47adb09b 100644
--- a/bot/exts/halloween/timeleft.py
+++ b/bot/exts/halloween/timeleft.py
@@ -13,20 +13,23 @@ class TimeLeft(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- @staticmethod
- def in_october() -> bool:
- """Return True if the current month is October."""
- return datetime.utcnow().month == 10
+ def in_hacktober(self) -> bool:
+ """Return True if the current time is within Hacktoberfest."""
+ _, end, start = self.load_date()
+
+ now = datetime.utcnow()
+
+ return start <= now <= end
@staticmethod
- def load_date() -> Tuple[int, datetime, datetime]:
+ def load_date() -> Tuple[datetime, datetime, datetime]:
"""Return of a tuple of the current time and the end and start times of the next October."""
now = datetime.utcnow()
year = now.year
if now.month > 10:
year += 1
- end = datetime(year, 11, 1, 11, 59, 59)
- start = datetime(year, 10, 1)
+ end = datetime(year, 11, 1, 12) # November 1st 12:00 (UTC-12:00)
+ start = datetime(year, 9, 30, 10) # September 30th 10:00 (UTC+14:00)
return now, end, start
@commands.command()
@@ -35,16 +38,23 @@ class TimeLeft(commands.Cog):
Calculates the time left until the end of Hacktober.
Whilst in October, displays the days, hours and minutes left.
- Only displays the days left until the beginning and end whilst in a different month
+ Only displays the days left until the beginning and end whilst in a different month.
+
+ This factors in that Hacktoberfest starts when it is October anywhere in the world
+ and ends with the same rules. It treats the start as UTC+14:00 and the end as
+ UTC-12.
"""
now, end, start = self.load_date()
diff = end - now
days, seconds = diff.days, diff.seconds
- if self.in_october():
+ if self.in_hacktober():
minutes = seconds // 60
hours, minutes = divmod(minutes, 60)
- await ctx.send(f"There is currently only {days} days, {hours} hours and {minutes}"
- "minutes left until the end of Hacktober.")
+
+ await ctx.send(
+ f"There are {days} days, {hours} hours and {minutes}"
+ f" minutes left until the end of Hacktober."
+ )
else:
start_diff = start - now
start_days = start_diff.days
diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py
index ef9ddc78..2696999f 100644
--- a/bot/exts/valentines/valentine_zodiac.py
+++ b/bot/exts/valentines/valentine_zodiac.py
@@ -1,7 +1,10 @@
+import calendar
+import json
import logging
import random
-from json import load
+from datetime import datetime
from pathlib import Path
+from typing import Tuple, Union
import discord
from discord.ext import commands
@@ -19,37 +22,123 @@ class ValentineZodiac(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- self.zodiacs = self.load_json()
+ self.zodiacs, self.zodiac_fact = self.load_comp_json()
@staticmethod
- def load_json() -> dict:
+ def load_comp_json() -> Tuple[dict, dict]:
"""Load zodiac compatibility from static JSON resource."""
- p = Path("bot/resources/valentines/zodiac_compatibility.json")
- with p.open(encoding="utf8") as json_data:
- zodiacs = load(json_data)
- return zodiacs
-
- @commands.command(name="partnerzodiac")
- async def counter_zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None:
- """Provides a counter compatible zodiac sign to the given user's zodiac sign."""
- try:
- compatible_zodiac = random.choice(self.zodiacs[zodiac_sign.lower()])
- except KeyError:
- return await ctx.send(zodiac_sign.capitalize() + " zodiac sign does not exist.")
-
- emoji1 = random.choice(HEART_EMOJIS)
- emoji2 = random.choice(HEART_EMOJIS)
- embed = discord.Embed(
- title="Zodic Compatibility",
- description=f'{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac["Zodiac"]}\n'
- f'{emoji2}Compatibility meter : {compatible_zodiac["compatibility_score"]}{emoji2}',
- color=Colours.pink
- )
- embed.add_field(
- name=f'A letter from Dr.Zodiac {LETTER_EMOJI}',
- value=compatible_zodiac['description']
- )
+ explanation_file = Path("bot/resources/valentines/zodiac_explanation.json")
+ compatibility_file = Path("bot/resources/valentines/zodiac_compatibility.json")
+ with explanation_file.open(encoding="utf8") as json_data:
+ zodiac_fact = json.load(json_data)
+ for zodiac_data in zodiac_fact.values():
+ zodiac_data['start_at'] = datetime.fromisoformat(zodiac_data['start_at'])
+ zodiac_data['end_at'] = datetime.fromisoformat(zodiac_data['end_at'])
+
+ with compatibility_file.open(encoding="utf8") as json_data:
+ zodiacs = json.load(json_data)
+
+ return zodiacs, zodiac_fact
+
+ def generate_invalidname_embed(self, zodiac: str) -> discord.Embed:
+ """Returns error embed."""
+ embed = discord.Embed()
+ embed.color = Colours.soft_red
+ error_msg = f"**{zodiac}** is not a valid zodiac sign, here is the list of valid zodiac signs.\n"
+ names = list(self.zodiac_fact)
+ middle_index = len(names) // 2
+ first_half_names = ", ".join(names[:middle_index])
+ second_half_names = ", ".join(names[middle_index:])
+ embed.description = error_msg + first_half_names + ",\n" + second_half_names
+ log.info("Invalid zodiac name provided.")
+ return embed
+
+ def zodiac_build_embed(self, zodiac: str) -> discord.Embed:
+ """Gives informative zodiac embed."""
+ zodiac = zodiac.capitalize()
+ embed = discord.Embed()
+ embed.color = Colours.pink
+ if zodiac in self.zodiac_fact:
+ log.trace("Making zodiac embed.")
+ embed.title = f"__{zodiac}__"
+ embed.description = self.zodiac_fact[zodiac]["About"]
+ embed.add_field(name='__Motto__', value=self.zodiac_fact[zodiac]["Motto"], inline=False)
+ embed.add_field(name='__Strengths__', value=self.zodiac_fact[zodiac]["Strengths"], inline=False)
+ embed.add_field(name='__Weaknesses__', value=self.zodiac_fact[zodiac]["Weaknesses"], inline=False)
+ embed.add_field(name='__Full form__', value=self.zodiac_fact[zodiac]["full_form"], inline=False)
+ embed.set_thumbnail(url=self.zodiac_fact[zodiac]["url"])
+ else:
+ embed = self.generate_invalidname_embed(zodiac)
+ log.trace("Successfully created zodiac information embed.")
+ return embed
+
+ def zodiac_date_verifier(self, query_date: datetime) -> str:
+ """Returns zodiac sign by checking date."""
+ for zodiac_name, zodiac_data in self.zodiac_fact.items():
+ if zodiac_data["start_at"].date() <= query_date.date() <= zodiac_data["end_at"].date():
+ log.trace("Zodiac name sent.")
+ return zodiac_name
+
+ @commands.group(name='zodiac', invoke_without_command=True)
+ async def zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None:
+ """Provides information about zodiac sign by taking zodiac sign name as input."""
+ final_embed = self.zodiac_build_embed(zodiac_sign)
+ await ctx.send(embed=final_embed)
+ log.trace("Embed successfully sent.")
+
+ @zodiac.command(name="date")
+ async def date_and_month(self, ctx: commands.Context, date: int, month: Union[int, str]) -> None:
+ """Provides information about zodiac sign by taking month and date as input."""
+ if isinstance(month, str):
+ month = month.capitalize()
+ try:
+ month = list(calendar.month_abbr).index(month[:3])
+ log.trace('Valid month name entered by user')
+ except ValueError:
+ log.info('Invalid month name entered by user')
+ await ctx.send(f"Sorry, but `{month}` is not a valid month name.")
+ return
+ if (month == 1 and 1 <= date <= 19) or (month == 12 and 22 <= date <= 31):
+ zodiac = "capricorn"
+ final_embed = self.zodiac_build_embed(zodiac)
+ else:
+ try:
+ zodiac_sign_based_on_date = self.zodiac_date_verifier(datetime(2020, month, date))
+ log.trace("zodiac sign based on month and date received.")
+ except ValueError as e:
+ final_embed = discord.Embed()
+ final_embed.color = Colours.soft_red
+ final_embed.description = f"Zodiac sign could not be found because.\n```{e}```"
+ log.info(f'Error in "zodiac date" command:\n{e}.')
+ else:
+ final_embed = self.zodiac_build_embed(zodiac_sign_based_on_date)
+
+ await ctx.send(embed=final_embed)
+ log.trace("Embed from date successfully sent.")
+
+ @zodiac.command(name="partnerzodiac", aliases=['partner'])
+ async def partner_zodiac(self, ctx: commands.Context, zodiac_sign: str) -> None:
+ """Provides a random counter compatible zodiac sign to the given user's zodiac sign."""
+ embed = discord.Embed()
+ embed.color = Colours.pink
+ zodiac_check = self.zodiacs.get(zodiac_sign.capitalize())
+ if zodiac_check:
+ compatible_zodiac = random.choice(self.zodiacs[zodiac_sign.capitalize()])
+ emoji1 = random.choice(HEART_EMOJIS)
+ emoji2 = random.choice(HEART_EMOJIS)
+ embed.title = "Zodiac Compatibility"
+ embed.description = (
+ f'{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac["Zodiac"]}\n'
+ f'{emoji2}Compatibility meter : {compatible_zodiac["compatibility_score"]}{emoji2}'
+ )
+ embed.add_field(
+ name=f'A letter from Dr.Zodiac {LETTER_EMOJI}',
+ value=compatible_zodiac['description']
+ )
+ else:
+ embed = self.generate_invalidname_embed(zodiac_sign)
await ctx.send(embed=embed)
+ log.trace("Embed from date successfully sent.")
def setup(bot: commands.Bot) -> None: