コード例 #1
0
ファイル: telegram.go プロジェクト: gobwas/kursobot
func (h *Handler) rateInline(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update, call slugger.Call) {
	if len(call.Query) != 2 {
		ctrl.Throw(ErrRateExpectTwoArguments)
		return
	}
	if err := validateCurrency(call.Query[0]); err != nil {
		ctrl.Throw(err)
		return
	}
	if err := validateCurrency(call.Query[1]); err != nil {
		ctrl.Throw(err)
		return
	}

	from, to := toCurrency(call.Query[0]), toCurrency(call.Query[1])
	rate, err := h.f.GetRate(ctrl.Context(), from, to)
	if err != nil {
		ctrl.Throw(err)
		return
	}

	bot.AnswerInlineQuery(tgbotapi.InlineConfig{
		InlineQueryID: update.InlineQuery.ID,
		Results: []interface{}{
			inlineResultArticle(from, to, rate.Rate),
		},
	})

	ctrl.Next()
}
コード例 #2
0
ファイル: condition.go プロジェクト: gobwas/telegram
func (self Condition) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
	if self.Matcher.Match(update) {
		self.Handler.Serve(ctrl, bot, update)
		return
	}

	ctrl.Next()
}
コード例 #3
0
ファイル: slugger.go プロジェクト: gobwas/telegram
func (r *Slugger) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
	var call Call

	text := strings.TrimPrefix(update.Message.Text, methodPrefix)
	fill(&call.Args, text)
	fill(&call.Query, update.InlineQuery.Query)

	ctrl.NextWithValue(reflect.TypeOf(call), call)
	ctrl.Next()
}
コード例 #4
0
ファイル: telegram.go プロジェクト: gobwas/kursobot
func (h *Handler) rouble(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update, call slugger.Call) {
	if len(call.Args) != 1 {
		ctrl.Throw(ErrRoubleExpectOneArgument)
		return
	}
	if err := validateCurrency(call.Args[0]); err != nil {
		ctrl.Throw(err)
		return
	}

	rate, err := h.f.GetRate(ctrl.Context(), toCurrency(call.Args[0]), finance.RUB)
	if err != nil {
		ctrl.Throw(err)
		return
	}

	bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, strconv.FormatFloat(rate.Rate, 'f', 2, 64)))
	ctrl.Next()
}
コード例 #5
0
ファイル: telegram.go プロジェクト: gobwas/kursobot
func (h *Handler) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
	msg := tgbotapi.NewMessage(update.Message.Chat.ID, help.HelpContents)
	msg.ParseMode = telegram.ParseModeMarkdown
	bot.Send(msg)
	ctrl.Next()
}
コード例 #6
0
ファイル: canceler.go プロジェクト: gobwas/telegram
func (c *Canceler) Serve(ctrl *telegram.Control, bot *tgbotapi.BotAPI, update tgbotapi.Update) {
	ctrl.NextWithTimeout(c.Timeout)
	ctrl.Next()
}