-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowner.py
102 lines (86 loc) · 4.05 KB
/
owner.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
import traceback
import discord
from discord import app_commands
from discord.ext import commands
import os
import config
import subprocess
import embeds
import glob
class Owner(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(hidden=True)
@commands.is_owner()
async def unload_cog(self, ctx, extension: str):
extension = extension.lower()
try:
await self.bot.unload_extension(f'cogs.{extension}')
await ctx.message.add_reaction("✅")
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
except:
await ctx.reply(embed=embeds.generic, content=traceback.print_exc())
@commands.command(hidden=True)
@commands.is_owner()
async def load_cog(self, ctx, extension: str):
extension = extension.lower()
try:
await self.bot.load_extension(f'cogs.{extension}')
await ctx.message.add_reaction("✅")
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
except:
await ctx.reply(embed=embeds.generic, content=traceback.print_exc())
@commands.command(hidden=True)
@commands.is_owner()
async def reload_cog(self, ctx, extension: str):
extension = extension.lower()
try:
await ctx.message.add_reaction("<a:load:1332186697823162489>")
await self.bot.reload_extension(f'cogs.{extension}')
await ctx.message.remove_reaction("<a:load:1332186697823162489>", self.bot.user)
await ctx.message.add_reaction("✅")
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
except:
await ctx.reply(embed=embeds.generic, content=traceback.print_exc())
@commands.command(hidden=True)
@commands.is_owner()
async def load_all(self, ctx):
await ctx.message.add_reaction("<a:load:1332186697823162489>")
for file_path in glob.glob('./cogs/**/*.py', recursive=True):
module_name = os.path.splitext(os.path.relpath(file_path, start='./cogs'))[0].replace(os.sep, '.')
await self.bot.load_extension(f'cogs.{module_name}')
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
await ctx.message.remove_reaction("<a:load:1332186697823162489>", self.bot.user)
await ctx.message.add_reaction("✅")
@commands.command(hidden=True)
@commands.is_owner()
async def unload_all(self, ctx):
await ctx.message.add_reaction("<a:load:1332186697823162489>")
for file_path in glob.glob('./cogs/**/*.py', recursive=True):
module_name = os.path.splitext(os.path.relpath(file_path, start='./cogs'))[0].replace(os.sep, '.')
if module_name != 'owner':
await self.bot.unload_extension(f'cogs.{module_name}')
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
await ctx.message.remove_reaction("<a:load:1332186697823162489>", self.bot.user)
await ctx.message.add_reaction("✅")
@commands.command(hidden=True)
@commands.is_owner()
async def reload(self, ctx):
await ctx.message.add_reaction("<a:load:1332186697823162489>")
for file_path in glob.glob('./cogs/**/*.py', recursive=True):
module_name = os.path.splitext(os.path.relpath(file_path, start='./cogs'))[0].replace(os.sep, '.')
await self.bot.reload_extension(f'cogs.{module_name}')
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
await ctx.message.remove_reaction("<a:load:1332186697823162489>", self.bot.user)
await ctx.message.add_reaction("✅")
@commands.command(hidden=True)
@commands.has_role(config.benbot_perms_role_id)
async def restart(self, ctx):
msg = await ctx.send('now restarting')
try:
os.chdir('/home/echo')
subprocess.run("./update.sh", shell=True)
except:
await ctx.reply(embed=embeds.generic, content=traceback.print_exc())
async def setup(bot):
await bot.add_cog(Owner(bot), guilds=[discord.Object(id=config.server_id)])