Skip to content

Commit 46a8f5e

Browse files
Merge pull request #37 from LewisProjects/development
1.7.1 patch
2 parents 7937a3b + 1e14d41 commit 46a8f5e

37 files changed

+3331
-286
lines changed

cogs/ErrorHandler.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, bot: OGIROID):
1818
self.debug_mode = self.bot.config.debug
1919
self.waitTime = 25
2020

21-
def TimeSinceStart(self) -> int:
21+
def TimeSinceStart(self) -> float:
2222
return round((datetime.now() - self.bot.uptime).total_seconds(), ndigits=1)
2323

2424
# noinspection PyUnboundLocalVariable
@@ -29,16 +29,22 @@ async def on_slash_command_error(self, inter: ApplicationCommandInteraction, err
2929
return
3030
elif error.__class__.__name__ in IGNORE_EXCEPTIONS:
3131
return
32-
if self.TimeSinceStart() < self.waitTime: # Databases and internal caches might not be fully loaded yet
32+
33+
# Databases and internal caches might not be fully loaded yet.
34+
# In debug mode we don't want to wait for them cause its fucking annoying.
35+
if self.TimeSinceStart() < self.waitTime and not self.debug_mode:
3336
return await errorEmb(
34-
inter, f"The bot just started, please wait {round(self.waitTime - self.TimeSinceStart(), ndigits=2)}s."
37+
inter,
38+
f"The bot just started, please wait {round(self.waitTime - self.TimeSinceStart(), ndigits=2)}s.",
3539
)
40+
3641
# non real error handling
3742
if isinstance(error, CommandNotFound):
3843
return await errorEmb(inter, "Command not found! use /help for a list of commands")
3944
elif isinstance(error, NotOwner):
4045
await errorEmb(
41-
inter, f"You must be the owner of {inter.me.display_name} to use `{inter.application_command.name}`"
46+
inter,
47+
f"You must be the owner of {inter.me.display_name} to use `{inter.application_command.name}`",
4248
)
4349
elif isinstance(error, HTTPException):
4450
await errorEmb(inter, error.text)

cogs/animals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def cat(self, inter):
2626
color=0xFFFFFF,
2727
)
2828
embed.set_image(url=data["image"])
29-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
29+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
3030
await inter.response.send_message(f"**Fun Fact: **" + data["fact"], embed=embed)
3131

3232
@animal.sub_command(name="dog", description="Get a random dog picture")
@@ -40,7 +40,7 @@ async def dog(self, inter):
4040
color=0xFFFFFF,
4141
)
4242
embed.set_image(url=data["image"])
43-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
43+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
4444
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
4545

4646
@animal.sub_command(name="bird", description="Get a random bird picture")
@@ -54,7 +54,7 @@ async def bird(self, inter):
5454
color=0xFFFFFF,
5555
)
5656
embed.set_image(url=data["image"])
57-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
57+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
5858
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
5959

6060
@animal.sub_command(name="fox", description="Get a random fox picture")
@@ -68,7 +68,7 @@ async def fox(self, inter):
6868
color=0xFFFFFF,
6969
)
7070
embed.set_image(url=data["image"])
71-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
71+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
7272
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
7373

7474
@animal.sub_command(name="panda", description="Get a random panda picture")
@@ -82,7 +82,7 @@ async def panda(self, inter):
8282
color=0xFFFFFF,
8383
)
8484
embed.set_image(url=data["image"])
85-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
85+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
8686
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
8787

8888
@animal.sub_command(name="koala", description="Get a random cat picture")
@@ -96,7 +96,7 @@ async def koala(self, inter):
9696
color=0xFFFFFF,
9797
)
9898
embed.set_image(url=data["image"])
99-
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.avatar)
99+
embed.set_footer(text=f"Command issued by: {inter.author.name}", icon_url=inter.author.display_avatar)
100100
await inter.response.send_message("**Fun Fact: **" + data["fact"], embed=embed)
101101

102102

cogs/blacklist.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ async def reason(self, inter, user: Member, reason: str):
9696
return await errorEmb(inter, f"{user.mention} is not in the blacklist")
9797
await self.blacklist.edit_reason(user.id, reason)
9898
await sucEmb(
99-
inter, f"Edited {user.mention}'s reason in the blacklist to see the full reason use /blacklist info {user.mention}"
99+
inter,
100+
f"Edited {user.mention}'s reason in the blacklist to see the full reason use /blacklist info {user.mention}",
100101
)
101102

