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
|
|
|
async def cog_check(self, ctx: commands.Context):
|
32
|
|
|
"""cog_check
|
33
|
|
|
---
|
34
|
|
|
|
35
|
|
|
cog_check is set for the whole cog. Which makes all the commands in health admin only.
|
36
|
|
|
|
37
|
|
|
Arguments:
|
38
|
|
|
---
|
39
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
40
|
|
|
|
41
|
|
|
Returns:
|
42
|
|
|
bool -- True if the user in the bot admins
|
43
|
|
|
"""
|
44
|
|
|
return await utils.check_admin(ctx)
|
45
|
|
|
|
46
|
|
|
@commands.command(
|
47
|
|
|
name="list-admins", aliases=["ladmins", "ladmin"], help="List users that are bot admins",
|
48
|
|
|
)
|
49
|
|
|
async def list_admins(self, ctx: commands.Context):
|
50
|
|
|
"""List-admins
|
51
|
|
|
---
|
52
|
|
|
Command that returns a list of the users that are in the bot_admin table.
|
53
|
|
|
|
54
|
|
|
Arguments:
|
55
|
|
|
---
|
56
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
57
|
|
|
"""
|
58
|
|
|
fetched = [x for x in await utils.fetch("bot_admins", "name") if x != "CCC-Dev-Bot"]
|
59
|
|
|
embed = await utils.make_embed(ctx, send=False, title="Bot Admins:")
|
60
|
|
|
admins = ""
|
61
|
|
|
for admin in fetched:
|
62
|
|
|
admins += "- {} \n".format(admin)
|
63
|
|
|
embed.add_field(name="Admins", value=admins, inline=False)
|
64
|
|
|
await ctx.send(embed=embed)
|
65
|
|
|
|
66
|
|
|
@commands.command(
|
67
|
|
|
name="check-admin", aliases=["cadmin", "am-admin"], help="Tells you if you are a bot admin",
|
68
|
|
|
)
|
69
|
|
|
async def check_admin(self, ctx: commands.Context):
|
70
|
|
|
"""Check Admin
|
71
|
|
|
---
|
72
|
|
|
|
73
|
|
|
Tells the user if they are in the bot admin table. Only return true or false.
|
74
|
|
|
|
75
|
|
|
Arguments:
|
76
|
|
|
---
|
77
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
78
|
|
|
"""
|
79
|
|
|
await utils.make_embed(ctx, title=await utils.check_admin(ctx))
|
80
|
|
|
|
81
|
|
|
@commands.command(name="add-admin", help="Adds <user> to the bot admins table.")
|
82
|
|
|
@commands.check(utils.check_admin)
|
83
|
|
|
async def add_admin(self, ctx: commands.Context, *, user: str):
|
84
|
|
|
"""Add-Admin
|
85
|
|
|
---
|
86
|
|
|
|
87
|
|
|
Adds `user` to the bot admin table.
|
88
|
|
|
|
89
|
|
|
Arguments:
|
90
|
|
|
---
|
91
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
92
|
|
|
user {str} -- The name of the user that you want to add to the bot_admin table
|
93
|
|
|
"""
|
94
|
|
|
new_admin = discord.utils.get(ctx.guild.members, name=user)
|
95
|
|
|
if new_admin:
|
96
|
|
|
await utils.insert("bot_admins", [new_admin.name, new_admin.id])
|
97
|
|
|
await utils.make_embed(
|
98
|
|
|
ctx, color="28b463", title="User: {} is now an admin.".format(new_admin)
|
99
|
|
|
)
|
100
|
|
|
else:
|
101
|
|
|
await utils.make_embed(ctx, color="FF0000", title="Error: User not found.")
|
102
|
|
|
|
103
|
|
|
@commands.command(name="add-admin-channel", help="Marks the channel as an admin channel")
|
104
|
|
|
@commands.guild_only()
|
105
|
|
|
@commands.check(utils.check_admin)
|
106
|
|
|
async def add_admin_channel(self, ctx: commands.Context, log_status=False):
|
107
|
|
|
"""add-admin-channel
|
108
|
|
|
---
|
109
|
|
|
|
110
|
|
|
Adds the channel where the command was run to the admin_channel table.
|
111
|
|
|
By default it sets logging as false.
|
112
|
|
|
|
113
|
|
|
Arguments:
|
114
|
|
|
---
|
115
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
116
|
|
|
|
117
|
|
|
Keyword Arguments:
|
118
|
|
|
---
|
119
|
|
|
log_status {bool} -- [If the channel is for logging all users] (default: {False})
|
120
|
|
|
"""
|
121
|
|
|
log_status = bool(log_status)
|
122
|
|
|
await utils.insert("admin_channels", [ctx.channel.name, ctx.channel.id, log_status])
|
123
|
|
|
await utils.make_embed(
|
124
|
|
|
ctx,
|
125
|
|
|
color="28b463",
|
126
|
|
|
title="Admin Channel Success",
|
127
|
|
|
description="Channel has been added with log status: {}".format(log_status),
|
128
|
|
|
)
|
129
|
|
|
|
130
|
|
|
@commands.command(name="reload-extension", help="reloads <extension>")
|
131
|
|
|
async def reload_extension(self, ctx: commands.Context, extension: str):
|
132
|
|
|
"""reload_extension
|
133
|
|
|
---
|
134
|
|
|
|
135
|
|
|
Command that reloads an extension.
|
136
|
|
|
|
137
|
|
|
Arguments:
|
138
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
139
|
|
|
extension {str} -- extension to reload
|
140
|
|
|
"""
|
141
|
|
|
self.bot.reload_extension(extension)
|
142
|
|
|
await utils.make_embed(ctx, color="28b463", title="Reloaded")
|
143
|
|
|
|
144
|
|
|
@commands.command(name="update-list", help="Updates the school_list.csv")
|
145
|
|
|
async def refresh_list(self, ctx):
|
146
|
|
|
"""refresh_list
|
147
|
|
|
---
|
148
|
|
|
|
149
|
|
|
Arguments:
|
150
|
|
|
ctx {discord.ext.commands.Context} -- Context of the command.
|
151
|
|
|
"""
|
152
|
|
|
await utils.update_list(self)
|
153
|
|
|
self.bot.list_updated = datetime.utcnow()
|
154
|
|
|
await ctx.send("List updated")
|
155
|
|
|
|
156
|
|
|
|
157
|
|
|
def setup(bot):
|
158
|
|
|
"""Needed for extension loading"""
|
159
|
|
|
bot.add_cog(AdminCog(bot))
|
160
|
|
|
|