chore: Fix bugs pointed out by linter

master
Luther Wen Xu 2020-05-31 11:23:23 +07:00
parent 2dc1c925ea
commit fa21b5abf6
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
4 changed files with 16 additions and 6 deletions

@ -14,7 +14,7 @@ var (
) )
func handleMacro(dg *discordgo.Session, m *discordgo.MessageCreate, split []string) { func handleMacro(dg *discordgo.Session, m *discordgo.MessageCreate, split []string) {
for k, _ := range split { for k := range split {
split[k] = strings.ToLower(split[k]) split[k] = strings.ToLower(split[k])
if val, ok := CommonReplacement[split[k]]; ok { if val, ok := CommonReplacement[split[k]]; ok {
split[k] = val split[k] = val

@ -18,5 +18,8 @@ func init() {
} }
func Close() { func Close() {
db.Close() err := db.Close()
if err != nil {
panic(err)
}
} }

@ -17,7 +17,7 @@ func QueueRoles(dg *discordgo.Session) {
for { for {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
for guildID, v := range ShouldCheck { for guildID, v := range ShouldCheck {
for userID, _ := range v { for userID := range v {
rank, _ := GetLevelFromXP(db.GetXP(userID)) rank, _ := GetLevelFromXP(db.GetXP(userID))
AssignRoles(dg, guildID, userID, rank) AssignRoles(dg, guildID, userID, rank)
delete(v, userID) delete(v, userID)
@ -46,6 +46,10 @@ OuterLoop:
continue OuterLoop continue OuterLoop
} }
} }
dg.GuildMemberRoleAdd(guildID, userID, Roles[i]) err := dg.GuildMemberRoleAdd(guildID, userID, Roles[i])
if err != nil {
util.ReportError(dg, err)
return
}
} }
} }

@ -42,8 +42,11 @@ func main() {
} }
fmt.Println("Bot is now running. Press CTRL-C to exit.") fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1) sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc <-sc
dg.Close() err = dg.Close()
if err != nil {
fmt.Println("error closing connection,", err)
}
db.Close() db.Close()
} }