Skip to content

Commit

Permalink
Merge pull request #80 from LewisProjects/development
Browse files Browse the repository at this point in the history
2.2
  • Loading branch information
LevaniVashadze authored Jul 31, 2023
2 parents 0dd689b + 627475a commit 5ee891c
Show file tree
Hide file tree
Showing 44 changed files with 1,517 additions and 628 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Main Contributors/Developers:
<li><a href="https://github.com/JasonLovesDoggo">JasonLovesDoggo</a></li>
<li><a href="https://github.com/LevaniVashadze">Levani Vashadze</a></li>
</ul>
The bot is currently on release: <b>2.0</b><br>
The bot is currently on release: <b>2.2</b><br>
License: MIT<br>

<h3>Contributing</h3>
Expand Down
24 changes: 19 additions & 5 deletions cogs/AI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import time
from io import BytesIO

from better_profanity import profanity
import disnake
from disnake.ext import commands

Expand All @@ -13,23 +13,37 @@ def __init__(self, bot: OGIROID):
self.bot = bot

@commands.slash_command(description="Generates ai art")
async def ai_art(self, inter: disnake.ApplicationCommandInteraction, text):
async def ai_art(
self, inter: disnake.ApplicationCommandInteraction, text: str
):
if profanity.contains_profanity(text):
return await inter.send(
f"NSFW requests are not allowed!", ephemeral=True
)
if "bot" in inter.channel.name or "command" in inter.channel.name:
hidden = False
else:
hidden = True
ETA = int(time.time() + 60)
await inter.send(
f"Go grab a coffee this may take a while... ETA: <t:{ETA}:R>",
ephemeral=True,
ephemeral=hidden,
)
response = await self.bot.session.post(
"https://backend.craiyon.com/generate", json={"prompt": text}
)
r = await response.json()
raw_images = r["images"]
images = [
disnake.File(BytesIO(base64.decodebytes(i.encode("utf-8"))), "image.png")
disnake.File(
BytesIO(base64.decodebytes(i.encode("utf-8"))), "image.png"
)
for i in raw_images
]

await inter.edit_original_response(files=images, content="Here you go!")
await inter.edit_original_response(
files=images, content="Here you go!"
)


def setup(bot):
Expand Down
52 changes: 39 additions & 13 deletions cogs/Animals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ class Animals(commands.Cog):
def __init__(self, bot: OGIROID):
self.bot = bot

@commands.slash_command(description="Gets a random picture of the specified animal")
@commands.slash_command(
description="Gets a random picture of the specified animal"
)
@commands.cooldown(1, 3, commands.BucketType.user)
async def animal(self, inter):
pass

