use bot token prefix as the redis store namespace

This commit is contained in:
c9s 2020-12-08 16:28:55 +08:00
parent f16cde3b26
commit 6b760c72b7

View File

@ -2,6 +2,7 @@ package telegramnotifier
import ( import (
"fmt" "fmt"
"strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2" tb "gopkg.in/tucnak/telebot.v2"
@ -36,7 +37,9 @@ func New(bot *tb.Bot, authToken string, options ...NotifyOption) *Notifier {
o(notifier) o(notifier)
} }
store := notifier.redis.NewStore("bbgo", "telegram") // use token prefix as the redis namespace
tt := strings.Split(bot.Token, ":")
store := notifier.redis.NewStore("bbgo", "telegram", tt[0])
if err := store.Load(notifier.chatUser) ; err == nil { if err := store.Load(notifier.chatUser) ; err == nil {
bot.Send(notifier.chatUser, fmt.Sprintf("Hi %s, I'm back", notifier.chatUser.Username)) bot.Send(notifier.chatUser, fmt.Sprintf("Hi %s, I'm back", notifier.chatUser.Username))
} }