mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 07:37:17 +03:00
main: Add symbol support
This commit is contained in:
parent
cb0bdc8e0e
commit
ced5767bbb
23
host.go
23
host.go
@ -95,7 +95,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
|||||||
user := message.NewUserScreen(id, term)
|
user := message.NewUserScreen(id, term)
|
||||||
user.OnChange = func() {
|
user.OnChange = func() {
|
||||||
term.SetPrompt(GetPrompt(user))
|
term.SetPrompt(GetPrompt(user))
|
||||||
user.SetHighlight(user.Name())
|
user.SetHighlight(user.ID())
|
||||||
}
|
}
|
||||||
cfg := user.Config()
|
cfg := user.Config()
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
|
|||||||
if completed == "/reply" {
|
if completed == "/reply" {
|
||||||
replyTo := u.ReplyTo()
|
replyTo := u.ReplyTo()
|
||||||
if replyTo != nil {
|
if replyTo != nil {
|
||||||
name := replyTo.Name()
|
name := replyTo.ID()
|
||||||
_, found := h.GetUser(name)
|
_, found := h.GetUser(name)
|
||||||
if found {
|
if found {
|
||||||
completed = "/msg " + name
|
completed = "/msg " + name
|
||||||
@ -634,10 +634,29 @@ func (h *Host) InitCommands(c *chat.Commands) {
|
|||||||
return errors.New("user not found")
|
return errors.New("user not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
symbolSet := false
|
||||||
|
if len(args) == 3 {
|
||||||
|
s := args[2]
|
||||||
|
if id, ok := member.Identifier.(*Identity); ok {
|
||||||
|
id.SetSymbol(s)
|
||||||
|
} else {
|
||||||
|
return errors.New("user does not support setting symbol")
|
||||||
|
}
|
||||||
|
|
||||||
|
body := fmt.Sprintf("Assigned symbol %q by %s.", s, msg.From().Name())
|
||||||
|
room.Send(message.NewSystemMsg(body, member.User))
|
||||||
|
symbolSet = true
|
||||||
|
}
|
||||||
|
|
||||||
oldID := member.ID()
|
oldID := member.ID()
|
||||||
newID := sanitize.Name(args[1])
|
newID := sanitize.Name(args[1])
|
||||||
if newID == oldID {
|
if newID == oldID {
|
||||||
return errors.New("new name is the same as the original")
|
return errors.New("new name is the same as the original")
|
||||||
|
} else if newID == "" && symbolSet {
|
||||||
|
if member.User.OnChange != nil {
|
||||||
|
member.User.OnChange()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
member.SetID(newID)
|
member.SetID(newID)
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
type Identity struct {
|
type Identity struct {
|
||||||
sshd.Connection
|
sshd.Connection
|
||||||
id string
|
id string
|
||||||
|
symbol string // symbol is displayed as a prefix to the name
|
||||||
created time.Time
|
created time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +42,15 @@ func (i *Identity) SetName(name string) {
|
|||||||
i.SetID(name)
|
i.SetID(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Identity) SetSymbol(symbol string) {
|
||||||
|
i.symbol = symbol
|
||||||
|
}
|
||||||
|
|
||||||
// Name returns the name for the Identity
|
// Name returns the name for the Identity
|
||||||
func (i Identity) Name() string {
|
func (i Identity) Name() string {
|
||||||
|
if i.symbol != "" {
|
||||||
|
return i.symbol + " " + i.id
|
||||||
|
}
|
||||||
return i.id
|
return i.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user