当前位置: 首页>>代码示例>>Golang>>正文


Golang Message.String方法代码示例

本文整理汇总了Golang中github.com/sorcix/irc.Message.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.String方法的具体用法?Golang Message.String怎么用?Golang Message.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/sorcix/irc.Message的用法示例。


在下文中一共展示了Message.String方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleMessage

// handleMessage gets messages received on the IRC network and parses them to recognize commands.
func (a *Amigo) handleMessage(msg *irc.Message) {
	// Handle panics
	defer func() {
		if r := recover(); r != nil {
			log.Println("!!! I'm panicking !!! ", r)
		}
	}()

	// Log message
	log.Println(msg.String())

	// Handle PING
	if msg.Command == "PING" {
		a.Send("PONG :" + msg.Trailing)
	}

	// Handle message
	if msg.Command == "PRIVMSG" {
		// Are you talking to me?
		if strings.HasPrefix(msg.Trailing, a.Nick) {
			a.handleCommand(msg)
		} else {
			// Free talk ('say when', 'cmd when')
			a.handleConversation(msg)
		}
	}
}
开发者ID:leonelquinteros,项目名称:amigo,代码行数:28,代码来源:ami.go

示例2: NewMessage

func (server *Server) NewMessage(msg *irc.Message, serverAddr string) (string, error) {
	message := &Message{
		Message: msg.String(),
		Server:  serverAddr,
	}

	serialized, err := json.Marshal(message)

	return string(serialized), err
}
开发者ID:Ell,项目名称:bot,代码行数:10,代码来源:message.go

示例3: MsgHandler

func MsgHandler(s ircx.Sender, m *irc.Message) {
	message := strings.Split(m.String(), " ")
	user := strings.Split(message[0], "!")[0][1:]

	err := db.Update(func(tx *bolt.Tx) error {
		words := make(map[string]uint64)
		message[3] = message[3][1:]

		for _, element := range message[3:] {
			words[element]++
		}

		b := tx.Bucket([]byte(*channel))
		bu := b.Bucket([]byte(users))
		bm := b.Bucket([]byte(messages))

		v := bu.Get([]byte(user))
		var count uint64 = 0
		if v != nil {
			count = ByteToUint64(v)
		}

		count = count + uint64(len(message[3:]))
		err := bu.Put([]byte(user), Uint64ToByte(count))
		if err != nil {
			return err
		}

		for word, count := range words {
			v := bm.Get([]byte(word))
			var sum uint64 = 0

			if v != nil {
				sum = ByteToUint64(v)
			}

			sum = sum + count
			err := bm.Put([]byte(word), Uint64ToByte(sum))
			if err != nil {
				return err
			}
		}

		return nil
	})

	if err != nil {
		log.Fatal(err)
	} else {
		log.Println(user + " said " + strings.Join(message[3:], " "))
	}
}
开发者ID:gmaliar,项目名称:twitch-irc-bot,代码行数:52,代码来源:main.go

示例4: logRaw

func (logger *Logger) logRaw(msg *irc.Message, server string) {
	timestamp := time.Now().Format(time.RFC3339)
	entry := &rawLog{
		Server:    server,
		TimeStamp: timestamp,
		Message:   msg.String(),
	}

	_, err := rdb.DB("bot").Table("raw_logs").Insert(entry).RunWrite(logger.DbSession)

	if err != nil {
		fmt.Println(err)
		return
	}
}
开发者ID:Ell,项目名称:bot,代码行数:15,代码来源:main.go

示例5: Send

func (sender ServerSender) Send(msg *irc.Message) error {
	fmt.Printf(">> %s\n", msg.String())
	return sender.writer.Encode(msg)
}
开发者ID:Ell,项目名称:bot,代码行数:4,代码来源:sender.go

示例6: SendStruct

// SendStruct sends a message.
func (b *Bot) SendStruct(msg *irc.Message) {
	b.SendString(msg.String())
}
开发者ID:JonathanLogan,项目名称:flockerbot,代码行数:4,代码来源:bot.go

示例7: rawHandler

func (net *netImpl) rawHandler(evt *msg.Message) {
	// libmauirc adds the trailing text as a param, remove it.
	evt.Params = evt.Params[:len(evt.Params)-1]
	net.Owner.SendMessage(messages.Container{Type: messages.MsgRaw, Object: messages.RawMessage{Network: net.GetName(), Message: evt.String()}})
}
开发者ID:tulir293,项目名称:mauirc-server,代码行数:5,代码来源:irchandlers.go

示例8: sendMessage

func (server *Server) sendMessage(msg *irc.Message) error {
	if msg.Command != irc.PRIVMSG {
		fmt.Printf(">> %s\n", msg.String())
	}
	return server.Writer.Encode(msg)
}
开发者ID:Ell,项目名称:bot,代码行数:6,代码来源:server.go

示例9: handlePrivMsg

