This repository was archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.py
189 lines (170 loc) · 9.98 KB
/
admin.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import discord
import inspect
from discord.ext import commands
import time
from datetime import datetime
from cogs.tools import client_role_color, errorcheck
import cogs.tools as tools
from utils.dataIO import fileIO
import traceback
class Admin(commands.Cog, name="admin"):
def __init__(self, client):
self.client = client
@commands.command()
async def test(self, ctx):
"""CATEG_OWN Responds with an embed."""
embed=discord.Embed(title="🔵 Test", description="Hello! :wave:", color=0x55acee, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
async def testerror(self, ctx):
"""CATEG_OWN Responds with a error embed."""
embed=discord.Embed(title="🔴 Error", description="This is an error.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
async def testwarning(self, ctx):
"""CATEG_OWN Responds with a warning embed."""
embed=discord.Embed(title=":warning: Warning", description="This is a warning.", color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
async def ping(self, ctx):
"""CATEG_GEN Sends the bot's latency."""
channel = ctx.message.channel
t1 = time.perf_counter()
await channel.trigger_typing()
t2 = time.perf_counter()
embed=discord.Embed(title="🏓 Pong!", description="This took me {}ms.".format(round((t2-t1)*1000)), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
async def say(self, ctx, *args):
"""CATEG_GEN Repeats after you."""
msg = " ".join(args)
await ctx.send(msg)
await ctx.message.delete()
@commands.command()
@commands.guild_only()
async def prefix(self, ctx, *, prefix):
"""CATEG_ADM Changes the prefix for this server."""
if await self.client.is_owner(ctx.message.author) == True or ctx.message.author.guild_permissions.manage_guild == True:
predata = "data/write/prefix.json"
db = fileIO(predata, "load")
channel = ctx.message.channel
author = ctx.message.author
embed=discord.Embed(title=":warning: Prefix", description="Are you sure you want to change this server's prefix to `{}`?".format(prefix), color=0xffcd4c, timestamp=datetime.utcnow())
embed.set_footer(text="Reply with yes to continue.")
await ctx.send(embed=embed)
def check(m):
return m.channel == channel and m.author == author
msg = await self.client.wait_for('message', check=check)
if msg.content == "yes" or msg.content == "y":
db[str(ctx.guild.id)] = prefix
fileIO(predata, "save", db)
embed=discord.Embed(title=":interrobang: Prefix", description="Successfully set this server's prefix to `{}`".format(prefix), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
else:
embed=discord.Embed(title=":interrobang: Prefix", description="Cancelling...", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
else:
return
@commands.command()
async def invite(self, ctx):
"""CATEG_GEN Sends the bot's invite link."""
url = discord.utils.oauth_url(client_id=self.client.user.id, permissions=discord.Permissions(permissions=1609952503))
embed = discord.Embed(title="📨 Invite Link", description="You can invite me using [this link]({})".format(url), color=0x7289da, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await tools.dmauthor(self, ctx, embed)
if ctx.guild != None:
embed=discord.Embed(title="📨 Invite", description="Check your DMs! :page_facing_up:", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
@commands.is_owner()
async def status(self, ctx, *args):
"""CATEG_OWN Changes the bot's status."""
game = " ".join(args)
if str(game) == "":
return
await self.client.change_presence(status=discord.Status.online, activity=discord.Streaming(name=game, url='https://www.twitch.tv/directory', twitch_name="directory"))
embed=discord.Embed(title="🎮 Status", description='Setting status to "{}".'.format(game), color=client_role_color(self, ctx))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
@commands.is_owner()
async def guildlist(self, ctx):
"""CATEG_OWN Sends a list of guilds the bot is in alongside their IDs."""
msg = discord.Embed(title="📃 Guild list", description="Currently in {} guilds, those are:".format(len(self.client.guilds)), color=client_role_color(self, ctx))
for x in self.client.guilds:
msg.add_field(name=x.name, value="ID: `" + str(x.id) + "`, " + str(len(x.members)) + " Members", inline=False)
msg.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await tools.dmauthor(self, ctx, embed=msg)
if ctx.guild != None:
await ctx.message.delete()
@commands.command()
@commands.is_owner()
async def leaveguild(self, ctx, id: int = 0000000):
"""CATEG_OWN Leaves a guild with the provided ID."""
if id == 0000000:
embed=discord.Embed(title="🔴 Error", description="You need to provide a valid guild ID.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
return
guild = discord.utils.get(self.client.guilds, id=id)
if guild == None:
embed=discord.Embed(title="🔴 Error", description="You need to provide a valid guild ID.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
return
try:
await guild.leave()
except:
embed=discord.Embed(title="🔴 Error", description="I'm not in that guild.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
return await ctx.send(embed=embed)
embed=discord.Embed(title="👋 Leave Guild", description="Successfully left the guild.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command(name='eval')
@commands.is_owner()
async def _eval(self, ctx, *, command):
"""CATEG_OWN Evaluates some code."""
if await self.client.is_owner(ctx.message.author) == True:
try:
command = command.strip("`")
res = eval(command)
if inspect.isawaitable(res):
res = await res
embed=discord.Embed(title="🤖 Eval", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.add_field(name="Output:", value="```py\n{}\n```".format(res), inline=False)
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🤖 Eval", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.add_field(name="Output:", value="```py\n{}\n```".format(res), inline=False)
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
except:
embed=discord.Embed(title="🤖 Eval", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.add_field(name="Output:", value="```py\n{}\n```".format(traceback.format_exc()), inline=False)
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
if ctx.guild != None:
msg=discord.Embed(title="🤖 Eval", description="I got an error, please check your DMs.", color=client_role_color(self, ctx), timestamp=datetime.utcnow())
msg.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=msg)
await tools.dmauthor(self, ctx, embed)
else:
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🔴 Error", description="Only my owner can do that.", color=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
await errorcheck(self, ctx, error)
def setup(client):
tools.jsoncheck()
client.add_cog(Admin(client))