🔖 Releasing v1.2
With buttons-menu, improved searching and 'delPack' command!
This commit is contained in:
parent
6ade04cfc9
commit
74430226b9
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// actions function check Message update on commands, sended stickers or other user stuff
|
||||
func actions(msg *tg.Message) {
|
||||
state, err := dbGetUserState(msg.From.ID)
|
||||
errCheck(err)
|
||||
|
||||
log.Ln("state:", state)
|
||||
switch state {
|
||||
case stateAddSticker:
|
||||
actionAdd(msg, false)
|
||||
case stateAddPack:
|
||||
actionAdd(msg, true)
|
||||
case stateDeleteSticker:
|
||||
actionDelete(msg, false)
|
||||
case stateDeletePack:
|
||||
actionDelete(msg, true)
|
||||
case stateReset:
|
||||
actionReset(msg)
|
||||
default:
|
||||
err = dbChangeUserState(msg.From.ID, stateNone)
|
||||
errCheck(err)
|
||||
|
||||
actionError(msg)
|
||||
}
|
||||
}
|
12
add.go
12
add.go
|
@ -47,11 +47,9 @@ func actionAdd(msg *tg.Message, pack bool) {
|
|||
|
||||
if !pack {
|
||||
var exist bool
|
||||
sticker := msg.Sticker
|
||||
exist, err = dbAddSticker(
|
||||
msg.From.ID,
|
||||
msg.Sticker.SetName,
|
||||
msg.Sticker.FileID,
|
||||
msg.Sticker.Emoji,
|
||||
msg.From.ID, sticker.SetName, sticker.FileID, sticker.Emoji,
|
||||
)
|
||||
errCheck(err)
|
||||
|
||||
|
@ -83,10 +81,7 @@ func actionAdd(msg *tg.Message, pack bool) {
|
|||
for _, sticker := range set.Stickers {
|
||||
var exist bool
|
||||
exist, err = dbAddSticker(
|
||||
msg.From.ID,
|
||||
sticker.SetName,
|
||||
sticker.FileID,
|
||||
sticker.Emoji,
|
||||
msg.From.ID, sticker.SetName, sticker.FileID, sticker.Emoji,
|
||||
)
|
||||
errCheck(err)
|
||||
|
||||
|
@ -96,7 +91,6 @@ func actionAdd(msg *tg.Message, pack bool) {
|
|||
}
|
||||
|
||||
log.Ln("All exists?", allExists)
|
||||
|
||||
if allExists {
|
||||
reply.Text = T("error_already_add_pack", map[string]interface{}{
|
||||
"SetTitle": set.Title,
|
||||
|
|
30
commands.go
30
commands.go
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"strings"
|
||||
|
||||
// log "github.com/kirillDanshin/dlog"
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
|
@ -19,31 +19,23 @@ const (
|
|||
)
|
||||
|
||||
func commands(msg *tg.Message) {
|
||||
T, err := switchLocale(msg.From.LanguageCode)
|
||||
errCheck(err)
|
||||
|
||||
switch {
|
||||
case strings.ToLower(msg.Command()) == strings.ToLower(cmdStart):
|
||||
log.Ln("command:", msg.Command())
|
||||
switch strings.ToLower(msg.Command()) {
|
||||
case strings.ToLower(cmdStart):
|
||||
commandStart(msg)
|
||||
case strings.ToLower(msg.Command()) == strings.ToLower(cmdHelp):
|
||||
case strings.ToLower(cmdHelp):
|
||||
commandHelp(msg)
|
||||
case msg.Text == T("button_add_sticker"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdAddSticker):
|
||||
case strings.ToLower(cmdAddSticker):
|
||||
commandAdd(msg, false)
|
||||
case msg.Text == T("button_add_pack"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdAddPack):
|
||||
case strings.ToLower(cmdAddPack):
|
||||
commandAdd(msg, true)
|
||||
case msg.Text == T("button_del_sticker"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdDeleteSticker):
|
||||
case strings.ToLower(cmdDeleteSticker):
|
||||
commandDelete(msg, false)
|
||||
case msg.Text == T("button_del_pack"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdDeletePack):
|
||||
case strings.ToLower(cmdDeletePack):
|
||||
commandDelete(msg, true)
|
||||
case msg.Text == T("button_reset"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdReset):
|
||||
case strings.ToLower(cmdReset):
|
||||
commandReset(msg)
|
||||
case msg.Text == T("button_cancel"),
|
||||
strings.ToLower(msg.Command()) == strings.ToLower(cmdCancel):
|
||||
case strings.ToLower(cmdCancel):
|
||||
commandCancel(msg)
|
||||
}
|
||||
}
|
||||
|
|
15
database.go
15
database.go
|
@ -5,8 +5,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
"github.com/tidwall/buntdb" // Redis-like database
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -57,11 +57,7 @@ func dbGetUsers() ([]int, error) {
|
|||
func dbChangeUserState(userID int, state string) error {
|
||||
log.Ln("Trying to change", userID, "state to", state)
|
||||
return db.Update(func(tx *buntdb.Tx) error {
|
||||
_, _, err := tx.Set(
|
||||
fmt.Sprint("user:", userID, ":state"), // key
|
||||
state, // val
|
||||
nil, // options
|
||||
)
|
||||
_, _, err := tx.Set(fmt.Sprint("user:", userID, ":state"), state, nil)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
@ -119,7 +115,9 @@ func dbDeleteSticker(userID int, setName, fileID string) (bool, error) {
|
|||
}
|
||||
|
||||
err := db.Update(func(tx *buntdb.Tx) error {
|
||||
_, err := tx.Delete(fmt.Sprint("user:", userID, ":set:", setName, ":sticker:", fileID))
|
||||
_, err := tx.Delete(
|
||||
fmt.Sprint("user:", userID, ":set:", setName, ":sticker:", fileID),
|
||||
)
|
||||
return err
|
||||
})
|
||||
|
||||
|
@ -215,7 +213,6 @@ func dbGetUserStickers(userID, offset int, query string) ([]string, int, error)
|
|||
}
|
||||
|
||||
total++
|
||||
|
||||
if count >= 51 {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// allowedUpdates is a value for parameter of updates configuration
|
||||
|
|
|
@ -54,14 +54,8 @@ error_unknown:
|
|||
other: |-
|
||||
I do not know what to do with this sticker.
|
||||
Please run /{{.AddStickerCommand}}, /{{.AddPackCommand}}, /{{.DeleteStickerCommand}} or /{{.DeletePackCommand}} command first.
|
||||
meta_key_phrase:
|
||||
key_phrase:
|
||||
other: Yes, I am totally sure.
|
||||
meta_reset_1:
|
||||
other: Wait. Who are you?
|
||||
meta_reset_2:
|
||||
other: What are you doing here?
|
||||
meta_reset_3:
|
||||
other: What am I doing here?
|
||||
reply_add_pack:
|
||||
other: Send an existing stickers from any other packs to add the entire packs to
|
||||
yourself.
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
meta_key_phrase:
|
||||
other: Yes, I am totally sure.
|
||||
meta_reset_1:
|
||||
other: Wait. Who are you?
|
||||
meta_reset_2:
|
||||
other: What are you doing here?
|
||||
meta_reset_3:
|
||||
other: What am I doing here?
|
|
@ -0,0 +1,2 @@
|
|||
key_phrase:
|
||||
other: Yes, I am totally sure.
|
|
@ -55,14 +55,8 @@ error_unknown:
|
|||
other: |-
|
||||
Я понятия не имею что делать с этим стикером.
|
||||
Пожалуйста, сначала примени /{{.AddStickerCommand}}, /{{.AddPackCommand}}, /{{.DeleteStickerCommand}} или /{{.DeletePackCommand}}.
|
||||
meta_key_phrase:
|
||||
key_phrase:
|
||||
other: Да, я абсолютно уверен.
|
||||
meta_reset_1:
|
||||
other: Подожди. Кто ты?
|
||||
meta_reset_2:
|
||||
other: Что ты здесь делаешь?
|
||||
meta_reset_3:
|
||||
other: Что Я здесь делаю?
|
||||
reply_add_pack:
|
||||
other: Пришли стикеры из любых других наборов чтобы целиком добавить их наборы в
|
||||
свой.
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
meta_key_phrase:
|
||||
other: Да, я абсолютно уверен.
|
||||
meta_reset_1:
|
||||
other: Подожди. Кто ты?
|
||||
meta_reset_2:
|
||||
other: Что ты здесь делаешь?
|
||||
meta_reset_3:
|
||||
other: Что Я здесь делаю?
|
|
@ -0,0 +1,2 @@
|
|||
key_phrase:
|
||||
other: Да, я абсолютно уверен.
|
6
init.go
6
init.go
|
@ -6,9 +6,9 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
"github.com/nicksnyder/go-i18n/i18n" // Internationalization and localization
|
||||
"github.com/olebedev/config" // Easy configuration file parsing
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
"github.com/olebedev/config"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
4
main.go
4
main.go
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// bot is general structure of the bot
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
package main
|
||||
|
||||
import tg "github.com/toby3d/telegram"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// message function check Message update on commands, sended stickers or other
|
||||
// user stuff
|
||||
func messages(msg *tg.Message) {
|
||||
state, err := dbGetUserState(msg.From.ID)
|
||||
T, err := switchLocale(msg.From.LanguageCode)
|
||||
errCheck(err)
|
||||
|
||||
switch state {
|
||||
case stateAddSticker:
|
||||
actionAdd(msg, false)
|
||||
case stateAddPack:
|
||||
actionAdd(msg, true)
|
||||
case stateDeleteSticker:
|
||||
actionDelete(msg, false)
|
||||
case stateDeletePack:
|
||||
actionDelete(msg, true)
|
||||
case stateReset:
|
||||
actionReset(msg)
|
||||
case stateNone:
|
||||
actionError(msg)
|
||||
default:
|
||||
err = dbChangeUserState(msg.From.ID, stateNone)
|
||||
errCheck(err)
|
||||
|
||||
messages(msg)
|
||||
switch {
|
||||
case strings.EqualFold(msg.Text, T("button_add_sticker")):
|
||||
commandAdd(msg, false)
|
||||
case strings.EqualFold(msg.Text, T("button_add_pack")):
|
||||
commandAdd(msg, true)
|
||||
case strings.EqualFold(msg.Text, T("button_del_sticker")):
|
||||
commandDelete(msg, false)
|
||||
case strings.EqualFold(msg.Text, T("button_del_pack")):
|
||||
commandDelete(msg, true)
|
||||
case strings.EqualFold(msg.Text, T("button_reset")):
|
||||
commandReset(msg)
|
||||
case strings.EqualFold(msg.Text, T("button_cancel")):
|
||||
commandCancel(msg)
|
||||
case strings.EqualFold(msg.Text, T("meta_key_phrase")):
|
||||
actions(msg)
|
||||
}
|
||||
}
|
||||
|
|
38
reset.go
38
reset.go
|
@ -1,10 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func commandReset(msg *tg.Message) {
|
||||
|
@ -24,7 +23,6 @@ func commandReset(msg *tg.Message) {
|
|||
reply := tg.NewMessage(msg.Chat.ID, T("error_already_reset"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = getMenuKeyboard(T)
|
||||
|
||||
_, err = bot.SendMessage(reply)
|
||||
errCheck(err)
|
||||
return
|
||||
|
@ -33,15 +31,12 @@ func commandReset(msg *tg.Message) {
|
|||
err = dbChangeUserState(msg.From.ID, stateReset)
|
||||
errCheck(err)
|
||||
|
||||
reply := tg.NewMessage(
|
||||
msg.Chat.ID,
|
||||
T("reply_reset", map[string]interface{}{
|
||||
"KeyPhrase": T("meta_key_phrase"),
|
||||
"CancelCommand": cmdCancel,
|
||||
}))
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("reply_reset", map[string]interface{}{
|
||||
"KeyPhrase": T("meta_key_phrase"),
|
||||
"CancelCommand": cmdCancel,
|
||||
}))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = getCancelButton(T)
|
||||
|
||||
_, err = bot.SendMessage(reply)
|
||||
errCheck(err)
|
||||
}
|
||||
|
@ -56,11 +51,10 @@ func actionReset(msg *tg.Message) {
|
|||
_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
|
||||
errCheck(err)
|
||||
|
||||
if msg.Text != T("meta_key_phrase") {
|
||||
if !strings.EqualFold(msg.Text, T("meta_key_phrase")) {
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("error_reset_phrase"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = getMenuKeyboard(T)
|
||||
|
||||
_, err = bot.SendMessage(reply)
|
||||
errCheck(err)
|
||||
return
|
||||
|
@ -71,23 +65,7 @@ func actionReset(msg *tg.Message) {
|
|||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("success_reset"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = tg.NewReplyKeyboardRemove(false)
|
||||
|
||||
reply.ReplyMarkup = getMenuKeyboard(T)
|
||||
_, err = bot.SendMessage(reply)
|
||||
errCheck(err)
|
||||
|
||||
for i := 1; i <= 3; i++ {
|
||||
_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
|
||||
errCheck(err)
|
||||
|
||||
text := T(fmt.Sprint("meta_reset_", i))
|
||||
|
||||
time.Sleep(time.Minute * time.Duration(len(text)) / 1000)
|
||||
|
||||
reply = tg.NewMessage(msg.Chat.ID, text)
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
|
||||
_, err = bot.SendMessage(reply)
|
||||
errCheck(err)
|
||||
}
|
||||
}
|
||||
|
|
14
start.go
14
start.go
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"strings"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func commandStart(msg *tg.Message) {
|
||||
|
@ -25,12 +25,10 @@ func commandStart(msg *tg.Message) {
|
|||
T, err := switchLocale(msg.From.LanguageCode)
|
||||
errCheck(err)
|
||||
|
||||
reply := tg.NewMessage(
|
||||
msg.Chat.ID, T("reply_start", map[string]interface{}{
|
||||
"Username": bot.Self.Username,
|
||||
"ID": bot.Self.ID,
|
||||
}),
|
||||
)
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("reply_start", map[string]interface{}{
|
||||
"Username": bot.Self.Username,
|
||||
"ID": bot.Self.ID,
|
||||
}))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = getMenuKeyboard(T)
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
"github.com/nicksnyder/go-i18n/i18n" // Internationalization and localization
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
const langFallback = "en"
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"time"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func updateChannelPost(post *tg.Message) {
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"strconv"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
tg "github.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
func updateInlineQuery(inlineQuery *tg.InlineQuery) {
|
||||
|
|
|
@ -11,10 +11,12 @@ func updateMessage(msg *tg.Message) {
|
|||
return
|
||||
}
|
||||
|
||||
if msg.IsCommand() || msg.Text != "" {
|
||||
switch {
|
||||
case bot.IsCommandToMe(msg):
|
||||
commands(msg)
|
||||
return
|
||||
case msg.Text != "":
|
||||
messages(msg)
|
||||
default:
|
||||
actions(msg)
|
||||
}
|
||||
|
||||
messages(msg)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue