From b791812c980f058d8150b18f9dae7c505221b74e Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 09:45:51 +0530 Subject: Hanukkah Embed file --- bot/seasons/christmas/hanukkah_embed | 110 +++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 bot/seasons/christmas/hanukkah_embed diff --git a/bot/seasons/christmas/hanukkah_embed b/bot/seasons/christmas/hanukkah_embed new file mode 100644 index 00000000..de69c63a --- /dev/null +++ b/bot/seasons/christmas/hanukkah_embed @@ -0,0 +1,110 @@ +from discord.ext import commands +from discord import Embed +import requests +import datetime +import logging + + +log = logging.getLogger(__name__) + +HANUKKAH_DAYS = [] +HANUKKAH_MONTHS = [] +HANUKKAH_YEARS = [] + + +class HanukkahEmbed(commands.Cog): + + def __init__(self, bot): + self.bot = bot + self.url = """https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on& + mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on""" + self.hanukkah_dates = self.get_hanukkah_dates() + + def get_hanukkah_dates(self): + hanukkah_dates = [] + r = requests.get(self.url) + json_data = r.json() + festivals = json_data['items'] + for festival in festivals: + if festival['title'].startswith('Chanukah'): + date = festival['date'] + hanukkah_dates.append(date) + return hanukkah_dates + + @commands.command(name='hanukkah', aliases=['chanukah']) + async def hanukkah_festival(self, ctx): + """ + Hanukkah embed + """ + self.hanukkah_dates_split() + + hanukkah_start_day = int(HANUKKAH_DAYS[0]) + hanukkah_start_month = int(HANUKKAH_MONTHS[0]) + hanukkah_start_year = int(HANUKKAH_YEARS[0]) + hanukkah_end_day = int(HANUKKAH_DAYS[8]) + hanukkah_end_month = int(HANUKKAH_MONTHS[8]) + hanukkah_end_year = int(HANUKKAH_YEARS[8]) + + hanukkah_start = datetime.date(hanukkah_start_year, hanukkah_start_month, hanukkah_start_day) + hanukkah_end = datetime.date(hanukkah_end_year, hanukkah_end_month, hanukkah_end_day) + # today = datetime.date.today() + today = datetime.date(2019, 12, 24) + day = str(today.day) + month = str(today.month) + year = str(today.year) + embed = Embed() + embed.title = 'Hanukkah Embed' + embed.colour = 0x68c290 + if day in HANUKKAH_DAYS and month in HANUKKAH_MONTHS and year in HANUKKAH_YEARS: + if int(day) == hanukkah_start_day: + now = datetime.datetime.utcnow() + now = str(now) + hours = int(now[11:13]) + 4 # using only hours + hanukkah_start_hour = 18 + if hours < hanukkah_start_hour: + embed.description = (f"Hanukkah hasnt started yet, " + f"it will start in about {hanukkah_start_hour-hours} hour/s.") + return await ctx.send(embed=embed) + elif hours > hanukkah_start_hour: + embed.description = (f'It is the starting day of Hanukkah ! ' + f'Its been {hours-hanukkah_start_hour} hours hanukkah started !') + return await ctx.send(embed=embed) + festival_day = HANUKKAH_DAYS.index(day) + number_suffixes = ['st', 'nd', 'rd', 'th'] + suffix = '' + if int(festival_day) == 1: + suffix = number_suffixes[0] + if int(festival_day) == 2: + suffix = number_suffixes[1] + if int(festival_day) == 3: + suffix = number_suffixes[2] + if int(festival_day) > 3: + suffix = number_suffixes[3] + message = '' + for i in range(1, festival_day + 1): + message += ':menorah:' + embed.description = f'It is the {festival_day}{suffix} day of Hanukkah ! \n {message}' + await ctx.send(embed=embed) + else: + if today < hanukkah_start: + festival_starting_month = hanukkah_start.strftime('%B') + embed.description = (f"Hanukkah has not started yet. " + f"Hanukkah will start at sundown on {hanukkah_start_day}th " + f"of {festival_starting_month}.") + else: + festival_end_month = hanukkah_end.strftime('%B') + embed.description = (f"Looks like you missed Hanukkah !" + f"Hanukkah ended on {hanukkah_end_day}th of {festival_end_month}.") + + await ctx.send(embed=embed) + + def hanukkah_dates_split(self): + for date in self.hanukkah_dates: + HANUKKAH_DAYS.append(date[8:10]) + HANUKKAH_MONTHS.append(date[5:7]) + HANUKKAH_YEARS.append(date[0:4]) + + +def setup(bot): + bot.add_cog(HanukkahEmbed(bot)) + log.info("AdventOfCode cog loaded") -- cgit v1.2.3 From 1005cee4cbd3910f035c31479a74e98a8194c94c Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 10:17:23 +0530 Subject: added .py extension, add doc strings,other changes will be coming in the next commit --- bot/seasons/christmas/hanukkah_embed | 110 ----------------------------- bot/seasons/christmas/hanukkah_embed.py | 120 ++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 110 deletions(-) delete mode 100644 bot/seasons/christmas/hanukkah_embed create mode 100644 bot/seasons/christmas/hanukkah_embed.py diff --git a/bot/seasons/christmas/hanukkah_embed b/bot/seasons/christmas/hanukkah_embed deleted file mode 100644 index de69c63a..00000000 --- a/bot/seasons/christmas/hanukkah_embed +++ /dev/null @@ -1,110 +0,0 @@ -from discord.ext import commands -from discord import Embed -import requests -import datetime -import logging - - -log = logging.getLogger(__name__) - -HANUKKAH_DAYS = [] -HANUKKAH_MONTHS = [] -HANUKKAH_YEARS = [] - - -class HanukkahEmbed(commands.Cog): - - def __init__(self, bot): - self.bot = bot - self.url = """https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on& - mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on""" - self.hanukkah_dates = self.get_hanukkah_dates() - - def get_hanukkah_dates(self): - hanukkah_dates = [] - r = requests.get(self.url) - json_data = r.json() - festivals = json_data['items'] - for festival in festivals: - if festival['title'].startswith('Chanukah'): - date = festival['date'] - hanukkah_dates.append(date) - return hanukkah_dates - - @commands.command(name='hanukkah', aliases=['chanukah']) - async def hanukkah_festival(self, ctx): - """ - Hanukkah embed - """ - self.hanukkah_dates_split() - - hanukkah_start_day = int(HANUKKAH_DAYS[0]) - hanukkah_start_month = int(HANUKKAH_MONTHS[0]) - hanukkah_start_year = int(HANUKKAH_YEARS[0]) - hanukkah_end_day = int(HANUKKAH_DAYS[8]) - hanukkah_end_month = int(HANUKKAH_MONTHS[8]) - hanukkah_end_year = int(HANUKKAH_YEARS[8]) - - hanukkah_start = datetime.date(hanukkah_start_year, hanukkah_start_month, hanukkah_start_day) - hanukkah_end = datetime.date(hanukkah_end_year, hanukkah_end_month, hanukkah_end_day) - # today = datetime.date.today() - today = datetime.date(2019, 12, 24) - day = str(today.day) - month = str(today.month) - year = str(today.year) - embed = Embed() - embed.title = 'Hanukkah Embed' - embed.colour = 0x68c290 - if day in HANUKKAH_DAYS and month in HANUKKAH_MONTHS and year in HANUKKAH_YEARS: - if int(day) == hanukkah_start_day: - now = datetime.datetime.utcnow() - now = str(now) - hours = int(now[11:13]) + 4 # using only hours - hanukkah_start_hour = 18 - if hours < hanukkah_start_hour: - embed.description = (f"Hanukkah hasnt started yet, " - f"it will start in about {hanukkah_start_hour-hours} hour/s.") - return await ctx.send(embed=embed) - elif hours > hanukkah_start_hour: - embed.description = (f'It is the starting day of Hanukkah ! ' - f'Its been {hours-hanukkah_start_hour} hours hanukkah started !') - return await ctx.send(embed=embed) - festival_day = HANUKKAH_DAYS.index(day) - number_suffixes = ['st', 'nd', 'rd', 'th'] - suffix = '' - if int(festival_day) == 1: - suffix = number_suffixes[0] - if int(festival_day) == 2: - suffix = number_suffixes[1] - if int(festival_day) == 3: - suffix = number_suffixes[2] - if int(festival_day) > 3: - suffix = number_suffixes[3] - message = '' - for i in range(1, festival_day + 1): - message += ':menorah:' - embed.description = f'It is the {festival_day}{suffix} day of Hanukkah ! \n {message}' - await ctx.send(embed=embed) - else: - if today < hanukkah_start: - festival_starting_month = hanukkah_start.strftime('%B') - embed.description = (f"Hanukkah has not started yet. " - f"Hanukkah will start at sundown on {hanukkah_start_day}th " - f"of {festival_starting_month}.") - else: - festival_end_month = hanukkah_end.strftime('%B') - embed.description = (f"Looks like you missed Hanukkah !" - f"Hanukkah ended on {hanukkah_end_day}th of {festival_end_month}.") - - await ctx.send(embed=embed) - - def hanukkah_dates_split(self): - for date in self.hanukkah_dates: - HANUKKAH_DAYS.append(date[8:10]) - HANUKKAH_MONTHS.append(date[5:7]) - HANUKKAH_YEARS.append(date[0:4]) - - -def setup(bot): - bot.add_cog(HanukkahEmbed(bot)) - log.info("AdventOfCode cog loaded") diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py new file mode 100644 index 00000000..a2e6c8c5 --- /dev/null +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -0,0 +1,120 @@ +import datetime +import logging + +import requests +from discord import Embed +from discord.ext import commands + + +log = logging.getLogger(__name__) + +HANUKKAH_DAYS = [] +HANUKKAH_MONTHS = [] +HANUKKAH_YEARS = [] + + +class HanukkahEmbed(commands.Cog): + """ + A cog that returns information about Hanukkah festival. + """ + def __init__(self, bot): + self.bot = bot + self.url = """https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on& + mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on""" + self.hanukkah_dates = self.get_hanukkah_dates() + + def get_hanukkah_dates(self): + """ + Gets the dates for hanukkah festival. + """ + hanukkah_dates = [] + r = requests.get(self.url) + json_data = r.json() + festivals = json_data['items'] + for festival in festivals: + if festival['title'].startswith('Chanukah'): + date = festival['date'] + hanukkah_dates.append(date) + return hanukkah_dates + + @commands.command(name='hanukkah', aliases=['chanukah']) + async def hanukkah_festival(self, ctx): + """ + Tells you about the Hanukkah Festival + (time of festival, festival day, etc) + """ + self.hanukkah_dates_split() + + hanukkah_start_day = int(HANUKKAH_DAYS[0]) + hanukkah_start_month = int(HANUKKAH_MONTHS[0]) + hanukkah_start_year = int(HANUKKAH_YEARS[0]) + hanukkah_end_day = int(HANUKKAH_DAYS[8]) + hanukkah_end_month = int(HANUKKAH_MONTHS[8]) + hanukkah_end_year = int(HANUKKAH_YEARS[8]) + + hanukkah_start = datetime.date(hanukkah_start_year, hanukkah_start_month, hanukkah_start_day) + hanukkah_end = datetime.date(hanukkah_end_year, hanukkah_end_month, hanukkah_end_day) + # today = datetime.date.today() + today = datetime.date(2019, 12, 24) + day = str(today.day) + month = str(today.month) + year = str(today.year) + embed = Embed() + embed.title = 'Hanukkah Embed' + embed.colour = 0x68c290 + if day in HANUKKAH_DAYS and month in HANUKKAH_MONTHS and year in HANUKKAH_YEARS: + if int(day) == hanukkah_start_day: + now = datetime.datetime.utcnow() + now = str(now) + hours = int(now[11:13]) + 4 # using only hours + hanukkah_start_hour = 18 + if hours < hanukkah_start_hour: + embed.description = (f"Hanukkah hasnt started yet, " + f"it will start in about {hanukkah_start_hour-hours} hour/s.") + return await ctx.send(embed=embed) + elif hours > hanukkah_start_hour: + embed.description = (f'It is the starting day of Hanukkah ! ' + f'Its been {hours-hanukkah_start_hour} hours hanukkah started !') + return await ctx.send(embed=embed) + festival_day = HANUKKAH_DAYS.index(day) + number_suffixes = ['st', 'nd', 'rd', 'th'] + suffix = '' + if int(festival_day) == 1: + suffix = number_suffixes[0] + if int(festival_day) == 2: + suffix = number_suffixes[1] + if int(festival_day) == 3: + suffix = number_suffixes[2] + if int(festival_day) > 3: + suffix = number_suffixes[3] + message = '' + for i in range(1, festival_day + 1): + message += ':menorah:' + embed.description = f'It is the {festival_day}{suffix} day of Hanukkah ! \n {message}' + await ctx.send(embed=embed) + else: + if today < hanukkah_start: + festival_starting_month = hanukkah_start.strftime('%B') + embed.description = (f"Hanukkah has not started yet. " + f"Hanukkah will start at sundown on {hanukkah_start_day}th " + f"of {festival_starting_month}.") + else: + festival_end_month = hanukkah_end.strftime('%B') + embed.description = (f"Looks like you missed Hanukkah !" + f"Hanukkah ended on {hanukkah_end_day}th of {festival_end_month}.") + + await ctx.send(embed=embed) + + def hanukkah_dates_split(self): + """ + We are splitting the dates for hanukkah into days, months and years. + """ + for date in self.hanukkah_dates: + HANUKKAH_DAYS.append(date[8:10]) + HANUKKAH_MONTHS.append(date[5:7]) + HANUKKAH_YEARS.append(date[0:4]) + + +def setup(bot): + bot.add_cog(HanukkahEmbed(bot)) + log.info("AdventOfCode cog loaded") -- cgit v1.2.3 From 9ed666afee4cb2259430e0bf196e2f5ea374c439 Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 10:43:54 +0530 Subject: made the following changes: 1. Added doc strings. 2. Changes loging info in setup method 3. Moved the varibales outside class into the __init__() --- bot/seasons/christmas/hanukkah_embed.py | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index a2e6c8c5..f791e094 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -8,10 +8,6 @@ from discord.ext import commands log = logging.getLogger(__name__) -HANUKKAH_DAYS = [] -HANUKKAH_MONTHS = [] -HANUKKAH_YEARS = [] - class HanukkahEmbed(commands.Cog): """ @@ -22,6 +18,9 @@ class HanukkahEmbed(commands.Cog): self.url = """https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on& mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on""" self.hanukkah_dates = self.get_hanukkah_dates() + self.hanukkah_days = [] + self.hanukkah_months = [] + self.hanukkah_years = [] def get_hanukkah_dates(self): """ @@ -41,28 +40,28 @@ class HanukkahEmbed(commands.Cog): async def hanukkah_festival(self, ctx): """ Tells you about the Hanukkah Festival - (time of festival, festival day, etc) + (time of festival, festival day, etc). """ self.hanukkah_dates_split() - hanukkah_start_day = int(HANUKKAH_DAYS[0]) - hanukkah_start_month = int(HANUKKAH_MONTHS[0]) - hanukkah_start_year = int(HANUKKAH_YEARS[0]) - hanukkah_end_day = int(HANUKKAH_DAYS[8]) - hanukkah_end_month = int(HANUKKAH_MONTHS[8]) - hanukkah_end_year = int(HANUKKAH_YEARS[8]) + hanukkah_start_day = int(self.hanukkah_days[0]) + hanukkah_start_month = int(self.hanukkah_months[0]) + hanukkah_start_year = int(self.hanukkah_years[0]) + hanukkah_end_day = int(self.hanukkah_days[8]) + hanukkah_end_month = int(self.hanukkah_months[8]) + hanukkah_end_year = int(self.hanukkah_years[8]) hanukkah_start = datetime.date(hanukkah_start_year, hanukkah_start_month, hanukkah_start_day) hanukkah_end = datetime.date(hanukkah_end_year, hanukkah_end_month, hanukkah_end_day) - # today = datetime.date.today() - today = datetime.date(2019, 12, 24) + today = datetime.date.today() + # today = datetime.date(2019, 12, 24) (for testing) day = str(today.day) month = str(today.month) year = str(today.year) embed = Embed() embed.title = 'Hanukkah Embed' embed.colour = 0x68c290 - if day in HANUKKAH_DAYS and month in HANUKKAH_MONTHS and year in HANUKKAH_YEARS: + if day in self.hanukkah_days and month in self.hanukkah_months and year in self.hanukkah_years: if int(day) == hanukkah_start_day: now = datetime.datetime.utcnow() now = str(now) @@ -76,7 +75,7 @@ class HanukkahEmbed(commands.Cog): embed.description = (f'It is the starting day of Hanukkah ! ' f'Its been {hours-hanukkah_start_hour} hours hanukkah started !') return await ctx.send(embed=embed) - festival_day = HANUKKAH_DAYS.index(day) + festival_day = self.hanukkah_days.index(day) number_suffixes = ['st', 'nd', 'rd', 'th'] suffix = '' if int(festival_day) == 1: @@ -88,7 +87,7 @@ class HanukkahEmbed(commands.Cog): if int(festival_day) > 3: suffix = number_suffixes[3] message = '' - for i in range(1, festival_day + 1): + for _ in range(1, festival_day + 1): message += ':menorah:' embed.description = f'It is the {festival_day}{suffix} day of Hanukkah ! \n {message}' await ctx.send(embed=embed) @@ -107,14 +106,15 @@ class HanukkahEmbed(commands.Cog): def hanukkah_dates_split(self): """ - We are splitting the dates for hanukkah into days, months and years. + We are splitting the dates for hanukkah + into days, months and years. """ for date in self.hanukkah_dates: - HANUKKAH_DAYS.append(date[8:10]) - HANUKKAH_MONTHS.append(date[5:7]) - HANUKKAH_YEARS.append(date[0:4]) + self.hanukkah_days.append(date[8:10]) + self.hanukkah_months.append(date[5:7]) + self.hanukkah_years.append(date[0:4]) def setup(bot): bot.add_cog(HanukkahEmbed(bot)) - log.info("AdventOfCode cog loaded") + log.info("Hanukkah embed cog loaded") -- cgit v1.2.3 From 05fd9426e18effddc0f2b9293bca5ab174b526b6 Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 12:12:25 +0530 Subject: using the Colours from constants.py and added 2 colors - blue for christmas and yellow for easter --- bot/constants.py | 2 ++ bot/seasons/christmas/hanukkah_embed.py | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/bot/constants.py b/bot/constants.py index b19d494b..3896dd83 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -59,6 +59,8 @@ class Client(NamedTuple): class Colours: + blue = 0x0279fd + yellow = 0xf9f586 soft_red = 0xcd6d6d soft_green = 0x68c290 bright_green = 0x01d277 diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index f791e094..be3b7e62 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -4,28 +4,26 @@ import logging import requests from discord import Embed from discord.ext import commands +from bot.constants import Colours log = logging.getLogger(__name__) class HanukkahEmbed(commands.Cog): - """ - A cog that returns information about Hanukkah festival. - """ + + """A cog that returns information about Hanukkah festival.""" def __init__(self, bot): self.bot = bot - self.url = """https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on& - mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on""" + self.url = ("https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&" + "year=now&month=x&ss=on&mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on") self.hanukkah_dates = self.get_hanukkah_dates() self.hanukkah_days = [] self.hanukkah_months = [] self.hanukkah_years = [] def get_hanukkah_dates(self): - """ - Gets the dates for hanukkah festival. - """ + """Gets the dates for hanukkah festival.""" hanukkah_dates = [] r = requests.get(self.url) json_data = r.json() @@ -38,10 +36,7 @@ class HanukkahEmbed(commands.Cog): @commands.command(name='hanukkah', aliases=['chanukah']) async def hanukkah_festival(self, ctx): - """ - Tells you about the Hanukkah Festival - (time of festival, festival day, etc). - """ + """Tells you about the Hanukkah Festivaltime of festival, festival day, etc).""" self.hanukkah_dates_split() hanukkah_start_day = int(self.hanukkah_days[0]) @@ -60,7 +55,7 @@ class HanukkahEmbed(commands.Cog): year = str(today.year) embed = Embed() embed.title = 'Hanukkah Embed' - embed.colour = 0x68c290 + embed.colour = Colours.blue if day in self.hanukkah_days and month in self.hanukkah_months and year in self.hanukkah_years: if int(day) == hanukkah_start_day: now = datetime.datetime.utcnow() @@ -105,10 +100,7 @@ class HanukkahEmbed(commands.Cog): await ctx.send(embed=embed) def hanukkah_dates_split(self): - """ - We are splitting the dates for hanukkah - into days, months and years. - """ + """We are splitting the dates for hanukkah into days, months and years.""" for date in self.hanukkah_dates: self.hanukkah_days.append(date[8:10]) self.hanukkah_months.append(date[5:7]) -- cgit v1.2.3 From 488b4364e819549c75f798e90781f2ee973e204e Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 12:21:17 +0530 Subject: fixed some linting and using colours from constants.py --- bot/seasons/christmas/hanukkah_embed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index be3b7e62..3e2e0747 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -4,6 +4,7 @@ import logging import requests from discord import Embed from discord.ext import commands + from bot.constants import Colours -- cgit v1.2.3 From 63ed875048f355ecefa20baad4ff4b5d3b51c26c Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 12:28:59 +0530 Subject: fixed lint errors --- bot/seasons/christmas/hanukkah_embed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index 3e2e0747..85d91675 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -12,7 +12,6 @@ log = logging.getLogger(__name__) class HanukkahEmbed(commands.Cog): - """A cog that returns information about Hanukkah festival.""" def __init__(self, bot): self.bot = bot -- cgit v1.2.3 From 033794a505af0debb2d1db08fac17676f3a0f64f Mon Sep 17 00:00:00 2001 From: Rohan Date: Sun, 31 Mar 2019 14:27:49 +0530 Subject: added doc strings to setup function and removed yellow color from constants cuz ill add it when i make PR for easter --- bot/constants.py | 1 - bot/seasons/christmas/hanukkah_embed.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index 3896dd83..993a0f81 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -60,7 +60,6 @@ class Client(NamedTuple): class Colours: blue = 0x0279fd - yellow = 0xf9f586 soft_red = 0xcd6d6d soft_green = 0x68c290 bright_green = 0x01d277 diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index 85d91675..ca69999e 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -108,5 +108,6 @@ class HanukkahEmbed(commands.Cog): def setup(bot): + """A function to add the cog.""" bot.add_cog(HanukkahEmbed(bot)) log.info("Hanukkah embed cog loaded") -- cgit v1.2.3 From f1014e21bc8619dabcbe7d8d4840e3a5ab2955e6 Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 9 Apr 2019 23:11:51 +0530 Subject: using aiohttp --- bot/seasons/christmas/hanukkah_embed.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index ca69999e..306570e8 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -1,7 +1,7 @@ import datetime import logging -import requests +import aiohttp from discord import Embed from discord.ext import commands @@ -13,20 +13,20 @@ log = logging.getLogger(__name__) class HanukkahEmbed(commands.Cog): """A cog that returns information about Hanukkah festival.""" + def __init__(self, bot): self.bot = bot self.url = ("https://www.hebcal.com/hebcal/?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&" "year=now&month=x&ss=on&mf=on&c=on&geo=geoname&geonameid=3448439&m=50&s=on") - self.hanukkah_dates = self.get_hanukkah_dates() self.hanukkah_days = [] self.hanukkah_months = [] self.hanukkah_years = [] - def get_hanukkah_dates(self): + async def get_hanukkah_dates(self): """Gets the dates for hanukkah festival.""" hanukkah_dates = [] - r = requests.get(self.url) - json_data = r.json() + async with self.bot.http_session.get(self.url) as response: + json_data = await response.json() festivals = json_data['items'] for festival in festivals: if festival['title'].startswith('Chanukah'): @@ -37,8 +37,8 @@ class HanukkahEmbed(commands.Cog): @commands.command(name='hanukkah', aliases=['chanukah']) async def hanukkah_festival(self, ctx): """Tells you about the Hanukkah Festivaltime of festival, festival day, etc).""" - self.hanukkah_dates_split() - + hanukkah_dates = await self.get_hanukkah_dates() + self.hanukkah_dates_split(hanukkah_dates) hanukkah_start_day = int(self.hanukkah_days[0]) hanukkah_start_month = int(self.hanukkah_months[0]) hanukkah_start_year = int(self.hanukkah_years[0]) @@ -54,7 +54,7 @@ class HanukkahEmbed(commands.Cog): month = str(today.month) year = str(today.year) embed = Embed() - embed.title = 'Hanukkah Embed' + embed.title = 'Hanukkah' embed.colour = Colours.blue if day in self.hanukkah_days and month in self.hanukkah_months and year in self.hanukkah_years: if int(day) == hanukkah_start_day: @@ -99,15 +99,19 @@ class HanukkahEmbed(commands.Cog): await ctx.send(embed=embed) - def hanukkah_dates_split(self): + def hanukkah_dates_split(self, hanukkah_dates): """We are splitting the dates for hanukkah into days, months and years.""" - for date in self.hanukkah_dates: + for date in hanukkah_dates: self.hanukkah_days.append(date[8:10]) self.hanukkah_months.append(date[5:7]) self.hanukkah_years.append(date[0:4]) + async def on_ready(self): + """A function that runs when ready.""" + self.bot.http_session = aiohttp.ClientSession() + def setup(bot): - """A function to add the cog.""" + """Cog load.""" bot.add_cog(HanukkahEmbed(bot)) log.info("Hanukkah embed cog loaded") -- cgit v1.2.3 From f8d9f4a0e72d7ae58af8be0e75dbbc3a3aca2434 Mon Sep 17 00:00:00 2001 From: Rohan Date: Fri, 19 Apr 2019 23:50:44 +0530 Subject: small changes --- bot/seasons/christmas/hanukkah_embed.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index 306570e8..f2abcc0b 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -106,10 +106,6 @@ class HanukkahEmbed(commands.Cog): self.hanukkah_months.append(date[5:7]) self.hanukkah_years.append(date[0:4]) - async def on_ready(self): - """A function that runs when ready.""" - self.bot.http_session = aiohttp.ClientSession() - def setup(bot): """Cog load.""" -- cgit v1.2.3 From 4424032b2318bb790f6172a61a83fd54eed2383d Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 23 Apr 2019 21:23:41 +0530 Subject: not importing aiohttp now --- bot/seasons/christmas/hanukkah_embed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/seasons/christmas/hanukkah_embed.py b/bot/seasons/christmas/hanukkah_embed.py index f2abcc0b..652a1f35 100644 --- a/bot/seasons/christmas/hanukkah_embed.py +++ b/bot/seasons/christmas/hanukkah_embed.py @@ -1,7 +1,6 @@ import datetime import logging -import aiohttp from discord import Embed from discord.ext import commands -- 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(-) 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