-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed_routine.py
More file actions
197 lines (177 loc) Β· 7.13 KB
/
embed_routine.py
File metadata and controls
197 lines (177 loc) Β· 7.13 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import discord
#API for this functionality
#To be called for a Message that is the !start command
async def start(message):
if '!start' == message.content.lower():
sessionMessage = await message.channel.send(embed = await embed_selector("start"))
for r in await embed_reaction_selector("start"):
await sessionMessage.add_reaction(r)
return
elif "!start dm" == message.content.lower():
sessionMessage = await message.channel.send(embed = await embed_selector("dm_start"))
for r in await embed_reaction_selector("dm_start"):
await sessionMessage.add_reaction(r)
return
return
async def edit(message,payload):
await edit_embed(message,payload)
return
#----------END of API-----------------------
#----------EMBED related code---------------
#EMBED GENERATORS
#The local embed types are strings for now.
#idea for a TODO - remake them as enums
#embedTypes = ["start","end","ERROR","dm_start","dm_colour_pick"]
#caller for all embed generators by type
async def embed_selector(type):
if "start" == type:
return await start_embed()
if "end" == type:
return await end_embed()
if "dm_start" == type:
return await start_dm_embed()
if "dm_colour_pick" == type:
return await colour_pick_dm_embed()
return
#a method to give the proper list of reactions for each embed type
async def embed_reaction_selector(type):
if "start" == type:
return ["π","π€","β","π€«"]
if "end" == type:
return []
if "dm_start" == type:
return ["π¨"]
if "dm_colour_pick" == type:
return ["π½","β€","π§‘","π","π","π","π"]
return
#a method to map the footer (unique ID) of an embed to it's type
async def embed_footer_to_type_selector(footer):
if footer == "Start of personal session":
return "start"
if footer == "End of personal session":
return "end"
if footer == "Start of private session":
return "dm_start"
if footer == "Colour settings of a private session":
return "dm_colour_pick"
return "ERROR"
#a method to make the proper change in embed upon a reaction
async def edit_embed(message,payload):
#get the old embed type
old_embed_type = await embed_footer_to_type_selector(message.embeds[0].footer.text)
#do not touch these ones, they aren't ours!
if old_embed_type == "ERROR":
return
#embed session was ended, pretent not to see it anymore
if old_embed_type == "end":
return
#make a decision for the next embed type, default is to stay with the current one
new_embed_type = old_embed_type
#make a decision for the embed color, default is to stay with the old one
new_embed_color = message.embeds[0].color
#check the emoji that was used - only unicode reactions can make a change in type
ems = str(payload.emoji)
if payload.emoji.is_unicode_emoji:
if ems == "β":
new_embed_type = "end"
elif old_embed_type == "start":
if ems == "π€«":
new_embed_type = "end"
dmSessionMessage = await payload.member.send(embed = await embed_selector("dm_start"))
for r in await embed_reaction_selector("dm_start"):
await dmSessionMessage.add_reaction(r)
elif old_embed_type == "dm_start":
if ems == "π¨":
new_embed_type = "dm_colour_pick"
elif old_embed_type == "dm_colour_pick":
new_embed_type = "dm_start"
if ems == "π½":
new_embed_color = 0xf5b7cd
elif ems == "β€":
new_embed_color = 0xeb1010
elif ems =="π§‘":
new_embed_color = 0xfc850d
elif ems == "π":
new_embed_color = 0xf5ed0f
elif ems =="π":
new_embed_color = 0x0ff51e
elif ems =="π":
new_embed_color = 0x0fcef5
elif ems == "π":
new_embed_color = 0x8605f0
#TODO - expand and change here as the embed types collection grows
#This is the actual logic spot of the embed session
#edit embed accordingly
if "dm" not in old_embed_type:
await message.clear_reactions()
newEmbed = await embed_selector(new_embed_type)
newEmbed.color = new_embed_color
await message.edit(embed = newEmbed)
for r in await embed_reaction_selector(new_embed_type):
await message.add_reaction(r)
else:
newEmbed = await embed_selector(new_embed_type)
newEmbed.color = new_embed_color
newMessage = await message.channel.send(embed = newEmbed)
for r in await embed_reaction_selector(new_embed_type):
await newMessage.add_reaction(r)
return
#----------------EMBED Creators----------------
#start of session
async def start_embed():
embed= discord.Embed(
title="Butler personal session",
description="Welcome to your personal session with Butler",
color=0xf5b7cd,
)
embed.add_field(
name= "Click on the reactions bellow to help me find you what you're looking for",
value= "π to change your colour in Discord\n"
"π€ to revert to the standard colour for your Discord rank\n"
"π€« to move this session into your private messages\n"
"β to close this session\n",
inline=False
)
embed.set_footer(text=("Start of personal session"))
return embed
#end of session
async def end_embed():
embed= discord.Embed(
title="Butler personal session",
description="Thank you for paying me a visit, my lovely friend!",
color=0xf5b7cd,
)
embed.set_footer(text=("End of personal session"))
return embed
async def start_dm_embed():
embed= discord.Embed(
title="Butler private session",
description="Welcome to your private session with Butler",
color=0xf5b7cd,
)
embed.add_field(
name= "Click on the reactions bellow to help me find you what you're looking for",
value= "π¨ to pick a new colour for this session\n",
inline=False
)
embed.set_footer(text=("Start of private session"))
return embed
async def colour_pick_dm_embed():
embed= discord.Embed(
title="Butler private session",
description="Welcome to your private session with Butler",
color=0xf5b7cd,
)
embed.add_field(
name= "Click on the reactions bellow to help me find you what you're looking for",
value= "π½ for piggy pink\n"
"β€ for red\n"
"π§‘ for organge\n"
"π for yellow\n"
"π for green\n"
"π for blue\n"
"π for purple\n",
inline=False
)
embed.set_footer(text=("Colour settings of a private session"))
return embed