Skip to content

Commit 2b8049d

Browse files
Merge pull request #49 from LewisProjects/development
1.8.5
2 parents 1fcfdb0 + 1f6dff3 commit 2b8049d

21 files changed

+442
-175
lines changed

cogs/AI.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import base64
2+
from io import BytesIO
3+
import time
4+
import disnake
5+
from disnake.ext import commands
6+
from utils.bot import OGIROID
7+
8+
9+
class AI(commands.Cog):
10+
def __init__(self, bot: OGIROID):
11+
self.bot = bot
12+
13+
@commands.slash_command(description="Generates ai art")
14+
async def ai_art(self, inter: disnake.ApplicationCommandInteraction, text):
15+
ETA = int(time.time() + 60)
16+
await inter.send(f"Go grab a coffee this may take a while... ETA: <t:{ETA}:R>")
17+
response = await self.bot.session.post("https://backend.craiyon.com/generate", json={"prompt": text})
18+
r = await response.json()
19+
images = r["images"]
20+
for i in images:
21+
image = BytesIO(base64.decodebytes(i.encode("utf-8")))
22+
await inter.delete_original_response()
23+
return await inter.send("Have fun...", file=disnake.File(image, "image.png"), ephemeral=True)
24+
25+
26+
def setup(bot):
27+
bot.add_cog(AI(bot))

