Passed
Push — master ( e17e00...ecdb37 )
by Cyb3r
01:27
created

utils.shared.TF_emoji()   A

Complexity

Conditions 2

Size

Total Lines 19
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nop 1
dl 0
loc 19
rs 10
c 0
b 0
f 0
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
    returned = [int(user_id) for user_id in await fetch("bot_admins", "id")]
26
    return ctx.message.author.id in returned
27
28
29
async def TF_emoji(status: bool) -> str:
30
    """TF_emoji
31
32
    Returns string for emoji for true false.
33
34
    Arguments:
35
    ---
36
        status {bool} -- If the value is true
37
    Returns
38
    ---
39
        str -- String value of emoji
40
41
42
    Returns:
43
        str -- either a check mark or x emoji
44
    """
45
    if status:
46
        return ":white_check_mark:"
47
    return ":x:"
48
49
50
async def check_react(ctx, user, reaction, expected_react: str):
51
    """check_reach
52
    ---
53
    Checks if the reaction on a message is correct and send by the same user that it was needed
54
        from.
55
56
    Arguments:
57
    ---
58
        ctx {discord.ext.commands.Context} -- Context of which the check was called.
59
        user {discord.User} -- User the reacted to the message
60
        reaction {discord.Reaction} -- The reaction that was added to the message
61
        expected_react {str} -- The desired reaction.
62
63
    Returns:
64
    ---
65
        bool -- Return 'TRUE' if it was the correct reaction from the correct user.
66
    """
67
    return user == ctx.author and str(reaction.emoji) == expected_react
68