Random quotes via /random, make test

This commit is contained in:
Pavel 2019-06-09 20:27:15 +03:00
parent f85a5ddd3a
commit 2ea533cad5
4 changed files with 14 additions and 1 deletions

View File

@ -3,4 +3,5 @@ language: go
go: go:
- "1.12" - "1.12"
script: script:
- "make" - "make test"
- "make build"

View File

@ -15,6 +15,10 @@ clean:
@echo Cleaning... @echo Cleaning...
@rm -rf $(dir ${BIN}) @rm -rf $(dir ${BIN})
test:
@echo Testing...
@$(GO) test $(SRC)
run: run:
@$(BIN) @$(BIN)

View File

@ -31,6 +31,10 @@ func GetLatestAbyssQuotes() ([]BashQuote, error) {
return extractQuotes("/abyss/", 25) return extractQuotes("/abyss/", 25)
} }
func GetRandomQuotes() ([]BashQuote, error) {
return extractQuotes("/random", 25)
}
func GetQuote(id int) (BashQuote, error) { func GetQuote(id int) (BashQuote, error) {
quotes, err := extractQuotes(fmt.Sprintf("/quote/%d", id), 1) quotes, err := extractQuotes(fmt.Sprintf("/quote/%d", id), 1)

View File

@ -115,6 +115,8 @@ func processUpdate(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
NewMessageWithQuotes(bot, update, &msgs, "Получаю свежие цитаты", update.Message.Command()) NewMessageWithQuotes(bot, update, &msgs, "Получаю свежие цитаты", update.Message.Command())
case "abyss": case "abyss":
NewMessageWithQuotes(bot, update, &msgs, "Получаю цитаты из Бездны", update.Message.Command()) NewMessageWithQuotes(bot, update, &msgs, "Получаю цитаты из Бездны", update.Message.Command())
case "random":
NewMessageWithQuotes(bot, update, &msgs, "Получаю случайные цитаты", update.Message.Command())
default: default:
msgs[len(msgs)-1].Text = "Как насчёт последних цитат? Используйте /latest" msgs[len(msgs)-1].Text = "Как насчёт последних цитат? Используйте /latest"
} }
@ -151,6 +153,8 @@ func NewMessageWithQuotes(
items, err = GetLatestQuotes() items, err = GetLatestQuotes()
case "abyss": case "abyss":
items, err = GetLatestAbyssQuotes() items, err = GetLatestAbyssQuotes()
case "random":
items, err = GetRandomQuotes()
default: default:
items, err = GetLatestQuotes() items, err = GetLatestQuotes()
} }