Total Complexity | 4 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
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 | """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 | :param rank: Name of rank to add |
||
27 | :type rank: str |
||
28 | :return: None |
||
29 | """ |
||
30 | user = ctx.message.author |
||
31 | ranks = ["student", "professor", "alumni"] |
||
32 | checked = [i for i in user.roles if i.name.lower() in ranks] |
||
33 | if len(checked) > 0: |
||
34 | await error_message(ctx, "You already have a rank.") |
||
35 | else: |
||
36 | await user.add_roles(discord.utils.get(ctx.guild.roles, name=rank)) |
||
37 | await make_embed( |
||
38 | ctx, |
||
39 | color="28b463", |
||
40 | title="Success", |
||
41 | description="Rank assigned successfully", |
||
42 | ) |
||
43 | |||
44 | |||
45 | def setup(bot): |
||
46 | """Needed for extension loading""" |
||
47 | bot.add_cog(RankCog(bot)) |
||
48 |