Skip to content

Commit

Permalink
Add Discord settings to info command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnpn committed Aug 15, 2019
1 parent 9f8a6a7 commit 2a108de
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
47 changes: 44 additions & 3 deletions commands_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func commandsQuery(session *discordgo.Session, cmd string, args []string, nargs
}
case "info":
if nargs < 1 {
stdutil.PrintErr("info <user/guild/channel> (for user: <id/@me>) [property] (or info u/g/c)", nil)
stdutil.PrintErr("info <user/guild/channel/settings> (for user: <id/@me>) [property] (or info u/g/c/s)", nil)
return
}
switch strings.ToLower(args[0]) {
Expand Down Expand Up @@ -196,10 +196,36 @@ func commandsQuery(session *discordgo.Session, cmd string, args []string, nargs
return
}

writeln(w, returnVal)
}
case "settings", "s":
if userType == typeBot {
stdutil.PrintErr(tl("invalid.onlyfor.users"), nil)
return
}
settings, err := session.UserSettings()
if err != nil {
stdutil.PrintErr(tl("failed.settings"), err)
return
}
values := settings2array(settings)

if nargs < 2 {
for _, keyval := range values {
writeln(w, keyval.String())
}
} else {
var ok bool
returnVal, ok = findValByKey(values, args[1])
if !ok {
stdutil.PrintErr(tl("invalid.value"), nil)
return
}

writeln(w, returnVal)
}
default:
stdutil.PrintErr("info <user/guild/channel> (for user: <id/@me>) [property] (or info u/g/c)", nil)
stdutil.PrintErr("info <user/guild/channel/settings> (for user: <id/@me>) [property] (or info u/g/c/s)", nil)
}
}
return
Expand Down Expand Up @@ -245,7 +271,6 @@ func user2array(user *discordgo.User) []*keyval {
&keyval{"Email", user.Email},
&keyval{"Name", user.Username},
&keyval{"Discrim", user.Discriminator},
&keyval{"Locale", user.Locale},
&keyval{"Avatar", user.Avatar},
&keyval{"Avatar URL", user.AvatarURL("1024")},
&keyval{"Verified", strconv.FormatBool(user.Verified)},
Expand All @@ -254,6 +279,22 @@ func user2array(user *discordgo.User) []*keyval {
}
}

func settings2array(settings *discordgo.Settings) []*keyval {
return []*keyval{
&keyval{"Theme", settings.Theme},
&keyval{"Compact", strconv.FormatBool(settings.MessageDisplayCompact)},
&keyval{"Locale", settings.Locale},
&keyval{"TTS", strconv.FormatBool(settings.EnableTtsCommand)},
&keyval{"Convert emotes", strconv.FormatBool(settings.ConvertEmoticons)},
&keyval{"Attachments", strconv.FormatBool(settings.InlineAttachmentMedia)},
&keyval{"Media embeds", strconv.FormatBool(settings.InlineEmbedMedia)},
&keyval{"Show embeds", strconv.FormatBool(settings.RenderEmbeds)},
&keyval{"Show current game", strconv.FormatBool(settings.ShowCurrentGame)},
&keyval{"Dev mode", strconv.FormatBool(settings.DeveloperMode)},
&keyval{"Platform accounts", strconv.FormatBool(settings.DetectPlatformAccounts)},
}
}

func invite2array(invite *discordgo.Invite) []*keyval {
values := make([]*keyval, 0)
if invite.Inviter != nil {
Expand Down
13 changes: 13 additions & 0 deletions completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func setCompleter(rl *readline.Instance) {
),
readline.PcItem("<id>"),
),
readline.PcItem("settings",
readline.PcItem("theme"),
readline.PcItem("compact"),
readline.PcItem("locale"),
readline.PcItem("tts"),
readline.PcItem("\"convert emotes\""),
readline.PcItem("attachments"),
readline.PcItem("\"media embeds\""),
readline.PcItem("\"show embeds\""),
readline.PcItem("\"show current game\""),
readline.PcItem("\"dev mode\""),
readline.PcItem("\"platform accounts\""),
),
),
readline.PcItem("messages",
readline.PcItem("all"),
Expand Down
2 changes: 1 addition & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func printHelp(search string) {
help = append(help, "")
help = append(help, "region <list/set> (<region>)\tSet current guild region.")
help = append(help, "")
help = append(help, "info <user/guild/channel> (for user: <id/@me>) [property] (or info u/g/c)\tGet information about a user, server or channel!")
help = append(help, "info <user/guild/channel/settings> (for user: <id/@me>) [property] (or info u/g/c/s)\tGet information about a user, server, channel or your set Discord settings!")
help = append(help, "read <message id> [property]\tRead or get info from a message. Properties: (empty), text, channel, timestamp, author, "+
"author_email, author_name, author_avatar, author_bot, embed; 'cache' may be used as message ID.")
help = append(help, "pin <message id>\tPin a message to the current channel.")
Expand Down

0 comments on commit 2a108de

Please sign in to comment.