Skip to content

Commit cb0047f

Browse files
Merge pull request #35 from LewisProjects/development
New release
2 parents c2b27c6 + 1219f17 commit cb0047f

32 files changed

+2181
-947
lines changed

CONTRIBUTING.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Contributing to Ogiroid 🤝!
2+
🎊👏 Firstly, thank you so much for taking out time to contribute to Ogiroid! 👏🎊
3+
4+
The following is a set of guidelines for contributing to Ogiroid, which is a part of [Lewis Projects](https://github.com/LewisProjects/) on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
5+
6+
### Table of Contents:
7+
1. [Code of Conduct](#code-of-conduct)
8+
2. [What do I require before getting started?](#prerequisites)
9+
3. [What can I do to contribute?](#contribution)
10+
4. [Additional Notes]()
11+
12+
<hr>
13+
14+
## [Code of Conduct](#code-of-conduct)
15+
> This project and everyone participating in it is governed by the Ogiroid code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to the developers.
16+
17+
## [What do I require before getting started?](#prerequisites)
18+
We expect you to be experienced with [Python](https://www.python.org/) and [Disnake](https://disnake.dev/) (a fork of [Discord.py](https://github.com/Rapptz/discord.py)). Having experience with Discord.py should also get you sailing, disnake and discord.py are almost the same.
19+
20+
## [What can I do to contribute?](#contribution)
21+
**1. Reporting any bugs 🐞:**
22+
23+
Cannot emphasize enough how much bug reporting/bug fixing helps us! It saves us numerous hours of painful code scouting. So you might ask yourself, how do I submit a bug report for Ogiroid? Quite simple honestly! First of all, did you:
24+
+ Come across a bug while using the Discord bot?
25+
+ Come across a bug in the code?
26+
27+
**Case 1: While using the Discord Bot:**
28+
29+
You need to headover to a channel in [Lewis' Menelaws discord server](https://discord.com/5uw4eCQf6Z) and then type: ``/reportbug``, you will then be greeted by a modal looking something like this:
30+
31+
![MODAL](https://cdn.discordapp.com/attachments/1005117336761675847/1007706426896040077/unknown.png)
32+
33+
Fill this form & click **submit**. Our developer team will then recieve your bug report, we can then look into it 😇! Thank you!
34+
35+
**Case 2: A bug in the code (hmmm... quite rare 😜):**
36+
37+
You can raise an [issue](https://github.com/LewisProjects/Ogiroid/issues) and we will look into it. Please ensure you follow the proper [format we have](#) and be as specific as you can while reporting a bug. Obviously, there can be somee cases where the format might not be as important as in other cases, please use your judgement in such cases.
38+
39+
Alternatively, you can headover to our [Discord Server](https://discord.com/5uw4eCQf6Z) and report the bug using the first method (scroll up if you missed it).
40+
41+
**__📚📚 Bug Reporting Guidelines 📚📚:__**
42+
43+
+ Please refrain from reporting your bug multiple times, this will lead to us blacklisting you (and potentially banning you permanently on the Discord server) 😒.
44+
+ Please check all the [issues](https://github.com/LewisProjects/Ogiroid/issues) before posting your bug, your bug report could really just be a duplicate 👀!
45+
+ Please ensure you be as specific as you can, this saves us a ton of time ⌚.
46+
+ Please use your right judgement 🎓.
47+
48+
With that being said, you have officially reported a bug! Thank you so much 🤩!
49+
50+
<!--Contributing.md: writeup #1-->

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<h1>Ogiroid - a multipurpose discord bot!</h1>
1+
<h1>Ogiroid - the most handsome Discord bot!</h1>
22
<hr>
33
<img src="https://media.discordapp.net/attachments/985729550732394536/1002138392554897479/Ogiroid.png?width=1440&height=583" alt="img">
44
<hr>
55
<h3>Introduction:</h3>
6-
Ogiroid is a multipurpose Discord Bot developed for the YouTuber, <a href="https://www.youtube.com/c/CodingwithLewis">Lewis Menelaws'</a> Discord Server.
6+
Ogiroid is a multipurpose Discord Bot (who is very handsome 😋😋) developed for the YouTuber, <a href="https://www.youtube.com/c/CodingwithLewis">Lewis Menelaws'</a> Discord Server.
77
This bot offers:
88
<ul>
99
<li>Fun Commands, example: /askogiroid, /beer, /sus and more! </li>
@@ -22,6 +22,7 @@ This bot offers:
2222
<hr>
2323
<h3>Bot Development Information:</h3>
2424
<p>Written in: <b>Python</b><br>Made using <a href="https://disnake.dev/">Disnake</a>, a Discord.py fork!</p>
25+
<p>NOTE: you need to use python 3.8+ for this bot</p>
2526
Developers:
2627
<ul>
2728
<li><a href="https://github.com/ImmaHarry">HarryDaDev</a></li>
@@ -30,8 +31,9 @@ Developers:
3031
<li><a href="https://github.com/LevaniVashadze">Levani Vashadze</a></li>
3132
<li><a href="https://github.com/DWAA1660">DWAA1660</a></li>
3233
</ul>
33-
The bot is currently on release: <b>1.6.0</b>
34-
License: MIT
34+
The bot is currently on release: <b>1.6.0</b><br>
35+
License: MIT<br>
36+
Wish to Contribute to this bot? Checkout: <a href="https://github.com/LewisProjects/Ogiroid/blob/development/contributing.md">contribution guidelines</a>
3537
<hr>
3638
<h3>Changelog 07-08-2022:</h3>
3739
<ol>

cogs/ErrorHandler.py

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,67 @@
44
from datetime import datetime
55

66
import disnake
7-
from disnake import Embed
8-
from disnake.ext import commands
7+
from disnake import Embed, ApplicationCommandInteraction, HTTPException
8+
from disnake.ext.commands import *
99

1010
from utils.CONSTANTS import IGNORE_EXCEPTIONS
1111
from utils.bot import OGIROID
12+
from utils.shortcuts import errorEmb, permsEmb
1213

1314

14-
class ErrorHandler(commands.Cog):
15+
class ErrorHandler(Cog):
1516
def __init__(self, bot: OGIROID):
1617
self.bot = bot
1718
self.debug_mode = self.bot.config.debug
19+
self.waitTime = 25
20+
21+
def TimeSinceStart(self) -> int:
22+
return round((datetime.now() - self.bot.uptime).total_seconds(), ndigits=1)
1823

1924
# noinspection PyUnboundLocalVariable
20-
@commands.Cog.listener()
21-
async def on_slash_command_error(self, inter, error):
25+
@Cog.listener()
26+
async def on_slash_command_error(self, inter: ApplicationCommandInteraction, error):
2227
try:
2328
if hasattr(inter.application_command, "on_error"):
2429
return
2530
elif error.__class__.__name__ in IGNORE_EXCEPTIONS:
2631
return
27-
else:
28-
error_channel = self.bot.get_channel(self.bot.config.channels.errors)
29-
30-
embed: Embed = await self.create_error_message(inter, error)
31-
await inter.send(embed=embed, ephemeral=True)
32-
bot_errors = traceback.format_exception(type(error), error, error.__traceback__)
33-
if self.bot.config.debug:
34-
print(bot_errors)
35-
36-
error_embed = disnake.Embed(
37-
title="Error Traceback",
38-
description=f"See below!\n\n{bot_errors}",
39-
timestamp=datetime.utcnow(),
32+
if self.TimeSinceStart() < self.waitTime: # Databases and internal caches might not be fully loaded yet
33+
return await errorEmb(
34+
inter, f"The bot just started, please wait {round(self.waitTime - self.TimeSinceStart(), ndigits=2)}s."
4035
)
41-
await error_channel.send(embed=error_embed)
42-
traceback_nice = "".join(traceback.format_exception(type(error), error, error.__traceback__, 4)).replace(
43-
"```", "```"
36+
# non real error handling
37+
if isinstance(error, CommandNotFound):
38+
return await errorEmb(inter, "Command not found! use /help for a list of commands")
39+
elif isinstance(error, NotOwner):
40+
await errorEmb(
41+
inter, f"You must be the owner of {inter.me.display_name} to use `{inter.application_command.name}`"
4442
)
45-
46-
debug_info = (
47-
f"```\n{inter.author} {inter.author.id}: /{inter.application_command.name}"[:200]
48-
+ "```"
49-
+ f"```py\n{traceback_nice}"[: 2000 - 206]
50-
+ "```"
43+
elif isinstance(error, HTTPException):
44+
await errorEmb(inter, error.text)
45+
return await self.send_traceback(inter, error)
46+
elif isinstance(error, MissingPermissions):
47+
return await permsEmb(inter, permissions=f"{', '.join(error.missing_permissions)}")
48+
elif isinstance(error, MaxConcurrencyReached):
49+
return await errorEmb(
50+
inter, "You've reached max capacity of command usage at once, please finish the previous one..."
5151
)
52-
await error_channel.send(debug_info)
52+
elif isinstance(error, CommandOnCooldown):
53+
return await errorEmb(inter, f"This command is on cooldown... try again in {error.retry_after:.2f} seconds.")
54+
elif isinstance(error, GuildNotFound):
55+
return await errorEmb(error, f"You can only use this command in a server")
56+
elif self.debug_mode:
57+
traceback_nice = "".join(traceback.format_exception(type(error), error, error.__traceback__, 4))
58+
print(traceback_nice)
59+
traceback.print_exc()
60+
return await errorEmb(inter, "check console for error")
61+
else: # actual error not just a check failure
62+
embed = await self.create_error_message(inter, error)
63+
await inter.send(embed=embed, ephemeral=True)
64+
await self.send_traceback(inter, error)
5365

5466
except Exception as e:
67+
error_channel = self.bot.get_channel(self.bot.config.channels.errors)
5568
embed = await self.create_error_message(inter, e)
5669
await inter.send(embed=embed, ephemeral=True)
5770
e_traceback = traceback.format_exception(type(e), e, e.__traceback__)
@@ -76,10 +89,30 @@ async def on_slash_command_error(self, inter, error):
7689
)
7790
await error_channel.send(debug_info_e)
7891

92+
async def send_traceback(self, inter, error):
93+
error_channel = self.bot.get_channel(self.bot.config.channels.errors)
94+
bot_errors = traceback.format_exception(type(error), error, error.__traceback__)
95+
96+
error_embed = disnake.Embed(
97+
title="Error Traceback",
98+
description=f"See below!\n\n{bot_errors}",
99+
timestamp=datetime.utcnow(),
100+
)
101+
await error_channel.send(embed=error_embed)
102+
traceback_nice = "".join(traceback.format_exception(type(error), error, error.__traceback__, 4)).replace("```", "```")
103+
104+
debug_info = (
105+
f"```\n{inter.author} {inter.author.id}: /{inter.application_command.name}"[:200]
106+
+ "```"
107+
+ f"```py\n{traceback_nice}"[: 2000 - 206]
108+
+ "```"
109+
)
110+
await error_channel.send(debug_info)
111+
79112
@staticmethod
80-
async def create_error_message(inter, error):
113+
async def create_error_message(inter, error) -> Embed:
81114
embed = disnake.Embed(
82-
title=f"❌An error occurred while executing: ``/{inter.application_command.name}``",
115+
title=f"❌An error occurred while executing: ``/{inter.application_command.qualified_name}``",
83116
description=f"{error}",
84117
colour=disnake.Color.blurple(),
85118
timestamp=datetime.utcnow(),

cogs/blacklist.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
from disnake.ext.commands import Cog
99

1010
from utils import timeconversions
11-
from utils.DBhandelers import BlacklistHandler
11+
from utils.CONSTANTS import timings
12+
from utils.DBhandlers import BlacklistHandler
1213
from utils.models import BlacklistedUser
1314
from utils.pagination import CreatePaginator
1415
from utils.shortcuts import sucEmb, errorEmb, get_expiry, wait_until
1516

16-
HOUR = 3600
17-
1817
if TYPE_CHECKING:
1918
from utils.bot import OGIROID
2019

@@ -49,15 +48,16 @@ async def check_user_removal(self, user: BlacklistedUser):
4948
return # already being removed
5049
elif user.is_expired():
5150
return True
52-
elif int(time.time()) <= user.expires <= (int(time.time()) + HOUR):
51+
elif int(time.time()) <= user.expires <= (int(time.time()) + timings.HOUR):
5352
self.del_que.append(user.id)
5453
await self.run_at(user.expires, self.blacklist.remove, user.id)
5554

5655
@commands.Cog.listener()
5756
async def on_ready(self):
58-
await self.bot.wait_until_ready()
59-
self.blacklist: BlacklistHandler = self.bot.blacklist
60-
self.check_blacklist.start()
57+
if not self.bot.ready_:
58+
await self.bot.wait_until_ready()
59+
self.blacklist: BlacklistHandler = self.bot.blacklist
60+
self.check_blacklist.start()
6161

6262
@commands.slash_command(description="Blacklist base command", hidden=True)
6363
async def blacklist(self, inter):
@@ -68,7 +68,7 @@ async def blacklist(self, inter):
6868
async def blacklist_info(self, inter, user: Member):
6969
if not await self.blacklist.blacklisted(user.id):
7070
return await errorEmb(inter, f"{user.mention} is not in the blacklist")
71-
bl_user = self.blacklist.get_user(user.id)
71+
bl_user = await self.blacklist.get_user(user.id)
7272
embed = Embed(title=f"Blacklisted user: {user.name}", color=disnake.Color.random(seed=user.name))
7373
embed.add_field(name="Reason", value=bl_user.reason, inline=False)
7474
embed.add_field(name="Expires", value=bl_user.get_expiry, inline=False)
@@ -107,7 +107,7 @@ async def expiry(self, inter, user: Member, expires: str):
107107
expiry = int((await timeconversions.convert(expires)).dt.timestamp())
108108
await self.blacklist.edit_expiry(user.id, expiry)
109109
await sucEmb(inter, f"Edited the expiry of {user.mention}'s blacklist to expire {get_expiry(expiry)}")
110-
await self.check_user_removal(self.blacklist.get_user(user.id))
110+
await self.check_user_removal(await self.blacklist.get_user(user.id))
111111

112112
@commands.has_permissions(manage_messages=True)
113113
@blacklist.sub_command(name="remove", description="Remove a user from the blacklist")
@@ -158,7 +158,7 @@ async def blacklist_add(self, inter, user, bot, tickets, tags, reason="No Reason
158158
f"{user.mention} added to blacklist\nthe user's blacklist will {f'expire on <t:{int(expires)}:R>' if str(expires) != str(9999999999) else 'never expire'}",
159159
ephemeral=False,
160160
)
161-
await self.check_user_removal(self.blacklist.get_user(user.id))
161+
await self.check_user_removal(await self.blacklist.get_user(user.id))
162162

163163
@commands.cooldown(1, 30, commands.BucketType.user)
164164
@blacklist.sub_command(name="list", description="List all blacklisted users")

cogs/botcmds.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import disnake
66
from disnake.ext import commands
77

8-
from utils.CONSTANTS import status
8+
from utils.CONSTANTS import status, __VERSION__
99
from utils.bot import OGIROID
1010
from utils.shortcuts import QuickEmb
1111

@@ -80,22 +80,28 @@ async def botinfo(self, inter):
8080
"""Shows the info of the bot"""
8181
embed = disnake.Embed(title="Ogiroid Information: ", description=" ", color=0xFFFFFF)
8282
embed.add_field(name="**Bot Name: **", value=f"```>> Ogiroid```", inline=False)
83-
embed.add_field(name="**Bot Version: **", value=f"```>> 1.4.0```", inline=False)
83+
embed.add_field(name="**Bot Version: **", value=f"```>> {__VERSION__}```", inline=False)
8484
embed.add_field(
8585
name="**Disnake Version: **",
8686
value=f"```>> {disnake.__version__}```",
8787
inline=False,
8888
)
8989
embed.add_field(
9090
name="**Bot Developers: **",
91-
value=f"__Owners:__\n`>` **[FreebieII](https://github.com/FreebieII) (<@744998591365513227>)** \n`>` **[HarryDaDev](https://github.com/ImmaHarry) (<@963860161976467498>) **\n\n__Contributors:__\n**`>`[JasonLovesDoggo](https://github.com/JasonLovesDoggo) (<@511724576674414600>),\n`>`[DWAA1660](https://github.com/DWAA1660) (<@491266830674034699>), \n`>`[LevaniVashadze](https://github.com/LevaniVashadze) (<@662656158129192961>),\n`>`[CordlessCoder](https://github.com/CordlessCoder) (<@577885109894512659>).**",
91+
value=f"__Owners:__\n`>` **[FreebieII](https://github.com/FreebieII) (<@744998591365513227>)** \n"
92+
f"`>` **[HarryDaDev](https://github.com/ImmaHarry) (<@963860161976467498>) **\n\n"
93+
f"__Contributors:__\n**`>`[JasonLovesDoggo](https://github.com/JasonLovesDoggo) (<@511724576674414600>)\n"
94+
f"`>`[DWAA1660](https://github.com/DWAA1660) (<@491266830674034699>) \n"
95+
f"`>`[LevaniVashadze](https://github.com/LevaniVashadze) (<@662656158129192961>)\n"
96+
f"`>`[CordlessCoder](https://github.com/CordlessCoder) (<@577885109894512659>)**",
9297
inline=False,
9398
)
9499
embed.set_thumbnail(
95100
url="https://cdn.discordapp.com/attachments/985729550732394536/987287532146393109/discord-avatar-512-NACNJ.png"
96101
)
97102

98-
await inter.response.send_message(embed=embed)
103+
button = disnake.ui.Button(label="Source", style=disnake.ButtonStyle.url, url="https://github.com/LewisProjects/Ogiroid")
104+
await inter.send(embed=embed, components=button)
99105

100106
@commands.slash_command()
101107
@commands.guild_only()
@@ -254,6 +260,17 @@ async def whois(self, inter, *, user: disnake.Member = None):
254260

255261
await inter.send(embed=e)
256262

263+
@commands.slash_command(name="avatar", description="Shows the avatar of a user.")
264+
async def avatar(self, inter: disnake.ApplicationCommandInteraction, user: disnake.Member = None):
265+
"""Shows the avatar of a user."""
266+
if user == None:
267+
user = inter.author
268+
269+
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)
272+
await inter.send(embed=embed)
273+
257274

258275
def setup(bot):
259276
bot.add_cog(Commands(bot))

cogs/code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from utils.CONSTANTS import VALID_CODE_LANGUAGES
88
from utils.bot import OGIROID
99
from utils.http import session
10+
from utils.shortcuts import errorEmb
1011

1112

1213
class CodeExec(Cog, name="Code"):
@@ -77,7 +78,10 @@ async def run_code(*, lang: str, code: str):
7778

7879
@staticmethod
7980
async def _send_result(inter, result: dict):
80-
output = result["output"]
81+
try:
82+
output = result["output"]
83+
except KeyError:
84+
return await errorEmb(inter, result["message"])
8185
# if len(output) > 2000: HAVE TO FIX THIS!!!!
8286
# url = await create_guest_paste_bin(self.session, output)
8387
# return await ctx.reply("Your output was too long, so here's the pastebin link " + url)

0 commit comments

Comments
 (0)