-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
174 lines (140 loc) · 8.62 KB
/
main.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import asyncio
import discord
import os
import logging
import time
from discord.ext import commands
from discord import app_commands
from dotenv import load_dotenv
from datetime import datetime
from utils.roleChecks import role_required
load_dotenv()
print("Launching...")
time.sleep(1)
print(r" _____ _____ _____ _____ _____ _____ ")
print(r" /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ ")
print(r" /::\ \ /::\____\ /::\ \ /::\ \ /::\____\ /::\ \ ")
time.sleep(0.3)
print(r" /::::\ \ /:::/ / /::::\ \ \:::\ \ /::::| | /::::\ \ ")
print(r" /::::::\ \ /:::/ / /::::::\ \ \:::\ \ /:::::| | /::::::\ \ ")
print(r" /:::/\:::\ \ /:::/ / /:::/\:::\ \ \:::\ \ /::::::| | /:::/\:::\ \ ")
time.sleep(0.3)
print(r" /:::/__\:::\ \ /:::/ / /:::/__\:::\ \ \:::\ \ /:::/|::| | /:::/__\:::\ \ ")
print(r" /::::\ \:::\ \ /:::/ / /::::\ \:::\ \ /::::\ \ /:::/ |::| | /::::\ \:::\ \ ")
print(r" /::::::\ \:::\ \ /:::/ / /::::::\ \:::\ \ ____ /::::::\ \ /:::/ |::| | _____ /::::::\ \:::\ \ ")
time.sleep(0.3)
print(r" /:::/\:::\ \:::\ \ /:::/ / /:::/\:::\ \:::\ \ /\ \ /:::/\:::\ \ /:::/ |::| |/\ \ /:::/\:::\ \:::\ \ ")
print(r"/:::/__\:::\ \:::\____\/:::/____/ /:::/ \:::\ \:::\____\/::\ \/:::/ \:::\____\/:: / |::| /::\____\/:::/ \:::\ \:::\____\ ")
print(r"\:::\ \:::\ \::/ /\:::\ \ \::/ \:::\ /:::/ /\:::\ /:::/ \::/ /\::/ /|::| /:::/ /\::/ \:::\ /:::/ / ")
time.sleep(0.3)
print(r" \:::\ \:::\ \/____/ \:::\ \ \/____/ \:::\/:::/ / \:::\/:::/ / \/____/ \/____/ |::| /:::/ / \/____/ \:::\/:::/ / ")
print(r" \:::\ \:::\ \ \:::\ \ \::::::/ / \::::::/ / |::|/:::/ / \::::::/ / ")
print(r" \:::\ \:::\____\ \:::\ \ \::::/ / \::::/____/ |::::::/ / \::::/ / ")
time.sleep(0.3)
print(r" \:::\ \::/ / \:::\ \ /:::/ / \:::\ \ |:::::/ / /:::/ / ")
print(r" \:::\ \/____/ \:::\ \ /:::/ / \:::\ \ |::::/ / /:::/ / ")
print(r" \:::\ \ \:::\ \ /:::/ / \:::\ \ /:::/ / /:::/ / ")
time.sleep(0.3)
print(r" \:::\____\ \:::\____\ /:::/ / \:::\____\ /:::/ / /:::/ / ")
print(r" \::/ / \::/ / \::/ / \::/ / \::/ / \::/ / ")
print(r" \/____/ \/____/ \/____/ \/____/ \/____/ \/____/ ")
TOKEN = os.getenv('DISCORD_TOKEN')
MY_GUILD = discord.Object(id=1116469018019233812)
loadedCogs = []
log_folder = 'logs'
os.makedirs(log_folder, exist_ok=True)
log_file_name = f"log_date_{datetime.now().strftime('%Y-%m-%d')}_time_{datetime.now().strftime('%H-%M-%S')}.txt"
log_file_path = os.path.join(log_folder, log_file_name)
logger = logging.getLogger('__name__')
logging.basicConfig(level=logging.INFO,
format='%(asctime)s:%(levelname)s:%(filename)s: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p',
filename=log_file_path)
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
intents.messages = True
bot = commands.Bot(command_prefix='!',
intents=intents,
application_id='991731064026448043',
guilds=[discord.Object(id=1116469018019233812)])
@bot.event
async def on_ready():
bot.tree.copy_global_to(guild=MY_GUILD)
await bot.tree.sync(guild=MY_GUILD)
logger.info(f'Logged in as {bot.user}')
print("Bot ready and loaded!")
@bot.tree.command(name='sync', description='syncs commands from cogs')
@role_required("RAT")
@app_commands.default_permissions(administrator=True)
async def sync(interaction: discord.Interaction):
fmt = await bot.tree.sync(guild=MY_GUILD)
await interaction.response.send_message(f"Refreshed {len(fmt)} commands.", ephemeral=True)
logger.info(f'Synced commands: {fmt}')
@sync.error
async def on_sync_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingRole):
await interaction.response.send_message(f"Sync command failed: {error}", ephemeral=True)
logger.error(f"Sync command failed: {error}")
@bot.tree.command(name='loaded', description='Checks what cogs are loaded')
@role_required("RAT")
@app_commands.default_permissions(administrator=True)
async def loaded(interaction: discord.Interaction):
loadedresponse = '\n'.join(loadedCogs)
await interaction.response.send_message(f"# Cogs loaded:\n{loadedresponse}", ephemeral=True)
logger.info(f'Loaded cogs: {loadedCogs}')
@loaded.error
async def on_sync_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingRole):
await interaction.response.send_message(f"Loaded command failed: {error}", ephemeral=True)
logger.error(f"Loaded command failed: {error}")
@bot.tree.command(name='unload', description='unloads a cog')
@role_required("RAT")
@app_commands.default_permissions(administrator=True)
async def unload(interaction: discord.Interaction, cog: str):
await bot.unload_extension(f"cogs.{cog}")
loadedCogs.remove(cog)
await interaction.response.send_message(f"Unloaded {cog}", ephemeral=True)
logger.info(f'Unloaded cogs: {cog}')
@unload.error
async def on_sync_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingRole):
await interaction.response.send_message(f"Unload command failed: {error}", ephemeral=True)
logger.error(f"Unload command failed: {error}")
@bot.tree.command(name='load', description='Loads a cog')
@role_required("RAT")
@app_commands.default_permissions(administrator=True)
async def load(interaction: discord.Interaction, cog: str):
for file in os.listdir('./cogs'):
if file.startswith(cog):
loadedCogs.append(file[:-3])
await bot.load_extension(f'cogs.{file[:-3]}')
await interaction.response.send_message(f"Loaded {cog}", ephemeral=True)
logger.info(f"Loaded cogs: {cog}")
@load.error
async def on_sync_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingRole):
await interaction.response.send_message(f"Load command failed: {error}", ephemeral=True)
logger.error(f"Load command failed: {error}")
@bot.tree.command(name='reload', description='Reloads a cog')
@role_required("RAT")
@app_commands.default_permissions(administrator=True)
async def reload(interaction: discord.Interaction, cog: str):
await bot.reload_extension(f"cogs.{cog}")
await interaction.response.send_message(f"Reloaded {cog}!", ephemeral=True)
logger.info(f"Reloaded cogs: {cog}")
@reload.error
async def on_sync_error(interaction: discord.Interaction, error: app_commands.AppCommandError):
if isinstance(error, app_commands.MissingRole):
await interaction.response.send_message(f"Reload command failed: {error}", ephemeral=True)
logger.error(f"Reload command failed: {error}")
async def loadCogs():
for file in os.listdir('./cogs'):
if file.endswith('.py'):
loadedCogs.append(file[:-3])
await bot.load_extension(f'cogs.{file[:-3]}')
logging.info(f'Loaded cog {file[:-3]}')
async def main():
await loadCogs()
await bot.start(TOKEN)
asyncio.run(main())