finished porting to disgo
This commit is contained in:
@@ -1,65 +1,67 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/events"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var cmd_autojoinroles Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
Name: "autojoinroles",
|
||||
Description: "Give users a role when they join",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "bot",
|
||||
Description: "Give bots a role when they join (Leave empty to remove current)",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
|
||||
Type: discordgo.ApplicationCommandOptionRole,
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionRole{
|
||||
Name: "role",
|
||||
Description: "The role bots should get when they join the server",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||
&discord.ApplicationCommandOptionSubCommand{
|
||||
Name: "user",
|
||||
Description: "Give users a role when they join (Leave empty to remove current)",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionRole,
|
||||
Options: []discord.ApplicationCommandOption{
|
||||
&discord.ApplicationCommandOptionRole{
|
||||
Name: "role",
|
||||
Description: "The role users should get when they join the server",
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
Interact: func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
var role string
|
||||
option := i.ApplicationCommandData().Options[0].Name
|
||||
option := *e.SlashCommandInteractionData().SubCommandName
|
||||
var content string
|
||||
if len(i.ApplicationCommandData().Options[0].Options) == 1 {
|
||||
var givenRole *discordgo.Role = i.ApplicationCommandData().Options[0].Options[0].RoleValue(s, i.GuildID)
|
||||
role = givenRole.ID
|
||||
botrole, err := getHighestRole(i.GuildID)
|
||||
if len(e.SlashCommandInteractionData().Options) == 1 {
|
||||
var givenRole discord.Role = e.SlashCommandInteractionData().Role("role")
|
||||
role = givenRole.ID.String()
|
||||
botrole, err := getHighestRole(e.GuildID().String(), e.Client())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if givenRole.Position >= botrole.Position {
|
||||
content = "<@&" + role + "> is not below the Bot's current highest role(<@&" + botrole.ID + ">). That makes it unable to manage it."
|
||||
content = "<@&" + role + "> is not below the Bot's current highest role(<@&" + botrole.ID.String() + ">). That makes it unable to manage it."
|
||||
} else {
|
||||
if setAutoJoinRole(i.GuildID, option, role) {
|
||||
if setAutoJoinRole(e.GuildID().String(), option, role) {
|
||||
content = "Updated auto join role for " + option + "s as <@&" + role + ">"
|
||||
} else {
|
||||
content = "Setup auto join role for " + option + "s as <@&" + role + ">"
|
||||
}
|
||||
}
|
||||
} else if setAutoJoinRole(i.GuildID, option, role) {
|
||||
} else if setAutoJoinRole(e.GuildID().String(), option, role) {
|
||||
content = "Deleted auto join role for " + option + "s"
|
||||
}
|
||||
err := respond(i.Interaction, content, true)
|
||||
if content == "" {
|
||||
content = "No auto join role set for " + option + "s to delete."
|
||||
}
|
||||
err := e.CreateMessage(discord.NewMessageCreateBuilder().SetContent(content).SetEphemeral(true).Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
purgeUnusedAutoJoinRoles(i.GuildID)
|
||||
purgeUnusedAutoJoinRoles(e.GuildID().String())
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
@@ -1,36 +1,41 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/events"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var cmd_autopublish Command = Command{
|
||||
Definition: discordgo.ApplicationCommand{
|
||||
Definition: discord.SlashCommandCreate{
|
||||
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) {
|
||||
err := respond(i.Interaction, "Autopublishing is now disabled on <#"+i.ChannelID+">", true)
|
||||
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||
channel := e.Channel()
|
||||
if channel.Type() == discord.ChannelTypeGuildNews {
|
||||
if toggleAutoPublish(e.GuildID().String(), e.Channel().ID().String()) {
|
||||
err := e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("Autopublishing is now disabled on " + discord.ChannelMention(e.Channel().ID())).SetEphemeral(true).
|
||||
Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
} else {
|
||||
err := respond(i.Interaction, "Autopublishing is now enabled on <#"+i.ChannelID+">", true)
|
||||
err := e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("Autopublishing is now enabled on " + discord.ChannelMention(e.Channel().ID())).SetEphemeral(true).
|
||||
Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err := respond(i.Interaction, "This is not an announcement channel!", true)
|
||||
err := e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||
SetContent("This is not an announcement channel!").SetEphemeral(true).
|
||||
Build())
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
28
handlers.go
28
handlers.go
@@ -26,7 +26,7 @@ type Command struct {
|
||||
AllowDM bool
|
||||
}
|
||||
|
||||
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form /*, cmd_autojoinroles, cmd_autopublish*/}
|
||||
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_autopublish, cmd_autojoinroles}
|
||||
|
||||
func ready(e *events.Ready) {
|
||||
logrus.Info("Starting up...")
|
||||
@@ -196,18 +196,19 @@ func messageCreate(e *events.MessageCreate) {
|
||||
updateStickyMessageID(e.Message.GuildID.String(), e.Message.ChannelID.String(), stickyMessage.ID.String())
|
||||
}
|
||||
}
|
||||
/*
|
||||
channel, _ := e.Channel()
|
||||
|
||||
if channel.Type() == discord.ChannelTypeGuildNews {
|
||||
if isAutopublishEnabled(e.GuildID.String(), e.ChannelID.String()) {
|
||||
_, err := e.Client().Rest().CrosspostMessage(e.ChannelID, e.MessageID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
channel, err := e.Client().Rest().GetChannel(e.Message.ChannelID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if channel != nil && channel.Type() == discord.ChannelTypeGuildNews {
|
||||
logrus.Debug("HERE")
|
||||
if isAutopublishEnabled(e.GuildID.String(), e.ChannelID.String()) {
|
||||
_, err := e.Client().Rest().CrosspostMessage(e.ChannelID, e.MessageID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func messageDelete(e *events.MessageDelete) { //TODO: also clear on bot start when message doesn't exist
|
||||
@@ -215,6 +216,7 @@ func messageDelete(e *events.MessageDelete) { //TODO: also clear on bot start wh
|
||||
}
|
||||
|
||||
func guildMemberJoin(e *events.GuildMemberJoin) {
|
||||
logrus.Debug("TESSST")
|
||||
role := getAutoJoinRole(e.GuildID.String(), e.Member.User.Bot)
|
||||
if role != "" {
|
||||
err := e.Client().Rest().AddMemberRole(e.GuildID, e.Member.User.ID, snowflake.MustParse(role))
|
||||
|
5
main.go
5
main.go
@@ -40,6 +40,7 @@ func main() {
|
||||
gateway.WithIntents(
|
||||
gateway.IntentGuilds,
|
||||
gateway.IntentGuildMessages,
|
||||
gateway.IntentGuildMembers,
|
||||
gateway.IntentDirectMessages,
|
||||
),
|
||||
),
|
||||
@@ -50,9 +51,7 @@ func main() {
|
||||
bot.WithEventListenerFunc(modalSubmitInteractionCreate),
|
||||
bot.WithEventListenerFunc(messageCreate),
|
||||
bot.WithEventListenerFunc(messageDelete),
|
||||
/*
|
||||
bot.WithEventListenerFunc(guildMemberJoin),
|
||||
*/
|
||||
bot.WithEventListenerFunc(guildMemberJoin),
|
||||
)
|
||||
if err != nil {
|
||||
logrus.Fatal("error creating Discord session,", err)
|
||||
|
Reference in New Issue
Block a user