-
Notifications
You must be signed in to change notification settings - Fork 0
/
other.py
65 lines (52 loc) · 1.78 KB
/
other.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
This module is used for some other functions and errors used in the bot.py module.
"""
import config
import discord
import re
from discord.ext import commands
# Functions
def is_admin(member: discord.Member):
"""
Verifies that the member has any of the admin roles.
Attributes:
member (discord.Member): The member to be verified.
Returns:
None
"""
# Loop though every role of the member. Set status to True if he has any of the admin roles.
status = False
for role in member.roles:
if role.id in config.BOT_ADMIN_ROLES:
status = True
break
if not status:
raise discord.ext.commands.MissingAnyRole(
config.BOT_ADMIN_ROLES) # Raise MissingAnyRole if the member hasn't any of the admin roles.
def check_giveaway_msg(msg: discord.Message, active: bool, bot: discord.User) -> bool:
if msg.channel.id != config.GIVEAWAY_CHANNEL.id or msg.author.id != bot:
return False
if len(msg.embeds) == 0:
return False
pattern = r"([^|]+) \| ([^:]+):$" # The pattern of the regex.
status = re.search(pattern, msg.embeds[0].footer).group(2)
if active:
if status == "Ends":
return True
elif not active:
if status == "Ended":
return True
return False
# Errors
class IncorrectUsageError(commands.CommandError):
"""
This error gets raised only in the create giveaway function (found in the main file).
It gets raised when the regex can't define any of the arguments.
"""
pass
class InexistentMessageError(commands.CommandError):
"""
This error gets raised only in the reroll function (found in the main file).
It gets raised when the discord API can't find any message with the given ID
"""
pass