mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-11 21:02:23 +03:00
feat: remove systembell and add 3 options to existing var 'Bell'
This commit is contained in:
parent
cc26a3c05d
commit
c94c5c50a5
@ -265,19 +265,48 @@ func InitCommands(c *Commands) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
c.Add(Command{
|
c.Add(Command{
|
||||||
Prefix: "/systembell",
|
Prefix: "/bell",
|
||||||
Help: "Toggle system bell for all messages.",
|
PrefixHelp: "[off|pm|all]",
|
||||||
|
Help: "Set system bell off, only for pm, or for all messages",
|
||||||
Handler: func(room *Room, msg message.CommandMsg) error {
|
Handler: func(room *Room, msg message.CommandMsg) error {
|
||||||
u := msg.From()
|
u := msg.From()
|
||||||
cfg := u.Config()
|
cfg := u.Config()
|
||||||
cfg.Systembell = !cfg.Systembell
|
|
||||||
|
args := msg.Args()
|
||||||
|
mode := ""
|
||||||
|
if len(args) >= 1 {
|
||||||
|
mode = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
switch mode {
|
||||||
|
case "":
|
||||||
|
// Toggle 0 and 1
|
||||||
|
if cfg.Bell != 0 {
|
||||||
|
cfg.Bell = 0
|
||||||
|
} else {
|
||||||
|
cfg.Bell = 1
|
||||||
|
}
|
||||||
|
case "off":
|
||||||
|
cfg.Bell = 0
|
||||||
|
case "pm":
|
||||||
|
cfg.Bell = 1
|
||||||
|
case "all":
|
||||||
|
cfg.Bell = 2
|
||||||
|
default:
|
||||||
|
return errors.New("bell value must be one of: off, pm, all")
|
||||||
|
}
|
||||||
|
|
||||||
u.SetConfig(cfg)
|
u.SetConfig(cfg)
|
||||||
|
|
||||||
var body string
|
var body string
|
||||||
if cfg.Systembell {
|
if cfg.Bell != 0 {
|
||||||
body = "System bell is toggled ON"
|
if cfg.Bell == 1 {
|
||||||
|
body = "Bell is toggled ON for private messages"
|
||||||
|
} else {
|
||||||
|
body = "Bell is toggled ON for all messages"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
body = "System bell is toggled OFF"
|
body = "Bell is toggled OFF"
|
||||||
}
|
}
|
||||||
room.Send(message.NewSystemMsg(body, u))
|
room.Send(message.NewSystemMsg(body, u))
|
||||||
return nil
|
return nil
|
||||||
|
@ -123,7 +123,7 @@ func (m PublicMsg) RenderFor(cfg UserConfig) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := cfg.Highlight.ReplaceAllString(m.body, cfg.Theme.Highlight("${1}"))
|
body := cfg.Highlight.ReplaceAllString(m.body, cfg.Theme.Highlight("${1}"))
|
||||||
if cfg.Bell {
|
if cfg.Bell != 0 {
|
||||||
body += Bel
|
body += Bel
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s: %s", cfg.Theme.ColorName(m.from), body)
|
return fmt.Sprintf("%s: %s", cfg.Theme.ColorName(m.from), body)
|
||||||
|
@ -215,13 +215,14 @@ func (u *User) render(m Message) string {
|
|||||||
return ""
|
return ""
|
||||||
} else {
|
} else {
|
||||||
out += m.RenderFor(cfg)
|
out += m.RenderFor(cfg)
|
||||||
if cfg.Systembell {
|
if cfg.Bell == 2 {
|
||||||
out += Bel
|
out += Bel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *PrivateMsg:
|
case *PrivateMsg:
|
||||||
out += m.Render(cfg.Theme)
|
out += m.Render(cfg.Theme)
|
||||||
if cfg.Bell {
|
//if u != m.From() && m.Command() != "reply" && cfg.Bell != 0 {
|
||||||
|
if u != m.From() && cfg.Bell != 0 {
|
||||||
out += Bel
|
out += Bel
|
||||||
}
|
}
|
||||||
case *CommandMsg:
|
case *CommandMsg:
|
||||||
@ -275,8 +276,7 @@ func (u *User) Send(m Message) error {
|
|||||||
// Container for per-user configurations.
|
// Container for per-user configurations.
|
||||||
type UserConfig struct {
|
type UserConfig struct {
|
||||||
Highlight *regexp.Regexp
|
Highlight *regexp.Regexp
|
||||||
Bell bool
|
Bell int
|
||||||
Systembell bool
|
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Echo bool // Echo shows your own messages after sending, disabled for bots
|
Echo bool // Echo shows your own messages after sending, disabled for bots
|
||||||
Timeformat *string
|
Timeformat *string
|
||||||
@ -289,8 +289,7 @@ var DefaultUserConfig UserConfig
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DefaultUserConfig = UserConfig{
|
DefaultUserConfig = UserConfig{
|
||||||
Bell: true,
|
Bell: 1,
|
||||||
Systembell: false,
|
|
||||||
Echo: true,
|
Echo: true,
|
||||||
Quiet: false,
|
Quiet: false,
|
||||||
}
|
}
|
||||||
|
10
host.go
10
host.go
@ -169,12 +169,10 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
|||||||
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
||||||
h.Room.HandleMsg(msg)
|
h.Room.HandleMsg(msg)
|
||||||
}
|
}
|
||||||
case "SSHCHAT_SYSTEMBELL":
|
case "SSHCHAT_BELL":
|
||||||
if e.Value != "" && e.Value != "0" {
|
if e.Value != "" && e.Value != "off" {
|
||||||
cmd := "/systembell"
|
cmd := "/bell"
|
||||||
if e.Value != "1" {
|
cmd += " " + e.Value
|
||||||
cmd += " " + e.Value
|
|
||||||
}
|
|
||||||
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
||||||
h.Room.HandleMsg(msg)
|
h.Room.HandleMsg(msg)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user