Ejemplo n.º 1
0
func (r plugin) CheckMessage(event plugins.BotEvent, message string) (bool, string) {
	cmdArgs, ok := event.BotCmdArgs(message)
	if !ok {
		return false, message
	}
	return true, strings.Join(cmdArgs, " ")
}
Ejemplo n.º 2
0
func (r plugin) DoAction(event plugins.BotEvent, message string) bool {
	// Contextを取得
	redisKey := buildRoomContextKey(event.Channel())
	dialogueCtx, _ := r.repository.Load(redisKey)

	// 雑談API叩く
	name := event.SenderName()
	req := docomo.DialogueRequest{
		Utt:      &message,
		Context:  &dialogueCtx,
		Nickname: &name,
	}
	res, err := r.client.Dialogue.Get(req, false)
	if err != nil {
		event.Reply("はて?")
		return true
	} else if res.RequestError.PolicyException.MessageID != "" {
		event.Reply(fmt.Sprintf("%s: %s",
			res.RequestError.PolicyException.MessageID,
			res.RequestError.PolicyException.Text),
		)
		return true
	}

	// 結果を返す
	event.Reply(res.Utt)

	// Contextを保存
	if dialogueCtx == "" {
		r.repository.Save(redisKey, res.Context)
	}

	return false // next ok
}
Ejemplo n.º 3
0
func (p *plugin) CheckMessage(event plugins.BotEvent, message string) (bool, string) {
	if p.debug {
		log.Printf("message            [%s]\n", message)
		log.Printf("botLinkID          [%s]\n", event.BotLinkID())
		log.Printf("botLinkIDForClient [%s]\n", event.BotLinkIDForClient())
		log.Printf("botName            [%s]\n", event.BotName())
		log.Printf("botID              [%s]\n", event.BotID())
	}

	cmdArgs, ok := event.BotCmdArgs(message)
	if !ok {
		return false, message
	}

	if len(cmdArgs) < 1 {
		return false, message
	}

	if p.debug {
		log.Println(cmdArgs)
	}

	for cmdKey, cmds := range p.commandMap {
		if cmds.Contains(cmdArgs[0]) {
			cmdArgs[0] = cmdKey
			return true, strings.Join(cmdArgs, " ")
		}
	}

	return false, message
}
Ejemplo n.º 4
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	sendMessage, isNext := GetLGTMImageURL(p.buildRandomURL(message))

	event.Reply(sendMessage)

	return isNext // next stop
}
Ejemplo n.º 5
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	cmdArgs := strings.Fields(message)
	if _, ok := p.commandMap[cmdArgs[0]]; !ok {
		return true
	}
	event.Reply(p.executeCommand(cmdArgs...))
	return false // next ok
}
Ejemplo n.º 6
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	query := strings.Replace(strings.TrimLeft(message, "image me"), "image me", "", 1)

	links, err := p.client.GetImageLinks(query)
	if err != nil {
		log.Println(err)
		return false
	}

	idx := int(p.rd.Int() % len(links))
	event.Reply(links[idx])

	return false // next ng
}
Ejemplo n.º 7
0
func (r *plugin) DoAction(event plugins.BotEvent, message string) bool {
	size := utf8.RuneCountInString(message)
	header := ""
	for i := 0; i < size+2; i++ {
		header += "人"
	}

	fotter := ""
	for i := 0; i < size; i++ {
		fotter += "^Y"
	}

	reMessage := "_" + header + "_"
	reMessage += "\n"
	reMessage += "> " + message + " <"
	reMessage += "\n"
	reMessage += " ̄Y" + fotter + " ̄"

	event.Reply(reMessage)

	return false // next ok
}
Ejemplo n.º 8
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	event.Reply(message)
	return true // next ok
}
Ejemplo n.º 9
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	c := CronCommand{}
	if err := c.Scan(message); err != nil {
		log.Printf("error %s", err)
		return false
	}

	switch c.Action {
	case AddAction, RandomAddAction:
		message := p.cron.AddCronCommand(event.Channel(), c)
		p.cron.RefreshCron(&event, event.Channel())
		event.Reply(message)
	case DelAction, DeleteAction, StopAction:
		message := p.cron.DelCronCommand(event.Channel(), c)
		p.cron.RefreshCron(&event, event.Channel())
		event.Reply(message)
	case ListAction:
		message := p.cron.ListCronCommand(event.Channel(), c)
		event.Reply(message)
	case RefreshAction:
		p.cron.RefreshCron(&event, event.Channel())
		event.Reply("```\nrefresh ok\n```")
	case HelpAction:
		message := p.cron.HelpCronCommand(event.Channel(), c)
		event.Reply(message)
	}
	return false
}
Ejemplo n.º 10
0
func (r plugin) DoAction(event plugins.BotEvent, message string) bool {
	event.Reply(r.kohaAPI.GetImageURL())
	return false // next ng
}
Ejemplo n.º 11
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	event.Reply(p.getRandomNaruhodo())
	return false // next ng
}
Ejemplo n.º 12
0
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	daisuki := strings.Replace(strings.TrimLeft(message, keyword), keyword, "", 1)
	event.Reply(fmt.Sprintf("わぁい%s あかり%s大好き", daisuki, daisuki))
	return false // next ok
}