Skip to content
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

Readme #34

Merged
merged 10 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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')
await bot.load_extension('cogs.readme')


@bot.event
Expand Down
68 changes: 67 additions & 1 deletion cogs/memes.py
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
"""defines commands for the memes functionality"""
"""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
import os


class Memes(commands.Cog):
"""A class fro memes command
"""
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):
"""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):
"""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)

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.

Args:
bot (command.Bot): instance of the bot.
"""
await bot.add_cog(Memes(bot))
58 changes: 58 additions & 0 deletions cogs/readme.py
Original file line number Diff line number Diff line change
@@ -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))
59 changes: 59 additions & 0 deletions data/readme_template1.md
Original file line number Diff line number Diff line change
@@ -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...
71 changes: 71 additions & 0 deletions data/readme_template2.md
Original file line number Diff line number Diff line change
@@ -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 (<https://github.com/yourname/yourproject/fork>)
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

<!-- Markdown link & img dfn's -->
[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
31 changes: 30 additions & 1 deletion utils/meme_api.py
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
"""defines a function make a request to the memes API and reatruns a meme"""
"""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