Skip to content

Commit 9e10c16

Browse files
elias-knodelpascal-zarrad
authored andcommitted
feat(comp): add modal for event creation
1 parent e7a98c3 commit 9e10c16

File tree

5 files changed

+260
-58
lines changed

5 files changed

+260
-58
lines changed

components/events/command.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"github.com/lazybytez/jojo-discord-bot/api/slash_commands"
2525
)
2626

27-
var embedColor = 0xF9E2AF
28-
2927
var eventsCommand = &api.Command{
3028
Cmd: &discordgo.ApplicationCommand{
3129
Name: "events",
@@ -61,7 +59,7 @@ func handleEventsCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
6159

6260
func handleList(s *discordgo.Session, i *discordgo.InteractionCreate, _ *discordgo.ApplicationCommandInteractionDataOption) {
6361
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
64-
Type: discordgo.InteractionResponseChannelMessageWithSource,
62+
Type: discordgo.InteractionResponseDeferredMessageUpdate,
6563
Data: buildListEmbed(s),
6664
})
6765
}
@@ -120,7 +118,7 @@ func buildManageEmbed(s *discordgo.Session) *discordgo.InteractionResponseData {
120118
},
121119
discordgo.Button{
122120
Emoji: discordgo.ComponentEmoji{
123-
Name: "🗑",
121+
Name: "🗑",
124122
},
125123
Label: "Delete",
126124
Style: discordgo.DangerButton,
@@ -135,8 +133,3 @@ func buildManageEmbed(s *discordgo.Session) *discordgo.InteractionResponseData {
135133

136134
return resp
137135
}
138-
139-
/*func handleEventButtons(s *discordgo.Session, i *discordgo.InteractionCreate) {
140-
C.Logger().Info("Executed interaction")
141-
}
142-
*/

components/events/events.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import (
2323
"github.com/lazybytez/jojo-discord-bot/api"
2424
)
2525

26+
// All embeds sent by this component will have the specified embedColor
27+
var embedColor = 0xF9E2AF
28+
2629
// C is the instance of the component.
2730
// Can be used to register the component or get information about it.
2831
var C = api.Component{
@@ -44,7 +47,11 @@ func init() {
4447
// LoadComponent loads the Component
4548
func LoadComponent(_ *discordgo.Session) error {
4649
_ = C.SlashCommandManager().Register(eventsCommand)
50+
4751
_ = C.SlashCommandManager().RegisterMessageAction(messageActionEventCreate)
52+
_ = C.SlashCommandManager().RegisterMessageAction(messageActionEventCreateModal)
53+
_ = C.SlashCommandManager().RegisterMessageAction(messageActionEventCreateModalAfter)
54+
4855
_ = C.SlashCommandManager().RegisterMessageAction(messageActionEventEdit)
4956
_ = C.SlashCommandManager().RegisterMessageAction(messageActionEventDelete)
5057

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/*
2+
* JOJO Discord Bot - An advanced multi-purpose discord bot
3+
* Copyright (C) 2022 Lazy Bytez (Elias Knodel, Pascal Zarrad)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package events
20+
21+
import (
22+
"github.com/bwmarrin/discordgo"
23+
"github.com/lazybytez/jojo-discord-bot/api"
24+
"github.com/lazybytez/jojo-discord-bot/api/slash_commands"
25+
)
26+
27+
var messageActionEventCreate = &api.MessageAction{
28+
CustomID: "event_create",
29+
Handler: handleEventCreation,
30+
}
31+
32+
var messageActionEventCreateModal = &api.MessageAction{
33+
CustomID: "event_create_data_category",
34+
Handler: handleEventCreationModal,
35+
}
36+
37+
var messageActionEventCreateModalAfter = &api.MessageAction{
38+
CustomID: "event_creation_modal",
39+
Handler: handleEventCreationModalAfter,
40+
}
41+
42+
var messageActionEventEdit = &api.MessageAction{
43+
CustomID: "event_edit",
44+
Handler: handleEventEditing,
45+
}
46+
47+
var messageActionEventDelete = &api.MessageAction{
48+
CustomID: "event_delete",
49+
Handler: handleEventDeletion,
50+
}
51+
52+
func handleEventCreation(s *discordgo.Session, i *discordgo.InteractionCreate) {
53+
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
54+
Type: discordgo.InteractionResponseUpdateMessage,
55+
Data: buildCreationCategorySelectionEmbed(s, i),
56+
})
57+
}
58+
59+
func handleEventCreationModal(s *discordgo.Session, i *discordgo.InteractionCreate) {
60+
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
61+
Type: discordgo.InteractionResponseModal,
62+
Data: buildCreationModal(s, i),
63+
})
64+
}
65+
66+
func handleEventCreationModalAfter(s *discordgo.Session, i *discordgo.InteractionCreate) {
67+
// TODO: Create Channel with Event
68+
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
69+
Type: discordgo.InteractionResponseUpdateMessage,
70+
Data: buildCreationCategorySelectionEmbed(s, i),
71+
})
72+
}
73+
74+
func handleEventEditing(s *discordgo.Session, i *discordgo.InteractionCreate) {
75+
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
76+
Type: discordgo.InteractionResponseChannelMessageWithSource,
77+
Data: buildEditingEmbed(),
78+
})
79+
}
80+
81+
func handleEventDeletion(s *discordgo.Session, i *discordgo.InteractionCreate) {
82+
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
83+
Type: discordgo.InteractionResponseChannelMessageWithSource,
84+
Data: buildDeletionEmbed(),
85+
})
86+
}
87+
88+
func buildCreationCategorySelectionEmbed(s *discordgo.Session, i *discordgo.InteractionCreate) *discordgo.InteractionResponseData {
89+
resp := slash_commands.GenerateEphemeralInteractionResponseTemplate(
90+
":calendar_spiral: Create an Event",
91+
"Choose the category to create you Event in :point_down:")
92+
93+
cudButtons := []discordgo.MessageComponent{
94+
discordgo.ActionsRow{
95+
Components: []discordgo.MessageComponent{
96+
discordgo.SelectMenu{
97+
// Select menu, as other components, must have a customID, so we set it to this value.
98+
CustomID: "event_create_data_category",
99+
Placeholder: "Categories",
100+
Options: buildSelectMenuChannelOptions(s, i),
101+
},
102+
},
103+
},
104+
}
105+
106+
resp.Embeds[0].Color = embedColor
107+
resp.Components = cudButtons
108+
109+
return resp
110+
}
111+
112+
func buildSelectMenuChannelOptions(s *discordgo.Session, i *discordgo.InteractionCreate) []discordgo.SelectMenuOption {
113+
var resp []discordgo.SelectMenuOption
114+
115+
channels, _ := s.GuildChannels(i.GuildID)
116+
117+
for _, c := range channels {
118+
// Only category channel get processed
119+
if c.Type != discordgo.ChannelTypeGuildCategory {
120+
continue
121+
}
122+
123+
categoryChannelOption := discordgo.SelectMenuOption{
124+
Label: c.Name,
125+
Value: c.ID,
126+
}
127+
resp = append(resp, categoryChannelOption)
128+
}
129+
130+
return resp
131+
}
132+
133+
func buildCreationModal(s *discordgo.Session, i *discordgo.InteractionCreate) *discordgo.InteractionResponseData {
134+
resp := &discordgo.InteractionResponseData{
135+
CustomID: "event_creation_modal",
136+
Title: "Create an Event",
137+
Components: []discordgo.MessageComponent{
138+
discordgo.ActionsRow{
139+
Components: []discordgo.MessageComponent{
140+
discordgo.TextInput{
141+
CustomID: "event_create_data_name",
142+
Label: "Event Name",
143+
Style: discordgo.TextInputShort,
144+
Placeholder: "A short Event Name",
145+
Required: true,
146+
MaxLength: 24,
147+
MinLength: 1,
148+
},
149+
},
150+
},
151+
discordgo.ActionsRow{
152+
Components: []discordgo.MessageComponent{
153+
discordgo.TextInput{
154+
CustomID: "event_create_data_description",
155+
Label: "What is this event about?",
156+
Style: discordgo.TextInputParagraph,
157+
Placeholder: "An optional description about your event",
158+
Required: false,
159+
MaxLength: 500,
160+
},
161+
},
162+
},
163+
discordgo.ActionsRow{
164+
Components: []discordgo.MessageComponent{
165+
discordgo.TextInput{
166+
CustomID: "event_create_data_date",
167+
Label: "When does the Event start? (DD/MM/YYYY HH:mm)",
168+
Style: discordgo.TextInputShort,
169+
Placeholder: "DD/MM/YYYY HH:mm",
170+
Required: true,
171+
MaxLength: 16,
172+
MinLength: 16,
173+
},
174+
},
175+
},
176+
discordgo.ActionsRow{
177+
Components: []discordgo.MessageComponent{
178+
discordgo.TextInput{
179+
CustomID: "event_create_data_group_number",
180+
Label: "How many groups participate? ('1' - '99')",
181+
Style: discordgo.TextInputShort,
182+
Placeholder: "Enter a number from '1' - '99'",
183+
Value: "1",
184+
Required: false,
185+
MaxLength: 2,
186+
MinLength: 1,
187+
},
188+
},
189+
},
190+
discordgo.ActionsRow{
191+
Components: []discordgo.MessageComponent{
192+
discordgo.TextInput{
193+
CustomID: "event_create_data_group_size",
194+
Label: "How big are the groups? ('1' - '99')",
195+
Style: discordgo.TextInputShort,
196+
Placeholder: "Enter a number from '1' - '99'",
197+
Value: "10",
198+
Required: false,
199+
MaxLength: 2,
200+
MinLength: 1,
201+
},
202+
},
203+
},
204+
},
205+
}
206+
207+
return resp
208+
}
209+
210+
func buildEditingEmbed() *discordgo.InteractionResponseData {
211+
resp := slash_commands.GenerateEphemeralInteractionResponseTemplate(
212+
":calendar_spiral: Which Event do you want to edit? :wrench:",
213+
"Here are all the Events listed you can edit.\n")
214+
215+
eventsField := []*discordgo.MessageEmbedField{
216+
{
217+
Name: "Events",
218+
Value: "- <#1025840920404435045>: <t:1664634300:F>\n" +
219+
"- <#1025840920404435045>: <t:1664634300:F>\n" +
220+
"- <#1025840920404435045>: <t:1664634300:F>\n" +
221+
"- <#1025840920404435045>: <t:1664634300:F>\n",
222+
},
223+
}
224+
225+
resp.Embeds[0].Fields = eventsField
226+
resp.Embeds[0].Color = embedColor
227+
228+
return resp
229+
}
230+
231+
func buildDeletionEmbed() *discordgo.InteractionResponseData {
232+
resp := slash_commands.GenerateEphemeralInteractionResponseTemplate(
233+
":calendar_spiral: Which Event do you want to delete? :wastebasket:",
234+
"Here are all the Events listed you can delete.\n")
235+
236+
eventsField := []*discordgo.MessageEmbedField{
237+
{
238+
Name: "Events",
239+
Value: "- <#1025840920404435045>: <t:1664634300:F>\n" +
240+
"- <#1025840920404435045>: <t:1664634300:F>\n" +
241+
"- <#1025840920404435045>: <t:1664634300:F>\n" +
242+
"- <#1025840920404435045>: <t:1664634300:F>\n",
243+
},
244+
}
245+
246+
resp.Embeds[0].Fields = eventsField
247+
resp.Embeds[0].Color = embedColor
248+
249+
return resp
250+
}

components/events/message_actions.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

core_components/bot_core/guild_component_management.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
// handleInitialComponentStatusOnGuildJoin ensures that components that are enabled by default
26-
// are written to the database and - if newly written enabled by default .
26+
// are written to the database and - if newly written enabled by default.
2727
func handleInitialComponentStatusOnGuildJoin(_ *discordgo.Session, create *discordgo.GuildCreate) {
2828
em := C.EntityManager()
2929
guild, err := em.Guilds().Get(create.ID)

0 commit comments

Comments
 (0)