-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbot.py
More file actions
108 lines (82 loc) · 2.99 KB
/
bot.py
File metadata and controls
108 lines (82 loc) · 2.99 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import datetime
import logging
import os
import sys
import traceback
from math import floor, isfinite
import disnake
from disnake import Intents
from disnake.ext import commands
from disnake.ext.commands import CheckFailure, CommandInvokeError, CommandNotFound, UserInputError
import constants
from lib.github import GitHubClient
from lib.reports import ReportException
ORG_NAME = os.environ.get("ORG_NAME", "avrae")
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
class Taine(commands.AutoShardedBot):
def __init__(self, *args, **kwargs):
super(Taine, self).__init__(*args, **kwargs)
intents = Intents.all()
bot = Taine(
command_prefix="~",
intents=intents,
test_guilds=constants.SLASH_TEST_GUILDS,
sync_commands_debug=False
)
log_formatter = logging.Formatter('%(levelname)s:%(name)s: %(message)s')
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(log_formatter)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(handler)
log = logging.getLogger('bot')
EXTENSIONS = ("web.web", "cogs.reports", "cogs.owner", "cogs.reactions", "cogs.repl", "cogs.inline")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, CommandNotFound):
return
if isinstance(error, CommandInvokeError):
error = error.original
await ctx.message.channel.send(f"Error: {error}")
for line in traceback.format_exception(type(error), error, error.__traceback__):
log.warning(line)
@bot.event
async def on_slash_command_error(inter, error):
if isinstance(error, CommandInvokeError):
error = error.original
await inter.response.send_message(f"Error: {error}")
for line in traceback.format_exception(type(error), error, error.__traceback__):
log.warning(line)
@bot.event
async def on_error(event, *args, **kwargs):
for line in traceback.format_exception(*sys.exc_info()):
log.warning(line)
@bot.event
async def on_message(message):
await bot.process_commands(message)
@bot.slash_command()
async def ping(
inter: disnake.ApplicationCommandInteraction
):
"""Returns the bot's latency to the Discord API."""
now = datetime.datetime.utcnow()
await inter.response.defer() # this makes an API call, we use the RTT of that call as the latency
delta = datetime.datetime.utcnow() - now
httping = floor(delta.total_seconds() * 1000)
wsping = floor(bot.latency * 1000) if isfinite(bot.latency) else "Unknown"
await inter.followup.send(f"Pong.\nHTTP Ping = {httping} ms.\nWS Ping = {wsping} ms.")
if __name__ == '__main__':
if not (DISCORD_TOKEN and GITHUB_TOKEN):
print("Discord/Github configuration not set")
else:
GitHubClient.initialize(GITHUB_TOKEN, ORG_NAME) # initialize
for extension in EXTENSIONS:
bot.load_extension(extension)
bot.run(DISCORD_TOKEN)