From 35e3d54ea3293c4cec71c6b0b912cfba432e8611 Mon Sep 17 00:00:00 2001 From: Lulzette Date: Sat, 23 Oct 2021 01:48:45 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BE=D1=82=20Redis=20=D0=B8=20=D1=83=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=BB=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D1=83=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B2=20crisp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 4 ---- main.go | 58 ++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e71cc35..bc8b8a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,3 @@ services: build: . volumes: - /root/config.yml:/app/config.yml - depends_on: - - db - db: - image: redis diff --git a/main.go b/main.go index aae8399..63d0b8d 100644 --- a/main.go +++ b/main.go @@ -8,15 +8,15 @@ import ( "time" "github.com/crisp-im/go-crisp-api/crisp" - "github.com/go-redis/redis" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" - "github.com/spf13/viper" "github.com/l0sted/Crisp_Telegram_bot/utils" + "github.com/spf13/viper" ) var bot *tgbotapi.BotAPI var client *crisp.Client -var redisClient *redis.Client + +// var redisClient *redis.Client var config *viper.Viper // CrispMessageInfo stores the original message @@ -35,6 +35,7 @@ func (s *CrispMessageInfo) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, s) } +/* func contains(s []interface{}, e int64) bool { for _, a := range s { if int64(a.(int)) == e { @@ -43,6 +44,8 @@ func contains(s []interface{}, e int64) bool { } return false } +*/ +/* //from tg to crisp func replyToUser(update *tgbotapi.Update) { if update.Message.ReplyToMessage == nil { @@ -51,7 +54,7 @@ func replyToUser(update *tgbotapi.Update) { return } - res, err := redisClient.Get(strconv.Itoa(update.Message.ReplyToMessage.MessageID)).Result() + // res, err := redisClient.Get(strconv.Itoa(update.Message.ReplyToMessage.MessageID)).Result() if err != nil { msg := tgbotapi.NewMessage(update.Message.Chat.ID, "ERROR: "+err.Error()) @@ -80,40 +83,44 @@ func replyToUser(update *tgbotapi.Update) { msg := tgbotapi.NewMessage(update.Message.Chat.ID, "回复成功!") bot.Send(msg) } +*/ //from crisp to tg func sendMsgToAdmins(text string, WebsiteID string, SessionID string) { for _, id := range config.Get("admins").([]interface{}) { msg := tgbotapi.NewMessage(int64(id.(int)), text) msg.ParseMode = "Markdown" sent, _ := bot.Send(msg) - - redisClient.Set(strconv.Itoa(sent.MessageID), &CrispMessageInfo{ - WebsiteID, - SessionID, - }, 12*time.Hour) + log.Println(strconv.Itoa(sent.MessageID)) + /* + redisClient.Set(strconv.Itoa(sent.MessageID), &CrispMessageInfo{ + WebsiteID, + SessionID, + }, 12*time.Hour) + */ } } -func init() { +func main() { config = utils.GetConfig() - + var chat_prefix = config.GetString("prefix") log.Printf("Initializing Redis...") + /* + redisClient = redis.NewClient(&redis.Options{ + Addr: config.GetString("redis.host"), + Password: config.GetString("redis.password"), + DB: config.GetInt("redis.db"), + }) - redisClient = redis.NewClient(&redis.Options{ - Addr: config.GetString("redis.host"), - Password: config.GetString("redis.password"), - DB: config.GetInt("redis.db"), - }) + var err error + _, err = redisClient.Ping().Result() + if err != nil { + log.Panic(err) + } + */ var err error - - _, err = redisClient.Ping().Result() - if err != nil { - log.Panic(err) - } - log.Printf("Initializing Bot...") bot, err = tgbotapi.NewBotAPI(config.GetString("telegram.key")) @@ -171,12 +178,17 @@ func init() { log.Fatal("Crisp listener error, check your API key or internet connection?") }, ) + for { + time.Sleep(1 * time.Second) + } } +/* func main() { var updates tgbotapi.UpdatesChannel log.Print("Start pooling") + u := tgbotapi.NewUpdate(0) u.Timeout = 60 @@ -199,5 +211,7 @@ func main() { if contains(config.Get("admins").([]interface{}), int64(update.Message.From.ID)) { // replyToUser(&update) } + } } +*/