func (channel *IrcChannel) handlePrivMsg(msg *irc.Message) {
	//fmt.Println(msg)
	fmt_msg := new(TwitchChat)
	fmt_msg.raw = msg.String()

	// Parse the tags out of the PRIVMSG for use in the front end

	// Parse usertype
	reUserType, err := regexp.Compile(`user-type\=(.*?)(\;|\s)`)
	if err != nil {
		log.Print("Could not parse UserType\n")
	}
	fmt_msg.usertype = reUserType.FindStringSubmatch(fmt_msg.raw)

	// Parse subscriber
	reSub, err := regexp.Compile(`subscriber\=(.*?)(\;|\s)`)
	if err != nil {
		log.Print("Could not parse Subscriber\n")
	}
	fmt_msg.sub = reSub.FindStringSubmatch(fmt_msg.raw)

	// Parse turbo
	reTurbo, err := regexp.Compile(`turbo\=(.*?)(\;|\s)`)
	if err != nil {
		log.Print("Could not parse Turbo\n")
	}
	fmt_msg.turbo = reTurbo.FindStringSubmatch(fmt_msg.raw)

	// Parse display name
	reDisp, err := regexp.Compile(`display-name\=(.*?)(\;|\s)`)
	if err != nil {
		log.Print("Could not parse DisplayName\n")
	}
	fmt_msg.disp_name = reDisp.FindStringSubmatch(fmt_msg.raw)

	// Parse color tag
	reColor, err := regexp.Compile(`#[[:xdigit:]]{6}`)
	if err != nil {
		log.Print("Could not parse Color\n")
	}
	fmt_msg.color = reColor.FindStringSubmatch(fmt_msg.raw)

	if len(fmt_msg.color) == 1 && len(fmt_msg.disp_name) >= 1 && len(fmt_msg.sub) >= 1 && len(fmt_msg.turbo) >= 1 && len(fmt_msg.usertype) >= 1 {
		// User has all fields (mod or staff)
		// <a href='https://www.twitch.tv/" + msg.Prefix.Name + "/profile' target='_blank'><strong>" + fmt_msg.disp_name[1] + "</strong></a>
		channel.ReadFromChannel <- []byte("<span data-usertype='" + fmt_msg.usertype[1] + "' data-sub='" + fmt_msg.sub[1] + "' data-turbo='" + fmt_msg.turbo[1] +
			"' style='color:" + fmt_msg.color[0] + "' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
	} else if len(fmt_msg.color) == 1 && len(fmt_msg.disp_name) >= 1 && len(fmt_msg.sub) >= 1 && len(fmt_msg.turbo) >= 1 {
		// User is missing user-type tag (non-mod)
		channel.ReadFromChannel <- []byte("<span data-sub='" + fmt_msg.sub[1] + "' data-turbo='" + fmt_msg.turbo[1] + "' style='color:" + fmt_msg.color[0] +
			"' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
	} else if len(fmt_msg.color) == 1 && len(fmt_msg.disp_name) >= 1 {
		// User is missing user-type, subscriber, and turbo tags (rare)
		channel.ReadFromChannel <- []byte("<span data-sub='0' data-turbo='0' style='color:" + fmt_msg.color[0] +
			"' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
	} else if len(fmt_msg.color) == 1 {
		// User is bot (or not authenticated)
		channel.ReadFromChannel <- []byte("<span style='color:" + fmt_msg.color[0] + "' id='username'><strong>" + msg.Prefix.Name + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
	} else {
		// Randomize colors if the user has never set them before
		rand.Seed(time.Now().UTC().UnixNano())
		colors := []string{
			"#FF0000",
			"#0000FF",
			"#008000",
			"#B22222",
			"#FF7F50",
			"#9ACD32",
			"#FF4500",
			"#2E8B57",
			"#DAA520",
			"#D2691E",
			"#5F9EA0",
			"#1E90FF",
			"#FF69B4",
			"#8A2BE2",
			"#00FF7F",
		}

		/* Map colors to the name, broken for some reason
		color, ok := fmt_msg.colorMap[msg.Prefix.Name]
		if !ok {
			color = colors[rand.Intn(len(colors))]
			fmt_msg.colorMap[msg.Prefix.Name] = color
		}*/

		color := colors[rand.Intn(len(colors))]

		if len(fmt_msg.disp_name) >= 1 && len(fmt_msg.sub) >= 1 && len(fmt_msg.turbo) >= 1 && len(fmt_msg.usertype) >= 1 {
			// User has all fields (mod or staff)
			channel.ReadFromChannel <- []byte("<span data-usertype='" + fmt_msg.usertype[1] + "' data-sub='" + fmt_msg.sub[1] + "' data-turbo='" + fmt_msg.turbo[1] +
				"' style='color:" + color + "' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
		} else if len(fmt_msg.disp_name) >= 1 && len(fmt_msg.sub) >= 1 && len(fmt_msg.turbo) >= 1 {
			// User is missing user-type tag (non-mod)
			channel.ReadFromChannel <- []byte("<span data-sub='" + fmt_msg.sub[1] + "' data-turbo='" + fmt_msg.turbo[1] + "' style='color:" + color +
				"' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
		} else if len(fmt_msg.disp_name) >= 1 {
			// User is missing user-type, subscriber, and turbo tags (rare)
			channel.ReadFromChannel <- []byte("<span data-sub='0' data-turbo='0' style='color:" + color +
				"' id='username'><strong>" + fmt_msg.disp_name[1] + "</strong></span><span id='text'>: " + html.EscapeString(msg.Trailing) + " </span>")
//.........这里部分代码省略.........
开发者ID:Larke12,项目名称:twicciand,代码行数:101,代码来源:chat.go


注:本文中的github.com/sorcix/irc.Message.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。