-
-
Notifications
You must be signed in to change notification settings - Fork 40
Add fun fact command #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fun fact command #446
Changes from all commits
8c779f8
dc81d10
44dcb5f
2552bc0
2463358
33b1ec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||
| import random | ||||||||||||||||||
|
|
||||||||||||||||||
| from discord.ext import commands | ||||||||||||||||||
|
|
||||||||||||||||||
| from tux.utils.embeds import EmbedCreator | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class Fact(commands.Cog): | ||||||||||||||||||
| def __init__(self, bot: commands.Bot) -> None: | ||||||||||||||||||
| self.bot = bot | ||||||||||||||||||
| self.facts = [ | ||||||||||||||||||
electron271 marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): Consider scalability for fact storage If there are plans to significantly expand the fact list in the future, you might want to consider a more scalable solution for storing and retrieving facts, such as loading from a file or database. |
||||||||||||||||||
| "The Linux kernel has over 36 million lines of code in its Git repository.", | ||||||||||||||||||
| "The vast majority of the world's supercomputers run on Linux.", | ||||||||||||||||||
| "Linux 1.0 was launched on September 17, 1991 featuring 176,250 lines of code.", | ||||||||||||||||||
| "There's an easter egg in `apt` if you enter `apt moo`.", | ||||||||||||||||||
| "Linus Torvalds was around 22 years old when he started work on the Linux Kernel in 1991. In the same year, he also released prototypes of the kernel publicly.", | ||||||||||||||||||
| "Linux's 1.0 release was in March 1994.", | ||||||||||||||||||
| "Less than 1% of the latest kernel release includes code written by Linus Torvalds.", | ||||||||||||||||||
| "Linux is used by every major space programme in the world.", | ||||||||||||||||||
| "Approximately 13.3% of the latest Linux kernel is made up of blank lines.", | ||||||||||||||||||
| "Vim has various easter eggs. A notable one is found by typing :help 42 into the command bar.", | ||||||||||||||||||
| "Slackware is the oldest active linux distribution being released on the 17th July 1993.", | ||||||||||||||||||
| "Freax was the original planned name for Linux.", | ||||||||||||||||||
| "The first GUI that ran on Linux was X Window System. It ran on Linux Kernel version 0.95.", | ||||||||||||||||||
| "The Linux Kernel was the first OS kernel to support x86-64 in 2001.", | ||||||||||||||||||
| "Over 14,600 individual developers from over 1,300 different companies have contributed to the kernel.", | ||||||||||||||||||
| "95% of the Linux kernel is written in the C programming Language. Assembly language is the second most used language for Linux at 2.8%.", | ||||||||||||||||||
| "The first kernel version - Version 0.01 - contained about 10,000 lines of code.", | ||||||||||||||||||
| "96.3% of the top 1,000,000 web servers were reported to run on Linux.", | ||||||||||||||||||
| "In the early 2000s, Steve Jobs, who at the time was the CEO of Apple, offered a job to Linus Torvalds to work on OSX which Torvalds declined.", | ||||||||||||||||||
| "Linus Torvalds said that he would have never created Linux if FreeBSD had been available at the time.", | ||||||||||||||||||
| "Linux is used by every major space programme in the world including NASA, SpaceX, and the European Space Agency.", | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Remove redundant fact This fact is a duplicate of the one on line 8. Consider removing one of these instances to avoid repetition.
Suggested change
|
||||||||||||||||||
| ] | ||||||||||||||||||
|
|
||||||||||||||||||
| @commands.hybrid_command( | ||||||||||||||||||
| name="fact", | ||||||||||||||||||
| aliases=["funfact"], | ||||||||||||||||||
| ) | ||||||||||||||||||
| async def fact(self, ctx: commands.Context[commands.Bot]) -> None: | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Improve or remove method comment The current comment doesn't provide much additional information. Consider either removing it or expanding it to include more meaningful details about the method's behavior or purpose.
Suggested change
|
||||||||||||||||||
| """ | ||||||||||||||||||
| Get a random fun fact. | ||||||||||||||||||
|
|
||||||||||||||||||
| Parameters | ||||||||||||||||||
| ---------- | ||||||||||||||||||
| ctx : commands.Context[commands.Bot] | ||||||||||||||||||
| The context object for the command. | ||||||||||||||||||
| """ | ||||||||||||||||||
| embed = EmbedCreator.create_info_embed( | ||||||||||||||||||
| title="Fun Fact", | ||||||||||||||||||
| description=random.choice(self.facts), | ||||||||||||||||||
| ctx=ctx, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # set author | ||||||||||||||||||
| embed.set_author( | ||||||||||||||||||
| name="Submit more facts here!", | ||||||||||||||||||
| url="https://github.com/allthingslinux/tux/blob/main/tux/cogs/fun/fact.py", | ||||||||||||||||||
| icon_url="https://github.com/allthingslinux/tux/blob/main/assets/emojis/tux_info.png?raw=true", | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| await ctx.send(embed=embed) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| async def setup(bot: commands.Bot) -> None: | ||||||||||||||||||
| await bot.add_cog(Fact(bot)) | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Optimize fact selection for better distribution
Consider shuffling the
factslist in the__init__method and selecting facts from the first 75% of the list in thefactmethod. This approach would provide a good balance between randomness and ensuring all facts are seen before repeats occur.