sticky messages now work without a modal and also with a context menu
This commit is contained in:
@@ -12,46 +12,15 @@ var cmd_sticky Command = Command{
|
|||||||
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageMessages),
|
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageMessages),
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
Name: "add",
|
Name: "message",
|
||||||
Description: "Stick messages to the bottom of the current channel",
|
Description: "The message you want to stick to the bottom of this channel",
|
||||||
},
|
Required: false,
|
||||||
{
|
|
||||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
|
||||||
Name: "remove",
|
|
||||||
Description: "Remove the sticky message of the current channel",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
switch i.ApplicationCommandData().Options[0].Name {
|
if len(i.ApplicationCommandData().Options) == 0 {
|
||||||
case "add":
|
|
||||||
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
||||||
Type: discordgo.InteractionResponseModal,
|
|
||||||
Data: &discordgo.InteractionResponseData{
|
|
||||||
CustomID: "sticky_modal",
|
|
||||||
Title: "Sticky message",
|
|
||||||
Components: []discordgo.MessageComponent{
|
|
||||||
discordgo.ActionsRow{
|
|
||||||
Components: []discordgo.MessageComponent{
|
|
||||||
discordgo.TextInput{
|
|
||||||
CustomID: "sticky_modal_text",
|
|
||||||
Label: "Text",
|
|
||||||
Style: discordgo.TextInputParagraph,
|
|
||||||
Placeholder: "The message you want to stick to the bottom of this channel",
|
|
||||||
Required: true,
|
|
||||||
MaxLength: 2000,
|
|
||||||
Value: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
case "remove":
|
|
||||||
if hasSticky(i.GuildID, i.ChannelID) {
|
if hasSticky(i.GuildID, i.ChannelID) {
|
||||||
err := s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
|
err := s.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -68,32 +37,58 @@ var cmd_sticky Command = Command{
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
inputStickyMessage(i)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ModalIDs: []string{"sticky_modal"},
|
}
|
||||||
ModalSubmit: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
||||||
text := i.ModalSubmitData().Components[0].(*discordgo.ActionsRow).Components[0].(*discordgo.TextInput).Value
|
var context_sticky Command = Command{
|
||||||
message, err := s.ChannelMessageSendEmbed(i.ChannelID, &discordgo.MessageEmbed{
|
Definition: discordgo.ApplicationCommand{
|
||||||
|
Name: "Stick to channel",
|
||||||
|
Type: discordgo.MessageApplicationCommand,
|
||||||
|
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageMessages),
|
||||||
|
},
|
||||||
|
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
inputStickyMessage(i)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func inputStickyMessage(i *discordgo.InteractionCreate) {
|
||||||
|
var messageText string
|
||||||
|
if len(i.ApplicationCommandData().Options) == 0 {
|
||||||
|
messageText = i.ApplicationCommandData().Resolved.Messages[i.ApplicationCommandData().TargetID].Content //TODO add more data then just content
|
||||||
|
} else {
|
||||||
|
messageText = i.ApplicationCommandData().Options[0].StringValue()
|
||||||
|
}
|
||||||
|
message, err := bot.ChannelMessageSendEmbed(i.ChannelID, &discordgo.MessageEmbed{
|
||||||
Type: discordgo.EmbedTypeArticle,
|
Type: discordgo.EmbedTypeArticle,
|
||||||
Footer: &discordgo.MessageEmbedFooter{
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
Text: "📌 Sticky message",
|
Text: "📌 Sticky message",
|
||||||
},
|
},
|
||||||
Color: hexToDecimal(color["primary"]),
|
Color: hexToDecimal(color["primary"]),
|
||||||
Description: text,
|
Description: messageText,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
if addSticky(i.GuildID, i.ChannelID, text, message.ID) {
|
|
||||||
err := respond(i.Interaction, "Sticky message in this channel was updated!", true)
|
if hasSticky(i.GuildID, i.ChannelID) {
|
||||||
|
err = bot.ChannelMessageDelete(i.ChannelID, getStickyMessageID(i.GuildID, i.ChannelID))
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err, getStickyMessageID(i.GuildID, i.ChannelID))
|
||||||
|
}
|
||||||
|
removeSticky(i.GuildID, i.ChannelID)
|
||||||
|
addSticky(i.GuildID, i.ChannelID, messageText, message.ID)
|
||||||
|
err = respond(i.Interaction, "Sticky message in this channel was updated!", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
addSticky(i.GuildID, i.ChannelID, messageText, message.ID)
|
||||||
err := respond(i.Interaction, "Message sticked to the channel!", true)
|
err := respond(i.Interaction, "Message sticked to the channel!", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"form_type": "template_general",
|
|
||||||
"title": "Add a Sticky message",
|
|
||||||
"form": [
|
|
||||||
{
|
|
||||||
"label": "Content",
|
|
||||||
"is_paragraph": true,
|
|
||||||
"required": true,
|
|
||||||
"max_length": 2000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@@ -21,7 +21,7 @@ type Command struct {
|
|||||||
DynamicModalIDs func() []string
|
DynamicModalIDs func() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish}
|
var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish, context_sticky}
|
||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
logrus.Info("Starting up...")
|
logrus.Info("Starting up...")
|
||||||
|
@@ -131,20 +131,12 @@ func getTagContent(guildID string, tagID string) string {
|
|||||||
return tagContent
|
return tagContent
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSticky(guildID string, channelID string, messageContent string, messageID string) bool {
|
func addSticky(guildID string, channelID string, messageContent string, messageID string) {
|
||||||
exists := hasSticky(guildID, channelID)
|
|
||||||
if exists {
|
|
||||||
_, err := db.Exec("UPDATE sticky SET message_content = $1 WHERE guild_id = $2 AND channel_id = $3", messageContent, guildID, channelID)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_, err := db.Exec("INSERT INTO sticky (guild_id, channel_id, message_id, message_content) VALUES ($1, $2, $3, $4)", guildID, channelID, messageID, messageContent)
|
_, err := db.Exec("INSERT INTO sticky (guild_id, channel_id, message_id, message_content) VALUES ($1, $2, $3, $4)", guildID, channelID, messageID, messageContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return exists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasSticky(guildID string, channelID string) bool {
|
func hasSticky(guildID string, channelID string) bool {
|
||||||
|
Reference in New Issue
Block a user