continued porting to disgo
This commit is contained in:
46
handlers.go
46
handlers.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -28,28 +27,30 @@ var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag /*, cmd_f
|
|||||||
|
|
||||||
func ready(e *events.Ready) {
|
func ready(e *events.Ready) {
|
||||||
logrus.Info("Starting up...")
|
logrus.Info("Starting up...")
|
||||||
findAndDeleteUnusedMessages()
|
//findAndDeleteUnusedMessages()
|
||||||
removeOldCommandFromAllGuilds()
|
removeOldCommandFromAllGuilds()
|
||||||
var existingCommandNames []string
|
/*
|
||||||
existingCommands, err := client.Rest().GetGlobalCommands(app.Bot.ID, false)
|
var existingCommandNames []string
|
||||||
if err != nil {
|
existingCommands, err := client.Rest().GetGlobalCommands(client.ApplicationID(), false)
|
||||||
logrus.Errorf("error fetching existing global commands: %v", err)
|
if err != nil {
|
||||||
} else {
|
logrus.Errorf("error fetching existing global commands: %v", err)
|
||||||
for _, existingCommand := range existingCommands {
|
} else {
|
||||||
existingCommandNames = append(existingCommandNames, existingCommand.Name())
|
for _, existingCommand := range existingCommands {
|
||||||
}
|
existingCommandNames = append(existingCommandNames, existingCommand.Name())
|
||||||
}
|
|
||||||
for _, command := range commands {
|
|
||||||
if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update="+command.Definition.Name) || slices.Contains(os.Args, "--update=all") || slices.Contains(os.Args, "--clean") {
|
|
||||||
cmd, err := client.Rest().CreateGlobalCommand(app.Bot.ID, command.Definition)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Errorf("error creating global command '%s': %v", cmd.Name(), err)
|
|
||||||
} else {
|
|
||||||
logrus.Infof("Added global command '%s'", cmd.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for _, command := range commands {
|
||||||
logrus.Info("Successfully started the Bot!")
|
if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update="+command.Definition.Name) || slices.Contains(os.Args, "--update=all") || slices.Contains(os.Args, "--clean") {
|
||||||
|
cmd, err := client.Rest().CreateGlobalCommand(client.ApplicationID(), command.Definition)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error creating global command '%s': %v", cmd.Name(), err)
|
||||||
|
} else {
|
||||||
|
logrus.Infof("Added global command '%s'", cmd.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logrus.Info("Successfully started the Bot!")
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationCommandInteractionCreate(e *events.ApplicationCommandInteractionCreate) {
|
func applicationCommandInteractionCreate(e *events.ApplicationCommandInteractionCreate) {
|
||||||
@@ -137,7 +138,9 @@ func modalSubmitInteractionCreate(e *events.ModalSubmitInteractionCreate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeOldCommandFromAllGuilds() {
|
func removeOldCommandFromAllGuilds() {
|
||||||
|
logrus.Debug(app.Bot.ID.String())
|
||||||
globalCommands, err := client.Rest().GetGlobalCommands(app.Bot.ID, false)
|
globalCommands, err := client.Rest().GetGlobalCommands(app.Bot.ID, false)
|
||||||
|
logrus.Debug("HERE") //doesnt get called
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error fetching existing global commands: %v", err)
|
logrus.Errorf("error fetching existing global commands: %v", err)
|
||||||
return
|
return
|
||||||
@@ -146,11 +149,10 @@ func removeOldCommandFromAllGuilds() {
|
|||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
commandNames = append(commandNames, command.Definition.Name)
|
commandNames = append(commandNames, command.Definition.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, existingCommand := range globalCommands {
|
for _, existingCommand := range globalCommands {
|
||||||
if slices.Contains(commandNames, existingCommand.Name()) {
|
if slices.Contains(commandNames, existingCommand.Name()) {
|
||||||
logrus.Infof("Deleting command '%s'", existingCommand.Name())
|
logrus.Infof("Deleting command '%s'", existingCommand.Name())
|
||||||
err := client.Rest().DeleteGlobalCommand(app.Bot.ID, existingCommand.ID())
|
err := client.Rest().DeleteGlobalCommand(client.ApplicationID(), existingCommand.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error deleting command %s: %v", existingCommand.Name(), err)
|
logrus.Errorf("error deleting command %s: %v", existingCommand.Name(), err)
|
||||||
}
|
}
|
||||||
|
18
main.go
18
main.go
@@ -23,8 +23,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
app *discord.Application
|
|
||||||
client bot.Client
|
client bot.Client
|
||||||
|
app *discord.Application
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,13 +47,13 @@ func main() {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
bot.WithEventListenerFunc(ready),
|
bot.WithEventListenerFunc(ready),
|
||||||
bot.WithEventListenerFunc(applicationCommandInteractionCreate),
|
//bot.WithEventListenerFunc(applicationCommandInteractionCreate),
|
||||||
bot.WithEventListenerFunc(autocompleteInteractionCreate),
|
//bot.WithEventListenerFunc(autocompleteInteractionCreate),
|
||||||
bot.WithEventListenerFunc(componentInteractionCreate),
|
//bot.WithEventListenerFunc(componentInteractionCreate),
|
||||||
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)
|
||||||
@@ -66,7 +66,7 @@ func main() {
|
|||||||
logrus.Error("error opening connection,", err)
|
logrus.Error("error opening connection,", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app, err := client.Rest().GetCurrentApplication()
|
app, err = client.Rest().GetCurrentApplication()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
2
tool.go
2
tool.go
@@ -102,7 +102,7 @@ func getModalByFormID(formID string) ModalJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHighestRole(guildID string) (*discord.Role, error) {
|
func getHighestRole(guildID string) (*discord.Role, error) {
|
||||||
botmember, err := client.Rest().GetMember(snowflake.MustParse(guildID), app.Bot.ID)
|
botmember, err := client.Rest().GetMember(snowflake.MustParse(guildID), client.ApplicationID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user