102103
@commands.has_permissions(manage_messages=True)
@@ -130,9 +131,17 @@ async def remove(self, inter, user: Member):
130131
required=True,
131132
),
132133
Option(
133-
"tickets", description="Whether to blacklist the user from using tickets", type=OptionType.boolean, required=True
134+
"tickets",
135+
description="Whether to blacklist the user from using tickets",
136+
type=OptionType.boolean,
137+
required=True,
138+
),
139+
Option(
140+
"tags",
141+
description="Whether to blacklist the user from using tags",
142+
type=OptionType.boolean,
143+
required=True,
134144
),
135-
Option("tags", description="Whether to blacklist the user from using tags", type=OptionType.boolean, required=True),
136145
Option(
137146
"expires",
138147
description="When the blacklist should expire (e.g. 1w, 5m, never)",
@@ -193,7 +202,8 @@ async def blacklist_list(self, inter):
193202
emb = Embed(color=self.bot.config.colors.invis, description="")
194203
for user in blacklist_list:
195204
emb.add_field(
196-
name=f"**{self.get_user(user.id).name}**", value=f"Expires: {user.get_expiry}\nReason: {user.reason}\n"
205+
name=f"**{self.get_user(user.id).name}**",
206+
value=f"Expires: {user.get_expiry}\nReason: {user.reason}\n",
197207
)
198208

199209
blacklist_embs.append(emb)

cogs/botcmds.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def ping(self, inter):
7171
)
7272
embed.set_footer(
7373
text=f"Command issued by: {inter.author.name}",
74-
icon_url=inter.author.avatar,
74+
icon_url=inter.author.display_avatar,
7575
)
7676
await inter.response.send_message(embed=embed)
7777

@@ -246,8 +246,7 @@ async def whois(self, inter, *, user: disnake.Member = None):
246246

247247
e.colour = 0xFFFFFF
248248

249-
if user.avatar:
250-
e.set_thumbnail(url=user.avatar.url)
249+
e.set_thumbnail(url=user.display_avatar.url)
251250

252251
if isinstance(user, disnake.User):
253252
e.set_footer(text="This member is not in this server.")
@@ -267,8 +266,8 @@ async def avatar(self, inter: disnake.ApplicationCommandInteraction, user: disna
267266
user = inter.author
268267

269268
embed = disnake.Embed(title=f"{user}'s avatar")
270-
embed.set_image(url=user.avatar.url)
271-
embed.set_author(name=f"{user}", icon_url=user.avatar.url)
269+
embed.set_image(url=user.display_avatar.url)
270+
embed.set_author(name=f"{user}", icon_url=user.display_avatar.url)
272271
await inter.send(embed=embed)
273272

274273

cogs/fun_cmds.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import random
55
import time
66
from datetime import datetime, timezone
7+
from urllib import request
78

89
import akinator as ak
910
import disnake
@@ -12,6 +13,7 @@
1213
from disnake.ext import commands
1314
from disnake.utils import utcnow
1415
from dotenv import load_dotenv
16+
import requests
1517

1618
from utils.CONSTANTS import morse
1719
from utils.assorted import renderBar
@@ -134,7 +136,7 @@ async def youtube(self, inter):
134136
)
135137
embed.set_footer(
136138
text=f"Command issued by: {inter.author.name}",
137-
icon_url=inter.author.avatar,
139+
icon_url=inter.author.display_avatar,
138140
)
139141
await inter.send(embed=embed)
140142
else:
@@ -151,7 +153,7 @@ async def joke(self, inter):
151153
embed = disnake.Embed(title="Joke!", description=data["joke"], color=0xFFFFFF)
152154
embed.set_footer(
153155
text=f"Command issued by: {inter.author.name}",
154-
icon_url=inter.message.author.avatar,
156+
icon_url=inter.message.author.display_avatar,
155157
)
156158
await inter.send(embed=embed)
157159

@@ -165,7 +167,7 @@ async def triggered(self, inter, member: disnake.Member = None):
165167
"""Time to get triggered."""
166168
if not member:
167169
member = inter.author
168-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/triggered?avatar={member.avatar.url}")
170+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/triggered?avatar={member.display_avatar.url}")
169171
imageData = io.BytesIO(await trigImg.read())
170172
await inter.send(file=disnake.File(imageData, "triggered.gif"))
171173

@@ -182,7 +184,7 @@ async def amongus(self, inter, member: disnake.Member = None):
182184
member = inter.author
183185
impostor = random.choice(["true", "false"])
184186
apikey = os.getenv("SRA_API_KEY")
185-
uri = f"https://some-random-api.ml/premium/amongus?username={member.name}&avatar={member.avatar.url}&impostor={impostor}&key={apikey}"
187+
uri = f"https://some-random-api.ml/premium/amongus?username={member.name}&avatar={member.display_avatar.url}&impostor={impostor}&key={apikey}"
186188
resp = await self.bot.session.get(uri)
187189
if 300 > resp.status >= 200:
188190
fp = io.BytesIO(await resp.read())
@@ -196,7 +198,7 @@ async def invert(self, inter, member: disnake.Member = None):
196198
"""Invert your profile picture."""
197199
if not member:
198200
member = inter.author
199-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/invert/?avatar={member.avatar.url}")
201+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/invert/?avatar={member.display_avatar.url}")
200202
imageData = io.BytesIO(await trigImg.read())
201203
await inter.send(file=disnake.File(imageData, "invert.png"))
202204

