forked from hzhreal/HTOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
76 lines (62 loc) · 2.04 KB
/
bot.py
File metadata and controls
76 lines (62 loc) · 2.04 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
from dotenv import load_dotenv
load_dotenv()
import discord
import argparse
from discord.ext import commands
from google_drive.gd_functions import gdapi, check_GDrive
from utils.constants import bot, TOKEN
from utils.workspace import WorkspaceOpt, startup, check_version
from utils.helpers import ThreadButton
from utils.conversions import round_half_up
import utils.embeds_assert as _
workspace_opt = WorkspaceOpt()
@bot.event
async def on_ready() -> None:
startup(workspace_opt)
await check_version()
bot.add_view(ThreadButton()) # make view persistent
if gdapi.is_available():
check_GDrive.start() # start gd daemon
print(
f"Bot is ready, invite link: https://discord.com/api/oauth2/authorize?client_id={bot.user.id}&permissions=0&scope=bot"
)
@bot.event
async def on_application_command_error(ctx: discord.ApplicationContext, error: discord.DiscordException) -> None:
match error:
case commands.CommandOnCooldown():
await ctx.respond(f"You are on cooldown. Try again in {round_half_up(error.retry_after)} seconds.", ephemeral=True)
case commands.NotOwner():
await ctx.respond("You are unauthorized to use this command.", ephemeral=True)
@bot.event
async def on_message(message: discord.Message) -> None:
if message.author.bot:
return
if message.content == "hello":
await message.channel.send("hi")
await bot.process_commands(message)
cogs_list = [
"change",
"convert",
"createsave",
"decrypt",
"encrypt",
"extra",
"misc",
"quick",
"reregion",
"resign",
"sealed_key",
"sfo",
]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ignore-startup", action="store_true")
args = parser.parse_args()
if args.ignore_startup:
workspace_opt.ignore_startup = True
for cog in cogs_list:
print(f"Loading cog: {cog}...")
bot.load_extension(f"cogs.{cog}")
print(f"Loaded cog: {cog}.")
print("Starting bot...\n\n")
bot.run(TOKEN)