本文整理汇总了Golang中github.com/iopred/bruxism.Message.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Type方法的具体用法?Golang Message.Type怎么用?Golang Message.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/iopred/bruxism.Message
的用法示例。
在下文中一共展示了Message.Type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Message
// Message handler.
func (p *comicPlugin) Message(bot *bruxism.Bot, service bruxism.Service, message bruxism.Message) {
if service.IsMe(message) {
return
}
p.Lock()
defer p.Unlock()
log, ok := p.log[message.Channel()]
if !ok {
log = []bruxism.Message{}
}
if bruxism.MatchesCommand(service, "customcomic", message) || bruxism.MatchesCommand(service, "customcomicsimple", message) {
ty := comicgen.ComicTypeChat
if bruxism.MatchesCommand(service, "customcomicsimple", message) {
ty = comicgen.ComicTypeSimple
}
service.Typing(message.Channel())
str, _ := bruxism.ParseCommand(service, message)
messages := []*comicgen.Message{}
splits := strings.Split(str, "|")
for _, line := range splits {
line := strings.Trim(line, " ")
text := ""
speaker := 0
author := ""
if strings.Index(line, ":") != -1 {
lineSplit := strings.Split(line, ":")
author = strings.ToLower(strings.Trim(lineSplit[0], " "))
var err error
speaker, err = strconv.Atoi(author)
if err != nil {
speaker = -1
}
text = strings.Trim(lineSplit[1], " ")
} else {
text = line
}
messages = append(messages, &comicgen.Message{
Speaker: speaker,
Text: text,
Author: author,
})
}
if len(messages) == 0 {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, you didn't add any text.", message.UserName()))
return
}
p.makeComic(bot, service, message, &comicgen.Script{
Messages: messages,
Author: fmt.Sprintf(service.UserName()),
Type: ty,
})
} else if bruxism.MatchesCommand(service, "comic", message) {
if len(log) == 0 {
service.SendMessage(message.Channel(), fmt.Sprintf("Sorry %s, I don't have enough messages to make a comic yet.", message.UserName()))
return
}
service.Typing(message.Channel())
lines := 0
linesString, parts := bruxism.ParseCommand(service, message)
if len(parts) > 0 {
lines, _ = strconv.Atoi(linesString)
}
if lines <= 0 {
lines = 1 + int(math.Floor((math.Pow(2*rand.Float64()-1, 3)/2+0.5)*float64(5)))
}
if lines > len(log) {
lines = len(log)
}
p.makeComic(bot, service, message, makeScriptFromMessages(service, message, log[len(log)-lines:]))
} else {
// Don't append commands.
if bruxism.MatchesCommand(service, "", message) {
return
}
switch message.Type() {
case bruxism.MessageTypeCreate:
if len(log) < 10 {
log = append(log, message)
} else {
//.........这里部分代码省略.........