mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-05 01:43:20 +03:00
/me works now, with test.
This commit is contained in:
parent
999e1919e7
commit
325f8921da
@ -50,4 +50,12 @@ func TestChannelJoin(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Errorf("Got: `%s`; Expected: `%s`", actual, expected)
|
t.Errorf("Got: `%s`; Expected: `%s`", actual, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ch.Send(ParseInput("/me says hello.", u))
|
||||||
|
u.ConsumeOne(s)
|
||||||
|
expected = []byte("** foo says hello." + Newline)
|
||||||
|
s.Read(&actual)
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("Got: `%s`; Expected: `%s`", actual, expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ func init() {
|
|||||||
me := strings.TrimLeft(msg.body, "/me")
|
me := strings.TrimLeft(msg.body, "/me")
|
||||||
if me == "" {
|
if me == "" {
|
||||||
me = " is at a loss for words."
|
me = " is at a loss for words."
|
||||||
|
} else {
|
||||||
|
me = me[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.Send(NewEmoteMsg(me, msg.From()))
|
channel.Send(NewEmoteMsg(me, msg.From()))
|
||||||
|
@ -96,13 +96,22 @@ func (m *PublicMsg) String() string {
|
|||||||
return m.Render(nil)
|
return m.Render(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmoteMsg is a /me message sent to the channel.
|
// EmoteMsg is a /me message sent to the channel. It specifically does not
|
||||||
|
// extend PublicMsg because it doesn't implement MessageFrom to allow the
|
||||||
|
// sender to see the emote.
|
||||||
type EmoteMsg struct {
|
type EmoteMsg struct {
|
||||||
PublicMsg
|
Msg
|
||||||
|
from *User
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEmoteMsg(body string, from *User) *EmoteMsg {
|
func NewEmoteMsg(body string, from *User) *EmoteMsg {
|
||||||
return &EmoteMsg{*NewPublicMsg(body, from)}
|
return &EmoteMsg{
|
||||||
|
Msg: Msg{
|
||||||
|
body: body,
|
||||||
|
timestamp: time.Now(),
|
||||||
|
},
|
||||||
|
from: from,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *EmoteMsg) Render(t *Theme) string {
|
func (m *EmoteMsg) Render(t *Theme) string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user