@animal.sub_command(name="cat", description="Get a random cat picture")
async def cat(self, inter):
"""Get a random cat picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/cat")
response = await self.bot.session.get(
"https://some-random-api.com/animal/cat"
)
data = await response.json()
embed = disnake.Embed(
title="Cat Picture! 🐱",
Expand All @@ -30,12 +34,16 @@ async def cat(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message(f"**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
f"**Fun Fact: **" + data["fact"], embed=embed
)

@animal.sub_command(name="dog", description="Get a random dog picture")
async def dog(self, inter):
"""Get a random dog picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/dog")
response = await self.bot.session.get(
"https://some-random-api.com/animal/dog"
)
data = await response.json()
embed = disnake.Embed(
title="Dog Picture! 🐶",
Expand All @@ -47,12 +55,16 @@ async def dog(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
"**Fun Fact: **" + data["fact"], embed=embed
)

@animal.sub_command(name="bird", description="Get a random bird picture")
async def bird(self, inter):
"""Get a random bird picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/bird")
response = await self.bot.session.get(
"https://some-random-api.com/animal/bird"
)
data = await response.json()
embed = disnake.Embed(
title="Bird Picture! 🐦",
Expand All @@ -64,12 +76,16 @@ async def bird(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
"**Fun Fact: **" + data["fact"], embed=embed
)

@animal.sub_command(name="fox", description="Get a random fox picture")
async def fox(self, inter):
"""Get a random fox picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/fox")
response = await self.bot.session.get(
"https://some-random-api.com/animal/fox"
)
data = await response.json()
embed = disnake.Embed(
title="Fox Picture! 🦊",
Expand All @@ -81,12 +97,16 @@ async def fox(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
"**Fun Fact: **" + data["fact"], embed=embed
)

@animal.sub_command(name="panda", description="Get a random panda picture")
async def panda(self, inter):
"""Get a random panda picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/panda")
response = await self.bot.session.get(
"https://some-random-api.com/animal/panda"
)
data = await response.json()
embed = disnake.Embed(
title="Panda Picture! 🐼",
Expand All @@ -98,12 +118,16 @@ async def panda(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
"**Fun Fact: **" + data["fact"], embed=embed
)

@animal.sub_command(name="koala", description="Get a random cat picture")
async def koala(self, inter):
"""Get a random koala picture!"""
response = await self.bot.session.get("https://some-random-api.ml/animal/koala")
response = await self.bot.session.get(
"https://some-random-api.com/animal/koala"
)
data = await response.json()
embed = disnake.Embed(
title="Koala Picture! 🐨",
Expand All @@ -115,7 +139,9 @@ async def koala(self, inter):
text=f"Command issued by: {inter.author.name}",
icon_url=inter.author.display_avatar,
)
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
await inter.response.send_message(
"**Fun Fact: **" + data["fact"], embed=embed
)


def setup(bot):
Expand Down
109 changes: 86 additions & 23 deletions cogs/Birthdays.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
from utils.shortcuts import QuickEmb, sucEmb, errorEmb


async def get_days_until_birthday(user_data) -> (int, str):
"""returns the days until the next birthday and the next birthday date formatted for discord"""
next_birthday = datetime.datetime.strptime(
user_data.birthday + f"/{dt.datetime.now().year}", "%d/%m/%Y"
)
if next_birthday < datetime.datetime.now():
next_birthday = datetime.datetime.strptime(
user_data.birthday + f"/{dt.datetime.now().year + 1}", "%d/%m/%Y"
)
return (
next_birthday - datetime.datetime.now()
).days, f"<t:{str(next_birthday.timestamp()).split('.')[0]}:D>"


class Birthday(commands.Cog):
def __init__(self, bot: OGIROID):
self.bot = bot
Expand All @@ -21,17 +35,22 @@ def __init__(self, bot: OGIROID):
@commands.Cog.listener()
async def on_ready(self):
if not self.bot.ready_:
self.birthday: BirthdayHandler = BirthdayHandler(self.bot, self.bot.db)
self.birthday: BirthdayHandler = BirthdayHandler(
self.bot, self.bot.db
)

def cog_unload(self):
self.birthday_check.cancel()

@commands.slash_command(name="birthday")
@commands.slash_command(
name="birthday", description="Birthdays base command"
)
async def birthday(self, inter: disnake.ApplicationCommandInteraction):
pass

@birthday.sub_command(
name="set", description="Set your birthday. Cant be removed without Staff."
name="set",
description="Set your birthday. Cant be removed without Staff.",
)
async def set(
self,
Expand All @@ -49,7 +68,9 @@ async def set(
),
):
if month is None or day is None:
return await errorEmb(inter, "You need to provide a month and a day")
return await errorEmb(
inter, "You need to provide a month and a day"
)
if day < 1 or day > 31:
return await errorEmb(inter, "The day must be between 1 and 31")

Expand All @@ -63,7 +84,8 @@ async def set(

@commands.has_permissions(manage_roles=True)
@birthday.sub_command(
name="edit", description="Edit a users birthday. Can only be done by Staff."
name="edit",
description="Edit a users birthday. Can only be done by Staff.",
)
async def edit(
self,
Expand All @@ -82,13 +104,18 @@ async def edit(
):
try:
await self.birthday.update_user(user.id, f"{day}/{month}")
return await sucEmb(inter, f"Birthday has been updated to {day}/{month}")
return await sucEmb(
inter, f"Birthday has been updated to {day}/{month}"
)
except UserNotFound:
return await errorEmb(inter, "The User doesn't have a birthday set")
return await errorEmb(
inter, "The User doesn't have a birthday set"
)

@commands.has_permissions(manage_roles=True)
@birthday.sub_command(
name="remove", description="Remove a birthday. Can only be done by Staff."
name="remove",
description="Remove a birthday. Can only be done by Staff.",
)
async def remove(
self,
Expand All @@ -100,13 +127,17 @@ async def remove(
try:
await self.birthday.delete_user(user.id)
except UserNotFound:
return await errorEmb(inter, "This user doesn't have a birthday set")
return await errorEmb(
inter, "This user doesn't have a birthday set"
)

await sucEmb(inter, "The birthday has been removed")

@birthday.sub_command(name="get", description="Get the birthday of a user")
async def get(
self, inter, user: disnake.User = commands.Param(name="user", default=None)
self,
inter,
user: disnake.User = commands.Param(name="user", default=None),
):
if user is None:
user = inter.author
Expand All @@ -115,42 +146,74 @@ async def get(

birthday = await self.birthday.get_user(user.id)
if birthday is None:
return await errorEmb(inter, "This user doesn't have a birthday set")
return await errorEmb(
inter, "This user doesn't have a birthday set"
)

next_birthday = datetime.datetime.strptime(
birthday.birthday + f"/{dt.datetime.now().year}", "%d/%m/%Y"
)
if next_birthday < datetime.datetime.now():
next_birthday = datetime.datetime.strptime(
birthday.birthday + f"/{dt.datetime.now().year + 1}", "%d/%m/%Y"
days, discord_date = await get_days_until_birthday(birthday)
await QuickEmb(
inter,
f"{user.mention}'s birthday is in {days} Days." f"{discord_date}",
).send()

@birthday.sub_command(name="next", description="Get the next birthday")
async def next(self, inter: disnake.ApplicationCommandInteraction):
upcoming_birthdays = []
# loop gets next birthday
for user in await self.birthday.get_users():
# gets days until birthday and the discord date
days, discord_date = await get_days_until_birthday(user)
# checks if user is in the guild
upcoming_birthdays.append(
{"days": days, "user": user, "discord_date": discord_date}
)

# sorts birthdays by days
upcoming_birthdays.sort(key=lambda x: x["days"])
# gets the next birthday's user
next_birthday = upcoming_birthdays[0]["user"]
# checks if user is in the guild
while await inter.guild.fetch_member(next_birthday.user_id) is None:
upcoming_birthdays.pop(0)
next_birthday = upcoming_birthdays[0]["user"]

member = await self.bot.fetch_user(next_birthday.user_id)

if next_birthday is None:
return await errorEmb(inter, "There are no birthdays set")

days, discord_date = await get_days_until_birthday(next_birthday)
await QuickEmb(
inter,
f"{user.mention}'s birthday is in {(next_birthday - datetime.datetime.now()).days} Days."
f" <t:{str(next_birthday.timestamp()).split('.')[0]}:D>",
f"{member.mention}'s birthday is in {days} Days."
f"{discord_date}",
).send()

# @tasks.loop(time=[dt.time(dt.datetime.utcnow().hour, dt.datetime.utcnow().minute, dt.datetime.utcnow().second + 10)])
# ^ use this when testing birthdays
@tasks.loop(time=[dt.time(8, 0, 0)])
# loops every day at 8:00 UTC time
async def birthday_check(self):
channel = self.bot.get_channel(self.bot.config.channels.birthdays)
guild = self.bot.get_guild(self.bot.config.guilds.main_guild)
channel = await self.bot.fetch_channel(
self.bot.config.channels.birthdays
)
guild = await self.bot.fetch_guild(self.bot.config.guilds.main_guild)
if channel is None:
return
today = dt.datetime.utcnow().strftime("%d/%m")
# Gets all users from the db
users = await self.birthday.get_users()
for user in users:
member = await guild.fetch_member(user.user_id)
member = await guild.getch_member(user.user_id)
# if the member is None, the user is not in the server anymore
if member is None:
continue

# if the birthday is today, congratulate the user
if user.birthday == today:
await member.add_roles(guild.get_role(self.bot.config.roles.birthday))
await member.add_roles(
guild.get_role(self.bot.config.roles.birthday)
)
congrats_msg = await channel.send(
f"{random.choice(congrats_messages)} {member.mention}! 🎂"
)
Expand Down
Loading

0 comments on commit 5ee891c

Please sign in to comment.