| Total Complexity | 4 |
| Total Lines | 68 |
| 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 | 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 |