now blocking autojoinroles with missing permissions
This commit is contained in:
@@ -38,11 +38,17 @@ var autojoinroles_command Command = Command{
|
|||||||
option := i.ApplicationCommandData().Options[0].Name
|
option := i.ApplicationCommandData().Options[0].Name
|
||||||
var content string
|
var content string
|
||||||
if len(i.ApplicationCommandData().Options[0].Options) == 1 {
|
if len(i.ApplicationCommandData().Options[0].Options) == 1 {
|
||||||
role = i.ApplicationCommandData().Options[0].Options[0].RoleValue(s, i.GuildID).ID
|
var givenRole *discordgo.Role = i.ApplicationCommandData().Options[0].Options[0].RoleValue(s, i.GuildID)
|
||||||
if setAutoJoinRole(i.GuildID, option, role) {
|
role = givenRole.ID
|
||||||
content = "Updated auto join role for " + option + "s as <@&" + role + ">"
|
botrole, _ := getHighestRole(s, i.GuildID)
|
||||||
|
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."
|
||||||
} else {
|
} else {
|
||||||
content = "Setup auto join role for " + option + "s as <@&" + role + ">"
|
if setAutoJoinRole(i.GuildID, 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(i.GuildID, option, role) {
|
||||||
content = "Deleted auto join role for " + option + "s"
|
content = "Deleted auto join role for " + option + "s"
|
||||||
|
16
main.go
16
main.go
@@ -5,8 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@@ -55,17 +53,3 @@ func main() {
|
|||||||
fmt.Println("\nShutting down...")
|
fmt.Println("\nShutting down...")
|
||||||
discord.Close()
|
discord.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func int64Ptr(i int64) *int64 {
|
|
||||||
return &i
|
|
||||||
}
|
|
||||||
|
|
||||||
func hexToDecimal(hexColor string) int {
|
|
||||||
// Remove the hash symbol if it's present
|
|
||||||
hexColor = strings.TrimPrefix(hexColor, "#")
|
|
||||||
decimal, err := strconv.ParseInt(hexColor, 16, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return int(decimal)
|
|
||||||
}
|
|
||||||
|
47
tool.go
47
tool.go
@@ -1,6 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
type ModalJsonField struct {
|
type ModalJsonField struct {
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
@@ -20,5 +26,42 @@ type ModalJson struct {
|
|||||||
func jsonStringShowModal(jsonString string, id string) {
|
func jsonStringShowModal(jsonString string, id string) {
|
||||||
var modal ModalJson
|
var modal ModalJson
|
||||||
json.Unmarshal([]byte(jsonString), &modal)
|
json.Unmarshal([]byte(jsonString), &modal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHighestRole(s *discordgo.Session, guildID string) (*discordgo.Role, error) {
|
||||||
|
botMember, err := s.GuildMember(guildID, s.State.User.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
roles, err := s.GuildRoles(guildID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var highestRole *discordgo.Role
|
||||||
|
for _, roleID := range botMember.Roles {
|
||||||
|
for _, role := range roles {
|
||||||
|
if role.ID == roleID {
|
||||||
|
if highestRole == nil || role.Position > highestRole.Position {
|
||||||
|
highestRole = role
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highestRole, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func int64Ptr(i int64) *int64 {
|
||||||
|
return &i
|
||||||
|
}
|
||||||
|
|
||||||
|
func hexToDecimal(hexColor string) int {
|
||||||
|
// Remove the hash symbol if it's present
|
||||||
|
hexColor = strings.TrimPrefix(hexColor, "#")
|
||||||
|
decimal, err := strconv.ParseInt(hexColor, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(decimal)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user