forked from CodersClashS01/Kryptonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emojis.py
73 lines (57 loc) · 1.97 KB
/
emojis.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
66
67
68
69
70
71
72
73
"""
A little library for loading globally used emojis in the bot.
"""
from typing import List
from discord import Emoji, Guild
from discord.ext.commands import Bot
from config import config
class WrongEmoteException(Exception):
"""
Exception risen when an :class:`discord.Emote` is found with a wrong name
"""
class MissingEmoteException(Exception):
"""
Exception risen when an Emote is missing in an :class:`EmoteArsenal`
"""
class EmoteArsenal(object):
"""
Contains a full arsenal of emojis used globally by the bot
"""
horse: Emoji
money: Emoji
def verify(self):
"""
verifies this emote arsenal to contain all required emojis
:raises MissingEmoteException: if an emote is missing
:raises WrongEmtoeException: if a wrongly named emote is found
:return: this arsenal
"""
try:
if self.horse.name != 'horse':
raise WrongEmoteException
if self.money.name != 'money':
raise WrongEmoteException
except AttributeError:
raise MissingEmoteException
return self
def get_arsenal(bot: Bot, support_guild: int = config.support_guild, no_verify: bool = False) -> EmoteArsenal:
"""
Gets all emotes the bot will use globally in a handy object
:param bot: the bot that will be used to find emojis in the support guild
:param support_guild: the guild id where we will search for emojis
:raises MissingEmoteException: If an emote is missing in the support guild
:return: a full emote arsenal
"""
guild: Guild = bot.get_guild(support_guild)
if guild is None:
raise MissingEmoteException
emojis: List[Emoji] = guild.emojis
arsenal = EmoteArsenal()
for emoji in emojis:
if emoji.name == 'horse':
arsenal.horse = emoji
elif emoji.name == 'money':
arsenal.money = emoji
if not no_verify:
arsenal.verify()
return arsenal