diff options
-rw-r--r-- | bot/exts/valentines/valentine_zodiac.py | 145 | ||||
-rw-r--r-- | bot/resources/valentines/zodiac_compatibility.json | 24 | ||||
-rw-r--r-- | bot/resources/valentines/zodiac_explanation.json | 122 |
3 files changed, 251 insertions, 40 deletions
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: diff --git a/bot/resources/valentines/zodiac_compatibility.json b/bot/resources/valentines/zodiac_compatibility.json index 3971d40d..ea9a7b37 100644 --- a/bot/resources/valentines/zodiac_compatibility.json +++ b/bot/resources/valentines/zodiac_compatibility.json @@ -1,5 +1,5 @@ { - "aries":[ + "Aries":[ { "Zodiac" : "Sagittarius", "description" : "The Archer is one of the most compatible signs Aries should consider when searching out relationships that will bear fruit. Sagittarians share a certain love of freedom with Aries that will help the two of them conquer new territory together.", @@ -21,7 +21,7 @@ "compatibility_score" : "74%" } ], - "taurus":[ + "Taurus":[ { "Zodiac" : "Virgo", "description" : "Although these signs have their set of differences, the Virgo Taurus compatibility is usually pretty strong. This is because both the signs want the same thing ultimately and have generally synchronous ways of reaching those points. This helps them complement each other and create a healthy relationship between them.", @@ -43,7 +43,7 @@ "compatibility_score" : "91%" } ], - "gemini":[ + "Gemini":[ { "Zodiac" : "Aries", "description" : "The theorem of astrology says that Aries and Gemini have a zero tolerance for boredom and will at once get rid of anything dull. An Arian will let a Geminian enjoy his personal freedom and the Gemini will respect his individuality.", @@ -65,7 +65,7 @@ "compatibility_score" : "91%" } ], - "cancer":[ + "Cancer":[ { "Zodiac" : "Taurus", "description" : "The Cancer Taurus zodiac relationship compatibility is strong because of their mutual love for safety, stability, and comfort. Their mutual understanding will always be powerful, which will be the pillar of strength of their relationship.", @@ -82,7 +82,7 @@ "compatibility_score" : "77%" } ], - "leo":[ + "Leo":[ { "Zodiac" : "Aries", "description" : "A Leo is generous and an Arian is open to life. Sharing the same likes and dislikes, they both crave for fun, romance and excitement. A Leo respects an Arian's need for freedom because an Arian does not interfere much in the life of a Leo. Aries will love the charisma and ideas of the Leo.", @@ -104,7 +104,7 @@ "compatibility_score" : "75%" } ], - "virgo":[ + "Virgo":[ { "Zodiac" : "Taurus", "description" : "Although these signs have their set of differences, the Virgo Taurus compatibility is usually pretty strong. This is because both the signs want the same thing ultimately and have generally synchronous ways of reaching those points. This helps them complement each other and create a healthy relationship between them.", @@ -126,7 +126,7 @@ "compatibility_score" : "77%" } ], - "libra":[ + "Libra":[ { "Zodiac" : "Leo", "description" : "Libra and Leo love match can work well for both the partners and truly help them learn from each other and grow individually, as well as together. Libra and Leo, when in the right frame of mind, form a formidable couple that attracts admiration and respect everywhere it goes.", @@ -148,7 +148,7 @@ "compatibility_score" : "71%" } ], - "scorpio":[ + "Scorpio":[ { "Zodiac" : "Cancer", "description" : "This union is not unusual, but will take a fair share of work in the start. A strong foundation of clear cut communication is mandatory to make this a loving and stress free relationship!", @@ -170,7 +170,7 @@ "compatibility_score" : "81%" } ], - "sagittarius":[ + "Sagittarius":[ { "Zodiac" : "Aries", "description" : "Sagittarius and Aries can make a very compatible pair. Their relationship will have a lot of passion, enthusiasm, and energy. These are very good traits to make their relationship deeper and stronger. Both Aries and Sagittarius will enjoy each other's company and their energy level rises as the relationship grows. Both will support and help in fighting hardships and failures.", @@ -192,7 +192,7 @@ "compatibility_score" : "83%" } ], - "capricorn":[ + "Capricorn":[ { "Zodiac" : "Taurus", "description" : "This is one of the most grounded and reliable bonds of the zodiac chart. If Capricorn and Taurus do find a way to handle their minor issues, they have a good chance of making it together and that too, in a happy, peaceful, and healthy relationship.", @@ -214,7 +214,7 @@ "compatibility_score" : "76%" } ], - "aquarius":[ + "Aquarius":[ { "Zodiac" : "Aries", "description" : "The relationship of Aries and Aquarius is very exciting, adventurous and interesting. They will enjoy each other's company as both of them love fun and freedom.This is a couple that lacks tenderness. They are not two brutes who let their relationship fade as soon as their passion does.", @@ -236,7 +236,7 @@ "compatibility_score" : "83%" } ], - "pisces":[ + "Pisces":[ { "Zodiac" : "Taurus", "description" : "This relationship will survive the test of time if both parties involved have unbreakable trust in each other and nurture that connection they have painstakingly built over the years. They must remember to be honest and committed to their partner through all times.If natural communication flows between them like clockwork, this will be a beautiful love story with a prominent tag of ‘happily-ever-after’ pinned right to it!", diff --git a/bot/resources/valentines/zodiac_explanation.json b/bot/resources/valentines/zodiac_explanation.json new file mode 100644 index 00000000..33864ea5 --- /dev/null +++ b/bot/resources/valentines/zodiac_explanation.json @@ -0,0 +1,122 @@ +{ + "Aries": { + "start_at": "2020-03-21", + "end_at": "2020-04-19", + "About": "Amazing people born between **March 21** to **April 19**. Aries loves to be number one, so it\u2019s no surprise that these audacious rams are the first sign of the zodiac. Bold and ambitious, Aries dives headfirst into even the most challenging situations.", + "Motto": "***\u201cWhen you know yourself, you're empowered. When you accept yourself, you're invincible.\u201d***", + "Strengths": "Courageous, determined, confident, enthusiastic, optimistic, honest, passionate.", + "Weaknesses": "Impatient, moody, short-tempered, impulsive, aggressive.", + "full_form": "__**A**__ssertive, __**R**__efreshing, __**I**__ndependent, __**E**__nergetic, __**S**__exy", + "url": "https://www.horoscope.com/images-US/signs/profile-aries.png" + }, + "Taurus": { + "start_at": "2020-04-20", + "end_at": "2020-05-20", + "About": "Amazing people born between **April 20** to **May 20**. Taurus is an earth sign represented by the bull. Like their celestial spirit animal, Taureans enjoy relaxing in serene, bucolic environments surrounded by soft sounds, soothing aromas, and succulent flavors", + "Motto": "***\u201cNothing worth having comes easy.\u201d***", + "Strengths": "Reliable, patient, practical, devoted, responsible, stable.", + "Weaknesses": "Stubborn, possessive, uncompromising.", + "full_form": "__**T**__railblazing, __**A**__mbitious, __**U**__nwavering, __**R**__eliable, __**U**__nderstanding, __**S**__table", + "url": "https://www.horoscope.com/images-US/signs/profile-taurus.png" + }, + "Gemini": { + "start_at": "2020-05-21", + "end_at": "2020-06-20", + "About": "Amazing people born between **May 21** to **June 20**. Have you ever been so busy that you wished you could clone yourself just to get everything done? That\u2019s the Gemini experience in a nutshell. Appropriately symbolized by the celestial twins, this air sign was interested in so many pursuits that it had to double itself.", + "Motto": "***\u201cI manifest my reality.\u201d***", + "Strengths": "Gentle, affectionate, curious, adaptable, ability to learn quickly and exchange ideas.", + "Weaknesses": "Nervous, inconsistent, indecisive.", + "full_form": "__**G**__enerous, __**E**__motionally in tune, __**M**__otivated, __**I**__maginative, __**N**__ice, __**I**__ntelligent", + "url": "https://www.horoscope.com/images-US/signs/profile-gemini.png" + }, + "Cancer": { + "start_at": "2020-06-21", + "end_at": "2020-07-22", + "About": "Amazing people born between **June 21 ** to **July 22**. Cancer is a cardinal water sign. Represented by the crab, this crustacean seamlessly weaves between the sea and shore representing Cancer\u2019s ability to exist in both emotional and material realms. Cancers are highly intuitive and their psychic abilities manifest in tangible spaces: For instance, Cancers can effortlessly pick up the energies in a room.", + "Motto": "***\u201cI feel, therefore I am.\u201d***", + "Strengths": "Tenacious, highly imaginative, loyal, emotional, sympathetic, persuasive.", + "Weaknesses": "Moody, pessimistic, suspicious, manipulative, insecuremoody, pessimistic, suspicious, manipulative, insecure.", + "full_form": "__**C**__aring, __**A**__mbitious, __**N**__ourishing, __**C**__reative, __**E**__motionally intelligent, __**R**__esilient", + "url": "https://www.horoscope.com/images-US/signs/profile-cancer.png" + }, + "Leo": { + "start_at": "2020-07-23", + "end_at": "2020-08-22", + "About": "Amazing people born between **July 23** to **August 22**. Roll out the red carpet because Leo has arrived. Leo is represented by the lion and these spirited fire signs are the kings and queens of the celestial jungle. They\u2019re delighted to embrace their royal status: Vivacious, theatrical, and passionate, Leos love to bask in the spotlight and celebrate themselves.", + "Motto": "***\u201cIf you know the way, go the way and show the way\u2014you're a leader.\u201d***", + "Strengths": "Creative, passionate, generous, warm-hearted, cheerful, humorous.", + "Weaknesses": "Arrogant, stubborn, self-centered, lazy, inflexible.", + "full_form": "__**L**__eaders, __**E**__nergetic, __**O**__ptimistic", + "url": "https://www.horoscope.com/images-US/signs/profile-leo.png" + }, + "Virgo": { + "start_at": "2020-08-23", + "end_at": "2020-09-22", + "About": "Amazing people born between **August 23** to **September 22**. Virgo is an earth sign historically represented by the goddess of wheat and agriculture, an association that speaks to Virgo\u2019s deep-rooted presence in the material world. Virgos are logical, practical, and systematic in their approach to life. This earth sign is a perfectionist at heart and isn\u2019t afraid to improve skills through diligent and consistent practice.", + "Motto": "***\u201cMy best can always be better.\u201d***", + "Strengths": "Loyal, analytical, kind, hardworking, practical.", + "Weaknesses": "Shyness, worry, overly critical of self and others, all work and no play.", + "full_form": "__**V**__irtuous, __**I**__ntelligent, __**R**__esponsible, __**G**__enerous, __**O**__ptimistic", + "url": "https://www.horoscope.com/images-US/signs/profile-virgo.png" + }, + "Libra": { + "start_at": "2020-09-23", + "end_at": "2020-10-22", + "About": "Amazing people born between **September 23** to **October 22**. Libra is an air sign represented by the scales (interestingly, the only inanimate object of the zodiac), an association that reflects Libra's fixation on balance and harmony. Libra is obsessed with symmetry and strives to create equilibrium in all areas of life.", + "Motto": "***\u201cNo person is an island.\u201d***", + "Strengths": "Cooperative, diplomatic, gracious, fair-minded, social.", + "Weaknesses": "Indecisive, avoids confrontations, will carry a grudge, self-pity.", + "full_form": "__**L**__oyal, __**I**__nquisitive, __**B**__alanced, __**R**__esponsible, __**A**__ltruistic", + "url": "https://www.horoscope.com/images-US/signs/profile-libra.png" + }, + "Scorpio": { + "start_at": "2020-10-23", + "end_at": "2020-11-21", + "About": "Amazing people born between **October 23** to **November 21**. Scorpio is one of the most misunderstood signs of the zodiac. Because of its incredible passion and power, Scorpio is often mistaken for a fire sign. In fact, Scorpio is a water sign that derives its strength from the psychic, emotional realm.", + "Motto": "***\u201cYou never know what you are capable of until you try.\u201d***", + "Strengths": "Resourceful, brave, passionate, stubborn, a true friend.", + "Weaknesses": "Distrusting, jealous, secretive, violent.", + "full_form": "__**S**__eductive, __**C**__erebral, __**O**__riginal, __**R**__eactive, __**P**__assionate, __**I**__ntuitive, __**O**__utstanding", + "url": "https://www.horoscope.com/images-US/signs/profile-scorpio.png" + }, + "Sagittarius": { + "start_at": "2020-11-22", + "end_at": "2020-12-21", + "About": "Amazing people born between **November 22** to **December 21**. Represented by the archer, Sagittarians are always on a quest for knowledge. The last fire sign of the zodiac, Sagittarius launches its many pursuits like blazing arrows, chasing after geographical, intellectual, and spiritual adventures.", + "Motto": "***\u201cTowering genius disdains a beaten path.\u201d***", + "Strengths": "Generous, idealistic, great sense of humor.", + "Weaknesses": "Promises more than can deliver, very impatient, will say anything no matter how undiplomatic.", + "full_form": "__**S**__eductive, __**A**__dventurous, __**G**__rateful, __**I**__ntelligent, __**T**__railblazing, __**T**__enacious adept, __**A**__dept, __**R**__esponsible, __**I**__dealistic, __**U**__nparalled, __**S**__ophisticated", + "url": "https://www.horoscope.com/images-US/signs/profile-sagittarius.png" + }, + "Capricorn": { + "start_at": "2020-12-22", + "end_at": "2021-01-19", + "About": "Amazing people born between **December 22** to **January 19**. The last earth sign of the zodiac, Capricorn is represented by the sea goat, a mythological creature with the body of a goat and tail of a fish. Accordingly, Capricorns are skilled at navigating both the material and emotional realms.", + "Motto": "***\u201cI can succeed at anything I put my mind to.\u201d***", + "Strengths": "Responsible, disciplined, self-control, good managers.", + "Weaknesses": "Know-it-all, unforgiving, condescending, expecting the worst.", + "full_form": "__**C**__onfident, __**A**__nalytical, __**P**__ractical, __**R**__esponsible, __**I**__ntelligent, __**C**__aring, __**O**__rganized, __**R**__ealistic, __**N**__eat", + "url": "https://www.horoscope.com/images-US/signs/profile-capricorn.png" + }, + "Aquarius": { + "start_at": "2020-01-20", + "end_at": "2020-02-18", + "About": "Amazing people born between **January 20** to **February 18**. Despite the \u201caqua\u201d in its name, Aquarius is actually the last air sign of the zodiac. Aquarius is represented by the water bearer, the mystical healer who bestows water, or life, upon the land. Accordingly, Aquarius is the most humanitarian astrological sign.", + "Motto": "***\u201cThere is no me, there is only we.\u201d***", + "Strengths": "Progressive, original, independent, humanitarian.", + "Weaknesses": "Runs from emotional expression, temperamental, uncompromising, aloof.", + "full_form": "__**A**__nalytical, __**Q**__uirky, __**U**__ncompromising, __**A**__ction-focused, __**R**__espectful, __**I**__ntelligent, __**U**__nique, __**S**__incere", + "url": "https://www.horoscope.com/images-US/signs/profile-aquarius.png" + }, + "Pisces": { + "start_at": "2020-02-19", + "end_at": "2020-03-20", + "About": "Amazing people born between **February 19** to **March 20**. Pisces, a water sign, is the last constellation of the zodiac. It's symbolized by two fish swimming in opposite directions, representing the constant division of Pisces' attention between fantasy and reality. As the final sign, Pisces has absorbed every lesson \u2014 the joys and the pain, the hopes and the fears \u2014 learned by all of the other signs.", + "Motto": "***\u201cI have a lot of love to give, it only takes a little patience and those worth giving it all to.\u201d***", + "Strengths": "Compassionate, artistic, intuitive, gentle, wise, musical.", + "Weaknesses": "Fearful, overly trusting, sad, desire to escape reality, can be a victim or a martyr.", + "full_form": "__**P**__sychic, __**I**__ntelligent, __**S**__urprising, __**C**__reative, __**E**__motionally-driven, __**S**__ensitive", + "url": "https://www.horoscope.com/images-US/signs/profile-pisces.png" + } +} |