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

bot.utils.shared   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 4

3 Functions

Rating   Name   Duplication   Size   Complexity  
A TF_emoji() 0 13 2
A check_react() 0 18 1
A check_admin() 0 14 1
1
"""Shared functions between cogs and main program"""
2
from .datahandler import fetch
3
4
5
class FailedReactionCheck(Exception):
6
    """FailedReactionCheck
7
    ---
8
    Exception if react checks fail
9
    """
10
11
12
async def check_admin(ctx) -> bool:
13
    """check_admin
14
    ---
15
    Checks to see if message author is in bot_admins
16
17
    Arguments:
18
    ---
19
        ctx {discord.ext.commands.Context} -- Context of which the check was called.
20
21
    Returns:
22
    ---
23
        bool -- Returns 'TRUE' if the message author is in bot_admins.
24
    """
25
    return ctx.message.author.id in [int(user_id) for user_id in await fetch("bot_admins", "id")]
26
27
28
async def TF_emoji(status: bool) -> str:
29
    """TF_emoji
30
31
    Returns string for emoji for true false.
32
33
    Arguments:
34
    ---
35
        status {bool} -- If the value is true
36
37
    Returns:
38
        str -- either a check mark or x emoji
39
    """
40
    return ":white_check_mark:" if status else ":x:"
41
42
43
async def check_react(ctx, user, reaction, expected_react: str):
44
    """check_reach
45
    ---
46
    Checks if the reaction on a message is correct and send by the same user that it was needed
47
        from.
48
49
    Arguments:
50
    ---
51
        ctx {discord.ext.commands.Context} -- Context of which the check was called.
52
        user {discord.User} -- User the reacted to the message
53
        reaction {discord.Reaction} -- The reaction that was added to the message
54
        expected_react {str} -- The desired reaction.
55
56
    Returns:
57
    ---
58
        bool -- Return 'TRUE' if it was the correct reaction from the correct user.
59
    """
60
    return user == ctx.author and str(reaction.emoji) == expected_react
61