-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
108 lines (94 loc) · 3.8 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
from datetime import datetime
from datetime import timezone
import discord
from discord.ext import commands
from modules.extension import Extension
from modules.utilities import logger as l
from modules.utilities import prefix
from modules.utilities import utilities as u
from modules.utilities import ylcb_config
class admin(Extension):
"""Admin Extension - ylcb-devs"""
def __init__(self, bot: commands.Bot):
"""
admin(bot)
Args:
bot (`commands.Bot`): `commands.Bot` Instance
"""
super().__init__(bot, "admin")
self.discord_time_format = "%Y-%m-%d %H:%M:%S.%f"
@commands.command(name="info", usage=f"{prefix}info [user:user]", brief="Get server or user info")
async def info(self, ctx, user: discord.Member = None):
"""
Get server or user info
Args:
user (`discord.Member`, optional): If defined gets user info instead of server info. Defaults to `None`.
"""
server_mode = True if not user else False
if server_mode:
perma_link = ""
for invite in await ctx.guild.invites():
invite: discord.Invite
if not invite.revoked and invite.max_age == 0 and not invite.temporary and invite.max_uses == 0:
perma_link = str(invite)
break
owner = await self.bot.fetch_user(ctx.guild.owner_id)
created = datetime.strptime(str(ctx.guild.created_at), self.discord_time_format)
embed_dict: dict = {
"type": "rich",
"timestamp": datetime.now().isoformat(),
"color": 0x6495ed,
"fields": [
{"name": "Owner", "value": u.discordify(str(owner)), "inline": True},
{"name": "Server Created", "value": created.strftime("%m/%d/%Y %H:%M"), "inline": True},
{"name": "Members", "value": str(ctx.guild.member_count), "inline": True},
{"name": "Region", "value": str(ctx.guild.region), "inline": True},
{"name": "Boosters", "value": str(ctx.guild.premium_subscription_count), "inline": True}
],
"author": {
"name": u.discordify(ctx.guild.name),
"icon_url": str(ctx.guild.icon_url)
},
"footer": {"text": f"ID: {ctx.guild.id}"}
}
if ctx.guild.description:
embed_dict["description"] = ctx.guild.description
if perma_link:
embed_dict["fields"].append({"name": "Perma Link", "value": perma_link, "inline": True})
await ctx.send(embed=discord.Embed.from_dict(embed_dict))
else:
embed_dict: dict = {
"title": str(user),
"type": "rich",
"color": user.color.value,
"timestamp": datetime.now().isoformat(),
"fields": [
{"name": "Account Created", "value": datetime.strptime(str(user.created_at), self.discord_time_format).strftime("%m/%d/%Y %H:%M"), "inline": True},
{"name": "Status", "value": user.status[0], "inline": True}
],
"author": {
"name": u.discordify(str(user)),
"icon_url": str(user.avatar_url)
},
"footer": {"text": f"ID: {user.id}"}
}
if user.activity:
if type(user.activity) == discord.Spotify:
embed_dict["fields"].append({"name": "Activity", "value": "Spotify", "inline": True})
embed_dict["fields"].append({"name": "Song", "value": f"{user.activity.title} - {', '.join(user.activity.artists)} - {user.activity.album}", "inline": True})
else:
embed_dict["fields"].append({"name": "Activity", "value": user.activity.name, "inline": True})
if user.premium_since:
embed_dict["fields"].append({"name": "Nitro Since", "value": datetime.strptime(str(user.premium_since), self.discord_time_format).strftime("%m/%d/%Y %H:%M"), "inline": True})
await ctx.send(embed=discord.Embed.from_dict(embed_dict))
@commands.command(name="ban", usage=f"{prefix}ban <user:user> [reason:str]")
@u.is_admin()
async def ban(self, ctx, user: discord.Member, reason: str = None):
"""
ban command
Args:
user (`discord.Member`): User to ban
reason (`str`, optional): Reason for ban. Defaults to `None`.
"""
def setup(bot):
bot.add_cog(admin(bot))