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