-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathowner.py
88 lines (74 loc) · 2.89 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
from discord.ext.commands import command
from jishaku.codeblocks import codeblock_converter
from jishaku.modules import ExtensionConverter
import discord
from core import Cog, models
from core import utils
import aiohttp
import subprocess
import os
import sys
class Owner(Cog, command_attrs={"hidden": True}):
def __init__(self, bot) -> None:
super().__init__(bot)
self.jishaku = bot.get_cog("Jishaku")
@command(name="eval")
async def _eval(self, ctx, *, code):
await self.jishaku.jsk_python(ctx, argument=codeblock_converter(code))
@command(aliases=["reload"])
async def load(self, ctx, *files: ExtensionConverter):
await self.jishaku.jsk_load(ctx, *files)
@command()
async def unload(self, ctx, *files: ExtensionConverter):
await self.jishaku.jsk_unload(ctx, *files)
@command()
async def shutdown(self, ctx):
await ctx.send("Shutting down.")
await self.bot.close()
@command()
async def restart(self, ctx):
await ctx.send("Restarting.")
os.execv(sys.executable, ['python'] + sys.argv)
@command()
async def pull(self, ctx, *to_load: ExtensionConverter):
await self.jishaku.jsk_git(ctx, argument=codeblock_converter("pull"))
await self.jishaku.jsk_load(ctx, *to_load)
@command()
# set bot status in the format of {presence_text}
async def presence(self, ctx, *, presence_text: str):
await models.BotModel.update_or_create(
{"presence_text": presence_text}
)
await self.bot.change_presence(
activity=discord.CustomActivity(
name=presence_text
)
)
await ctx.reply(f"Presence updated to `{presence_text}`")
@command(aliases=["percent"])
# the percentage of users who have used a bot command (check if commandsUsed exists for each user)
async def command_percentage(self, ctx):
user_data_list = await models.UserModel.all()
active_users = 0
for user_data in user_data_list:
if user_data.commands_used:
active_users += 1
percentage = (active_users / len(user_data_list)) * 100
await ctx.reply(f"{percentage:.2f}% of users have used a command.")
@command()
async def manlog(self, ctx):
#manually call the log_data_to_csv function
await utils.log_data(self.bot)
await ctx.reply("Data logged to db.")
async def cog_check(self, ctx):
return ctx.author.id in self.bot.owner_ids
@command()
async def ytdlp(self, ctx):
# pip upgrade yt-dlp package
sys = subprocess.run(["python3", "-m", "pip", "install", "--upgrade", "yt-dlp"])
if sys.returncode == 0:
await ctx.reply("yt-dlp upgraded successfully.\nRestart the bot to apply changes.")
else:
await ctx.reply("yt-dlp upgrade failed.")
def setup(bot):
bot.add_cog(Owner(bot))