1
|
|
|
"""Cog that has the admin features""" |
2
|
|
|
|
3
|
|
|
from datetime import datetime |
4
|
|
|
import discord.utils |
5
|
|
|
from discord.ext import commands |
6
|
|
|
import utils |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class AdminCog(commands.Cog, name="Admin"): |
10
|
|
|
"""AdminCog |
11
|
|
|
--- |
12
|
|
|
|
13
|
|
|
Cog that contains the commands for admin functions. |
14
|
|
|
|
15
|
|
|
Commands: |
16
|
|
|
--- |
17
|
|
|
`list-admins`: Sends a message that contain a list of the bot admin users. |
18
|
|
|
`am-admin`: Returns true of false depending on if the user is in the bot_admins table. |
19
|
|
|
`add-admin`: Add a user to the bot admin table. |
20
|
|
|
`add-admin-channel`: Add the channel that it was called in to the admin_channel table. |
21
|
|
|
`reload-extension`: Reloads the extensions names. |
22
|
|
|
|
23
|
|
|
Arguments: |
24
|
|
|
--- |
25
|
|
|
bot {discord.commands.Bot} -- The bot |
26
|
|
|
""" |
27
|
|
|
|
28
|
|
|
def __init__(self, bot): |
29
|
|
|
self.bot = bot |
30
|
|
|
|
31
|
|
|
@commands.command( |
32
|
|
|
name="list-admins", aliases=["ladmins", "ladmin"], help="List users that are bot admins", |
33
|
|
|
) |
34
|
|
|
async def list_admins(self, ctx: commands.Context): |
35
|
|
|
"""List-admins |
36
|
|
|
--- |
37
|
|
|
Command that returns a list of the users that are in the bot_admin table. |
38
|
|
|
|
39
|
|
|
Arguments: |
40
|
|
|
--- |
41
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
42
|
|
|
""" |
43
|
|
|
fetched = [x for x in await utils.fetch("bot_admins", "name") if x != "CCC-Dev-Bot"] |
44
|
|
|
embed = await utils.make_embed(ctx, send=False, title="Bot Admins:") |
45
|
|
|
admins = "" |
46
|
|
|
for admin in fetched: |
47
|
|
|
admins += "- {} \n".format(admin) |
48
|
|
|
embed.add_field(name="Admins", value=admins, inline=False) |
49
|
|
|
await ctx.send(embed=embed) |
50
|
|
|
|
51
|
|
|
@commands.command( |
52
|
|
|
name="check-admin", aliases=["cadmin", "am-admin"], help="Tells you if you are a bot admin", |
53
|
|
|
) |
54
|
|
|
async def check_admin(self, ctx: commands.Context): |
55
|
|
|
"""Check Admin |
56
|
|
|
--- |
57
|
|
|
|
58
|
|
|
Tells the user if they are in the bot admin table. Only return true or false. |
59
|
|
|
|
60
|
|
|
Arguments: |
61
|
|
|
--- |
62
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
63
|
|
|
""" |
64
|
|
|
await utils.make_embed(ctx, title=await utils.check_admin(ctx)) |
65
|
|
|
|
66
|
|
|
@commands.command(name="add-admin", help="Adds <user> to the bot admins table.") |
67
|
|
|
@commands.check(utils.check_admin) |
68
|
|
|
async def add_admin(self, ctx: commands.Context, *, user: str): |
69
|
|
|
"""Add-Admin |
70
|
|
|
--- |
71
|
|
|
|
72
|
|
|
Adds `user` to the bot admin table. |
73
|
|
|
|
74
|
|
|
Arguments: |
75
|
|
|
--- |
76
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
77
|
|
|
user {str} -- The name of the user that you want to add to the bot_admin table |
78
|
|
|
""" |
79
|
|
|
new_admin = discord.utils.get(ctx.guild.members, name=user) |
80
|
|
|
if new_admin: |
81
|
|
|
await utils.insert("bot_admins", [new_admin.name, new_admin.id]) |
82
|
|
|
await utils.make_embed( |
83
|
|
|
ctx, color="28b463", title="User: {} is now an admin.".format(new_admin) |
84
|
|
|
) |
85
|
|
|
else: |
86
|
|
|
await utils.make_embed(ctx, color="FF0000", title="Error: User not found.") |
87
|
|
|
|
88
|
|
|
@commands.command(name="add-admin-channel", help="Marks the channel as an admin channel") |
89
|
|
|
@commands.guild_only() |
90
|
|
|
@commands.check(utils.check_admin) |
91
|
|
|
async def add_admin_channel(self, ctx: commands.Context, log_status=False): |
92
|
|
|
"""add-admin-channel |
93
|
|
|
--- |
94
|
|
|
|
95
|
|
|
Adds the channel where the command was run to the admin_channel table. |
96
|
|
|
By default it sets logging as false. |
97
|
|
|
|
98
|
|
|
Arguments: |
99
|
|
|
--- |
100
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
101
|
|
|
|
102
|
|
|
Keyword Arguments: |
103
|
|
|
--- |
104
|
|
|
log_status {bool} -- [If the channel is for logging all users] (default: {False}) |
105
|
|
|
""" |
106
|
|
|
log_status = bool(log_status) |
107
|
|
|
await utils.insert("admin_channels", [ctx.channel.name, ctx.channel.id, log_status]) |
108
|
|
|
await utils.make_embed( |
109
|
|
|
ctx, |
110
|
|
|
color="28b463", |
111
|
|
|
title="Admin Channel Success", |
112
|
|
|
description="Channel has been added with log status: {}".format(log_status), |
113
|
|
|
) |
114
|
|
|
|
115
|
|
|
@commands.command(name="reload-extension", help="reloads <extension>") |
116
|
|
|
async def reload_extension(self, ctx: commands.Context, extension: str): |
117
|
|
|
"""reload_extension |
118
|
|
|
--- |
119
|
|
|
|
120
|
|
|
Command that reloads an extension. |
121
|
|
|
|
122
|
|
|
Arguments: |
123
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
124
|
|
|
extension {str} -- extension to reload |
125
|
|
|
""" |
126
|
|
|
self.bot.reload_extension(extension) |
127
|
|
|
await utils.make_embed(ctx, color="28b463", title="Reloaded") |
128
|
|
|
|
129
|
|
|
@commands.command(name="update-list", help="Updates the school_list.csv") |
130
|
|
|
async def refresh_list(self, ctx): |
131
|
|
|
"""refresh_list |
132
|
|
|
--- |
133
|
|
|
|
134
|
|
|
Arguments: |
135
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command. |
136
|
|
|
""" |
137
|
|
|
await utils.update_list(self) |
138
|
|
|
self.bot.list_updated = datetime.utcnow() |
139
|
|
|
await ctx.send("List updated") |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
def setup(bot): |
143
|
|
|
"""Needed for extension loading""" |
144
|
|
|
bot.add_cog(AdminCog(bot)) |
145
|
|
|
|