mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-21 03:07:40 +03:00
Merge c94c5c50a51d75f9433408d414d239baf1c73866 into 1fc7f7b10b25cb48c5d1041ea52e4921f349a899
This commit is contained in:
commit
2f6d85f6ab
@ -264,6 +264,55 @@ func InitCommands(c *Commands) {
|
||||
},
|
||||
})
|
||||
|
||||
c.Add(Command{
|
||||
Prefix: "/bell",
|
||||
PrefixHelp: "[off|pm|all]",
|
||||
Help: "Set system bell off, only for pm, or for all messages",
|
||||
Handler: func(room *Room, msg message.CommandMsg) error {
|
||||
u := msg.From()
|
||||
cfg := u.Config()
|
||||
|
||||
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)
|
||||
|
||||
var body string
|
||||
if cfg.Bell != 0 {
|
||||
if cfg.Bell == 1 {
|
||||
body = "Bell is toggled ON for private messages"
|
||||
} else {
|
||||
body = "Bell is toggled ON for all messages"
|
||||
}
|
||||
} else {
|
||||
body = "Bell is toggled OFF"
|
||||
}
|
||||
room.Send(message.NewSystemMsg(body, u))
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
c.Add(Command{
|
||||
Prefix: "/slap",
|
||||
PrefixHelp: "NAME",
|
||||
|
@ -123,7 +123,7 @@ func (m PublicMsg) RenderFor(cfg UserConfig) string {
|
||||
}
|
||||
|
||||
body := cfg.Highlight.ReplaceAllString(m.body, cfg.Theme.Highlight("${1}"))
|
||||
if cfg.Bell {
|
||||
if cfg.Bell != 0 {
|
||||
body += Bel
|
||||
}
|
||||
return fmt.Sprintf("%s: %s", cfg.Theme.ColorName(m.from), body)
|
||||
|
@ -215,10 +215,14 @@ func (u *User) render(m Message) string {
|
||||
return ""
|
||||
} else {
|
||||
out += m.RenderFor(cfg)
|
||||
if cfg.Bell == 2 {
|
||||
out += Bel
|
||||
}
|
||||
}
|
||||
case *PrivateMsg:
|
||||
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
|
||||
}
|
||||
case *CommandMsg:
|
||||
@ -272,7 +276,7 @@ func (u *User) Send(m Message) error {
|
||||
// Container for per-user configurations.
|
||||
type UserConfig struct {
|
||||
Highlight *regexp.Regexp
|
||||
Bell bool
|
||||
Bell int
|
||||
Quiet bool
|
||||
Echo bool // Echo shows your own messages after sending, disabled for bots
|
||||
Timeformat *string
|
||||
@ -285,9 +289,9 @@ var DefaultUserConfig UserConfig
|
||||
|
||||
func init() {
|
||||
DefaultUserConfig = UserConfig{
|
||||
Bell: true,
|
||||
Echo: true,
|
||||
Quiet: false,
|
||||
Bell: 1,
|
||||
Echo: true,
|
||||
Quiet: false,
|
||||
}
|
||||
|
||||
// TODO: Seed random?
|
||||
|
8
host.go
8
host.go
@ -169,6 +169,14 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
||||
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
||||
h.Room.HandleMsg(msg)
|
||||
}
|
||||
case "SSHCHAT_BELL":
|
||||
if e.Value != "" && e.Value != "off" {
|
||||
cmd := "/bell"
|
||||
cmd += " " + e.Value
|
||||
if msg, ok := message.NewPublicMsg(cmd, user).ParseCommand(); ok {
|
||||
h.Room.HandleMsg(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user