Total Complexity | 4 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """Shared functions between cogs and main program""" |
||
2 | import discord |
||
3 | |||
4 | from .datahandler import fetch |
||
5 | |||
6 | |||
7 | class FailedReactionCheck(Exception): |
||
8 | """FailedReactionCheck |
||
9 | --- |
||
10 | Exception if react checks fail |
||
11 | """ |
||
12 | |||
13 | |||
14 | async def check_admin(ctx) -> bool: |
||
15 | """Check Admin |
||
16 | |||
17 | Checks to see if message author is in bot_admins table |
||
18 | |||
19 | :param ctx: |
||
20 | :type ctx: discord.ext.commands.Context |
||
21 | :return: Message author is in bot_admins. |
||
22 | :rtype: bool |
||
23 | """ |
||
24 | return ctx.message.author.id in [int(user_id) for user_id in await fetch("bot_admins", "id")] |
||
25 | |||
26 | |||
27 | async def TF_emoji(status: bool) -> str: |
||
28 | """True or False emoji |
||
29 | |||
30 | :param status: Return the true value emoji |
||
31 | :type status: bool |
||
32 | :return: Check mark or X |
||
33 | :rtype str: |
||
34 | """ |
||
35 | return ":white_check_mark:" if status else ":x:" |
||
36 | |||
37 | |||
38 | async def check_react( |
||
39 | ctx, member: discord.Member, reaction: discord.Reaction, expected_react: str |
||
40 | ) -> bool: |
||
41 | """Check reaction |
||
42 | |||
43 | Checks if the reaction on a message is correct and send by the same member that it was needed |
||
44 | from. |
||
45 | |||
46 | :param ctx: Message context |
||
47 | :param member: Member who reacted to the message |
||
48 | :type member: discord.Member |
||
49 | :param reaction: Reaction that was added to the message |
||
50 | :type reaction: discord.Reaction |
||
51 | :param expected_react: String of wanted reaction |
||
52 | :type expected_react: str |
||
53 | :return: Correct reaction from the correct member. |
||
54 | :rtype bool: |
||
55 | """ |
||
56 | return member == ctx.author and str(reaction.emoji) == expected_react |
||
57 |