Skip to content

Commit

Permalink
Merge pull request #58 from zekroTJA/dev
Browse files Browse the repository at this point in the history
pre 0.12
  • Loading branch information
zekroTJA authored Apr 18, 2019
2 parents d4e5120 + 3d9e0af commit 571109d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
11 changes: 11 additions & 0 deletions internal/commands/cmdautorole.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"strings"
"time"

"github.com/zekroTJA/shinpuru/internal/core"
Expand Down Expand Up @@ -59,6 +60,16 @@ func (c *CmdAutorole) Exec(args *CommandArgs) error {
return err
}

if strings.ToLower(args.Args[0]) == "reset" {
err := args.CmdHandler.db.SetGuildAutoRole(args.Guild.ID, "")
if err != nil {
return err
}
_, err = util.SendEmbed(args.Session, args.Channel.ID,
"Autorole reseted.", "", util.ColorEmbedUpdated)
return err
}

newAutoRole, err := util.FetchRole(args.Session, args.Guild.ID, args.Args[0])
if err != nil {
msg, err := util.SendEmbedError(args.Session, args.Channel.ID,
Expand Down
11 changes: 8 additions & 3 deletions internal/listeners/jdoodle.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func (l *ListenerJdoodle) Handler(s *discordgo.Session, e *discordgo.MessageCrea
return
}

executor, _ := s.GuildMember(eReact.GuildID, eReact.UserID)

emb := &discordgo.MessageEmbed{
Color: util.ColorEmbedCyan,
Title: "Compilation Result",
Expand All @@ -237,9 +239,12 @@ func (l *ListenerJdoodle) Handler(s *discordgo.Session, e *discordgo.MessageCrea
Inline: true,
},
},
Footer: &discordgo.MessageEmbedFooter{
Text: "Provided by jdoodle.com",
},
}

if executor != nil {
emb.Footer = &discordgo.MessageEmbedFooter{
Text: "Executed by " + executor.User.String(),
}
}

s.ChannelMessageEditEmbed(resMsg.ChannelID, resMsg.ID, emb)
Expand Down
12 changes: 7 additions & 5 deletions internal/listeners/memberadd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func (l *ListenerMemberAdd) Handler(s *discordgo.Session, e *discordgo.GuildMemb
if err != nil && !core.IsErrDatabaseNotFound(err) {
util.Log.Errorf("Failed getting autorole for guild '%s' from database: %s", e.GuildID, err.Error())
}
err = s.GuildMemberRoleAdd(e.GuildID, e.User.ID, autoRoleID)
if err != nil && strings.Contains(err.Error(), `{"code": 10011, "message": "Unknown Role"}`) {
l.db.SetGuildAutoRole(e.GuildID, "")
} else if err != nil {
util.Log.Errorf("Failed setting autorole for member '%s': %s", e.User.ID, err.Error())
if autoRoleID != "" {
err = s.GuildMemberRoleAdd(e.GuildID, e.User.ID, autoRoleID)
if err != nil && strings.Contains(err.Error(), `{"code": 10011, "message": "Unknown Role"}`) {
l.db.SetGuildAutoRole(e.GuildID, "")
} else if err != nil {
util.Log.Errorf("Failed setting autorole for member '%s': %s", e.User.ID, err.Error())
}
}
}

0 comments on commit 571109d

Please sign in to comment.