Passed
Push — master ( eb55fd...7c4853 )
by Yohann
01:08
created

welcome_role   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A WorkerRole.on_member_update() 0 8 2
A WorkerRole.on_ready() 0 3 1
A WorkerRole.__init__() 0 4 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A setup() 0 2 1
1
from typing import Optional
2
3
from discord import TextChannel
4
from discord.ext import commands
5
6
from app.bot import Bot
7
8
CHANNEL_ID = 900370744263966821
9
ROLE_ID = 888527962935296091
10
11
12
class WorkerRole(commands.Cog):
13
    """A simple commands cog template."""
14
15
    def __init__(self, client: Bot):
16
        """Link to bot instance."""
17
        self.client: Bot = client
18
        self.channel: Optional[TextChannel] = None
19
20
    @commands.Cog.listener()
21
    async def on_ready(self):
22
        self.channel = self.client.guild.get_channel(CHANNEL_ID)
23
24
    @commands.Cog.listener()
25
    async def on_member_update(self, before, after):
26
        diff_roles = [
27
            role.id for role in after.roles if role not in before.roles
28
        ]
29
30
        if ROLE_ID in diff_roles:
31
            await self.channel.send(f"{after.mention}")
32
33
34
def setup(client: Bot):
35
    client.add_cog(WorkerRole(client))
36