Add better help for /toggle
This commit is contained in:
parent
ae770a97e2
commit
bb5f9156c9
@ -30,6 +30,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
"github.com/russross/blackfriday/v2"
|
"github.com/russross/blackfriday/v2"
|
||||||
@ -560,6 +561,7 @@ func cmdSetState(cmd *Command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ToggleMessage interface {
|
type ToggleMessage interface {
|
||||||
|
Name() string
|
||||||
Format(state bool) string
|
Format(state bool) string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,6 +575,10 @@ func (hm HideMessage) Format(state bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (hm HideMessage) Name() string {
|
||||||
|
return string(hm)
|
||||||
|
}
|
||||||
|
|
||||||
type SimpleToggleMessage string
|
type SimpleToggleMessage string
|
||||||
|
|
||||||
func (stm SimpleToggleMessage) Format(state bool) string {
|
func (stm SimpleToggleMessage) Format(state bool) string {
|
||||||
@ -583,9 +589,13 @@ func (stm SimpleToggleMessage) Format(state bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stm SimpleToggleMessage) Name() string {
|
||||||
|
return string(unicode.ToUpper(rune(stm[0]))) + string(stm[1:])
|
||||||
|
}
|
||||||
|
|
||||||
var toggleMsg = map[string]ToggleMessage{
|
var toggleMsg = map[string]ToggleMessage{
|
||||||
"rooms": HideMessage("room list sidebar"),
|
"rooms": HideMessage("Room list sidebar"),
|
||||||
"users": HideMessage("user list sidebar"),
|
"users": HideMessage("User list sidebar"),
|
||||||
"baremessages": SimpleToggleMessage("bare message view"),
|
"baremessages": SimpleToggleMessage("bare message view"),
|
||||||
"images": SimpleToggleMessage("image rendering"),
|
"images": SimpleToggleMessage("image rendering"),
|
||||||
"typingnotif": SimpleToggleMessage("typing notifications"),
|
"typingnotif": SimpleToggleMessage("typing notifications"),
|
||||||
@ -596,39 +606,52 @@ var toggleMsg = map[string]ToggleMessage{
|
|||||||
"notifications": SimpleToggleMessage("desktop notifications"),
|
"notifications": SimpleToggleMessage("desktop notifications"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeUsage() string {
|
||||||
|
var buf strings.Builder
|
||||||
|
buf.WriteString("Usage: /toggle <things...>\n\n")
|
||||||
|
buf.WriteString("List of Things:\n")
|
||||||
|
for key, value := range toggleMsg {
|
||||||
|
_, _ = fmt.Fprintf(&buf, "* %s - %s\n", key, value.Name())
|
||||||
|
}
|
||||||
|
return buf.String()[:buf.Len()-1]
|
||||||
|
}
|
||||||
|
|
||||||
func cmdToggle(cmd *Command) {
|
func cmdToggle(cmd *Command) {
|
||||||
if len(cmd.Args) == 0 {
|
if len(cmd.Args) == 0 {
|
||||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
cmd.Reply(makeUsage())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var val *bool
|
for _, thing := range cmd.Args {
|
||||||
switch cmd.Args[0] {
|
var val *bool
|
||||||
case "rooms":
|
switch thing {
|
||||||
val = &cmd.Config.Preferences.HideRoomList
|
case "rooms":
|
||||||
case "users":
|
val = &cmd.Config.Preferences.HideRoomList
|
||||||
val = &cmd.Config.Preferences.HideUserList
|
case "users":
|
||||||
case "baremessages":
|
val = &cmd.Config.Preferences.HideUserList
|
||||||
val = &cmd.Config.Preferences.BareMessageView
|
case "baremessages":
|
||||||
case "images":
|
val = &cmd.Config.Preferences.BareMessageView
|
||||||
val = &cmd.Config.Preferences.DisableImages
|
case "images":
|
||||||
case "typingnotif":
|
val = &cmd.Config.Preferences.DisableImages
|
||||||
val = &cmd.Config.Preferences.DisableTypingNotifs
|
case "typingnotif":
|
||||||
case "emojis":
|
val = &cmd.Config.Preferences.DisableTypingNotifs
|
||||||
val = &cmd.Config.Preferences.DisableEmojis
|
case "emojis":
|
||||||
case "html":
|
val = &cmd.Config.Preferences.DisableEmojis
|
||||||
val = &cmd.Config.Preferences.DisableHTML
|
case "html":
|
||||||
case "markdown":
|
val = &cmd.Config.Preferences.DisableHTML
|
||||||
val = &cmd.Config.Preferences.DisableMarkdown
|
case "markdown":
|
||||||
case "downloads":
|
val = &cmd.Config.Preferences.DisableMarkdown
|
||||||
val = &cmd.Config.Preferences.DisableDownloads
|
case "downloads":
|
||||||
case "notifications":
|
val = &cmd.Config.Preferences.DisableDownloads
|
||||||
val = &cmd.Config.Preferences.DisableNotifications
|
case "notifications":
|
||||||
default:
|
val = &cmd.Config.Preferences.DisableNotifications
|
||||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
default:
|
||||||
return
|
cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*val = !(*val)
|
||||||
|
debug.Print(thing, *val)
|
||||||
|
cmd.Reply(toggleMsg[thing].Format(*val))
|
||||||
}
|
}
|
||||||
*val = !(*val)
|
|
||||||
cmd.Reply(toggleMsg[cmd.Args[0]].Format(*val))
|
|
||||||
cmd.UI.Render()
|
cmd.UI.Render()
|
||||||
go cmd.Matrix.SendPreferencesToMatrix()
|
go cmd.Matrix.SendPreferencesToMatrix()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user