Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Dec 31, 2018
2 parents 87d0928 + 0f0753d commit 50d8a2f
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 7 deletions.
118 changes: 118 additions & 0 deletions commands/cmdban.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package commands

import (
"fmt"
"strings"
"time"

"github.com/bwmarrin/discordgo"
"github.com/zekroTJA/shinpuru/util"
)

type CmdBan struct {
}

func (c *CmdBan) GetInvokes() []string {
return []string{"ban", "userban"}
}

func (c *CmdBan) GetDescription() string {
return "ban users with creating a report entry"
}

func (c *CmdBan) GetHelp() string {
return "`ban <UserResolvable> <Reason>`"
}

func (c *CmdBan) GetGroup() string {
return GroupModeration
}

func (c *CmdBan) GetPermission() int {
return 8
}

func (c *CmdBan) Exec(args *CommandArgs) error {
if len(args.Args) < 2 {
msg, err := util.SendEmbedError(args.Session, args.Channel.ID,
"Invalid command arguments. Please use `help ban` to see how to use this command.")
util.DeleteMessageLater(args.Session, msg, 8*time.Second)
return err
}
victim, err := util.FetchMember(args.Session, args.Guild.ID, args.Args[0])
if err != nil || victim == nil {
msg, err := util.SendEmbedError(args.Session, args.Channel.ID,
"Sorry, could not find any member :cry:")
util.DeleteMessageLater(args.Session, msg, 10*time.Second)
return err
}

repMsg := strings.Join(args.Args[1:], " ")
var repType int
for i, v := range util.ReportTypes {
if v == "BAN" {
repType = i
}
}
repID := util.ReportNodes[repType].Generate()

acceptMsg := util.AcceptMessage{
Embed: &discordgo.MessageEmbed{
Color: util.ReportColors[repType],
Title: "Ban Check",
Description: "Is everything okay so far?",
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "Victim",
Value: fmt.Sprintf("<@%s> (%s#%s)",
victim.User.ID, victim.User.Username, victim.User.Discriminator),
},
&discordgo.MessageEmbedField{
Name: "ID",
Value: repID.String(),
},
&discordgo.MessageEmbedField{
Name: "Type",
Value: util.ReportTypes[repType],
},
&discordgo.MessageEmbedField{
Name: "Description",
Value: repMsg,
},
},
},
Session: args.Session,
UserID: args.User.ID,
DeleteMsgAfter: true,
AcceptFunc: func(msg *discordgo.Message) {
rep := &util.Report{
ID: repID,
Type: repType,
GuildID: args.Guild.ID,
ExecutorID: args.User.ID,
VictimID: victim.User.ID,
Msg: repMsg,
}
err = args.Session.GuildBanCreateWithReason(args.Guild.ID, victim.User.ID, repMsg, 7)
if err != nil {
util.SendEmbedError(args.Session, args.Channel.ID,
"Failed creating ban: ```\n"+err.Error()+"\n```")
return
}
err = args.CmdHandler.db.AddReport(rep)
if err != nil {
util.SendEmbedError(args.Session, args.Channel.ID,
"Failed creating report: ```\n"+err.Error()+"\n```")
return
}
args.Session.ChannelMessageSendEmbed(args.Channel.ID, rep.AsEmbed())
if modlogChan, err := args.CmdHandler.db.GetGuildModLog(args.Guild.ID); err == nil {
args.Session.ChannelMessageSendEmbed(modlogChan, rep.AsEmbed())
}
},
}

_, err = acceptMsg.Send(args.Channel.ID)

return err
}
2 changes: 1 addition & 1 deletion commands/cmdinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CmdInfo struct {
}

func (c *CmdInfo) GetInvokes() []string {
return []string{"info", "information", "description", "credits"}
return []string{"info", "information", "description", "credits", "version"}
}

