rank   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

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

2 Methods

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

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
import cyberjake
5
6
7
class RankCog(commands.Cog, name="Rank"):
8
    """Rank Cog
9
    Cog that deals with rank commands
10
11
    **Commands:**
12
        - `add-rank`: Command that add either student, alumni, or professor role.
13
    """
14
15
    def __init__(self, bot):
16
        self.bot = bot
17
18
    @commands.command(name="add-rank", help="Assigns student, alumni or professor role.")
19
    @commands.has_role("verified")
20
    async def add_rank(self, ctx: commands.Context, *, rank: str) -> None:
21
        """Add Rank
22
23
        Allows users to set student, alumni or professor role.
24
25
        :param ctx: Command context
26
        :type ctx: discord.ext.commands.Context
27
        :param rank: Name of rank to add
28
        :type rank: str
29
        :return: None
30
        """
31
        user = ctx.message.author
32
        ranks = ["student", "professor", "alumni"]
33
        checked = [i for i in user.roles if i.name.lower() in ranks]
34
        if len(checked) > 0:
35
            await cyberjake.error_embed(ctx, "You already have a rank.")
36
        else:
37
            await user.add_roles(discord.utils.get(ctx.guild.roles, name=rank))
38
            await cyberjake.make_embed(
39
                ctx,
40
                color="28b463",
41
                title="Success",
42
                description="Rank assigned successfully",
43
            )
44
45
46
async def setup(bot):
47
    """Needed for extension loading"""
48
    await bot.add_cog(RankCog(bot))
49