From f92b0b8b37825f4a456a04cb68007e188e792850 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Wed, 14 Aug 2024 18:18:39 +0300 Subject: [PATCH 01/10] Added a function to get memes --- utils/meme_api.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/utils/meme_api.py b/utils/meme_api.py index 50c2192..194496d 100644 --- a/utils/meme_api.py +++ b/utils/meme_api.py @@ -1 +1,30 @@ -"""defines a function make a request to the memes API and reatruns a meme""" \ No newline at end of file +"""defines a function make a request to the memes API and reatruns a meme""" +import requests +import os +from dotenv import load_dotenv + +load_dotenv() +RAPIDAPI_KEY = os.getenv("RAPIDAPI_KEY") + + +def get_meme(): + """Make an api request to programming memes rapidapi + + Returns: + str: link of a meme + """ + + url = "https://programming-memes-images.p.rapidapi.com/v1/memes" + + headers = { + "x-rapidapi-key": RAPIDAPI_KEY, + "x-rapidapi-host": "programming-memes-images.p.rapidapi.com" + } + + response = requests.get(url, headers=headers) + if response.status_code == 200: + data = response.json() + image = data[0]['image'] + return image + else: + return From 96a5b368edf5e809d99c9070da84470b01224242 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Wed, 14 Aug 2024 18:20:26 +0300 Subject: [PATCH 02/10] Added meme command --- cogs/memes.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cogs/memes.py b/cogs/memes.py index 183fca9..a15afb2 100644 --- a/cogs/memes.py +++ b/cogs/memes.py @@ -1 +1,30 @@ -"""defines commands for the memes functionality""" \ No newline at end of file +"""defines commands for the memes functionality""" +from discord.ext import commands +from discord import app_commands +import discord +from utils.meme_api import get_meme + + +class Memes(commands.Cog): + """ + """ + def __init__(self, bot): + """initalization function""" + self.bot = bot + + @app_commands.command(name='meme', + description='A meme to light up your day') + async def meme_command(self, interaction: discord.Interaction): + """ + """ + meme_link = get_meme() + await interaction.response.send_message(meme_link) + + +async def setup(bot): + """ loads the memes Cog into the bot. + + Args: + bot (command.Bot): instance of the bot. + """ + await bot.add_cog(Memes(bot)) From af72b5dfe0c3f066a4b69e4b271f88609ed66941 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Wed, 14 Aug 2024 18:22:21 +0300 Subject: [PATCH 03/10] loaded the meme command cog --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index d198e33..b2d88d5 100644 --- a/bot.py +++ b/bot.py @@ -22,7 +22,7 @@ async def load_cogs(): await bot.load_extension('cogs.youtube') await bot.load_extension('cogs.quotes') # await bot.load_extension('cogs.projects') -# await bot.load_extension('cogs.memes') + await bot.load_extension('cogs.memes') @bot.event From 8f24c84d0819687844986f3ec4bf07ae168ac2ad Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 15:29:59 +0300 Subject: [PATCH 04/10] Added buttons to meme --- cogs/memes.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cogs/memes.py b/cogs/memes.py index a15afb2..ffe07f2 100644 --- a/cogs/memes.py +++ b/cogs/memes.py @@ -3,6 +3,7 @@ from discord import app_commands import discord from utils.meme_api import get_meme +import os class Memes(commands.Cog): @@ -18,8 +19,26 @@ async def meme_command(self, interaction: discord.Interaction): """ """ meme_link = get_meme() - await interaction.response.send_message(meme_link) + await self.send_meme(interaction, meme_link) + async def send_meme(self, interaction: discord.Interaction, content: str) -> None: + """ + """ + new_meme_button = discord.ui.button(label='New Meme😜', + style=discord.ButtonStyle.primary) + async def new_meme_callback(interaction: discord.Interaction): + """_summary_ + """ + new_meme = get_meme() + await self.send_meme(interaction, new_meme) + + new_meme_button.callback = new_meme_callback + + view = discord.ui.View() + view.add_item(new_meme_button) + view.add_item(discord.ui.Button(label="Invite", url=os.getenv('INVITE_LINK'), style=discord.ButtonStyle.link)) + + await interaction.response.send_message(content, view=view) async def setup(bot): """ loads the memes Cog into the bot. From 3c78280098a4c443f8dae0b1e7199cb809bf13e8 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 15:34:27 +0300 Subject: [PATCH 05/10] Added documentation --- cogs/memes.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cogs/memes.py b/cogs/memes.py index ffe07f2..1dd8a11 100644 --- a/cogs/memes.py +++ b/cogs/memes.py @@ -7,7 +7,7 @@ class Memes(commands.Cog): - """ + """A class fro memes command """ def __init__(self, bot): """initalization function""" @@ -16,18 +16,30 @@ def __init__(self, bot): @app_commands.command(name='meme', description='A meme to light up your day') async def meme_command(self, interaction: discord.Interaction): - """ + """defines and set up the 'meme' command that get's a meme to user. + + Args: + interaction (discord.Interaction): object for interacting with + commands. """ meme_link = get_meme() await self.send_meme(interaction, meme_link) async def send_meme(self, interaction: discord.Interaction, content: str) -> None: - """ + """prepare the command response and send it as a response + also defines a button and a callback for the command. + Args: + interaction (discord.interaction): command interaction object. + content (str): content returned by the command. """ new_meme_button = discord.ui.button(label='New Meme😜', style=discord.ButtonStyle.primary) async def new_meme_callback(interaction: discord.Interaction): - """_summary_ + """Nested recursive function to handle button callback. + it graps a new meme and send it back to user. + + Args: + interaction (discord.Interaction): command interaction object """ new_meme = get_meme() await self.send_meme(interaction, new_meme) From e7370fc37f2d92a42962edd93e44cd045564057a Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 15:52:34 +0300 Subject: [PATCH 06/10] updated code styling --- cogs/memes.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cogs/memes.py b/cogs/memes.py index 1dd8a11..22310b4 100644 --- a/cogs/memes.py +++ b/cogs/memes.py @@ -17,7 +17,7 @@ def __init__(self, bot): description='A meme to light up your day') async def meme_command(self, interaction: discord.Interaction): """defines and set up the 'meme' command that get's a meme to user. - + Args: interaction (discord.Interaction): object for interacting with commands. @@ -25,7 +25,9 @@ async def meme_command(self, interaction: discord.Interaction): meme_link = get_meme() await self.send_meme(interaction, meme_link) - async def send_meme(self, interaction: discord.Interaction, content: str) -> None: + async def send_meme(self, + interaction: discord.Interaction, + content: str) -> None: """prepare the command response and send it as a response also defines a button and a callback for the command. Args: @@ -34,6 +36,7 @@ async def send_meme(self, interaction: discord.Interaction, content: str) -> Non """ new_meme_button = discord.ui.button(label='New Meme😜', style=discord.ButtonStyle.primary) + async def new_meme_callback(interaction: discord.Interaction): """Nested recursive function to handle button callback. it graps a new meme and send it back to user. @@ -48,10 +51,13 @@ async def new_meme_callback(interaction: discord.Interaction): view = discord.ui.View() view.add_item(new_meme_button) - view.add_item(discord.ui.Button(label="Invite", url=os.getenv('INVITE_LINK'), style=discord.ButtonStyle.link)) + view.add_item(discord.ui.Button(label="Invite", + url=os.getenv('INVITE_LINK'), + style=discord.ButtonStyle.link)) await interaction.response.send_message(content, view=view) + async def setup(bot): """ loads the memes Cog into the bot. From 2c7a4d252281bfdd2aa5a17e42b17765cbf31cc6 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 17:26:42 +0300 Subject: [PATCH 07/10] Added a markdown template for readmefile --- data/readme_template1.md | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 data/readme_template1.md diff --git a/data/readme_template1.md b/data/readme_template1.md new file mode 100644 index 0000000..62de530 --- /dev/null +++ b/data/readme_template1.md @@ -0,0 +1,59 @@ +# Project Title + +A short description about the project and/or client. + +## Getting Started + +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. + +### Prerequisites + +The things you need before installing the software. + +* You need this +* And you need this +* Oh, and don't forget this + +### Installation + +A step by step guide that will tell you how to get the development environment up and running. + +\`\`\` +$ First step +$ Another step +$ Final step +\`\`\` + +## Usage + +A few examples of useful commands and/or tasks. + +\`\`\` +$ First example +$ Second example +$ And keep this in mind +\`\`\` + +## Deployment + +Additional notes on how to deploy this on a live or release system. Explaining the most important branches, what pipelines they trigger and how to update the database (if anything special). + +### Server + +* Live: +* Release: +* Development: + +### Branches + +* Master: +* Feature: +* Bugfix: +* etc... + +## Additional Documentation and Acknowledgments + +* Project folder on server: +* Confluence link: +* Asana board: +* etc... From 8d18d404f6f57bd1d725e7503f18ba644f72a445 Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 17:27:24 +0300 Subject: [PATCH 08/10] added markdown template for readme file --- data/readme_template2.md | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 data/readme_template2.md diff --git a/data/readme_template2.md b/data/readme_template2.md new file mode 100644 index 0000000..9f2bb58 --- /dev/null +++ b/data/readme_template2.md @@ -0,0 +1,71 @@ +# Product Name +> Short blurb about what your product does. + +[![NPM Version][npm-image]][npm-url] +[![Build Status][travis-image]][travis-url] +[![Downloads Stats][npm-downloads]][npm-url] + +One to two paragraph statement about your product and what it does. + +![](header.png) + +## Installation + +OS X & Linux: + +/`/`/`sh +npm install my-crazy-module --save +/`/`/` + +Windows: + +/`/`/`sh +edit autoexec.bat +/`/`/` + +## Usage example + +A few motivating and useful examples of how your product can be used. Spice this up with code blocks and potentially more screenshots. + +_For more examples and usage, please refer to the [Wiki][wiki]._ + +## Development setup + +Describe how to install all development dependencies and how to run an automated test-suite of some kind. Potentially do this for multiple platforms. + +/`/`/`sh +make install +npm test +/`/`/` + +## Release History + +* 0.1.1 + * FIX: Crash when calling `baz()` (Thanks @GenerousContributorName!) +* 0.1.0 + * The first proper release + * CHANGE: Rename `foo()` to `bar()` +* 0.0.1 + * Work in progress + +## Meta + +Your Name – [@YourTwitter](https://twitter.com/dbader_org) – YourEmail@example.com + +Distributed under the XYZ license. See ``LICENSE`` for more information. + +[https://github.com/yourname/github-link](https://github.com/dbader/) + +## Contributing + +1. Fork it () +2. Create your feature branch (`git checkout -b feature/fooBar`) +3. Commit your changes (`git commit -am 'Add some fooBar'`) +4. Push to the branch (`git push origin feature/fooBar`) +5. Create a new Pull Request + + +[npm-image]: https://img.shields.io/npm/v/datadog-metrics.svg?style=flat-square +[npm-url]: https://npmjs.org/package/datadog-metrics +[npm-downloads]: https://img.shields.io/npm/dm/datadog-metrics.svg?style=flat-square +[wiki]: https://github.com/yourname/yourproject/wiki From 1616a924a5d3cbb35582ecdb7ad59b887a853f6e Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 17:29:58 +0300 Subject: [PATCH 09/10] Added readme command --- cogs/readme.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 cogs/readme.py diff --git a/cogs/readme.py b/cogs/readme.py new file mode 100644 index 0000000..ed046d2 --- /dev/null +++ b/cogs/readme.py @@ -0,0 +1,58 @@ +from discord.ext import commands +from discord import app_commands +import discord + + +class Readme(commands.Cog): + """ Class for the Readme command """ + + def __init__(self, bot): + """initialization function + """ + self.bot = bot + + with open('data/readme_template1.md', 'r') as f: + self.temp1 = f.read() + + # Load Would You Rather data + with open('data/readme_template2.md', 'r') as f: + self.temp2 = f.read() + + @app_commands.command(name='readme', + description='templates for creating a readme file') + async def readme_command(self, interaction: discord.Interaction): + """ a command for getting a readme file template. + + Args: + interaction (discord.Interaction): object for interactiong + with commands. + """ + temp1_button = discord.ui.Button(label="📑Template 1", + style=discord.ButtonStyle.primary) + temp2_button = discord.ui.Button(label="📑Template 2", + style=discord.ButtonStyle.primary) + + async def temp1_callback(interaction: discord.Interaction): + await interaction.response.send_message(f"```{self.temp1}```") + + async def temp2_callback(interaction: discord.Interaction): + await interaction.response.send_message(f"```{self.temp2}```") + + temp1_button.callback = temp1_callback + temp2_button.callback = temp2_callback + + view = discord.ui.View() + view.add_item(temp1_button) + view.add_item(temp2_button) + + await interaction.response.send_message(content="Choose template", + view=view) + + +async def setup(bot): + """ loads the quote Cog into the bot. + + Args: + bot (command.Bot): instance of the bot. + """ + await bot.add_cog(Readme(bot)) From 967d76461889002c966f2590aea5462def5fc6be Mon Sep 17 00:00:00 2001 From: Y4h14 Date: Thu, 15 Aug 2024 17:30:44 +0300 Subject: [PATCH 10/10] added readme command to bot --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index b2d88d5..c4d3b06 100644 --- a/bot.py +++ b/bot.py @@ -23,6 +23,7 @@ async def load_cogs(): await bot.load_extension('cogs.quotes') # await bot.load_extension('cogs.projects') await bot.load_extension('cogs.memes') + await bot.load_extension('cogs.readme') @bot.event