added more tool functions

This commit is contained in:
2024-03-05 21:31:44 +01:00
parent 34b0f95464
commit 0fd339dad3
10 changed files with 50 additions and 70 deletions

View File

@@ -16,19 +16,11 @@ var cmd_ask Command = Command{
},
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
},
},
},
},
})
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
}}, false)
},
}

View File

@@ -53,7 +53,7 @@ var cmd_autojoinroles Command = Command{
} else if setAutoJoinRole(i.GuildID, option, role) {
content = "Deleted auto join role for " + option + "s"
}
respondEphemeral(s, i.Interaction, content)
respond(s, i.Interaction, content, true)
purgeUnusedAutoJoinRoles(i.GuildID)
},
}

View File

@@ -11,12 +11,12 @@ var cmd_autopublish Command = Command{
channel, _ := s.State.Channel(i.ChannelID)
if channel.Type == discordgo.ChannelTypeGuildNews {
if toggleAutoPublish(i.GuildID, i.ChannelID) {
respondEphemeral(s, i.Interaction, "Autopublishing is now disabled on <#"+i.ChannelID+">")
respond(s, i.Interaction, "Autopublishing is now disabled on <#"+i.ChannelID+">", true)
} else {
respondEphemeral(s, i.Interaction, "Autopublishing is now enabled on <#"+i.ChannelID+">")
respond(s, i.Interaction, "Autopublishing is now enabled on <#"+i.ChannelID+">", true)
}
} else {
respondEphemeral(s, i.Interaction, "This is not an announcement channel!")
respond(s, i.Interaction, "This is not an announcement channel!", true)
}
},
}

View File

@@ -15,20 +15,12 @@ var cmd_cat Command = Command{
Description: "Random cat pictures",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: GetCatImageURL(),
},
},
},
},
})
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
Type: discordgo.EmbedTypeImage,
Color: hexToDecimal(color["primary"]),
Image: &discordgo.MessageEmbedImage{
URL: GetCatImageURL(),
}}, false)
},
}

View File

@@ -10,11 +10,6 @@ var cmd_dadjoke Command = Command{
Description: "Gives you a random joke that is as bad as your dad would tell them",
},
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string),
},
})
respond(s, i.Interaction, simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string), false)
},
}

View File

@@ -118,7 +118,7 @@ var cmd_form Command = Command{
},
})
case "custom":
respondEphemeral(s, i.Interaction, "Feature not available yet use `/form add` instead")
respond(s, i.Interaction, "Feature not available yet use `/form add` instead", true)
case "add":
var title, formID, overwriteTitle, acceptChannelID string
var modsCanComment bool
@@ -180,12 +180,12 @@ var cmd_form Command = Command{
},
})
addFormButton(i.GuildID, i.ChannelID, message.ID, formManageID.String(), formID, options.Options[0].ChannelValue(s).ID, overwriteTitle, acceptChannelID, modsCanComment)
respondEphemeral(s, i.Interaction, "Successfully added form button!")
respond(s, i.Interaction, "Successfully added form button!", true)
}
},
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
respondEphemeral(s, i.Interaction, getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")))
respond(s, i.Interaction, getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")), true)
}
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
@@ -229,7 +229,7 @@ var cmd_form Command = Command{
},
ModalIDs: getFormTypes(),
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
respondEphemeral(s, i.Interaction, "The form data would be send to a specified channel. 🤲")
respond(s, i.Interaction, "The form data would be send to a specified channel. 🤲", true)
},
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
choices := []*discordgo.ApplicationCommandOptionChoice{

View File

@@ -36,19 +36,10 @@ var cmd_ping Command = Command{
} else {
ping_color = "red"
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Embeds: []*discordgo.MessageEmbed{
{
Title: s.State.User.Username + " ping",
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
Type: discordgo.EmbedTypeArticle,
Color: hexToDecimal(color[ping_color]),
},
},
},
})
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
Title: s.State.User.Username + " ping",
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
Type: discordgo.EmbedTypeArticle,
Color: hexToDecimal(color[ping_color])}, true)
},
}

View File

@@ -53,9 +53,9 @@ var cmd_sticky Command = Command{
if hasSticky(i.GuildID, i.ChannelID) {
s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
removeSticky(i.GuildID, i.ChannelID)
respondEphemeral(s, i.Interaction, "The sticky message was removed from this channel!")
respond(s, i.Interaction, "The sticky message was removed from this channel!", true)
} else {
respondEphemeral(s, i.Interaction, "This channel has no sticky message!")
respond(s, i.Interaction, "This channel has no sticky message!", true)
}
}
},
@@ -74,9 +74,9 @@ var cmd_sticky Command = Command{
log.Println(err)
}
if addSticky(i.GuildID, i.ChannelID, text, message.ID) {
respondEphemeral(s, i.Interaction, "Sticky message in this channel was updated!")
respond(s, i.Interaction, "Sticky message in this channel was updated!", true)
} else {
respondEphemeral(s, i.Interaction, "Message sticked to the channel!")
respond(s, i.Interaction, "Message sticked to the channel!", true)
}
},
}

View File

@@ -88,7 +88,7 @@ var cmd_tag Command = Command{
})
case "remove":
removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue())
respondEphemeral(s, i.Interaction, "Tag removed!")
respond(s, i.Interaction, "Tag removed!", true)
}
},
ModalIDs: []string{"tag_add_modal"},
@@ -96,7 +96,7 @@ var cmd_tag Command = Command{
tagName := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
addTag(i.GuildID, tagName, tagContent)
respondEphemeral(s, i.Interaction, "Tag \""+tagName+"\" added!")
respond(s, i.Interaction, "Tag \""+tagName+"\" added!", true)
},
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
AutocompleteTag(s, i)
@@ -126,12 +126,7 @@ var cmd_tag_short Command = Command{
}
func GetTagCommand(s *discordgo.Session, i *discordgo.InteractionCreate, option *discordgo.ApplicationCommandInteractionDataOption) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: getTagContent(i.GuildID, option.Value.(string)),
},
})
respond(s, i.Interaction, getTagContent(i.GuildID, option.Value.(string)), false)
}
func AutocompleteTag(s *discordgo.Session, i *discordgo.InteractionCreate) {

19
tool.go
View File

@@ -66,12 +66,27 @@ func hexToDecimal(hexColor string) int {
return int(decimal)
}
func respondEphemeral(s *discordgo.Session, interaction *discordgo.Interaction, content string) {
func respond(s *discordgo.Session, interaction *discordgo.Interaction, content string, ephemeral bool) {
var flag discordgo.MessageFlags
if ephemeral {
flag = discordgo.MessageFlagsEphemeral
}
s.InteractionRespond(interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: content,
Flags: discordgo.MessageFlagsEphemeral,
Flags: flag,
},
})
}
func respondEmbed(s *discordgo.Session, interaction *discordgo.Interaction, embed discordgo.MessageEmbed, ephemeral bool) {
s.InteractionRespond(interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
&embed,
},
},
})
}