本文整理汇总了Golang中github.com/sorcix/irc.ParseMessage函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseMessage函数的具体用法?Golang ParseMessage怎么用?Golang ParseMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRequestReceivers
func TestRequestReceivers(t *testing.T) {
success := []struct {
msg *irc.Message
rec []string
}{
{
msg: irc.ParseMessage(":Angel PRIVMSG user1, user2 :example message"),
rec: []string{"Angel"},
},
{
msg: irc.ParseMessage(":Angel PRIVMSG #general :example message"),
rec: []string{"#general"},
},
{
msg: irc.ParseMessage(":Angel PRIVMSG #general , #privatechannel :example message"),
rec: []string{"#general", "#privatechannel"},
},
}
for _, args := range success {
req := &relay.Request{Message: args.msg}
rec := req.Receivers()
assert.Equal(t, args.rec, rec)
}
}
示例2: Raw
func Raw(s ircx.Sender, m *irc.Message, message string) {
if !isOwner(s, m.Name) {
return
}
log.Printf("RAW: %s\n%+v", message, irc.ParseMessage(message))
messages.QueueMessages(s, irc.ParseMessage(message))
}
示例3: TestServerQuit
func TestServerQuit(t *testing.T) {
i, ids := stdIRCServerWithServices()
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":services.robustirc.net NICK blorgh 1 1425542735 enforcer services.robustirc.net services.robustirc.net 0 :Services Enforcer"))
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":blorgh QUIT")),
":[email protected]/0x13c6cdee3e749faf QUIT :")
}
示例4: relevantNick
func relevantNick(msg *irc.Message, prev, next logCursor, reset logReset) (bool, error) {
if len(msg.Params) < 1 {
return false, nil
}
last, err := isLastMessage(prev, next, reset)
if err != nil {
return true, err
}
if last {
return false, nil
}
// Forever retain the first NICK message so that the connection is logged in.
earliestNick := true
for {
rmsg, err := prev(types.RobustIRCFromClient)
if err != nil {
if err == CursorEOF {
break
}
return true, err
}
nmsg := irc.ParseMessage(rmsg.Data)
if strings.ToUpper(nmsg.Command) == irc.NICK {
earliestNick = false
}
}
if earliestNick {
return true, err
}
reset()
for {
rmsg, err := next(types.RobustIRCFromClient)
if err != nil {
if err == CursorEOF {
break
}
return true, err
}
nmsg := irc.ParseMessage(rmsg.Data)
// TOPIC relies on the NICK.
if nmsg.Command == irc.TOPIC {
return true, nil
}
// There is a newer NICK command, so discard this one.
if nmsg.Command == irc.NICK {
return false, nil
}
}
return true, nil
}
示例5: TestServerInvite
func TestServerInvite(t *testing.T) {
i, ids := stdIRCServerWithServices()
i.ProcessMessage(types.RobustId{}, ids["secure"], irc.ParseMessage("JOIN #test"))
mustMatchIrcmsgs(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ INVITE mero #test")),
[]*irc.Message{
irc.ParseMessage(":robustirc.net 341 ChanServ mero #test"),
irc.ParseMessage(":[email protected] INVITE mero :#test"),
irc.ParseMessage(":robustirc.net NOTICE #test :ChanServ invited mero into the channel."),
})
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ INVITE moro #test")),
":robustirc.net 401 ChanServ moro :No such nick/channel")
i.ProcessMessage(types.RobustId{}, ids["mero"], irc.ParseMessage("JOIN #test"))
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ INVITE mero #test")),
":robustirc.net 443 ChanServ mero #test :is already on channel")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ INVITE mero #toast")),
":robustirc.net 403 ChanServ #toast :No such channel")
}
示例6: stdIRCServerWithServices
func stdIRCServerWithServices() (*IRCServer, map[string]types.RobustId) {
i, ids := stdIRCServer()
i.Config.IRC.Services = append(i.Config.IRC.Services, config.Service{
Password: "mypass",
})
ids["services"] = types.RobustId{Id: 0x13c6cdee3e749faf}
i.CreateSession(ids["services"], "auth-server")
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("PASS :services=mypass"))
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SERVER services.robustirc.net 1 :Services for IRC Networks"))
return i, ids
}
示例7: TestServerPrivmsg
func TestServerPrivmsg(t *testing.T) {
i, ids := stdIRCServerWithServices()
i.ProcessMessage(types.RobustId{}, ids["secure"], irc.ParseMessage("JOIN #test"))
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG secure :ohai")),
":[email protected] PRIVMSG secure :ohai")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG socoro :ohai")),
":robustirc.net 401 ChanServ socoro :No such nick/channel")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG #test :ohai")),
":[email protected] PRIVMSG #test :ohai")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG")),
":robustirc.net 411 ChanServ :No recipient given (PRIVMSG)")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG #test")),
":robustirc.net 412 ChanServ :No text to send")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ PRIVMSG #toast :a")),
":robustirc.net 403 ChanServ #toast :No such channel")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage(":ChanServ NOTICE")),
":robustirc.net 411 ChanServ :No recipient given (NOTICE)")
}
示例8: TestServerSvsmode
func TestServerSvsmode(t *testing.T) {
i, ids := stdIRCServerWithServices()
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["secure"], irc.ParseMessage("MODE secure")),
":[email protected]/0x13b5aa0a2bcfb8ad MODE sECuRE :+")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SVSMODE secure +r")),
":services.robustirc.net MODE sECuRE :+r")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SVSMODE socoro +r")),
":robustirc.net 401 * socoro :No such nick/channel")
mustMatchIrcmsgs(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SVSMODE secure +rq")),
[]*irc.Message{
irc.ParseMessage(":robustirc.net 501 * :Unknown MODE flag"),
irc.ParseMessage(":services.robustirc.net MODE sECuRE :+r"),
})
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SVSMODE secure +d-r")),
":services.robustirc.net MODE sECuRE :+")
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["services"], irc.ParseMessage("SVSMODE secure d-r")),
":robustirc.net 501 * :Unknown MODE flag")
}
示例9: relevantUser
func relevantUser(msg *irc.Message, prev, next logCursor, reset logReset) (bool, error) {
if len(msg.Params) < 1 {
return false, nil
}
// This is the first USER message. If the next message is a QUIT message,
// this session cannot have modified any state.
rmsg, err := next(types.RobustAny)
if err == nil && isDeleteSession(rmsg) {
return false, nil
}
prev(types.RobustAny)
for {
rmsg, err := prev(types.RobustIRCFromClient)
if err != nil {
if err == CursorEOF {
break
}
return true, err
}
pmsg := irc.ParseMessage(rmsg.Data)
// There already was a USER message, so discard this one.
if pmsg.Command == irc.USER {
return false, nil
}
}
return true, nil
}
示例10: relevantJoin
func relevantJoin(msg *irc.Message, prev, next logCursor, reset logReset) (bool, error) {
if len(msg.Params) < 1 {
return false, nil
}
lcnames := multipleChannels(msg.Params[0])
for {
rmsg, err := next(types.RobustIRCFromClient)
if err != nil {
if err == CursorEOF {
break
}
return true, err
}
nmsg := irc.ParseMessage(rmsg.Data)
if nmsg.Command == irc.TOPIC &&
len(nmsg.Params) > 0 &&
lcnames[ChanToLower(nmsg.Params[0])] {
return true, nil
}
// TODO: support KICK
if nmsg.Command == irc.PART && len(nmsg.Params) > 0 {
for channelname := range multipleChannels(nmsg.Params[0]) {
delete(lcnames, channelname)
}
if len(lcnames) == 0 {
return false, nil
}
}
}
return true, nil
}
示例11: Handle
func Handle(input string, DB *neoism.Database) {
msg := irc.ParseMessage(input)
if msg == nil {
fmt.Println("Could not parse message")
}
store(msg, DB)
}
示例12: handleAdmin
func handleAdmin(c *sirc.IConn, m *irc.Message) bool {
matches := adminRE.FindStringSubmatch(m.Trailing)
if len(matches) == 0 {
return false
}
adminState.Lock()
// lifo defer order
defer adminState.Save()
defer adminState.Unlock()
host := strings.TrimSpace(matches[2])
switch matches[1] {
case "addadmin":
admins[host] = struct{}{}
c.Notice(m, "Added host successfully")
case "deladmin":
delete(admins, host)
c.Notice(m, "Removed host successfully")
case "raw":
nm := irc.ParseMessage(matches[2])
if nm == nil {
c.Notice(m, "Could not parse, are you sure you know the irc protocol?")
} else {
go c.Write(nm)
}
}
return true
}
示例13: TestServerSjoin
func TestServerSjoin(t *testing.T) {
i, ids := stdIRCServerWithServices()
mustMatchMsg(t,
i.ProcessMessage(types.RobustId{}, ids["secure"], irc.ParseMessage("SJOIN 1 #test :ChanServ")),
":robustirc.net 421 sECuRE SJOIN :Unknown command")
}
示例14: TestServerWelcome
func TestServerWelcome(t *testing.T) {
events := make(chan Event, 10)
srv := NewServer(testServerName)
srv.Subscribe(events)
defer srv.Close()
send, receive := make(chan *irc.Message, 10), make(chan *irc.Message, 10)
u := NewUserMock(send, receive)
go srv.Connect(u)
receive <- irc.ParseMessage("NICK foo")
receive <- irc.ParseMessage("USER root 0 * :Foo Bar")
if msg := <-send; msg.Command != irc.RPL_WELCOME {
t.Errorf("got %v; want %v", msg, irc.RPL_WELCOME)
}
expectEvent(t, events, ConnectEvent)
}
示例15: PrivacyFilterMsg
func PrivacyFilterMsg(message *types.RobustMessage) *types.RobustMessage {
return &types.RobustMessage{
Id: message.Id,
Session: message.Session,
Type: message.Type,
Data: PrivacyFilterIrcmsg(irc.ParseMessage(message.Data)).String(),
}
}