Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
.vscode
57 changes: 0 additions & 57 deletions Bot/assistant_bot.py

This file was deleted.

7 changes: 7 additions & 0 deletions cogs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Cogs

Functionality of the Code Network bot is organised into cogs, discord.py's way of separating concerns within the codebase. Information about cogs can be found here: https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html.

## Naming convention

The file name and cog name should be suffixed with "cog", so for example if my cog was concerned with authentication, the file would be called `auth_cog.py` and the class should be named `AuthCog`.
10 changes: 10 additions & 0 deletions cogs/basics_cog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from discord.ext import commands


class BasicsCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot

async def hello(self, ctx: commands.Context):
await ctx.channel.send(f"Hello humans!") # reply with Hello!
# await message.author.send('Hello there!') # send a message to the author
41 changes: 41 additions & 0 deletions cogs/inspire_cog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from discord.ext import commands
import requests
import random

SAD_WORDS = ["sad", "depressed", "unhappy", "angry", "miserable", "depressing"]

STARTER_ENCOURAGEMENTS = [
"Cheer up!",
"You can do it!",
"Hang in there!",
"You are a star!",
"You are a great person!",
]

def get_quote() -> str:
"""
This function gets a random quote from the API
"""
url = "https://zenquotes.io/api/random"
response = requests.get(url)
json_data = response.json()
quote = json_data[0]["q"] + " - " + json_data[0]["a"]
return quote


class InspireCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot

@commands.command()
async def inspire(self, ctx: commands.Context):
author_name = ctx.author.name.split()[0] # get the author's name
quote = get_quote()
# await message.channel.send(quote)
await ctx.reply(author_name + ", " + quote)

@commands.Cog.listener()
async def sad_reply(self, ctx: commands.Context):
if any(word in ctx.message.content.lower() for word in SAD_WORDS):
await ctx.channel.send(random.choice(STARTER_ENCOURAGEMENTS))
# message.channel.send("I'm sorry to hear that. I'm always here to help!")
27 changes: 27 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from discord.ext import commands
from dotenv import load_dotenv
import asyncio

from cogs.basics_cog import BasicsCog
from cogs.inspire_cog import InspireCog

BOT = commands.Bot(command_prefix='$')

@BOT.event
async def on_ready(): # when the bot is ready to use
print(f"We have logged in as {BOT.user}")
# "Hey there! I'm your personal assistant. I can help you with anything you need. Just ask me!"


BOT.add_cog(BasicsCog(BOT))
BOT.add_cog(InspireCog(BOT))

async def main():
async with BOT:
load_dotenv()
token = os.getenv("AUTH_TOKEN")
await BOT.start(token) # run the bot with the token

if __name__ == "__main__":
asyncio.run(main)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests==2.28.1
discord.py==2.0.1
python-dotenv==0.21.0