cogs/Error_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def on_slash_command_error(self, inter: ApplicationCommandInteraction, err
8686
e_embed = disnake.Embed(
8787
title="Error Traceback",
8888
description=f"See below!\n\n{e_traceback}",
89-
timestamp=datetime.utcnow(),
89+
timestamp=datetime.now(),
9090
)
9191

9292
await error_channel.send(embed=e_embed)
@@ -109,7 +109,7 @@ async def send_traceback(self, inter, error):
109109
error_embed = disnake.Embed(
110110
title="Error Traceback",
111111
description=f"See below!\n\n{bot_errors}",
112-
timestamp=datetime.utcnow(),
112+
timestamp=datetime.now(),
113113
)
114114
await error_channel.send(embed=error_embed)
115115
traceback_nice = "".join(traceback.format_exception(type(error), error, error.__traceback__, 4)).replace("```", "```")
@@ -128,7 +128,7 @@ async def create_error_message(inter, error) -> Embed:
128128
title=f"❌An error occurred while executing: ``/{inter.application_command.qualified_name}``",
129129
description=f"{error}",
130130
colour=disnake.Color.blurple(),
131-
timestamp=datetime.utcnow(),
131+
timestamp=datetime.now(),
132132
)
133133
embed.add_field(
134134
name="Something not right?",

cogs/Fun.py

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import io
32
import os
43
import random
54
import time
@@ -114,10 +113,12 @@ async def poll(
114113

115114
embed = disnake.Embed(title=question, description=choices_str, colour=0xFFFFFF)
116115

117-
embed.set_footer(text=f'{f"Poll by {inter.author}" if inter.author else ""}{datetime.utcnow().strftime("%m/%d/%Y")}')
116+
if inter.author:
117+
embed.set_footer(text=f"Poll by {inter.author}")
118+
embed.timestamp = datetime.now()
118119

119120
await inter.response.send_message(embed=embed)
120-
poll = await inter.original_message() # Gets the message wich got sent
121+
poll = await inter.original_message() # Gets the message which got sent
121122
for emoji in emojis:
122123
await poll.add_reaction(emoji)
123124

@@ -131,7 +132,7 @@ async def youtube(self, inter):
131132
title="YouTube",
132133
description=f"Click __[here]({link})__ to start the YouTube together session.",
133134
color=0xFF0000,
134-
timestamp=datetime.utcnow(),
135+
timestamp=datetime.now(),
135136
)
136137
embed.set_footer(
137138
text=f"Command issued by: {inter.author.name}",
@@ -156,72 +157,6 @@ async def joke(self, inter: ApplicationCommandInteraction):
156157
)
157158
await inter.send(embed=embed)
158159

159-
@commands.slash_command(
160-
name="trigger",
161-
brief="Trigger",
162-
description="For when you're feeling triggered.",
163-
)
164-
@commands.cooldown(1, 10, commands.BucketType.user)
165-
async def triggered(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
166-
"""Time to get triggered."""
167-
if not member:
168-
member = inter.author
169-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/triggered?avatar={member.display_avatar.url}")
170-
imageData = io.BytesIO(await trigImg.read())
171-
await inter.send(file=disnake.File(imageData, "triggered.gif"))
172-
173-
@commands.slash_command(
174-
name="sus",
175-
brief="Sus-Inator4200",
176-
description="Check if your friend is kinda ***SUS***",
177-
)
178-
@commands.cooldown(1, 10, commands.BucketType.user)
179-
async def amongus(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
180-
"""Check if your friends are sus or not"""
181-
await inter.send("Testing for sus-ness...")
182-
if not member:
183-
member = inter.author
184-
impostor = random.choice(["true", "false"])
185-
apikey = os.getenv("SRA_API_KEY")
186-
uri = f"https://some-random-api.ml/premium/amongus?username={member.name}&avatar={member.display_avatar.url}&impostor={impostor}&key={apikey}"
187-
resp = await self.bot.session.get(uri)
188-
if 300 > resp.status >= 200:
189-
fp = io.BytesIO(await resp.read())
190-
await inter.send(file=disnake.File(fp, "amogus.gif"))
191-
else:
192-
await inter.send("Couldnt get image :(")
193-
194-
@commands.slash_command(name="invert", brief="invert", description="Invert the colours of your icon")
195-
@commands.cooldown(1, 5, commands.BucketType.user)
196-
async def invert(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
197-
"""Invert your profile picture."""
198-
if not member:
199-
member = inter.author
200-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/invert/?avatar={member.display_avatar.url}")
201-
imageData = io.BytesIO(await trigImg.read())
202-
await inter.send(file=disnake.File(imageData, "invert.png"))
203-
204-
@commands.slash_command(name="pixelate", brief="pixelate", description="Turn yourself into 144p!")
205-
@commands.cooldown(1, 5, commands.BucketType.user)
206-
async def pixelate(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
207-
"""Turn yourself into pixels"""
208-
if not member:
209-
member = inter.author
210-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/pixelate/?avatar={member.display_avatar.url}")
211-
imageData = io.BytesIO(await trigImg.read())
212-
await inter.send(file=disnake.File(imageData, "pixelate.png"))
213-
214-
@commands.slash_command(name="jail", brief="jail", description="Go to jail!")
215-
@commands.cooldown(1, 5, commands.BucketType.user)
216-
async def jail(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
217-
"""Go to horny jail"""
218-
if not member:
219-
member = inter.author
220-
221-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/jail?avatar={member.display_avatar.url}")
222-
imageData = io.BytesIO(await trigImg.read())
223-
await inter.send(file=disnake.File(imageData, "jail.png"))
224-
225160
@commands.slash_command(
226161
name="beer", description="Give someone a beer! 🍻"
227162
) # Credit: AlexFlipNote - https://github.com/AlexFlipnote
@@ -466,15 +401,6 @@ async def info(
466401
return await errorEmb(inter, f"{key}")
467402
return await inter.send(embed=embed)
468403

469-
@commands.slash_command(name="urltoqr", description="Converts a URL to a QR code.")
470-
async def urltoqr(self, inter: ApplicationCommandInteraction, url: str, size: int):
471-
url = url.replace("http://", "").replace("https://", "")
472-
qr = f"https://api.qrserver.com/v1/create-qr-code/?size={size}x{size}&data={url}"
473-
embed = disnake.Embed(title=f"URL created for: {url}", color=0xFFFFFF)
474-
embed.set_image(url=qr)
475-
embed.set_footer(text=f"Requested by: {inter.author.name}")
476-
return await inter.send(embed=embed)
477-
478404
@commands.slash_command(name="urlshortner", description="Shortens a URL.")
479405
async def urlshortner(self, inter: ApplicationCommandInteraction, url: str):
480406
# checking if url starts with http:// or https://, if it does not, adding https:// towards the start

cogs/Github.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def __init__(self, bot: OGIROID):
1212

1313
# Command to get information about a GitHub user
1414
@commands.slash_command(name="ghperson", description="Gets the Profile of the github person.")
15-
async def ghperson(self, ctx, ghuser: str):
15+
async def ghperson(self, inter, ghuser: str):
1616
person_raw = await self.bot.session.get(f"https://api.github.com/users/{ghuser}")
1717
if person_raw.status != 200:
18-
return await ctx.send("User not found!")
18+
return await inter.send("User not found!")
1919
else:
2020
person = await person_raw.json()
2121
# Returning an Embed containing all the information:
@@ -25,23 +25,24 @@ async def ghperson(self, ctx, ghuser: str):
2525
color=0xFFFFFF,
2626
)
2727
embed.set_thumbnail(url=f"{person['avatar_url']}")
28-
embed.add_field(name="Username 📛: ", value=f"__[{person['name']}]({person['html_url']})__", inline=True)
28+
embed.add_field(name="Username 📛: ", value=f"{person['name']}", inline=True)
2929
# embed.add_field(name="Email ✉: ", value=f"{person['email']}", inline=True) Commented due to GitHub not responding with the correct email
3030
embed.add_field(name="Repos 📁: ", value=f"{person['public_repos']}", inline=True)
3131
embed.add_field(name="Location 📍: ", value=f"{person['location']}", inline=True)
3232
embed.add_field(name="Company 🏢: ", value=f"{person['company']}", inline=True)
3333
embed.add_field(name="Followers 👥: ", value=f"{person['followers']}", inline=True)
34-
embed.add_field(name="Following 👥: ", value=f"{person['following']}", inline=True)
35-
await ctx.send(embed=embed)
34+
embed.add_field(name="Website 🖥️: ", value=f"{person['blog']}", inline=True)
35+
button = disnake.ui.Button(label="Link", style=disnake.ButtonStyle.url, url=person["html_url"])
36+
await inter.send(embed=embed, components=button)
3637

3738
# Command to get search for GitHub repositories:
3839
@commands.slash_command(name="ghsearchrepo", description="Searches for the specified repo.")
39-
async def ghsearchrepo(self, ctx, query: str):
40+
async def ghsearchrepo(self, inter, query: str):
4041
pages = 1
4142
url = f"https://api.github.com/search/repositories?q={query}&{pages}"
4243
repos_raw = await self.bot.session.get(url)
4344
if repos_raw.status != 200:
44-
return await ctx.send("Repo not found!")
45+
return await inter.send("Repo not found!")
4546
else:
4647
repos = await repos_raw.json() # Getting first repository from the query
4748
repo = repos["items"][0]
@@ -60,6 +61,7 @@ async def ghsearchrepo(self, ctx, query: str):
6061
embed.add_field(name="Stars ⭐:", value=f"{repo['stargazers_count']}", inline=True)
6162
embed.add_field(name="Forks 🍴:", value=f"{repo['forks_count']}", inline=True)
6263
embed.add_field(name="Language 💻:", value=f"{repo['language']}", inline=True)
64+
embed.add_field(name="Size 🗃️:", value=f"{round(repo['size'] / 1000, 2)} MB", inline=True)
6365
if repo["license"]:
6466
spdx_id = repo["license"]["spdx_id"]
6567
embed.add_field(
@@ -69,8 +71,8 @@ async def ghsearchrepo(self, ctx, query: str):
6971
)
7072
else:
7173
embed.add_field(name="License name 📃:", value=f"This Repo doesn't have a license", inline=True)
72-
embed.add_field(name="URL 🔍:", value=f"[Click here!]({repo['html_url']})", inline=True)
73-
await ctx.send(embed=embed)
74+
button = disnake.ui.Button(label="Link", style=disnake.ButtonStyle.url, url=repo["html_url"])
75+
await inter.send(embed=embed, components=button)
7476

7577

7678
def setup(bot):

cogs/Image.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import io
2+
import os
3+
import random
4+
import disnake
5+
6+
from disnake import ApplicationCommandInteraction
7+
from disnake.ext import commands
8+
from utils.bot import OGIROID
9+
10+
from PIL import Image, ImageDraw, ImageFont
11+
from io import BytesIO
12+
import textwrap
13+
14+
15+
class ImageCommands(commands.Cog, name="Image"):
16+
"""Image Commands!"""
17+
18+
def __init__(self, bot: OGIROID):
19+
self.bot = bot
20+
21+
@commands.slash_command(
22+
name="trigger",
23+
brief="Trigger",
24+
description="For when you're feeling triggered.",
25+
)
26+
@commands.cooldown(1, 10, commands.BucketType.user)
27+
async def triggered(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
28+
"""Time to get triggered."""
29+
if not member:
30+
member = inter.author
31+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/triggered?avatar={member.display_avatar.url}")
32+
imageData = io.BytesIO(await trigImg.read())
33+
await inter.send(file=disnake.File(imageData, "triggered.gif"))
34+
35+
@commands.slash_command(
36+
name="sus",
37+
brief="Sus-Inator4200",
38+
description="Check if your friend is kinda ***SUS***",
39+
)
40+
@commands.cooldown(1, 10, commands.BucketType.user)
41+
async def amongus(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
42+
"""Check if your friends are sus or not"""
43+
await inter.send("Testing for sus-ness...")
44+
if not member:
45+
member = inter.author
46+
impostor = random.choice(["true", "false"])
47+
apikey = os.getenv("SRA_API_KEY")
48+
uri = f"https://some-random-api.ml/premium/amongus?username={member.name}&avatar={member.display_avatar.url}&impostor={impostor}&key={apikey}"
49+
resp = await self.bot.session.get(uri)
50+
if 300 > resp.status >= 200:
51+
fp = io.BytesIO(await resp.read())
52+
await inter.send(file=disnake.File(fp, "amogus.gif"))
53+
else:
54+
await inter.send("Couldnt get image :(")
55+
56+
@commands.slash_command(name="invert", brief="invert", description="Invert the colours of your icon")
57+
@commands.cooldown(1, 5, commands.BucketType.user)
58+
async def invert(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
59+
"""Invert your profile picture."""
60+
if not member:
61+
member = inter.author
62+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/invert/?avatar={member.display_avatar.url}")
63+
imageData = io.BytesIO(await trigImg.read())
64+
await inter.send(file=disnake.File(imageData, "invert.png"))
65+
66+
@commands.slash_command(name="pixelate", brief="pixelate", description="Turn yourself into 144p!")
67+
@commands.cooldown(1, 5, commands.BucketType.user)
68+
async def pixelate(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
69+
"""Turn yourself into pixels"""
70+
if not member:
71+
member = inter.author
72+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/pixelate/?avatar={member.display_avatar.url}")
73+
imageData = io.BytesIO(await trigImg.read())
74+
await inter.send(file=disnake.File(imageData, "pixelate.png"))
75+
76+
@commands.slash_command(name="jail", brief="jail", description="Go to jail!")
77+
@commands.cooldown(1, 5, commands.BucketType.user)
78+
async def jail(self, inter: ApplicationCommandInteraction, member: disnake.Member = None):
79+
"""Go to horny jail"""
80+
if not member:
81+
member = inter.author
82+
83+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/jail?avatar={member.display_avatar.url}")
84+
imageData = io.BytesIO(await trigImg.read())
85+
await inter.send(file=disnake.File(imageData, "jail.png"))
86+
87+
@commands.slash_command(name="urltoqr", description="Converts a URL to a QR code.")
88+
async def urltoqr(self, inter: ApplicationCommandInteraction, url: str, size: int):
89+
url = url.replace("http://", "").replace("https://", "")
90+
qr = f"https://api.qrserver.com/v1/create-qr-code/?size={size}x{size}&data={url}"
91+
embed = disnake.Embed(title=f"URL created for: {url}", color=0xFFFFFF)
92+
embed.set_image(url=qr)
93+
embed.set_footer(text=f"Requested by: {inter.author.name}")
94+
return await inter.send(embed=embed)
95+
96+
@staticmethod
97+
def draw_multiple_line_text(image, text, font, text_color, text_start_height):
98+
draw = ImageDraw.Draw(image)
99+
image_width, image_height = image.size
100+
y_text = text_start_height
101+
lines = textwrap.wrap(text, width=45)
102+
for line in lines:
103+
nothing1, nothing2, line_width, line_height = font.getbbox(line)
104+
# draw shadow on text
105+
draw.text(((image_width - line_width) / 2 + 2, y_text + 2), line, font=font, fill=(0, 0, 0))
106+
draw.text(((image_width - line_width) / 2, y_text), line, font=font, fill=text_color)
107+
y_text += line_height
108+
# Return the bottom pixel of the text
109+
return y_text
110+
111+
# Command to get information about a Quote user
112+
@commands.slash_command(name="quote", description="Generates an image with a quote and random background")
113+
async def quote(self, inter):
114+
"""Generates an image with a quote and random background"""
115+
await inter.response.defer()
116+
# Use api.quotable.io/random to get a random quote
117+
main = await self.bot.session.get("https://api.quotable.io/random")
118+
data = await main.json()
119+
quote = data["content"]
120+
author = data["author"]
121+
122+
# Use unsplash.com to get a random image
123+
resolution = "1080x1080"
124+
response = await self.bot.session.get(f"https://source.unsplash.com/random/{resolution}")
125+
image_bytes = io.BytesIO(await response.read())
126+
image = Image.open(image_bytes)
127+
128+
draw = ImageDraw.Draw(image)
129+
font = ImageFont.truetype("utils/data/Roboto-Italic.ttf", 50)
130+
font2 = ImageFont.truetype("utils/data/Roboto-Bold.ttf", 50)
131+
if len(quote) > 350:
132+
text_start_height = (image.height - font.getbbox(quote)[3]) / 2 - 500
133+
elif len(quote) > 250:
134+
text_start_height = (image.height - font.getbbox(quote)[3]) / 2 - 200
135+
elif len(quote) > 150:
136+
text_start_height = (image.height - font.getbbox(quote)[3]) / 2 - 50
137+
else:
138+
text_start_height = (image.height - font.getbbox(quote)[3]) / 2
139+
end = self.draw_multiple_line_text(image, quote, font, text_color=(255, 255, 255), text_start_height=text_start_height)
140+
# Draw the author shadow
141+
draw.text(((image.width - font2.getbbox(author)[2]) / 2 + 2, end + 50), author, font=font2, fill=(0, 0, 0))
142+
# Draw the author
143+
draw.text(((image.width - font2.getbbox(author)[2]) / 2, end + 50), author, font=font2, fill=(255, 255, 255))
144+
with BytesIO() as image_binary:
145+
image.save(image_binary, "PNG")
146+
image_binary.seek(0)
147+
await inter.send(file=disnake.File(fp=image_binary, filename="image.png"))
148+
149+
150+
def setup(bot):
151+
bot.add_cog(ImageCommands(bot))

0 commit comments

Comments
 (0)