Misc: Remove Member Count, Remove f.Config.Guild

master
Marc Egerton 2020-12-29 07:57:33 +00:00
parent 8cc0c09db1
commit bc1a7952a3
6 changed files with 35 additions and 28 deletions

View File

@ -65,6 +65,8 @@ func main() {
// Enable Message Caching (Last 1024 Events) // Enable Message Caching (Last 1024 Events)
bot.State.MaxMessageCount = 1024 bot.State.MaxMessageCount = 1024
bot.State.TrackChannels = true
bot.State.TrackMembers = true
// Open Connection // Open Connection
err = bot.Open() err = bot.Open()
@ -73,12 +75,14 @@ func main() {
} }
// Setup Auth // Setup Auth
Config.Guild, err = bot.Guild(Config.GuildID) g, err := bot.Guild(Config.GuildID)
if err != nil { if err != nil {
log.Fatal("[!] Error: " + err.Error()) log.Fatal("[!] Error: " + err.Error())
} }
var p *permissions.Permissions var p *permissions.Permissions
p = permissions.New(&Config, Config.Guild) p = permissions.New(&Config, g)
Config.GuildName = g.Name
// Setup Handlers // Setup Handlers
f := features.Features{ f := features.Features{

View File

@ -160,7 +160,7 @@ func (f *Features) ProcessUserJoin(s *discordgo.Session, m *discordgo.GuildMembe
} }
for _, roleID := range f.Config.JoinRoleIDs { for _, roleID := range f.Config.JoinRoleIDs {
err = s.GuildMemberRoleAdd(f.Permissions.Guild.ID, m.User.ID, roleID) err = s.GuildMemberRoleAdd(f.Config.GuildID, m.User.ID, roleID)
if err != nil { if err != nil {
log.Print("[!] Error (User Join)" + err.Error()) log.Print("[!] Error (User Join)" + err.Error())
return err return err

View File

@ -250,7 +250,7 @@ func (f *Features) handleInfo(s *discordgo.Session, m *discordgo.MessageCreate)
desc += "**Language**: Go\n" desc += "**Language**: Go\n"
desc += "**Commands**: See `" + f.Config.CommandKey + "help`\n\n\n" desc += "**Commands**: See `" + f.Config.CommandKey + "help`\n\n\n"
gm, err := s.GuildMember(f.Config.Guild.ID, s.State.User.ID) gm, err := s.GuildMember(f.Config.GuildID, s.State.User.ID)
if err != nil { if err != nil {
return err return err
} }
@ -351,7 +351,7 @@ func (f *Features) handleRules(s *discordgo.Session, m *discordgo.MessageCreate)
} }
msg := f.Config.RulesText msg := f.Config.RulesText
embedTitle := "Rules (" + f.Config.Guild.Name + ")" embedTitle := "Rules (" + f.Config.GuildName + ")"
embed := f.CreateDefinedEmbed(embedTitle, msg, "success", m.Author) embed := f.CreateDefinedEmbed(embedTitle, msg, "success", m.Author)
_, err := s.ChannelMessageSendEmbed(m.ChannelID, embed) _, err := s.ChannelMessageSendEmbed(m.ChannelID, embed)
@ -579,7 +579,7 @@ func (f *Features) handleUserInfo(s *discordgo.Session, m *discordgo.MessageCrea
userSplit := strings.Split(m.Content, " ") userSplit := strings.Split(m.Content, " ")
if len(userSplit) < 2 { if len(userSplit) < 2 {
mHandle, err = s.GuildMember(f.Config.Guild.ID, m.Author.ID) mHandle, err = s.GuildMember(f.Config.GuildID, m.Author.ID)
requester = mHandle requester = mHandle
if err != nil { if err != nil {
return err return err
@ -588,11 +588,11 @@ func (f *Features) handleUserInfo(s *discordgo.Session, m *discordgo.MessageCrea
idStr := strings.ReplaceAll(userSplit[1], "<@!", "") idStr := strings.ReplaceAll(userSplit[1], "<@!", "")
idStr = strings.ReplaceAll(idStr, "<@", "") idStr = strings.ReplaceAll(idStr, "<@", "")
idStr = strings.ReplaceAll(idStr, ">", "") idStr = strings.ReplaceAll(idStr, ">", "")
mHandle, err = s.GuildMember(f.Config.Guild.ID, idStr) mHandle, err = s.GuildMember(f.Config.GuildID, idStr)
if err != nil { if err != nil {
return err return err
} }
requester, err = s.GuildMember(f.Config.Guild.ID, m.Author.ID) requester, err = s.GuildMember(f.Config.GuildID, m.Author.ID)
if err != nil { if err != nil {
return err return err
} }
@ -663,21 +663,28 @@ func (f *Features) handleUserInfo(s *discordgo.Session, m *discordgo.MessageCrea
} }
func (f *Features) handleServerInfo(s *discordgo.Session, m *discordgo.MessageCreate) error { func (f *Features) handleServerInfo(s *discordgo.Session, m *discordgo.MessageCreate) error {
sID := f.Config.Guild.ID g, err := s.Guild(f.Config.GuildID)
sName := f.Config.Guild.Name if err != nil {
sChannels := strconv.Itoa(len(f.Config.Guild.Channels)) return err
sEmojis := strconv.Itoa(len(f.Config.Guild.Emojis)) }
sMembers := strconv.Itoa(f.Config.Guild.MemberCount)
sRoles := strconv.Itoa(len(f.Config.Guild.Roles)) sID := f.Config.GuildID
sRegion := f.Config.Guild.Region sName := f.Config.GuildName
sJoinedAt, _ := f.Config.Guild.JoinedAt.Parse()
sIconURL := f.Config.Guild.IconURL() chans, _ := s.GuildChannels(f.Config.GuildID)
sChannels := strconv.Itoa(len(chans))
sEmojis := strconv.Itoa(len(g.Emojis))
sRoles := strconv.Itoa(len(g.Roles))
sRegion := g.Region
sJoinedAt, _ := g.JoinedAt.Parse()
sIconURL := g.IconURL()
user := m.Author user := m.Author
desc := "**Server ID**: `" + sID + "`\n" desc := "**Server ID**: `" + sID + "`\n"
desc += "**Server Name**: `" + sName + "`\n" desc += "**Server Name**: `" + sName + "`\n"
desc += "**Server Members**: `" + sMembers + "`\n"
desc += "**Server Channels**: `" + sChannels + "`\n" desc += "**Server Channels**: `" + sChannels + "`\n"
desc += "**Server Emojis**: `" + sEmojis + "`\n" desc += "**Server Emojis**: `" + sEmojis + "`\n"
desc += "**Server Roles**: `" + sRoles + "`\n" desc += "**Server Roles**: `" + sRoles + "`\n"
@ -708,7 +715,7 @@ func (f *Features) handleServerInfo(s *discordgo.Session, m *discordgo.MessageCr
msg := f.CreateCustomEmbed(&embedData) msg := f.CreateCustomEmbed(&embedData)
_, err := s.ChannelMessageSendEmbed(m.ChannelID, msg) _, err = s.ChannelMessageSendEmbed(m.ChannelID, msg)
if err != nil { if err != nil {
return err return err
} }

View File

@ -88,12 +88,12 @@ func (f *Features) handleKickUser(s *discordgo.Session, m *discordgo.MessageCrea
idStr := strings.ReplaceAll(member, "<@!", "") idStr := strings.ReplaceAll(member, "<@!", "")
idStr = strings.ReplaceAll(idStr, "<@", "") idStr = strings.ReplaceAll(idStr, "<@", "")
idStr = strings.ReplaceAll(idStr, ">", "") idStr = strings.ReplaceAll(idStr, ">", "")
mHandle, err = s.GuildMember(f.Config.Guild.ID, idStr) mHandle, err = s.GuildMember(f.Config.GuildID, idStr)
if err != nil { if err != nil {
return err return err
} }
err = s.GuildMemberDeleteWithReason(f.Config.Guild.ID, mHandle.User.ID, kickReason) err = s.GuildMemberDeleteWithReason(f.Config.GuildID, mHandle.User.ID, kickReason)
if err != nil { if err != nil {
return err return err
} }
@ -140,7 +140,7 @@ func (f *Features) handleBanUser(s *discordgo.Session, m *discordgo.MessageCreat
return err return err
} }
err = s.GuildBanCreateWithReason(f.Config.Guild.ID, mHandle.ID, banReason, 0) err = s.GuildBanCreateWithReason(f.Config.GuildID, mHandle.ID, banReason, 0)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,7 +1,5 @@
package models package models
import discordgo "github.com/bwmarrin/discord.go"
type ColorRole struct { type ColorRole struct {
Name string `json:"color"` Name string `json:"color"`
ID string `json:"id"` ID string `json:"id"`
@ -22,7 +20,8 @@ type CommandRestriction struct {
type Configuration struct { type Configuration struct {
CommandKey string `json:"command_key"` CommandKey string `json:"command_key"`
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`
GuildName string `json:"guild_name"`
StatusText string `json:"status_text"` StatusText string `json:"status_text"`
WelcomeText string `json:"welcome_text"` WelcomeText string `json:"welcome_text"`
@ -40,6 +39,5 @@ type Configuration struct {
LoggingChannel string `json:"logging_channel"` LoggingChannel string `json:"logging_channel"`
Guild *discordgo.Guild
ConfigPath string ConfigPath string
} }

View File

@ -14,7 +14,6 @@ type AdminRole struct {
type Permissions struct { type Permissions struct {
AdminRoles []AdminRole AdminRoles []AdminRole
CommandRestrictions []models.CommandRestriction CommandRestrictions []models.CommandRestriction
Guild *discordgo.Guild
Config *models.Configuration Config *models.Configuration
} }
@ -49,7 +48,6 @@ func New(config *models.Configuration, guild *discordgo.Guild) *Permissions {
AdminRoles: ars, AdminRoles: ars,
CommandRestrictions: crs, CommandRestrictions: crs,
Config: config, Config: config,
Guild: guild,
} }
} }