func (c *CmdInfo) GetDescription() string {
Expand Down
118 changes: 118 additions & 0 deletions commands/cmdkick.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package commands

import (
"fmt"
"strings"
"time"

"github.com/bwmarrin/discordgo"
"github.com/zekroTJA/shinpuru/util"
)

type CmdKick struct {
}

func (c *CmdKick) GetInvokes() []string {
return []string{"kick", "userkick"}
}

func (c *CmdKick) GetDescription() string {
return "kick users with creating a report entry"
}

func (c *CmdKick) GetHelp() string {
return "`kick <UserResolvable> <Reason>`"
}

func (c *CmdKick) GetGroup() string {
return GroupModeration
}

func (c *CmdKick) GetPermission() int {
return 6
}

func (c *CmdKick) Exec(args *CommandArgs) error {
if len(args.Args) < 2 {
msg, err := util.SendEmbedError(args.Session, args.Channel.ID,
"Invalid command arguments. Please use `help kick` to see how to use this command.")
util.DeleteMessageLater(args.Session, msg, 8*time.Second)
return err
}
victim, err := util.FetchMember(args.Session, args.Guild.ID, args.Args[0])
if err != nil || victim == nil {
msg, err := util.SendEmbedError(args.Session, args.Channel.ID,
"Sorry, could not find any member :cry:")
util.DeleteMessageLater(args.Session, msg, 10*time.Second)
return err
}

repMsg := strings.Join(args.Args[1:], " ")
var repType int
for i, v := range util.ReportTypes {
if v == "KICK" {
repType = i
}
}
repID := util.ReportNodes[repType].Generate()

acceptMsg := util.AcceptMessage{
Embed: &discordgo.MessageEmbed{
Color: util.ReportColors[repType],
Title: "Kick Check",
Description: "Is everything okay so far?",
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "Victim",
Value: fmt.Sprintf("<@%s> (%s#%s)",
victim.User.ID, victim.User.Username, victim.User.Discriminator),
},
&discordgo.MessageEmbedField{
Name: "ID",
Value: repID.String(),
},
&discordgo.MessageEmbedField{
Name: "Type",
Value: util.ReportTypes[repType],
},
&discordgo.MessageEmbedField{
Name: "Description",
Value: repMsg,
},
},
},
Session: args.Session,
UserID: args.User.ID,
DeleteMsgAfter: true,
AcceptFunc: func(msg *discordgo.Message) {
rep := &util.Report{
ID: repID,
Type: repType,
GuildID: args.Guild.ID,
ExecutorID: args.User.ID,
VictimID: victim.User.ID,
Msg: repMsg,
}
err = args.Session.GuildMemberDeleteWithReason(args.Guild.ID, victim.User.ID, repMsg)
if err != nil {
util.SendEmbedError(args.Session, args.Channel.ID,
"Failed kicking member: ```\n"+err.Error()+"\n```")
return
}
err = args.CmdHandler.db.AddReport(rep)
if err != nil {
util.SendEmbedError(args.Session, args.Channel.ID,
"Failed creating report: ```\n"+err.Error()+"\n```")
return
}
args.Session.ChannelMessageSendEmbed(args.Channel.ID, rep.AsEmbed())
if modlogChan, err := args.CmdHandler.db.GetGuildModLog(args.Guild.ID); err == nil {
args.Session.ChannelMessageSendEmbed(modlogChan, rep.AsEmbed())
}
},
}

_, err = acceptMsg.Send(args.Channel.ID)

return err
}
9 changes: 4 additions & 5 deletions commands/cmdreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *CmdReport) Exec(args *CommandArgs) error {

acceptMsg := util.AcceptMessage{
Embed: &discordgo.MessageEmbed{
Color: util.ColorEmbedDefault,
Color: util.ReportColors[repType],
Title: "Report Check",
Description: "Is everything okay so far?",
Fields: []*discordgo.MessageEmbedField{
Expand Down Expand Up @@ -144,9 +144,8 @@ func (c *CmdReport) Exec(args *CommandArgs) error {
}
err = args.CmdHandler.db.AddReport(rep)
if err != nil {
msg, _ := util.SendEmbedError(args.Session, args.Channel.ID,
util.SendEmbedError(args.Session, args.Channel.ID,
"Failed creating report: ```\n"+err.Error()+"\n```")
util.DeleteMessageLater(args.Session, msg, 10*time.Second)
} else {
args.Session.ChannelMessageSendEmbed(args.Channel.ID, rep.AsEmbed())
if modlogChan, err := args.CmdHandler.db.GetGuildModLog(args.Guild.ID); err == nil {
Expand All @@ -156,7 +155,7 @@ func (c *CmdReport) Exec(args *CommandArgs) error {
},
}

acceptMsg.Send(args.Channel.ID)
_, err = acceptMsg.Send(args.Channel.ID)

return nil
return err
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func main() {
cmdHandler.RegisterCommand(new(commands.CmdAutorole))
cmdHandler.RegisterCommand(new(commands.CmdReport))
cmdHandler.RegisterCommand(new(commands.CmdModlog))
cmdHandler.RegisterCommand(new(commands.CmdKick))
cmdHandler.RegisterCommand(new(commands.CmdBan))

//////////////////////////
// BOT SESSION CREATION //
Expand Down
7 changes: 7 additions & 0 deletions util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ var ReportTypes = []string{
"WARN",
"AD",
}

var ReportColors = []int{
0xD81B60,
0xe53935,
0xFB8C00,
0x8E24AA,
}
2 changes: 1 addition & 1 deletion util/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (r *Report) GetTimestamp() time.Time {
func (r *Report) AsEmbed() *discordgo.MessageEmbed {
return &discordgo.MessageEmbed{
Title: "Case " + r.ID.String(),
Color: ColorEmbedDefault,
Color: ReportColors[r.Type],
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Inline: true,
Expand Down

0 comments on commit 50d8a2f

Please sign in to comment.