added more tool functions
This commit is contained in:
20
cmd_ask.go
20
cmd_ask.go
@@ -16,19 +16,11 @@ var cmd_ask Command = Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.EmbedTypeImage,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Color: hexToDecimal(color["primary"]),
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Image: &discordgo.MessageEmbedImage{
|
||||||
{
|
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
|
||||||
Type: discordgo.EmbedTypeImage,
|
}}, false)
|
||||||
Color: hexToDecimal(color["primary"]),
|
|
||||||
Image: &discordgo.MessageEmbedImage{
|
|
||||||
URL: simpleGetFromAPI("image", "https://yesno.wtf/api").(string),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ var cmd_autojoinroles Command = Command{
|
|||||||
} else if setAutoJoinRole(i.GuildID, option, role) {
|
} else if setAutoJoinRole(i.GuildID, option, role) {
|
||||||
content = "Deleted auto join role for " + option + "s"
|
content = "Deleted auto join role for " + option + "s"
|
||||||
}
|
}
|
||||||
respondEphemeral(s, i.Interaction, content)
|
respond(s, i.Interaction, content, true)
|
||||||
purgeUnusedAutoJoinRoles(i.GuildID)
|
purgeUnusedAutoJoinRoles(i.GuildID)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -11,12 +11,12 @@ var cmd_autopublish Command = Command{
|
|||||||
channel, _ := s.State.Channel(i.ChannelID)
|
channel, _ := s.State.Channel(i.ChannelID)
|
||||||
if channel.Type == discordgo.ChannelTypeGuildNews {
|
if channel.Type == discordgo.ChannelTypeGuildNews {
|
||||||
if toggleAutoPublish(i.GuildID, i.ChannelID) {
|
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 {
|
} 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 {
|
} else {
|
||||||
respondEphemeral(s, i.Interaction, "This is not an announcement channel!")
|
respond(s, i.Interaction, "This is not an announcement channel!", true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
20
cmd_cat.go
20
cmd_cat.go
@@ -15,20 +15,12 @@ var cmd_cat Command = Command{
|
|||||||
Description: "Random cat pictures",
|
Description: "Random cat pictures",
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.EmbedTypeImage,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Color: hexToDecimal(color["primary"]),
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Image: &discordgo.MessageEmbedImage{
|
||||||
{
|
URL: GetCatImageURL(),
|
||||||
Type: discordgo.EmbedTypeImage,
|
}}, false)
|
||||||
Color: hexToDecimal(color["primary"]),
|
|
||||||
Image: &discordgo.MessageEmbedImage{
|
|
||||||
URL: GetCatImageURL(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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",
|
Description: "Gives you a random joke that is as bad as your dad would tell them",
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
respond(s, i.Interaction, simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string), false)
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Content: simpleGetFromAPI("joke", "https://icanhazdadjoke.com/").(string),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -118,7 +118,7 @@ var cmd_form Command = Command{
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
case "custom":
|
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":
|
case "add":
|
||||||
var title, formID, overwriteTitle, acceptChannelID string
|
var title, formID, overwriteTitle, acceptChannelID string
|
||||||
var modsCanComment bool
|
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)
|
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) {
|
ComponentInteract: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
if strings.HasPrefix(i.Interaction.MessageComponentData().CustomID, "form:") {
|
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" {
|
if i.Interaction.MessageComponentData().CustomID == "form_demo" {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
@@ -229,7 +229,7 @@ var cmd_form Command = Command{
|
|||||||
},
|
},
|
||||||
ModalIDs: getFormTypes(),
|
ModalIDs: getFormTypes(),
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
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) {
|
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
choices := []*discordgo.ApplicationCommandOptionChoice{
|
choices := []*discordgo.ApplicationCommandOptionChoice{
|
||||||
|
19
cmd_ping.go
19
cmd_ping.go
@@ -36,19 +36,10 @@ var cmd_ping Command = Command{
|
|||||||
} else {
|
} else {
|
||||||
ping_color = "red"
|
ping_color = "red"
|
||||||
}
|
}
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
respondEmbed(s, i.Interaction, discordgo.MessageEmbed{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Title: s.State.User.Username + " ping",
|
||||||
Data: &discordgo.InteractionResponseData{
|
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
|
||||||
Flags: discordgo.MessageFlagsEphemeral,
|
Type: discordgo.EmbedTypeArticle,
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Color: hexToDecimal(color[ping_color])}, true)
|
||||||
{
|
|
||||||
Title: s.State.User.Username + " ping",
|
|
||||||
Description: fmt.Sprintf("# %.2fms", ping.Seconds()*1000),
|
|
||||||
Type: discordgo.EmbedTypeArticle,
|
|
||||||
Color: hexToDecimal(color[ping_color]),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -53,9 +53,9 @@ var cmd_sticky Command = Command{
|
|||||||
if hasSticky(i.GuildID, i.ChannelID) {
|
if hasSticky(i.GuildID, i.ChannelID) {
|
||||||
s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
|
s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
|
||||||
removeSticky(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 {
|
} 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)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
if addSticky(i.GuildID, i.ChannelID, text, message.ID) {
|
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 {
|
} else {
|
||||||
respondEphemeral(s, i.Interaction, "Message sticked to the channel!")
|
respond(s, i.Interaction, "Message sticked to the channel!", true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
11
cmd_tag.go
11
cmd_tag.go
@@ -88,7 +88,7 @@ var cmd_tag Command = Command{
|
|||||||
})
|
})
|
||||||
case "remove":
|
case "remove":
|
||||||
removeTag(i.GuildID, i.ApplicationCommandData().Options[0].Options[0].StringValue())
|
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"},
|
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
|
tagName := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
||||||
tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
tagContent := i.ModalSubmitData().Components[1].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
||||||
addTag(i.GuildID, tagName, tagContent)
|
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) {
|
Autocomplete: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
AutocompleteTag(s, i)
|
AutocompleteTag(s, i)
|
||||||
@@ -126,12 +126,7 @@ var cmd_tag_short Command = Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTagCommand(s *discordgo.Session, i *discordgo.InteractionCreate, option *discordgo.ApplicationCommandInteractionDataOption) {
|
func GetTagCommand(s *discordgo.Session, i *discordgo.InteractionCreate, option *discordgo.ApplicationCommandInteractionDataOption) {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
respond(s, i.Interaction, getTagContent(i.GuildID, option.Value.(string)), false)
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
Content: getTagContent(i.GuildID, option.Value.(string)),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AutocompleteTag(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func AutocompleteTag(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
19
tool.go
19
tool.go
@@ -66,12 +66,27 @@ func hexToDecimal(hexColor string) int {
|
|||||||
return int(decimal)
|
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{
|
s.InteractionRespond(interaction, &discordgo.InteractionResponse{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Content: content,
|
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,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user