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
|
|
|
**Asynchronous Function** |
18
|
|
|
|
19
|
|
|
Checks to see if message author is in bot_admins table |
20
|
|
|
|
21
|
|
|
:param ctx: |
22
|
|
|
:type ctx: discord.ext.commands.Context |
23
|
|
|
:return: Message author is in bot_admins. |
24
|
|
|
:rtype: bool |
25
|
|
|
""" |
26
|
|
|
return ctx.message.author.id in [int(user_id) for user_id in await fetch("bot_admins", "id")] |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
async def TF_emoji(status: bool) -> str: |
30
|
|
|
"""True or False emoji |
31
|
|
|
|
32
|
|
|
**Asynchronous Function** |
33
|
|
|
|
34
|
|
|
:param status: Return the true value emoji |
35
|
|
|
:type status: bool |
36
|
|
|
:return: Check mark or X |
37
|
|
|
:rtype str: |
38
|
|
|
""" |
39
|
|
|
return ":white_check_mark:" if status else ":x:" |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
async def check_react( |
43
|
|
|
ctx, member: discord.Member, reaction: discord.Reaction, expected_react: str |
44
|
|
|
) -> bool: |
45
|
|
|
"""Check reaction |
46
|
|
|
|
47
|
|
|
**Asynchronous Function** |
48
|
|
|
|
49
|
|
|
Checks if the reaction on a message is correct and send by the same member that it was needed |
50
|
|
|
from. |
51
|
|
|
|
52
|
|
|
:param ctx: Message context |
53
|
|
|
:param member: Member who reacted to the message |
54
|
|
|
:type member: discord.Member |
55
|
|
|
:param reaction: Reaction that was added to the message |
56
|
|
|
:type reaction: discord.Reaction |
57
|
|
|
:param expected_react: String of wanted reaction |
58
|
|
|
:type expected_react: str |
59
|
|
|
:return: Correct reaction from the correct member. |
60
|
|
|
:rtype bool: |
61
|
|
|
""" |
62
|
|
|
return member == ctx.author and str(reaction.emoji) == expected_react |
63
|
|
|
|