Passed
Push — master ( 58f506...9afc6c )
by Cyb3r
01:28 queued 11s
created

cogs.admin.AdminCog.check_admin()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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