Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lets get some Voteythumbs in here #36

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions applications/votey_thumbs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package applications

import (
"github.com/aussiebroadwan/tony/framework"
"github.com/bwmarrin/discordgo"
)

func RegisterVoteyThumbsApp(bot *framework.Bot) framework.Route {
return framework.NewRoute(bot, "voteythumbs",
// voteythumbs
&VoteyThumbsCommand{},
)
}

type VoteyThumbsCommand struct {
framework.ApplicationCommand
}

func (vtc VoteyThumbsCommand) GetType() framework.AppType {
return framework.AppTypeCommand
}

func (vtc VoteyThumbsCommand) GetDefinition() *discordgo.ApplicationCommand {
return &discordgo.ApplicationCommand{
Name: "voteythumbs",
Description: "Respectfully debate things that probably don't matter",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "question",
Description: "The topic of debate",
Required: true,
},
},
}
}

func (vtc VoteyThumbsCommand) OnCommand(ctx framework.CommandContext) {
interaction := ctx.Interaction()
commandOptions := interaction.ApplicationCommandData().Options

// Get question that the user gave
question, err := framework.GetOption(commandOptions, "question")
if err != nil {
ctx.Session().InteractionRespond(ctx.Interaction(), &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: "**Error:** question is required",
},
})
return
}

// Send the question
ctx.Session().InteractionRespond(ctx.Interaction(), &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: question.StringValue(),
},
})

// Now get the ID for the interaction and react to it.
response, err := ctx.Session().InteractionResponse(ctx.Interaction())
if err != nil {
// If this happens, real chaos
ctx.Logger().Warn("Failed to get interaction response on VoteyThumbs.")
return
}

ctx.Session().MessageReactionAdd(response.ChannelID, response.ID, "👍")
ctx.Session().MessageReactionAdd(response.ChannelID, response.ID, "👎")
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func main() {
walletApp.RegisterWalletApp(bot),

app.RegisterPingApp(bot),
app.RegisterVoteyThumbsApp(bot),

remind.RegisterRemindApp(bot),
autopin.RegisterAutopinApp(bot),
Expand Down