Merge c94c5c50a51d75f9433408d414d239baf1c73866 into 1fc7f7b10b25cb48c5d1041ea52e4921f349a899

This commit is contained in:
izenynn 2023-02-10 17:00:06 +09:00 committed by GitHub
commit 2f6d85f6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 6 deletions

View File

@ -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{ c.Add(Command{
Prefix: "/slap", Prefix: "/slap",
PrefixHelp: "NAME", PrefixHelp: "NAME",

View File

@ -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)

View File

@ -215,10 +215,14 @@ func (u *User) render(m Message) string {
return "" return ""
} else { } else {
out += m.RenderFor(cfg) out += m.RenderFor(cfg)
if cfg.Bell == 2 {
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:
@ -272,7 +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
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
@ -285,9 +289,9 @@ var DefaultUserConfig UserConfig
func init() { func init() {
DefaultUserConfig = UserConfig{ DefaultUserConfig = UserConfig{
Bell: true, Bell: 1,
Echo: true, Echo: true,
Quiet: false, Quiet: false,
} }
// TODO: Seed random? // TODO: Seed random?

View File

@ -169,6 +169,14 @@ 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_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)
}
}
} }
} }