-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (57 loc) · 2.01 KB
/
main.py
File metadata and controls
73 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from util.githubcmds import GithubCommands
from util.utils import Utils
from nextcord.ext import commands
import nextcord
import dotenv
import os
import datetime
import sys
import requests
import json
import loggerthyst as log
from util.shared_data import SharedData
intents = nextcord.Intents.all()
dotenv.load_dotenv()
bot = commands.Bot(intents=intents)
bot.add_cog(GithubCommands(bot))
bot.add_cog(Utils(bot))
# https://github.com/Bluemethyst/Gitmethyst
WEBHOOK_URL = os.getenv("DISCORD_ERROR_WEBHOOK")
async def send_exception_notification(extype, value, traceback, ctx):
embed = {
"title": "Unhandled Exception Occurred",
"color": 0x3346D1,
"fields": [
{"name": "Type", "value": str(extype), "inline": False},
{"name": "Context", "value": str(ctx), "inline": False},
{"name": "Exception", "value": str(value), "inline": False},
{"name": "Traceback", "value": str(traceback), "inline": False},
],
}
data = {
"embeds": [embed],
"username": "Gitmethyst",
"avatar_url": "https://raw.githubusercontent.com/Bluemethyst/Gitmethyst/master/assets/gitmethyst.png",
}
result = requests.post(
WEBHOOK_URL, data=json.dumps(data), headers={"Content-Type": "application/json"}
)
if result.status_code != 204:
print(
f"Webhook failed with status code {result.status_code}. Response: {result.text}"
)
@bot.event
async def on_ready():
await bot.change_presence(
activity=nextcord.Activity(
name="github requests", type=nextcord.ActivityType.listening
)
)
shared_data = SharedData()
shared_data.set_bot_start_time(datetime.datetime.now())
log.info(f"We have logged in as {bot.user}!")
@bot.event
async def on_application_command_error(event, *args, **kwargs):
exc_type, exc_value, exc_traceback = sys.exc_info()
await send_exception_notification(exc_type, exc_value, exc_traceback, args[0])
bot.run(os.getenv("DISCORD_TOKEN"))