From 0d0833849abcfe56fc0582cb1cf168e93cd4a588 Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 9 Apr 2019 21:40:30 +0530 Subject: done with the easter egg fact cmd and background task --- bot/resources/easter/easter_egg_facts.json | 22 ++++++++++++++ bot/seasons/easter/egg_facts.py | 46 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 bot/resources/easter/easter_egg_facts.json create mode 100644 bot/seasons/easter/egg_facts.py diff --git a/bot/resources/easter/easter_egg_facts.json b/bot/resources/easter/easter_egg_facts.json new file mode 100644 index 00000000..c8f72c8d --- /dev/null +++ b/bot/resources/easter/easter_egg_facts.json @@ -0,0 +1,22 @@ +{ + "facts": [ + "The first story of a rabbit (later named the \"Easter Bunny\") hiding eggs in a garden was published in 1680.", + "Rabbits are known to be prolific pro creators and are an ancient symbol of fertility and new life. The German immigrants brought the tale of Easter Bunny in the 1700s with the tradition of an egg-laying hare called ‘Osterhase\". The kids then would make nests in which the creature would lay coloured eggs. The tradition has been revolutionized in the form of candies and gifts instead of eggs.", + "In earlier days, a festival of egg throwing was held in church, when the priest would throw a hard-boiled egg to one of the choirboys. It was then tossed from one choirboy to the next and whoever held the egg when the clock struck 12 on Easter, was the winner and could keep it.", + "In medieval times, Easter eggs were boiled with onions to give them a golden sheen. Edward I went beyond this tradition in 1290 and ordered 450 eggs to be covered in gold leaf and given as Easter gifts.", + "Decorating Easter eggs is an ancient tradition that dates back to 13th century. One of the explanations for this custom is that eggs were considered as a forbidden food during the Lenten season (40 days before Easter). Therefore, people would paint and decorate them to mark an end of the period of penance and fasting and later eat them on Easter. The tradition of decorating eggs is called Pysanka which is creating a traditional Ukrainian folk design using wax-resist method.", + "Members of the Greek Orthodox faith often paint their Easter eggs red, which symbolizes Jesus\" blood and his victory over death. The color red, symbolizes renewal of life, such as, Jesus\" resurrection.", + "Eggs rolling take place in many parts of the world which symbolizes stone which was rolled away from the tomb where Jesus\" body was laid after his death.", + "Easter eggs have been considered as a symbol of fertility, rebirth and new life. The custom of giving eggs has been derived from Egyptians, Persians, Gauls, Greeks and Romans.", + "The first chocolate Easter egg was made by Fry\"s in 1873. Before this, people would give hollow cardboard eggs, filled with gifts.", + "The tallest chocolate Easter egg was made in Italy in 2011. Standing 10.39 metres tall and weighing 7,200 kg, it was taller than a giraffe and heavier than an elephant.", + "The largest ever Easter egg hunt was in Florida, where 9,753 children searched for 501,000 eggs.", + "In 2007, an Easter egg covered in diamonds sold for almost £9 million. Every hour, a cockerel made of jewels pops up from the top of the Faberge egg, flaps its wings four times, nods its head three times and makes a crowing noise. The gold-and-pink enamel egg was made by the Russian royal family as an engagement gift for French aristocrat Baron Edouard de Rothschild.", + "The White House held their first official egg roll in 1878 when Rutherford B. Hayes was the President. It is a race in which children push decorated, hard-boiled eggs across the White House lawn as an annual event held the Monday after Easter. In 2009, the Obamas hosted their first Easter egg roll with the theme, ‘Let\"s go play\" which was meant to encourage young people to lead healthy and active lives.", + "80 million chocolate Easter eggs are sold each year. This accounts for 10% of Britain\"s annual spending on chocolate!", + "The tradition of giving eggs at Easter has been traced back to Egyptians, Persians, Gauls, Greeks and Romans, who saw the egg as a symbol of life.", + "Medieval Easter eggs were boiled with onions to give them a golden sheen. Edward I, however, went one better and in 1290 he ordered 450 eggs to be covered in gold leaf and given as Easter gifts.", + "The first chocolate Easter egg was produced in 1873 by Fry\"s. Before this, people would give hollow cardboard eggs, filled with gifts.", + "John Cadbury soon followed suit and made his first Cadbury Easter egg in 1875. By 1892 the company was producing 19 different lines, all made from dark chocolate." + ] +} \ No newline at end of file diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py new file mode 100644 index 00000000..1080f6c6 --- /dev/null +++ b/bot/seasons/easter/egg_facts.py @@ -0,0 +1,46 @@ +from discord.ext import commands +import discord +import asyncio +from pathlib import Path +from json import load +import random +from bot.constants import Colours + + +class EasterFacts(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.facts = self.load_json() + + @staticmethod + def load_json(): + p = Path('bot', 'resources', 'easter', 'easter_egg_facts.json') + with p.open(encoding="utf8") as f: + facts = load(f) + return facts + + async def background(self): + channel = self.bot.get_channel(426566445124812815) + while True: + embed = self.make_embed() + await channel.send(embed=embed) + await asyncio.sleep(24*60*60) + + @commands.command(name='eggfact', aliases=['fact']) + async def easter_facts(self, ctx): + embed = self.make_embed() + await ctx.send(embed=embed) + + def make_embed(self): + embed = discord.Embed() + embed.colour = Colours.soft_red + embed.title = 'Easter Egg Fact' + random_fact = random.choice(self.facts['facts']) + embed.description = random_fact + return embed + + +def setup(bot): + bot.loop.create_task(EasterFacts(bot).background()) + bot.add_cog(EasterFacts(bot)) -- cgit v1.2.3 From 592cd2826b865e8abe1bea15fb48fd736a7c3f53 Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 9 Apr 2019 22:17:14 +0530 Subject: fixed lint errors --- bot/seasons/easter/egg_facts.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index 1080f6c6..dcc15078 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -1,26 +1,30 @@ -from discord.ext import commands -import discord import asyncio -from pathlib import Path -from json import load import random +from json import load +from pathlib import Path + +import discord +from discord.ext import commands + from bot.constants import Colours class EasterFacts(commands.Cog): - + """A cog for easter egg facts.""" def __init__(self, bot): self.bot = bot self.facts = self.load_json() @staticmethod def load_json(): + """Loading the json data""" p = Path('bot', 'resources', 'easter', 'easter_egg_facts.json') with p.open(encoding="utf8") as f: facts = load(f) return facts async def background(self): + """A background task that sends a easter egg fact.""" channel = self.bot.get_channel(426566445124812815) while True: embed = self.make_embed() @@ -29,10 +33,12 @@ class EasterFacts(commands.Cog): @commands.command(name='eggfact', aliases=['fact']) async def easter_facts(self, ctx): + """Get easter egg facts.""" embed = self.make_embed() await ctx.send(embed=embed) def make_embed(self): + """Makes a nice embed for the message to be sent.""" embed = discord.Embed() embed.colour = Colours.soft_red embed.title = 'Easter Egg Fact' @@ -42,5 +48,6 @@ class EasterFacts(commands.Cog): def setup(bot): + """Loading the cog""" bot.loop.create_task(EasterFacts(bot).background()) bot.add_cog(EasterFacts(bot)) -- cgit v1.2.3 From e7e0e5d918dcb761cdfda2a2e3f02941973cff95 Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 23 Apr 2019 21:15:52 +0530 Subject: using top level array in json file --- bot/resources/easter/easter_egg_facts.json | 6 ++---- bot/seasons/easter/egg_facts.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bot/resources/easter/easter_egg_facts.json b/bot/resources/easter/easter_egg_facts.json index c8f72c8d..7248045e 100644 --- a/bot/resources/easter/easter_egg_facts.json +++ b/bot/resources/easter/easter_egg_facts.json @@ -1,5 +1,4 @@ -{ - "facts": [ +[ "The first story of a rabbit (later named the \"Easter Bunny\") hiding eggs in a garden was published in 1680.", "Rabbits are known to be prolific pro creators and are an ancient symbol of fertility and new life. The German immigrants brought the tale of Easter Bunny in the 1700s with the tradition of an egg-laying hare called ‘Osterhase\". The kids then would make nests in which the creature would lay coloured eggs. The tradition has been revolutionized in the form of candies and gifts instead of eggs.", "In earlier days, a festival of egg throwing was held in church, when the priest would throw a hard-boiled egg to one of the choirboys. It was then tossed from one choirboy to the next and whoever held the egg when the clock struck 12 on Easter, was the winner and could keep it.", @@ -18,5 +17,4 @@ "Medieval Easter eggs were boiled with onions to give them a golden sheen. Edward I, however, went one better and in 1290 he ordered 450 eggs to be covered in gold leaf and given as Easter gifts.", "The first chocolate Easter egg was produced in 1873 by Fry\"s. Before this, people would give hollow cardboard eggs, filled with gifts.", "John Cadbury soon followed suit and made his first Cadbury Easter egg in 1875. By 1892 the company was producing 19 different lines, all made from dark chocolate." - ] -} \ No newline at end of file +] diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index dcc15078..c4cd8cf9 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -42,7 +42,7 @@ class EasterFacts(commands.Cog): embed = discord.Embed() embed.colour = Colours.soft_red embed.title = 'Easter Egg Fact' - random_fact = random.choice(self.facts['facts']) + random_fact = random.choice(self.facts) embed.description = random_fact return embed -- cgit v1.2.3 From 9c0685abac0bcb97fd5361d802780d4964c282d2 Mon Sep 17 00:00:00 2001 From: Rohan Date: Fri, 26 Apr 2019 09:52:53 +0530 Subject: changes a few doc strings and renamed the background method --- bot/seasons/easter/egg_facts.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index c4cd8cf9..e5abd685 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -10,21 +10,28 @@ from bot.constants import Colours class EasterFacts(commands.Cog): - """A cog for easter egg facts.""" + """ + A cog contains a command that will return an easter egg fact when called. + + It also contains a background task which sends an easter egg fact in the event channel everyday. + """ + def __init__(self, bot): self.bot = bot self.facts = self.load_json() @staticmethod def load_json(): - """Loading the json data""" + """Load a list of easter egg facts from the resource JSON file.""" + p = Path('bot', 'resources', 'easter', 'easter_egg_facts.json') with p.open(encoding="utf8") as f: facts = load(f) return facts - async def background(self): - """A background task that sends a easter egg fact.""" + async def send_egg_fact_daily(self): + """A background task that sends an easter egg fact in the event channel everyday.""" + channel = self.bot.get_channel(426566445124812815) while True: embed = self.make_embed() @@ -34,11 +41,13 @@ class EasterFacts(commands.Cog): @commands.command(name='eggfact', aliases=['fact']) async def easter_facts(self, ctx): """Get easter egg facts.""" + embed = self.make_embed() await ctx.send(embed=embed) def make_embed(self): """Makes a nice embed for the message to be sent.""" + embed = discord.Embed() embed.colour = Colours.soft_red embed.title = 'Easter Egg Fact' @@ -48,6 +57,7 @@ class EasterFacts(commands.Cog): def setup(bot): - """Loading the cog""" - bot.loop.create_task(EasterFacts(bot).background()) + """EasterEgg facts loaded.""" + + bot.loop.create_task(EasterFacts(bot).send_egg_fact_daily()) bot.add_cog(EasterFacts(bot)) -- cgit v1.2.3 From fdf447498231539f21d19b77b73b5a1dd9e014ec Mon Sep 17 00:00:00 2001 From: Rohan Date: Fri, 26 Apr 2019 09:57:53 +0530 Subject: fixed a small lint error --- bot/seasons/easter/egg_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index e5abd685..9ddb9440 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -57,7 +57,7 @@ class EasterFacts(commands.Cog): def setup(bot): - """EasterEgg facts loaded.""" + """Easter Egg facts loaded.""" bot.loop.create_task(EasterFacts(bot).send_egg_fact_daily()) bot.add_cog(EasterFacts(bot)) -- cgit v1.2.3 From 38405eacfb41650d69b91163ae3b12712128cc9b Mon Sep 17 00:00:00 2001 From: Rohan Date: Sat, 22 Jun 2019 22:27:06 +0530 Subject: made the requested following changes : 1. Using the seasonalbot channel id from the constants file 2. Added logging to the setup funciton. --- bot/seasons/easter/egg_facts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index 9ddb9440..74733910 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -1,4 +1,5 @@ import asyncio +import logging import random from json import load from pathlib import Path @@ -6,9 +7,13 @@ from pathlib import Path import discord from discord.ext import commands +from bot.constants import Channels from bot.constants import Colours +log = logging.getLogger(__name__) + + class EasterFacts(commands.Cog): """ A cog contains a command that will return an easter egg fact when called. @@ -32,7 +37,7 @@ class EasterFacts(commands.Cog): async def send_egg_fact_daily(self): """A background task that sends an easter egg fact in the event channel everyday.""" - channel = self.bot.get_channel(426566445124812815) + channel = Channels.seasonalbot_chat while True: embed = self.make_embed() await channel.send(embed=embed) @@ -61,3 +66,4 @@ def setup(bot): bot.loop.create_task(EasterFacts(bot).send_egg_fact_daily()) bot.add_cog(EasterFacts(bot)) + log.info("EasterFacts cog loaded") -- cgit v1.2.3 From 1898c3cca4ea70767fe50bcd0020ad95fe295252 Mon Sep 17 00:00:00 2001 From: Rohan Date: Sat, 22 Jun 2019 22:34:49 +0530 Subject: removed blank lines after function doc strings --- bot/seasons/easter/egg_facts.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index 74733910..2597714b 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -20,7 +20,6 @@ class EasterFacts(commands.Cog): It also contains a background task which sends an easter egg fact in the event channel everyday. """ - def __init__(self, bot): self.bot = bot self.facts = self.load_json() @@ -28,7 +27,6 @@ class EasterFacts(commands.Cog): @staticmethod def load_json(): """Load a list of easter egg facts from the resource JSON file.""" - p = Path('bot', 'resources', 'easter', 'easter_egg_facts.json') with p.open(encoding="utf8") as f: facts = load(f) @@ -36,7 +34,6 @@ class EasterFacts(commands.Cog): async def send_egg_fact_daily(self): """A background task that sends an easter egg fact in the event channel everyday.""" - channel = Channels.seasonalbot_chat while True: embed = self.make_embed() @@ -46,13 +43,11 @@ class EasterFacts(commands.Cog): @commands.command(name='eggfact', aliases=['fact']) async def easter_facts(self, ctx): """Get easter egg facts.""" - embed = self.make_embed() await ctx.send(embed=embed) def make_embed(self): """Makes a nice embed for the message to be sent.""" - embed = discord.Embed() embed.colour = Colours.soft_red embed.title = 'Easter Egg Fact' @@ -63,7 +58,6 @@ class EasterFacts(commands.Cog): def setup(bot): """Easter Egg facts loaded.""" - bot.loop.create_task(EasterFacts(bot).send_egg_fact_daily()) bot.add_cog(EasterFacts(bot)) log.info("EasterFacts cog loaded") -- cgit v1.2.3 From 4c2f1c619025b348c91642716b7d0f9091765a3b Mon Sep 17 00:00:00 2001 From: Rohan Date: Sat, 22 Jun 2019 22:37:25 +0530 Subject: gave a blank line after class doc string... --- bot/seasons/easter/egg_facts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index 2597714b..094190ed 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -20,6 +20,7 @@ class EasterFacts(commands.Cog): It also contains a background task which sends an easter egg fact in the event channel everyday. """ + def __init__(self, bot): self.bot = bot self.facts = self.load_json() -- cgit v1.2.3 From 764d52390fcd483ff466c94b0bd3ef70703a67a5 Mon Sep 17 00:00:00 2001 From: Rohan Date: Sat, 22 Jun 2019 22:43:05 +0530 Subject: removed blank spaces in blank line... --- bot/seasons/easter/egg_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py index 094190ed..1a19e48f 100644 --- a/bot/seasons/easter/egg_facts.py +++ b/bot/seasons/easter/egg_facts.py @@ -20,7 +20,7 @@ class EasterFacts(commands.Cog): It also contains a background task which sends an easter egg fact in the event channel everyday. """ - + def __init__(self, bot): self.bot = bot self.facts = self.load_json() -- cgit v1.2.3