added new tool function

This commit is contained in:
2024-03-05 14:38:28 +01:00
parent c90e2d59fc
commit 34b0f95464
6 changed files with 24 additions and 98 deletions

View File

@@ -53,13 +53,7 @@ var cmd_autojoinroles Command = Command{
} else if setAutoJoinRole(i.GuildID, option, role) {
content = "Deleted auto join role for " + option + "s"
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: content,
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, content)
purgeUnusedAutoJoinRoles(i.GuildID)
},
}

View File

@@ -11,30 +11,12 @@ var cmd_autopublish Command = Command{
channel, _ := s.State.Channel(i.ChannelID)
if channel.Type == discordgo.ChannelTypeGuildNews {
if toggleAutoPublish(i.GuildID, i.ChannelID) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Autopublishing is now disabled on <#" + i.ChannelID + ">",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Autopublishing is now disabled on <#"+i.ChannelID+">")
} else {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Autopublishing is now enabled on <#" + i.ChannelID + ">",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Autopublishing is now enabled on <#"+i.ChannelID+">")
}
} else {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "This is not an announcement channel!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "This is not an announcement channel!")
}
},
}

View File

@@ -118,13 +118,7 @@ var cmd_form Command = Command{
},
})
case "custom":
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Feature not available yet use `/form add` instead",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Feature not available yet use `/form add` instead")
case "add":
var title, formID, overwriteTitle, acceptChannelID string
var modsCanComment bool
@@ -186,24 +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)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Successfully added form button!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Successfully added form button!")
}
},
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")),
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, getFormType(strings.TrimPrefix(i.Interaction.MessageComponentData().CustomID, "form:")))
}
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
@@ -247,13 +229,7 @@ var cmd_form Command = Command{
},
ModalIDs: getFormTypes(),
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "The form data would be send to a specified channel. 🤲",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "The form data would be send to a specified channel. 🤲")
},
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
choices := []*discordgo.ApplicationCommandOptionChoice{

View File

@@ -53,21 +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)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "The sticky message was removed from this channel!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "The sticky message was removed from this channel!")
} else {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "This channel has no sticky message!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "This channel has no sticky message!")
}
}
},
@@ -86,21 +74,9 @@ var cmd_sticky Command = Command{
log.Println(err)
}
if addSticky(i.GuildID, i.ChannelID, text, message.ID) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Sticky message in this channel was updated!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Sticky message in this channel was updated!")
} else {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Message sticked to the channel!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Message sticked to the channel!")
}
},
}

View File

@@ -88,13 +88,7 @@ var cmd_tag Command = Command{
})
case "remove":
removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue())
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Tag removed!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Tag removed!")
}
},
ModalIDs: []string{"tag_add_modal"},
@@ -102,13 +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)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Tag \"" + tagName + "\" added!",
Flags: discordgo.MessageFlagsEphemeral,
},
})
respondEphemeral(s, i.Interaction, "Tag \""+tagName+"\" added!")
},
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
AutocompleteTag(s, i)

10
tool.go
View File

@@ -65,3 +65,13 @@ func hexToDecimal(hexColor string) int {
}
return int(decimal)
}
func respondEphemeral(s *discordgo.Session, interaction *discordgo.Interaction, content string) {
s.InteractionRespond(interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: content,
Flags: discordgo.MessageFlagsEphemeral,
},
})
}