Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gachabot #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions stou/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ func NewOmikujiBot(out chan *model.Message) *Bot {
}
}

// NewGachaBot は"大吉", "吉", "中吉", "小吉", "末吉", "凶"のいずれかをランダムで返す新しいBotの構造体のポインタを返します
func NewGachaBot(out chan *model.Message) *Bot {
in := make(chan *model.Message)

checker := NewRegexpChecker("\\Agacha\\z")

processor := &GachaProcessor{}

return &Bot{
name: "gachabot",
in: in,
out: out,
checker: checker,
processor: processor,
}
}

// NewKeywordBot はメッセージ本文からキーワードを抽出して返す新しいBotの構造体のポインタを返します
func NewKeywordBot(out chan *model.Message) *Bot {
in := make(chan *model.Message)
Expand Down
20 changes: 19 additions & 1 deletion stou/bot/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"fmt"

"net/url"

"github.com/VG-Tech-Dojo/vg-1day-2018-06-10/stou/env"
"github.com/VG-Tech-Dojo/vg-1day-2018-06-10/stou/model"
"net/url"
)

const (
Expand All @@ -27,6 +28,9 @@ type (
// OmikujiProcessor は"大吉", "吉", "中吉", "小吉", "末吉", "凶"のいずれかをランダムで作るprocessorの構造体です
OmikujiProcessor struct{}

// GachaProcessor は"SSレア", "Sレア", "レア", "ノーマル"のいずれかをランダムで作るprocessorの構造体です
GachaProcessor struct{}

// KeywordProcessor はメッセージ本文からキーワードを抽出するprocessorの構造体です
KeywordProcessor struct{}
)
Expand Down Expand Up @@ -54,6 +58,20 @@ func (p *OmikujiProcessor) Process(msgIn *model.Message) (*model.Message, error)
}, nil
}

// Process は"SSレア", "Sレア", "レア", "ノーマル"のいずれかがbodyにセットされたメッセージへのポインタを返します
func (p *GachaProcessor) Process(msgIn *model.Message) (*model.Message, error) {
fortunes := []string{
"SSレア",
"Sレア",
"レア",
"ノーマル",
}
result := fortunes[randIntn(len(fortunes))]
return &model.Message{
Body: result,
}, nil
}

// Process はメッセージ本文からキーワードを抽出します
func (p *KeywordProcessor) Process(msgIn *model.Message) (*model.Message, error) {
r := regexp.MustCompile("\\Akeyword (.+)")
Expand Down
2 changes: 2 additions & 0 deletions stou/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func (s *Server) Init(dbconf, env string) error {
s.bots = append(s.bots, helloWorldBot)
omikujiBot := bot.NewOmikujiBot(s.poster.In)
s.bots = append(s.bots, omikujiBot)
gachaBot := bot.NewGachaBot(s.poster.In)
s.bots = append(s.bots, gachaBot)
keywordBot := bot.NewKeywordBot(s.poster.In)
s.bots = append(s.bots, keywordBot)

Expand Down