本文整理汇总了Golang中github.com/iopred/bruxism.Message.RawMessage方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.RawMessage方法的具体用法?Golang Message.RawMessage怎么用?Golang Message.RawMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/iopred/bruxism.Message
的用法示例。
在下文中一共展示了Message.RawMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: avatarMessageFunc
func avatarMessageFunc(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if !service.IsMe(message) {
if bruxism.MatchesCommand(service, "avatar", message) {
query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")
id := message.UserID()
match := userIDRegex.FindStringSubmatch(query)
if match != nil {
id = match[1]
}
discord := service.(*bruxism.Discord)
u, err := discord.Session.User(id)
if err != nil {
return
}
service.SendMessage(message.Channel(), discordgo.EndpointUserAvatar(u.ID, u.Avatar))
}
}
}
示例2: Message
func (p *playedPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
defer bruxism.MessageRecover()
if service.Name() == bruxism.DiscordServiceName && !service.IsMe(message) {
if bruxism.MatchesCommand(service, "played", message) {
query := strings.Join(strings.Split(message.RawMessage(), " ")[1:], " ")
id := message.UserID()
match := userIDRegex.FindStringSubmatch(query)
if match != nil {
id = match[1]
}
p.Lock()
defer p.Unlock()
u := p.Users[id]
if u == nil {
service.SendMessage(message.Channel(), "I haven't seen that user.")
return
}
if len(u.Entries) == 0 {
service.SendMessage(message.Channel(), "I haven't seen anything played by that user.")
return
}
lc := humanize.Time(u.LastChanged)
u.Update(u.Current, time.Now())
pes := make(byDuration, len(u.Entries))
i := 0
for _, pe := range u.Entries {
pes[i] = pe
i++
}
sort.Sort(pes)
messageText := fmt.Sprintf("*First seen %s, last update %s*\n", humanize.Time(u.FirstSeen), lc)
for i = 0; i < len(pes) && i < 5; i++ {
pe := pes[i]
du := pe.Duration
ds := ""
hours := int(du / time.Hour)
if hours > 0 {
ds += fmt.Sprintf("%dh ", hours)
du -= time.Duration(hours) * time.Hour
}
minutes := int(du / time.Minute)
if minutes > 0 || len(ds) > 0 {
ds += fmt.Sprintf("%dm ", minutes)
du -= time.Duration(minutes) * time.Minute
}
seconds := int(du / time.Second)
ds += fmt.Sprintf("%ds", seconds)
messageText += fmt.Sprintf("**%s**: %s\n", pe.Name, ds)
}
service.SendMessage(message.Channel(), messageText)
}
}
}