@@ -206,7 +208,7 @@ async def pixelate(self, inter, member: disnake.Member = None):
206208
"""Turn yourself into pixels"""
207209
if not member:
208210
member = inter.author
209-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/pixelate/?avatar={member.avatar.url}")
211+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/pixelate/?avatar={member.display_avatar.url}")
210212
imageData = io.BytesIO(await trigImg.read())
211213
await inter.send(file=disnake.File(imageData, "pixelate.png"))
212214

@@ -217,7 +219,7 @@ async def jail(self, inter, member: disnake.Member = None):
217219
if not member:
218220
member = inter.author
219221

220-
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/jail?avatar={member.avatar.url}")
222+
trigImg = await self.bot.session.get(f"https://some-random-api.ml/canvas/jail?avatar={member.display_avatar.url}")
221223
imageData = io.BytesIO(await trigImg.read())
222224
await inter.send(file=disnake.File(imageData, "jail.png"))
223225

@@ -461,6 +463,32 @@ async def info(self, inter, pokem: str = commands.ParamInfo(name="pokemon", desc
461463
return await errorEmb(inter, f"{key}")
462464
return await inter.send(embed=embed)
463465

466+
@commands.slash_command(name="urltoqr", description="Converts a URL to a QR code.")
467+
async def urltoqr(self, inter, url: str, size: int):
468+
url = url.replace("http://", "").replace("https://", "")
469+
qr = f"https://api.qrserver.com/v1/create-qr-code/?size={size}x{size}&data={url}"
470+
embed = disnake.Embed(title=f"URL created for: {url}", color=0xFFFFFF)
471+
embed.set_image(url=qr)
472+
embed.set_footer(text=f"Requested by: {inter.author.name}")
473+
return await inter.send(embed=embed)
474+
475+
@commands.slash_command(name="urlshortner", description="Shortens a URL.")
476+
async def urlshortner(self, inter, url: str):
477+
# checking if url starts with http:// or https://, if it does not, adding https:// towards the start
478+
if not url.startswith("http://") and not url.startswith("https://"):
479+
url = f"https://{url}"
480+
response = requests.post(f"https://u.jasoncodes.ca/add/{url}")
481+
if response.status_code == 200:
482+
embed = disnake.Embed(
483+
title=f"URL created for: {url.replace('http://', '').replace('https://', '')}",
484+
color=0xFFFFFF,
485+
description=f"Your shortend URL is: {response.json()['short_url']}, or click [here]({response.json()['short_url']}) to visit it.",
486+
)
487+
embed.set_footer(text=f"Requested by: {inter.author.name}")
488+
return await inter.send(embed=embed)
489+
else:
490+
return await errorEmb(inter, "An unexpected error occurred! Please try again later.")
491+
464492

465493
def setup(bot):
466494
bot.add_cog(Fun(bot))

cogs/help.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from disnake.ext import commands
33

44
from utils.bot import OGIROID
5+
from utils.pagination import CreatePaginator
56

67

78
class HelpCommand(commands.Cog, name="Help"):
@@ -14,38 +15,34 @@ def __init__(self, bot: OGIROID):
1415
@commands.slash_command(name="help", description="Lists all commands")
1516
async def help(self, inter):
1617
"""Lists all commands"""
17-
embed = disnake.Embed(title="Bot Commands", colour=self.COLOUR)
18-
embed.set_author(
19-
name="Ogiroid's help menu!",
20-
url="https://freebie.codes",
21-
icon_url="https://cdn.discordapp.com/avatars/984802008403959879/7016c34bd6bce62f9b0f2534f8918c49.png?size=1024",
22-
)
18+
embeds = []
2319

2420
cogs = self.bot.cogs.items()
2521
for cog_name, cog in cogs:
22+
embed = disnake.Embed(title=cog.qualified_name, colour=self.COLOUR)
2623
if cog is None:
2724
continue
2825
cmds = cog.get_slash_commands()
2926
name = cog.qualified_name
3027

31-
value = " ".join(f"`/{cmd.name}`" for cmd in cmds)
28+
value = ""
29+
for cmd in cmds:
30+
value += f"`/{cmd.qualified_name}` - {cmd.description}\n"
31+
if cmd.children:
32+
for children, sub_command in cmd.children.items():
33+
try:
34+
value += f"`/{sub_command.qualified_name}` - {sub_command.description}\n"
35+
except AttributeError:
36+
pass
3237

3338
if value == "":
3439
continue
3540

36-
if name == "Tickets":
37-
continue
38-
39-
if cog and cog.description:
40-
value = "{0}\n{1}".format(cog.description, value)
41-
42-
embed.add_field(name=name, value=value)
41+
embed.description = f"{cog.description}\n\n{value}"
42+
embeds.append(embed)
4343

44-
embed.set_footer(
45-
text="If you want more information on a particular command start typing out the command "
46-
"and a description will show up"
47-
)
48-
await inter.send(embed=embed)
44+
paginator = CreatePaginator(embeds, inter.author.id, timeout=300.0)
45+
await inter.send(embed=embeds[0], view=paginator)
4946

5047

5148
def setup(bot: commands.Bot):

cogs/level.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)