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 pathgeneral.py
465 lines (420 loc) · 22 KB
/
general.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import discord
import math
from math import sqrt
from cogs.tools import client_role_color
from utils.dataIO import fileIO
from discord.ext import commands
from datetime import datetime
class General(commands.Cog, name='general'):
def __init__(self, client):
self.client = client
@commands.command(aliases=['profile'])
async def userinfo(self, ctx, *, user: discord.Member = None):
"""CATEG_GEN Sends some information about a given user."""
author = ctx.message.author
guild = ctx.message.guild
if not user:
user = author
try:
dbs = fileIO("data/write/strikedata.json", "load")
except FileNotFoundError:
dbs = None
try:
dbm = fileIO("data/write/meritdata.json", "load")
except FileNotFoundError:
dbm = None
roles = [x.name for x in user.roles if x.name != '@everyone']
if not dbs:
scount = 0
elif not dbs[str(guild.id)]:
scount = 0
elif str(user.id) in dbs[str(guild.id)]:
scount = len(dbs[str(guild.id)][str(user.id)])
elif str(user.id) not in dbs[str(guild.id)] or str(guild.id) not in dbs:
scount = 0
if not dbm:
mcount = 0
elif not dbm[str(guild.id)]:
mcount = 0
elif str(user.id) in dbm[str(guild.id)]:
mcount = len(dbm[str(guild.id)][str(user.id)])
elif str(user.id) not in dbm[str(guild.id)] or str(guild.id) not in dbm:
mcount = 0
if scount == 0:
sres = "None"
else:
sres = str(scount)
if mcount == 0:
mres = "None"
else:
mres = str(mcount)
joined_at = user.joined_at
since_created = (ctx.message.created_at - user.created_at).days
since_joined = (ctx.message.created_at - joined_at).days
user_joined = joined_at.strftime("%d %b %Y, %H:%M")
user_created = user.created_at.strftime("%d %b %Y, %H:%M")
created_on = "{} ({} days ago)".format(user_created, since_created)
joined_on = "{} ({} days ago)".format(user_joined, since_joined)
# Bots cannot fetch profiles as of writing
if 69 == 0:
#nitro_since = "Not subscribed."
badgelist = []
profile = await user.profile()
if profile.staff == True:
badgelist.append("Staff")
if profile.partner == True:
badgelist.append("Discord Partner")
if profile.nitro == True:
badgelist.append("Nitro")
#nitro_days = (ctx.message.created_at - profile.premium_since).days
#nitro_since = "Since {}\n({} days ago)".format(profile.premium_since, nitro_days)
if profile.bug_hunter == True:
badgelist.append("Bug Hunter")
if profile.early_supporter == True:
badgelist.append("Early Supporter")
if profile.hypesquad == True:
house = ", ".join(profile.hypesquad_houses)
badgelist.append(house)
#badges = ", ".join(badgelist)
if user.status == discord.Status.online:
game = "Online"
if user.status == discord.Status.offline:
game = "Offline"
if user.status == discord.Status.dnd:
game = "Busy"
if user.status == discord.Status.idle:
game = "Idle"
if user.activity != None:
if user.activity.type.name == "playing":
game = "Playing {}".format(user.activity.name)
if user.activity.type.name == "streaming":
game = "Streaming: [{}]({})".format(user.activity.name, user.activity.url)
if roles:
roles = sorted(roles, key=[x.name for x in guild.roles
if x.name != "@everyone"].index, reverse=True)
roles = ", ".join(roles)
else:
roles = "None"
name = str(user)
if user.nick:
name = "{} ({})".format(str(user), user.nick)
data = discord.Embed(title=name, description=game, colour=client_role_color(self, ctx))
data.add_field(name="📅 Joined Discord on", value=created_on, inline=False)
data.add_field(name="🗓️ Joined this server on", value=joined_on, inline=False)
data.add_field(name="🔨 Strikes", value=sres, inline=False)
data.add_field(name="🌟 Merits", value=mres, inline=False)
data.add_field(name="💍 Married to", value="Marriage isn't implemented yet!", inline=False)
data.add_field(name="🔧 Roles", value=roles, inline=False)
data.set_footer(text="User ID: {}".format(user.id))
if user.avatar_url:
data.set_thumbnail(url=user.avatar_url)
try:
await ctx.send(embed=data)
except discord.HTTPException:
await ctx.send("I need the `Embed links` permission "
"to send this")
@commands.command(aliases=['hinfo', 'hackinfo'])
async def getuser(self, ctx, uid: int=0):
"""CATEG_GEN Finds info about a user based on their ID. Works on people that aren't in the current guild, but sends less info. The bot needs to share a guild with that user."""
if uid == 0 or len(str(uid)) != 18:
embed=discord.Embed(title="🔴 Error", description="Invalid 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
user = self.client.get_user(id=uid)
if user == None:
embed=discord.Embed(title="🔴 Error", description="I couldn't find that user. Please check if I share any servers with them.", 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
since_created = (ctx.message.created_at - user.created_at).days
user_created = user.created_at.strftime("%d %b %Y, %H:%M")
created_on = "{} ({} days ago)".format(user_created, since_created)
data = discord.Embed(title=str(user), colour=client_role_color(self, ctx))
data.add_field(name="📅 Joined Discord on", value=created_on, inline=False)
data.add_field(name="🤖 Bot", value=str(user.bot), inline=False)
data.add_field(name="💍 Married to", value="Marriage isn't implemented yet!", inline=False)
data.add_field(name="#️⃣ User ID", value=str(user.id), inline=False)
if user.avatar_url:
data.set_thumbnail(url=user.avatar_url)
try:
await ctx.send(embed=data)
except discord.HTTPException:
await ctx.send("I need the `Embed links` permission to send this")
@commands.command(aliases=['server', 'guild', 'guildinfo'])
@commands.guild_only()
async def serverinfo(self, ctx):
"""CATEG_GEN Returns information on the current server."""
guild = ctx.message.guild
text_channels = len([x for x in guild.text_channels])
voice_channels = len([x for x in guild.voice_channels])
passed = (ctx.message.created_at - guild.created_at).days
created_at = ("Since {}. That's over {} days ago!"
"".format(guild.created_at.strftime("%d %b %Y %H:%M"),
passed))
bot_count = 0
for member in guild.members:
if member.bot == True:
bot_count = bot_count + 1
total_users = len(guild.members) - bot_count
boosters = len(guild.premium_subscribers)
if boosters < 2:
boost_level = 0
if boosters >= 2 and boosters < 15:
boost_level = 1
if boosters >= 15 and boosters < 30:
boost_level = 2
if boosters >= 30:
boost_level = 3
if guild.region == discord.VoiceRegion.amsterdam:
fancyregion = "🇳Amsterdam"
elif guild.region == discord.VoiceRegion.brazil:
fancyregion = "Brazil"
elif guild.region == discord.VoiceRegion.eu_central:
fancyregion = "Central Europe"
elif guild.region == discord.VoiceRegion.eu_west:
fancyregion = "West Europe"
elif guild.region == discord.VoiceRegion.frankfurt:
fancyregion = "Frankfurt"
elif guild.region == discord.VoiceRegion.hongkong:
fancyregion = "Hong Kong"
elif guild.region == discord.VoiceRegion.japan:
fancyregion = "Japan"
elif guild.region == discord.VoiceRegion.london:
fancyregion = "London"
elif guild.region == discord.VoiceRegion.russia:
fancyregion = "Russia"
elif guild.region == discord.VoiceRegion.singapore:
fancyregion = "Singapore"
elif guild.region == discord.VoiceRegion.southafrica:
fancyregion = "South Africa"
elif guild.region == discord.VoiceRegion.sydney:
fancyregion = "Sydney"
elif guild.region == discord.VoiceRegion.us_central:
fancyregion = "US Central"
elif guild.region == discord.VoiceRegion.us_east:
fancyregion = "US East"
elif guild.region == discord.VoiceRegion.us_south:
fancyregion = "US South"
elif guild.region == discord.VoiceRegion.us_west:
fancyregion = "US West"
elif guild.region == discord.VoiceRegion.vip_amsterdam:
fancyregion = "VIP Amsterdam"
elif guild.region == discord.VoiceRegion.vip_us_east:
fancyregion = "VIP US East"
elif guild.region == discord.VoiceRegion.vip_us_west:
fancyregion = "VIP US West"
elif guild.region == "europe":
fancyregion = "Europe"
data = discord.Embed(title=guild.name, description=created_at, colour=client_role_color(self, ctx))
data.add_field(name="🌍 Region", value=str(fancyregion), inline=False)
data.add_field(name="👥 Members", value="{} members, {} bots".format(total_users, bot_count), inline=False)
data.add_field(name="💬 Text Channels", value=text_channels, inline=False)
data.add_field(name="🔊 Voice Channels", value=voice_channels, inline=False)
data.add_field(name="💠 Boosting", value="Level {}, {} boosters".format(boost_level, boosters), inline=False)
data.add_field(name="🔧 Roles", value=len(guild.roles), inline=False)
data.add_field(name="👑 Owner", value=str(guild.owner), inline=False)
data.set_footer(text="Server ID: " + str(guild.id))
if guild.icon_url:
data.set_thumbnail(url=guild.icon_url)
try:
await ctx.send(embed=data)
except discord.HTTPException:
await ctx.send("I need the `Embed links` permission to do this.")
@commands.command(aliases=['hguild', 'hackguild'])
async def getguild(self, ctx, uid: int = 0):
"""CATEG_GEN Returns information on a guild with the given ID. The bot has to be a member of the guild."""
if uid == 0 or len(str(uid)) != 18:
embed=discord.Embed(title="🔴 Error", description="Invalid 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 = self.client.get_guild(id=uid)
if guild == None:
embed=discord.Embed(title="🔴 Error", description="Couldn't find a guild. Please check if I'm in that server.", 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
text_channels = len([x for x in guild.text_channels])
voice_channels = len([x for x in guild.voice_channels])
passed = (ctx.message.created_at - guild.created_at).days
created_at = ("Since {}. That's over {} days ago!"
"".format(guild.created_at.strftime("%d %b %Y %H:%M"),
passed))
bot_count = 0
for member in guild.members:
if member.bot == True:
bot_count = bot_count + 1
total_users = len(guild.members) - bot_count
boosters = len(guild.premium_subscribers)
if boosters < 2:
boost_level = 0
if boosters >= 2 and boosters < 15:
boost_level = 1
if boosters >= 15 and boosters < 30:
boost_level = 2
if boosters >= 30:
boost_level = 3
if guild.region == discord.VoiceRegion.amsterdam:
fancyregion = "🇳Amsterdam"
elif guild.region == discord.VoiceRegion.brazil:
fancyregion = "Brazil"
elif guild.region == discord.VoiceRegion.eu_central:
fancyregion = "Central Europe"
elif guild.region == discord.VoiceRegion.eu_west:
fancyregion = "West Europe"
elif guild.region == discord.VoiceRegion.frankfurt:
fancyregion = "Frankfurt"
elif guild.region == discord.VoiceRegion.hongkong:
fancyregion = "Hong Kong"
elif guild.region == discord.VoiceRegion.japan:
fancyregion = "Japan"
elif guild.region == discord.VoiceRegion.london:
fancyregion = "London"
elif guild.region == discord.VoiceRegion.russia:
fancyregion = "Russia"
elif guild.region == discord.VoiceRegion.singapore:
fancyregion = "Singapore"
elif guild.region == discord.VoiceRegion.southafrica:
fancyregion = "South Africa"
elif guild.region == discord.VoiceRegion.sydney:
fancyregion = "Sydney"
elif guild.region == discord.VoiceRegion.us_central:
fancyregion = "US Central"
elif guild.region == discord.VoiceRegion.us_east:
fancyregion = "US East"
elif guild.region == discord.VoiceRegion.us_south:
fancyregion = "US South"
elif guild.region == discord.VoiceRegion.us_west:
fancyregion = "US West"
elif guild.region == discord.VoiceRegion.vip_amsterdam:
fancyregion = "VIP Amsterdam"
elif guild.region == discord.VoiceRegion.vip_us_east:
fancyregion = "VIP US East"
elif guild.region == discord.VoiceRegion.vip_us_west:
fancyregion = "VIP US West"
elif guild.region == "europe":
fancyregion = "Europe"
data = discord.Embed(title=guild.name, description=created_at, colour=client_role_color(self, ctx))
data.add_field(name="🌍 Region", value=str(fancyregion), inline=False)
data.add_field(name="👥 Members", value="{} members, {} bots".format(total_users, bot_count), inline=False)
data.add_field(name="💬 Text Channels", value=text_channels, inline=False)
data.add_field(name="🔊 Voice Channels", value=voice_channels, inline=False)
data.add_field(name="💠 Boosting", value="Level {}, {} boosters".format(boost_level, boosters), inline=False)
data.add_field(name="🔧 Roles", value=len(guild.roles), inline=False)
data.add_field(name="👑 Owner", value=str(guild.owner), inline=False)
data.set_footer(text="Server ID: " + str(guild.id))
if guild.icon_url:
data.set_thumbnail(url=guild.icon_url)
try:
await ctx.send(embed=data)
except discord.HTTPException:
await ctx.send("I need the `Embed links` permission to do this.")
@commands.command()
async def calc(self, ctx, *, maths):
"""CATEG_GEN Does the math for you"""
equation = maths.strip().replace('^', '**').replace('x', '*')
try:
if '=' in equation:
left = eval(equation.split('=')[0], {"__builtins__": None}, {"sqrt": sqrt})
right = eval(equation.split('=')[1], {"__builtins__": None}, {"sqrt": sqrt})
answer = str(left == right)
else:
answer = str(eval(equation, {"__builtins__": None}, {"sqrt": sqrt}))
except TypeError:
return await ctx.send("Invalid calculation query.")
try:
em = discord.Embed(title='🧮 Calculator', color=client_role_color(self, ctx))
em.add_field(name='Input:', value=maths.replace('**', '^').replace('x', '*'), inline=False)
em.add_field(name='Output:', value=answer, inline=False)
await ctx.send(embed=em)
except discord.HTTPException:
await ctx.send("I need the `Embed links` permission to do this.")
@commands.command(aliases=['assign'], pass_context=True)
@commands.guild_only()
async def role(self, ctx, *, role: discord.Role = None):
"""CATEG_GEN Assigns you a role that is below your highest one."""
user = ctx.message.author
if role is None:
embed=discord.Embed(title="🔴 Error", description="You haven't specified a role!", 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)
if role not in ctx.message.guild.roles:
embed=discord.Embed(title="🔴 Error", description="That role doesn't exist.", 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)
if role.position < user.top_role.position:
if role not in ctx.message.author.roles:
await user.add_roles(role, reason='Role add requested by {}'.format(str(user)))
embed=discord.Embed(title="✅ Role", description="``{}`` has been added to {}.".format(role, user.mention), 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)
elif role in ctx.message.author.roles:
await user.remove_roles(role, reason='Role removal requested by {}'.format(str(user)))
embed=discord.Embed(title="✅ Role", description="``{}`` has been removed from {}.".format(role, user.mention), 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="🔴 Error", description="That role is higher than your top role.", 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(aliases=['pfp', 'icon'])
async def avatar(self, ctx, user: discord.User = None):
"""CATEG_GEN Returns a user's avatar."""
if not user:
user = ctx.message.author
icon = user.avatar_url
embed=discord.Embed(title="🖼️ Here's **{}'s** avatar.".format(user), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_image(url=str(icon))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command(aliases=['guildicon'])
@commands.guild_only()
async def servericon(self, ctx):
"""CATEG_GEN Returns the server's icon."""
user = ctx.message.guild
icon = user.icon_url
if icon._url == None:
embed=discord.Embed(title="🔴 Error", description="**{}** has no icon.".format(user), colour=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
embed.set_image(url=str(icon))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🖼️ Here's **{}'s** icon.".format(user), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_image(url=str(icon))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
@commands.guild_only()
async def banner(self, ctx):
"""CATEG_GEN Returns the server's banner."""
user = ctx.message.guild
icon = user.banner_url
if icon._url == None:
embed=discord.Embed(title="🔴 Error", description="**{}** has no banner.".format(user), colour=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
embed.set_image(url=str(icon))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🖼️ Here's **{}'s** banner.".format(user), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_image(url=str(icon))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
@commands.command()
@commands.guild_only()
async def splash(self, ctx):
"""CATEG_GEN Returns the server's invite splash."""
user = ctx.message.guild
icon = user.splash_url
if icon._url == None:
embed=discord.Embed(title="🔴 Error", description="**{}** has no invite splash.".format(user), colour=0xdd2e44, timestamp=datetime.utcnow())
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
embed.set_image(url=str(icon))
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="🖼️ Here's **{}'s** invite splash.".format(user), color=client_role_color(self, ctx), timestamp=datetime.utcnow())
embed.set_image(url=str(icon))
embed.set_footer(icon_url=self.client.user.avatar_url, text=self.client.user.name)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(General(client))