|
| 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 | +} |
0 commit comments