Skip to content

Commit

Permalink
Add game command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnpn committed Aug 12, 2019
1 parent 60da3cb commit e024939
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func commandRaw(session *discordgo.Session, source commandSource, cmd string, ar
loc.push(lastLoc.guild, lastLoc.channel)
case "ban":
if nargs < 1 {
stdutil.PrintErr("ban <user id> <optional description>", nil)
stdutil.PrintErr("ban <user id> [description]", nil)
return
}
if loc.guild == nil {
Expand Down Expand Up @@ -485,7 +485,7 @@ func commandRaw(session *discordgo.Session, source commandSource, cmd string, ar
}
case "kick":
if nargs < 1 {
stdutil.PrintErr("kick <user id> <optional reason>", nil)
stdutil.PrintErr("kick <user id> [reason]", nil)
return
}
if loc.guild == nil {
Expand Down Expand Up @@ -775,7 +775,7 @@ func commandRaw(session *discordgo.Session, source commandSource, cmd string, ar

cacheRead = nil
cacheUser = nil
case "avatar", "name", "playing", "streaming", "typing", "nick", "status":
case "avatar", "name", "playing", "streaming", "typing", "nick", "status", "game":
returnVal = commandsUserMod(session, cmd, args, nargs, w)
case "read", "cinfo", "ginfo", "uinfo":
returnVal = commandsQuery(session, cmd, args, nargs, w)
Expand Down
2 changes: 1 addition & 1 deletion commands_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ func invite2array(invite *discordgo.Invite) []*keyval {
&keyval{"Temporary", strconv.FormatBool(invite.Temporary)},
)
return values
}
}
31 changes: 31 additions & 0 deletions commands_usermod.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/bwmarrin/discordgo"
"github.com/jD91mZM2/stdutil"
Expand Down Expand Up @@ -198,6 +199,36 @@ func commandsUserMod(session *discordgo.Session, cmd string, args []string, narg
return
}
writeln(w, tl("status.status"))
case "game":
if nargs < 2 {
stdutil.PrintErr("game <streaming/watching/listening> <name> [details] [extra text]", nil)
return
}
status, ok := typeGames[strings.ToLower(args[0])]
if !ok {
stdutil.PrintErr(tl("invalid.value"), nil)
return
}
details := ""
lt := ""
if nargs == 2 {
details = args[2]
}
if nargs == 3 {
lt = args[3]
}
game := &discordgo.Game{
Name: args[1],
Details: details,
Type: status,
TimeStamps: discordgo.TimeStamps{StartTimestamp: time.Now().Unix()},
Assets: discordgo.Assets{LargeText: lt},
}
statusData := discordgo.UpdateStatusData{new(int), game, false, ""}
err := session.UpdateStatusComplex(statusData)
if err != nil {
stdutil.PrintErr(tl("failed.status"), err)
}
}
return
}
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ var typeStatuses = map[string]discordgo.Status{
"dnd": discordgo.StatusDoNotDisturb,
"invisible": discordgo.StatusInvisible,
}
var typeGames = map[string]discordgo.GameType{
"streaming": discordgo.GameTypeStreaming,
"listening": discordgo.GameTypeListening,
"watching": discordgo.GameTypeWatching,
}
var typeChannel = map[discordgo.ChannelType]string{
discordgo.ChannelTypeDM: "DM",
discordgo.ChannelTypeGroupDM: "Group",
Expand Down

0 comments on commit e024939

Please sign in to comment.