renamed command variables and added autopublishing
This commit is contained in:
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var ask_command Command = Command{
|
||||
var cmd_ask Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "ask",
|
||||
Description: "Ask anything and get a gif as response!",
|
||||
|
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var autojoinroles_command Command = Command{
|
||||
var cmd_autojoinroles Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "autojoinroles",
|
||||
Description: "Give users a role when they join",
|
||||
|
40
cmd_autopublish.go
Normal file
40
cmd_autopublish.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
|
||||
var cmd_autopublish Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "autopublish",
|
||||
Description: "Toggle automatically publishing every post in a announcement channel",
|
||||
},
|
||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
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,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Autopublishing is now enabled on <#" + i.ChannelID + ">",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
}
|
||||
} else {
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "This is not an announcement channel!",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var cat_command Command = Command{
|
||||
var cmd_cat Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "cat",
|
||||
Description: "Random cat pictures",
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var dadjoke_command Command = Command{
|
||||
var cmd_dadjoke Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "dadjoke",
|
||||
Description: "Gives you a random joke that is as bad as your dad would tell them",
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
var fileData []byte
|
||||
|
||||
var form_command Command = Command{
|
||||
var cmd_form Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "form",
|
||||
Description: "Create custom forms right inside Discord",
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var ping_command Command = Command{
|
||||
var cmd_ping Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "ping",
|
||||
Description: "Returns the ping of the bot",
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var sticky_command Command = Command{
|
||||
var cmd_sticky Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "sticky",
|
||||
Description: "Stick messages to the bottom of the current channel",
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var tag_command Command = Command{
|
||||
var cmd_tag Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "tag",
|
||||
DefaultMemberPermissions: int64Ptr(discordgo.PermissionManageServer),
|
||||
@@ -115,7 +115,7 @@ var tag_command Command = Command{
|
||||
},
|
||||
}
|
||||
|
||||
var short_get_tag_command Command = Command{
|
||||
var cmd_tag_short Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Name: "g",
|
||||
Description: "A short command to get presaved messages.",
|
||||
|
@@ -20,7 +20,7 @@ type Command struct {
|
||||
ModalIDs []string
|
||||
}
|
||||
|
||||
var commands []Command = []Command{form_command, tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command, autojoinroles_command}
|
||||
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}
|
||||
|
||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||
fmt.Print("\nStarting up...")
|
||||
@@ -123,6 +123,12 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
updateStickyMessageID(m.GuildID, m.ChannelID, stickyMessage.ID)
|
||||
}
|
||||
}
|
||||
channel, _ := s.Channel(m.ChannelID)
|
||||
if channel.Type == discordgo.ChannelTypeGuildNews {
|
||||
if isAutopublishEnabled(m.GuildID, m.ChannelID) {
|
||||
s.ChannelMessageCrosspost(m.ChannelID, m.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func guildMemberJoin(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
||||
|
@@ -45,6 +45,11 @@ func initTables() {
|
||||
bot_role TEXT,
|
||||
user_role TEXT,
|
||||
PRIMARY KEY (guild_id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS autopublish (
|
||||
guild_id TEXT NOT NULL,
|
||||
news_channel_id TEXT NOT NULL,
|
||||
PRIMARY KEY (guild_id, news_channel_id)
|
||||
)
|
||||
`
|
||||
|
||||
@@ -282,3 +287,32 @@ func getAutoJoinRole(guildID string, isBot bool) string {
|
||||
}
|
||||
return role
|
||||
}
|
||||
|
||||
func toggleAutoPublish(guildID string, newsChannelID string) bool {
|
||||
var exists bool
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM autopublish WHERE guild_id = $1 AND news_channel_id = $2)", guildID, newsChannelID).Scan(&exists)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
if exists {
|
||||
_, err := db.Exec("DELETE FROM autopublish WHERE guild_id = $1 AND news_channel_id = $2", guildID, newsChannelID)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
} else {
|
||||
_, err := db.Exec("INSERT INTO autopublish (guild_id, news_channel_id) VALUES ($1, $2)", guildID, newsChannelID)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
return exists
|
||||
}
|
||||
|
||||
func isAutopublishEnabled(guildID string, newsChannelID string) bool {
|
||||
var enabled bool
|
||||
err := db.QueryRow("SELECT EXISTS (SELECT 1 FROM autopublish WHERE guild_id = $1 AND news_channel_id = $2)", guildID, newsChannelID).Scan(&enabled)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
Reference in New Issue
Block a user