mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-18 17:57:41 +03:00
Silence timer.
This commit is contained in:
parent
69d56919f8
commit
0c42706d88
30
client.go
30
client.go
@ -113,7 +113,7 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(line, " ", 2)
|
parts := strings.SplitN(line, " ", 3)
|
||||||
isCmd := strings.HasPrefix(parts[0], "/")
|
isCmd := strings.HasPrefix(parts[0], "/")
|
||||||
|
|
||||||
if isCmd {
|
if isCmd {
|
||||||
@ -125,6 +125,13 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
c.WriteLines(strings.Split(HELP_TEXT, "\n"))
|
c.WriteLines(strings.Split(HELP_TEXT, "\n"))
|
||||||
case "/about":
|
case "/about":
|
||||||
c.WriteLines(strings.Split(ABOUT_TEXT, "\n"))
|
c.WriteLines(strings.Split(ABOUT_TEXT, "\n"))
|
||||||
|
case "/me":
|
||||||
|
msg := fmt.Sprintf("* %s %s", c.Name, line)
|
||||||
|
if c.IsSilenced() {
|
||||||
|
c.Msg <- fmt.Sprintf("-> Message rejected, silenced.")
|
||||||
|
} else {
|
||||||
|
c.Server.Broadcast(msg, c)
|
||||||
|
}
|
||||||
case "/nick":
|
case "/nick":
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
c.Server.Rename(c, parts[1])
|
c.Server.Rename(c, parts[1])
|
||||||
@ -177,6 +184,27 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
c.Server.Op(fingerprint)
|
c.Server.Op(fingerprint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "/silence":
|
||||||
|
if !c.Server.IsOp(c) {
|
||||||
|
c.Msg <- fmt.Sprintf("-> You're not an admin.")
|
||||||
|
} else if len(parts) < 2 {
|
||||||
|
c.Msg <- fmt.Sprintf("-> Missing $NAME from: /silence $NAME")
|
||||||
|
} else {
|
||||||
|
duration := time.Duration(5) * time.Minute
|
||||||
|
if len(parts) >= 3 {
|
||||||
|
parsedDuration, err := time.ParseDuration(parts[2])
|
||||||
|
if err == nil {
|
||||||
|
duration = parsedDuration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client := c.Server.Who(parts[1])
|
||||||
|
if client == nil {
|
||||||
|
c.Msg <- fmt.Sprintf("-> No such name: %s", parts[1])
|
||||||
|
} else {
|
||||||
|
client.Silence(duration)
|
||||||
|
client.Write(fmt.Sprintf("-> Silenced for %s by %s.", duration, c.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
c.Msg <- fmt.Sprintf("-> Invalid command: %s", line)
|
c.Msg <- fmt.Sprintf("-> Invalid command: %s", line)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user