Passed
Pull Request — master (#50)
by Cyb3r
01:40
created

bot.cogs.rank   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A RankCog.__init__() 0 2 1
A RankCog.add_rank() 0 25 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A setup() 0 3 1
1
"""Rank features cog for CCC Bot"""
2
import discord.utils
3
from discord.ext import commands
4
from bot.utils import make_embed, error_message
5
6
7
class RankCog(commands.Cog, name="Rank"):
8
    """RankCog
9
    ---
10
11
    Cog that deals with rank commands
12
13
    Commands:
14
    ---
15
        `add-rank`: Command that add either student, alumni, or professor role.
16
17
    Arguments:
18
    ---
19
        bot {discord.commands.Bot} -- The bot
20
    """
21
22
    def __init__(self, bot):
23
        self.bot = bot
24
25
    @commands.command(name="add-rank", help="Assigns student, alumni or professor role.")
26
    @commands.has_role("verified")
27
    async def add_rank(self, ctx: commands.Context, *, rank: str):
28
        """Add_Rank
29
        ---
30
31
        Allows users to set student, alumni or professor role.
32
33
        Arguments:
34
        ---
35
            ctx {discord.ext.commands.Context} -- Context of the command.
36
            rank {str} -- name of rank to add.
37
        """
38
        user = ctx.message.author
39
        ranks = ["student", "professor", "alumni"]
40
        checked = [i for i in user.roles if i.name.lower() in ranks]
41
        if len(checked) > 0:
42
            await error_message(ctx, "You already have a rank.")
43
        else:
44
            await user.add_roles(discord.utils.get(ctx.guild.roles, name=rank))
45
            await make_embed(
46
                ctx,
47
                color="28b463",
48
                title="Success",
49
                description="Rank assigned successfully",
50
            )
51
52
53
def setup(bot):
54
    """Needed for extension loading"""
55
    bot.add_cog(RankCog(bot))
56