mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
* squash * balance too low message * add context to start * add translations * translation readme * translations for all * equalize * new faucet empty message * commands * localize * add more commands * adjust * add language code * add languageCode context * cancel handler with struct language * inline objects use their language * button translations * send language * add GetLnbitsUser * different localizers * fix publicLanguageCode * translate balance and donate * whatever bro * translateUser * pull bro * asd * Create nl.toml (#74) * Create nl.toml * Update nl.toml * I18n (#75) * Whatever brah * Update es.toml * Whatever brah * Update nl.toml (#76) * clean comments * fix amount Co-authored-by: lngohumble <lngohumble@gmail.com> Co-authored-by: maxmerlin78 <91363235+maxmerlin78@users.noreply.github.com> Co-authored-by: Koty <89604768+kotyauditore@users.noreply.github.com>
112 lines
3.1 KiB
Go
112 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
tb "gopkg.in/tucnak/telebot.v2"
|
|
)
|
|
|
|
const queryImage = "https://avatars.githubusercontent.com/u/88730856?v=4"
|
|
|
|
func (bot TipBot) inlineQueryInstructions(ctx context.Context, q *tb.Query) {
|
|
instructions := []struct {
|
|
url string
|
|
title string
|
|
description string
|
|
}{
|
|
{
|
|
url: queryImage,
|
|
title: TranslateUser(ctx, "inlineQuerySendTitle"),
|
|
description: fmt.Sprintf(TranslateUser(ctx, "inlineQuerySendDescription"), bot.telegram.Me.Username),
|
|
},
|
|
{
|
|
url: queryImage,
|
|
title: TranslateUser(ctx, "inlineQueryReceiveTitle"),
|
|
description: fmt.Sprintf(TranslateUser(ctx, "inlineQueryReceiveDescription"), bot.telegram.Me.Username),
|
|
},
|
|
{
|
|
url: queryImage,
|
|
title: TranslateUser(ctx, "inlineQueryFaucetTitle"),
|
|
description: fmt.Sprintf(TranslateUser(ctx, "inlineQueryFaucetDescription"), bot.telegram.Me.Username),
|
|
},
|
|
}
|
|
results := make(tb.Results, len(instructions)) // []tb.Result
|
|
for i, instruction := range instructions {
|
|
result := &tb.ArticleResult{
|
|
//URL: instruction.url,
|
|
Text: instruction.description,
|
|
Title: instruction.title,
|
|
Description: instruction.description,
|
|
// required for photos
|
|
ThumbURL: instruction.url,
|
|
}
|
|
results[i] = result
|
|
// needed to set a unique string ID for each result
|
|
results[i].SetResultID(strconv.Itoa(i))
|
|
}
|
|
|
|
err := bot.telegram.Answer(q, &tb.QueryResponse{
|
|
Results: results,
|
|
CacheTime: 5, // a minute
|
|
IsPersonal: true,
|
|
QueryID: q.ID,
|
|
})
|
|
|
|
if err != nil {
|
|
log.Errorln(err)
|
|
}
|
|
}
|
|
|
|
func (bot TipBot) inlineQueryReplyWithError(q *tb.Query, message string, help string) {
|
|
results := make(tb.Results, 1) // []tb.Result
|
|
result := &tb.ArticleResult{
|
|
// URL: url,
|
|
Text: help,
|
|
Title: message,
|
|
Description: help,
|
|
// required for photos
|
|
ThumbURL: queryImage,
|
|
}
|
|
id := fmt.Sprintf("inl-error-%d-%s", q.From.ID, RandStringRunes(5))
|
|
result.SetResultID(id)
|
|
results[0] = result
|
|
err := bot.telegram.Answer(q, &tb.QueryResponse{
|
|
Results: results,
|
|
CacheTime: 1, // 60 == 1 minute, todo: make higher than 1 s in production
|
|
|
|
})
|
|
if err != nil {
|
|
log.Errorln(err)
|
|
}
|
|
}
|
|
|
|
func (bot TipBot) anyChosenInlineHandler(q *tb.ChosenInlineResult) {
|
|
fmt.Printf(q.Query)
|
|
}
|
|
|
|
func (bot TipBot) anyQueryHandler(ctx context.Context, q *tb.Query) {
|
|
if q.Text == "" {
|
|
bot.inlineQueryInstructions(ctx, q)
|
|
return
|
|
}
|
|
|
|
// create the inline send result
|
|
if strings.HasPrefix(q.Text, "/") {
|
|
q.Text = strings.TrimPrefix(q.Text, "/")
|
|
}
|
|
if strings.HasPrefix(q.Text, "send") || strings.HasPrefix(q.Text, "pay") {
|
|
bot.handleInlineSendQuery(ctx, q)
|
|
}
|
|
|
|
if strings.HasPrefix(q.Text, "faucet") || strings.HasPrefix(q.Text, "giveaway") || strings.HasPrefix(q.Text, "zapfhahn") || strings.HasPrefix(q.Text, "kraan") {
|
|
bot.handleInlineFaucetQuery(ctx, q)
|
|
}
|
|
|
|
if strings.HasPrefix(q.Text, "receive") || strings.HasPrefix(q.Text, "get") || strings.HasPrefix(q.Text, "payme") || strings.HasPrefix(q.Text, "request") {
|
|
bot.handleInlineReceiveQuery(ctx, q)
|
|
}
|
|
}
|