From 7ba7149c688ba35d60934fdc68b92b82862065c7 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Tue, 16 Feb 2021 09:10:57 -0800 Subject: Add .pyfacts command --- bot/exts/evergreen/pythonfacts.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bot/exts/evergreen/pythonfacts.py (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py new file mode 100644 index 00000000..ba792561 --- /dev/null +++ b/bot/exts/evergreen/pythonfacts.py @@ -0,0 +1,23 @@ +import random + +import discord +from discord.ext import commands +from discord.ext.commands.bot import Bot + + +class PythonFacts(commands.Cog): + """Gives a random fun fact about Python.""" + + def __init__(self, bot: Bot) -> None: + self.bot = bot + + @commands.command(name='pythonfact', aliases=['pyfact']) + async def get_python_fact(self, ctx: commands.Context) -> None: + """Gives a Random fun fact about Python.""" + with open('bot/resources/evergreen/python_facts.txt') as file: + await ctx.send(embed=discord.Embed(title='Python Facts', description=f'**{random.choice(list(file))}**')) + + +def setup(bot: commands.Bot) -> None: + """Adding the cog to the bot.""" + bot.add_cog(PythonFacts(bot)) -- cgit v1.2.3 From fdfa5c75b74a898512bfac6fa3ac14d452eae05d Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Tue, 16 Feb 2021 10:44:21 -0800 Subject: Remove unused import --- bot/exts/evergreen/pythonfacts.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index ba792561..b1c28d4b 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -2,13 +2,12 @@ import random import discord from discord.ext import commands -from discord.ext.commands.bot import Bot class PythonFacts(commands.Cog): """Gives a random fun fact about Python.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: commands.Bot) -> None: self.bot = bot @commands.command(name='pythonfact', aliases=['pyfact']) -- cgit v1.2.3 From 06d600f0fd927e566d23879638d10c6d66a63a21 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Tue, 16 Feb 2021 10:48:13 -0800 Subject: Move loading of file outside of command --- bot/exts/evergreen/pythonfacts.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index b1c28d4b..c6592add 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -4,6 +4,10 @@ import discord from discord.ext import commands +with open('bot/resources/evergreen/python_facts.txt') as file: + FACTS = list(file) + + class PythonFacts(commands.Cog): """Gives a random fun fact about Python.""" @@ -13,8 +17,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Gives a Random fun fact about Python.""" - with open('bot/resources/evergreen/python_facts.txt') as file: - await ctx.send(embed=discord.Embed(title='Python Facts', description=f'**{random.choice(list(file))}**')) + await ctx.send(embed=discord.Embed(title='Python Facts', description=f'**{random.choice(FACTS)}**')) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From 57aec016ac74465212744a9ec4173515dca98ba1 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon <74436682+MrKomodoDragon@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:57:51 -0800 Subject: Remove bold Co-authored-by: Shivansh-007 <69356296+Shivansh-007@users.noreply.github.com> --- bot/exts/evergreen/pythonfacts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index c6592add..fcb78168 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -17,7 +17,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Gives a Random fun fact about Python.""" - await ctx.send(embed=discord.Embed(title='Python Facts', description=f'**{random.choice(FACTS)}**')) + await ctx.send(embed=discord.Embed(title='Python Facts', description=random.choice(FACTS))) def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From a68e8f558cfee18bdb04c9e9a07cc9d293bd6c71 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon <74436682+MrKomodoDragon@users.noreply.github.com> Date: Tue, 16 Feb 2021 17:58:31 -0800 Subject: Update docstring for Cog Co-authored-by: Shivansh-007 <69356296+Shivansh-007@users.noreply.github.com> --- bot/exts/evergreen/pythonfacts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index fcb78168..dbc38ef4 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -21,5 +21,5 @@ class PythonFacts(commands.Cog): def setup(bot: commands.Bot) -> None: - """Adding the cog to the bot.""" + """Load PythonFacts Cog.""" bot.add_cog(PythonFacts(bot)) -- cgit v1.2.3 From 6aae339f33ee471bafe9338db5046b774c6b4aad Mon Sep 17 00:00:00 2001 From: MrKomodoDragon <74436682+MrKomodoDragon@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:03:31 -0800 Subject: Change Docstring for command Co-authored-by: Shivansh-007 <69356296+Shivansh-007@users.noreply.github.com> --- bot/exts/evergreen/pythonfacts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index dbc38ef4..c0cdf111 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -16,7 +16,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: - """Gives a Random fun fact about Python.""" + """Sends a Random fun fact about Python.""" await ctx.send(embed=discord.Embed(title='Python Facts', description=random.choice(FACTS))) -- cgit v1.2.3 From 5164ba4e367efbfe78f8dd2b08646fe6605a8b42 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Tue, 16 Feb 2021 18:21:12 -0800 Subject: Add colors and move embed out of send statement; add more info about Monty Python for Fact 1 --- bot/exts/evergreen/pythonfacts.py | 7 +++++-- bot/resources/evergreen/python_facts.txt | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index c0cdf111..734782b8 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -7,9 +7,11 @@ from discord.ext import commands with open('bot/resources/evergreen/python_facts.txt') as file: FACTS = list(file) +COLORS = [0x4B8BBE, 0xFFD43B, ] + class PythonFacts(commands.Cog): - """Gives a random fun fact about Python.""" + """Sends a random fun fact about Python.""" def __init__(self, bot: commands.Bot) -> None: self.bot = bot @@ -17,7 +19,8 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Sends a Random fun fact about Python.""" - await ctx.send(embed=discord.Embed(title='Python Facts', description=random.choice(FACTS))) + embed = discord.Embed(title='Python Facts', description=random.choice(FACTS), colour=random.choice(COLORS)) + await ctx.send(embed=embed) def setup(bot: commands.Bot) -> None: diff --git a/bot/resources/evergreen/python_facts.txt b/bot/resources/evergreen/python_facts.txt index d9e63a11..0abd971b 100644 --- a/bot/resources/evergreen/python_facts.txt +++ b/bot/resources/evergreen/python_facts.txt @@ -1,3 +1,3 @@ -Python was named after Monty Python, which Guido van Rossum likes. +Python was named after Monty Python, a British Comedy Troupe, which Guido van Rossum likes. If you type `import this` in the Python REPL, you'll get a poem about the philosophies about Python. (check it out by doing !zen in <#267659945086812160>) If you type `import antigravity` in the Python REPL, you'll be directed to an [xkcd comic](https://xkcd.com/353/) about how easy Python is. -- cgit v1.2.3 From 16476ab7b4d5efe36a9e101b382f7be24888dec5 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Mon, 22 Feb 2021 11:13:01 -0800 Subject: Switch to itertools.cycle and add colors to constants.py --- bot/constants.py | 2 ++ bot/exts/evergreen/pythonfacts.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/constants.py b/bot/constants.py index bb538487..3aec6ba3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -156,6 +156,8 @@ class Colours: soft_orange = 0xf9cb54 soft_red = 0xcd6d6d yellow = 0xf9f586 + python_blue = 0x4B8BBE + python_yellow = 0xFFD43B class Emojis: diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index 734782b8..8e6d300b 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -1,13 +1,16 @@ -import random +import itertools import discord from discord.ext import commands +from bot.constants import Colours with open('bot/resources/evergreen/python_facts.txt') as file: FACTS = list(file) + FACT_CYCLE = itertools.cycle(FACTS) -COLORS = [0x4B8BBE, 0xFFD43B, ] +COLORS = [Colours.python_blue, Colours.python_yellow] +COLOR_CYCLE = itertools.cycle(COLORS) class PythonFacts(commands.Cog): @@ -19,7 +22,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Sends a Random fun fact about Python.""" - embed = discord.Embed(title='Python Facts', description=random.choice(FACTS), colour=random.choice(COLORS)) + embed = discord.Embed(title='Python Facts', description=next(FACT_CYCLE), colour=next(COLOR_CYCLE)) await ctx.send(embed=embed) -- cgit v1.2.3 From aef25cb560eb525305c583a8ff2834b503cb91d4 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Tue, 23 Feb 2021 09:03:05 -0800 Subject: Remove unused variables --- bot/exts/evergreen/pythonfacts.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index 8e6d300b..11b258f9 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -6,11 +6,9 @@ from discord.ext import commands from bot.constants import Colours with open('bot/resources/evergreen/python_facts.txt') as file: - FACTS = list(file) - FACT_CYCLE = itertools.cycle(FACTS) + FACTS = itertools.cycle(list(file)) -COLORS = [Colours.python_blue, Colours.python_yellow] -COLOR_CYCLE = itertools.cycle(COLORS) +COLORS = itertools.cycle([Colours.python_blue, Colours.python_yellow]) class PythonFacts(commands.Cog): @@ -22,7 +20,7 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Sends a Random fun fact about Python.""" - embed = discord.Embed(title='Python Facts', description=next(FACT_CYCLE), colour=next(COLOR_CYCLE)) + embed = discord.Embed(title='Python Facts', description=next(FACTS), colour=next(COLORS)) await ctx.send(embed=embed) -- cgit v1.2.3 From 55e33789830c00fc970c74be142857f90678cda7 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Thu, 4 Mar 2021 11:20:37 -0800 Subject: Add link to discussion for suggesting facts in Embed --- bot/exts/evergreen/pythonfacts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index 11b258f9..fb96a19d 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -20,7 +20,12 @@ class PythonFacts(commands.Cog): @commands.command(name='pythonfact', aliases=['pyfact']) async def get_python_fact(self, ctx: commands.Context) -> None: """Sends a Random fun fact about Python.""" - embed = discord.Embed(title='Python Facts', description=next(FACTS), colour=next(COLORS)) + embed = discord.Embed(title='Python Facts', + description=next(FACTS), + colour=next(COLORS)) + embed.add_field(name='Suggestions', + value="Want to suggest more facts? " + "Suggest more facts [here!](https://github.com/python-discord/meta/discussions/93)") await ctx.send(embed=embed) -- cgit v1.2.3 From 1669b50e026678fd8e9fe6f72677e1de5943dd66 Mon Sep 17 00:00:00 2001 From: MrKomodoDragon Date: Thu, 4 Mar 2021 12:18:25 -0800 Subject: Remove "Want to suggest a fact?" for consistency --- bot/exts/evergreen/pythonfacts.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/exts/evergreen/pythonfacts.py') diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/evergreen/pythonfacts.py index fb96a19d..457c2fd3 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/evergreen/pythonfacts.py @@ -24,8 +24,7 @@ class PythonFacts(commands.Cog): description=next(FACTS), colour=next(COLORS)) embed.add_field(name='Suggestions', - value="Want to suggest more facts? " - "Suggest more facts [here!](https://github.com/python-discord/meta/discussions/93)") + value="Suggest more facts [here!](https://github.com/python-discord/meta/discussions/93)") await ctx.send(embed=embed) -- cgit v1.2.3