Browse Source

minimal behavior for group chat

master
Nicolas Massé 6 years ago
parent
commit
c3a2d30262
  1. 29
      main.go

29
main.go

@ -2,11 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/spf13/viper"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"gopkg.in/yaml.v2"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
@ -16,6 +11,12 @@ import (
"strings" "strings"
"time" "time"
"unicode" "unicode"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/spf13/viper"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"gopkg.in/yaml.v2"
) )
var chatDB map[string]int64 = make(map[string]int64) var chatDB map[string]int64 = make(map[string]int64)
@ -33,6 +34,7 @@ func main() {
viper.SetDefault("MsgNoUsername", "Sorry, you need to set your username") viper.SetDefault("MsgNoUsername", "Sorry, you need to set your username")
viper.SetDefault("MsgThankYouMedia", "Got it, thanks!") viper.SetDefault("MsgThankYouMedia", "Got it, thanks!")
viper.SetDefault("MsgThankYouText", "Thank you!") viper.SetDefault("MsgThankYouText", "Thank you!")
viper.SetDefault("MsgSendMeSomething", "OK. Send me something.")
viper.SetConfigName("photo-bot") // name of config file (without extension) viper.SetConfigName("photo-bot") // name of config file (without extension)
viper.AddConfigPath("/etc/photo-bot/") viper.AddConfigPath("/etc/photo-bot/")
@ -152,6 +154,12 @@ func main() {
} else { } else {
replyWithMessage(bot, update.Message, viper.GetString("MsgInfoNoAlbum")) replyWithMessage(bot, update.Message, viper.GetString("MsgInfoNoAlbum"))
} }
case "pourLouise":
if !albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum"))
continue
}
replyWithForcedReply(bot, update.Message, viper.GetString("MsgSendMeSomething"))
case "cloreAlbum": case "cloreAlbum":
if !albumAlreadyOpen() { if !albumAlreadyOpen() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoAlbum"))
@ -182,7 +190,6 @@ func main() {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgServerError")) replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgServerError"))
continue continue
} }
//dispatchMessage(bot, update.Message)
replyWithMessage(bot, update.Message, viper.GetString("MsgThankYouText")) replyWithMessage(bot, update.Message, viper.GetString("MsgThankYouText"))
} }
} else if update.Message.Photo != nil { } else if update.Message.Photo != nil {
@ -253,6 +260,16 @@ func updateChatDB(message *tgbotapi.Message) error {
return nil return nil
} }
func replyWithForcedReply(bot *tgbotapi.BotAPI, message *tgbotapi.Message, text string) error {
msg := tgbotapi.NewMessage(message.Chat.ID, text)
msg.ReplyMarkup = tgbotapi.ForceReply{
ForceReply: true,
Selective: true,
}
_, err := bot.Send(msg)
return err
}
func replyToCommandWithMessage(bot *tgbotapi.BotAPI, message *tgbotapi.Message, text string) error { func replyToCommandWithMessage(bot *tgbotapi.BotAPI, message *tgbotapi.Message, text string) error {
msg := tgbotapi.NewMessage(message.Chat.ID, text) msg := tgbotapi.NewMessage(message.Chat.ID, text)
msg.ReplyToMessageID = message.MessageID msg.ReplyToMessageID = message.MessageID

Loading…
Cancel
Save