| Total Complexity | 4 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Changes | 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 | 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 |