🚚 Moving to GitLab
This commit is contained in:
parent
ade07764c0
commit
c086448a32
35 changed files with 240 additions and 213 deletions
|
@ -1,20 +0,0 @@
|
|||
<!--
|
||||
Welcome to my repo! 👋
|
||||
|
||||
Need help or you have a question? Please come chat in Discord: https://discord.gg/KYQB9FR
|
||||
Found a bug? Want a new feature? Please fill out the sections below. Thanks! 👍
|
||||
-->
|
||||
### Summary
|
||||
<!-- A summary of the issue or, maybe, your ideas for the feature. -->
|
||||
|
||||
### How-To
|
||||
<!--
|
||||
1. This is the first step
|
||||
2. This is the second step, etc.
|
||||
|
||||
Any other info e.g. Why do you consider this to be a bug? What did you expect to happen instead?
|
||||
|
||||
If this is a feature, then describe how it works, what it can potentially be useful, and so on.
|
||||
|
||||
P.S.: Bugs are always in priority over the new functionality, unless, of course, it was offered by a sponsor on my Patreon: https://patreon.com/toby3d
|
||||
-->
|
|
@ -1,16 +0,0 @@
|
|||
<!--
|
||||
Thanks for your help to my repo! 👋
|
||||
|
||||
Need help or you have a question? Please come chat in Discord: https://discord.gg/KYQB9FR
|
||||
Fixed a bug? Added new feature? Make a new translation? Please fill out the section below. Thanks! 👍
|
||||
-->
|
||||
### Summary
|
||||
<!--
|
||||
Describe the essence of your commits.
|
||||
|
||||
- Is it a fix, feature or a translation?
|
||||
- What issue is closed by your commits?
|
||||
- You are totally sure what are you removed all warnings by [gometalinter](https://github.com/alecthomas/gometalinter)?
|
||||
- Your code is compiled without errors?
|
||||
- Your code works without obvious errors?
|
||||
-->
|
|
@ -2,10 +2,10 @@ package actions
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Action function check Message update on commands, sended stickers or other
|
||||
|
|
|
@ -2,13 +2,13 @@ package actions
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Add action add sticker or set to user's pack
|
||||
|
@ -24,7 +24,7 @@ func Add(msg *tg.Message, pack bool) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("success_add_sticker"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
|
||||
if !pack {
|
||||
var exist bool
|
||||
|
@ -36,7 +36,7 @@ func Add(msg *tg.Message, pack bool) {
|
|||
reply.Text = T("error_already_add_sticker")
|
||||
}
|
||||
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
return
|
||||
|
@ -75,7 +75,7 @@ func Add(msg *tg.Message, pack bool) {
|
|||
}
|
||||
}
|
||||
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ package actions
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Delete action remove sticker or set from user's pack
|
||||
|
@ -23,8 +23,8 @@ func Delete(msg *tg.Message, pack bool) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("success_del_sticker"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
|
||||
var notExist bool
|
||||
if pack {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package actions
|
||||
|
||||
import (
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Error action send error reply about invalid user request
|
||||
|
@ -25,8 +25,8 @@ func Error(msg *tg.Message) {
|
|||
"DeletePackCommand": models.CommandDeletePack,
|
||||
}),
|
||||
)
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
|
|
|
@ -3,13 +3,13 @@ package actions
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Reset action checks key phrase and reset user's pack
|
||||
|
@ -25,8 +25,8 @@ func Reset(msg *tg.Message) {
|
|||
|
||||
if !strings.EqualFold(msg.Text, T("key_phrase")) {
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("error_reset_phrase"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
|
@ -37,8 +37,8 @@ func Reset(msg *tg.Message) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("success_reset"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package bot
|
||||
|
||||
import tg "github.com/toby3d/telegram"
|
||||
import tg "gitlab.com/toby3d/telegram"
|
||||
|
||||
// Bot is a main object of Telegram bot
|
||||
var Bot *tg.Bot
|
||||
|
||||
// New just create new bot by configuration credentials
|
||||
func New(accessToken string) (*tg.Bot, error) {
|
||||
func New(accessToken string) (bot *tg.Bot, err error) {
|
||||
return tg.New(accessToken)
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@ package commands
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Add command prepare user for adding some stickers or sets to his pack
|
||||
|
@ -20,8 +20,8 @@ func Add(msg *tg.Message, pack bool) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("reply_add_sticker"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
|
||||
err = db.DB.ChangeUserState(msg.From, models.StateAddSticker)
|
||||
errors.Check(err)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Cancel just cancel current user operation
|
||||
|
@ -41,7 +41,7 @@ func Cancel(msg *tg.Message) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, text)
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
|
|
|
@ -2,17 +2,17 @@ package commands
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Command check's got user command
|
||||
func Command(msg *tg.Message) {
|
||||
log.Ln("command:", msg.Command())
|
||||
switch {
|
||||
case msg.IsCommandEqual(models.CommandStart):
|
||||
case msg.IsCommandEqual(tg.CommandStart):
|
||||
Start(msg)
|
||||
case msg.IsCommandEqual(models.CommandHelp):
|
||||
case msg.IsCommandEqual(tg.CommandHelp):
|
||||
Help(msg)
|
||||
case msg.IsCommandEqual(models.CommandAddSticker):
|
||||
Add(msg, false)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Delete prepare user to remove some stickers or sets from his pack
|
||||
|
@ -26,15 +26,15 @@ func Delete(msg *tg.Message, pack bool) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("error_empty_del"))
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
return
|
||||
}
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("reply_del_sticker"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
|
||||
err = db.DB.ChangeUserState(msg.From, models.StateDeleteSticker)
|
||||
errors.Check(err)
|
||||
|
@ -53,7 +53,7 @@ func Delete(msg *tg.Message, pack bool) {
|
|||
errors.Check(err)
|
||||
|
||||
reply = tg.NewMessage(msg.Chat.ID, T("reply_switch_button"))
|
||||
reply.ReplyMarkup = helpers.SwitchButton(T)
|
||||
reply.ReplyMarkup = utils.SwitchButton(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Help just send instructions about bot usage
|
||||
|
@ -32,8 +32,8 @@ func Help(msg *tg.Message) {
|
|||
"Username": bot.Bot.Username,
|
||||
}),
|
||||
)
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Reset prepare user to reset his pack
|
||||
|
@ -26,8 +26,8 @@ func Reset(msg *tg.Message) {
|
|||
errors.Check(err)
|
||||
|
||||
reply := tg.NewMessage(msg.Chat.ID, T("error_already_reset"))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
return
|
||||
|
@ -40,8 +40,8 @@ func Reset(msg *tg.Message) {
|
|||
"KeyPhrase": T("key_phrase"),
|
||||
"CancelCommand": models.CommandCancel,
|
||||
}))
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.CancelButton(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.CancelButton(T)
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"strings"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Start just send introduction about bot to user
|
||||
|
@ -23,7 +23,7 @@ func Start(msg *tg.Message) {
|
|||
|
||||
if msg.HasCommandArgument() {
|
||||
log.Ln("Received a", msg.Command(), "command with", msg.CommandArgument(), "argument")
|
||||
if strings.EqualFold(msg.CommandArgument(), models.CommandHelp) {
|
||||
if strings.EqualFold(msg.CommandArgument(), tg.CommandHelp) {
|
||||
Help(msg)
|
||||
return
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ func Start(msg *tg.Message) {
|
|||
"ID": bot.Bot.ID,
|
||||
}),
|
||||
)
|
||||
reply.ParseMode = tg.ModeMarkdown
|
||||
reply.ReplyMarkup = helpers.MenuKeyboard(T)
|
||||
reply.ParseMode = tg.StyleMarkdown
|
||||
reply.ReplyMarkup = utils.MenuKeyboard(T)
|
||||
|
||||
_, err = bot.Bot.SendMessage(reply)
|
||||
errors.Check(err)
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// AddSticker add sticker FileID, Emoji and SetName meta for UserID
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// ChangeUserState change current user state on input state.
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// DeletePack remove all keys for UserID which contains input SetName
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// DeleteSticker just remove specified sticker key from database.
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// UserState return current state for UserID
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// GetUserStickers return array of saved stickers for input UserID and his total count
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// ResetUser just drop out all stickers keys for input UserID
|
||||
|
|
31
internal/db/user_state.go
Normal file
31
internal/db/user_state.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/tidwall/buntdb"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// UserState return current state for UserID
|
||||
func (db *DataBase) UserState(usr *tg.User) (string, error) {
|
||||
log.Ln("Trying to get", usr.ID, "state")
|
||||
var state string
|
||||
err := DB.View(func(tx *buntdb.Tx) error {
|
||||
var err error
|
||||
state, err = tx.Get(fmt.Sprint("user:", usr.ID, ":state"))
|
||||
return err
|
||||
})
|
||||
|
||||
switch err {
|
||||
case buntdb.ErrNotFound:
|
||||
log.Ln(usr.ID, "not found, create new one")
|
||||
if err = db.ChangeUserState(usr, models.StateNone); err != nil {
|
||||
return state, err
|
||||
}
|
||||
}
|
||||
|
||||
return state, err
|
||||
}
|
|
@ -2,7 +2,7 @@ package i18n
|
|||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
)
|
||||
|
||||
// SwitchTo try load locales by input language codes and return TranslateFunc
|
||||
|
|
|
@ -3,11 +3,11 @@ package messages
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/toby3d/MyPackBot/internal/actions"
|
||||
"github.com/toby3d/MyPackBot/internal/commands"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/actions"
|
||||
"gitlab.com/toby3d/mypackbot/internal/commands"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Message checks user message on response, stickers, reset key phrase, else do
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package models
|
||||
|
||||
import tg "github.com/toby3d/telegram"
|
||||
import tg "gitlab.com/toby3d/telegram"
|
||||
|
||||
// Commands... represents available and supported bot commands
|
||||
const (
|
||||
CommandAddPack = "addPack"
|
||||
CommandAddSticker = "addSticker"
|
||||
CommandCancel = "cancel"
|
||||
CommandHelp = "help"
|
||||
CommandDeleteSticker = "delSticker"
|
||||
CommandDeletePack = "delPack"
|
||||
CommandReset = "reset"
|
||||
CommandStart = "start"
|
||||
)
|
||||
|
||||
// State... represents current state of user action
|
||||
|
|
|
@ -2,58 +2,67 @@ package updates
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/config"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/config"
|
||||
"gitlab.com/toby3d/mypackbot/internal/models"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Channel return webhook or long polling channel with bot updates
|
||||
func Channel(webhookMode bool) tg.UpdatesChannel {
|
||||
func Channel(webhookMode bool) (updates tg.UpdatesChannel, err error) {
|
||||
log.Ln("Preparing channel for updates...")
|
||||
if !webhookMode {
|
||||
log.Ln("Use LongPolling updates")
|
||||
|
||||
info, err := bot.Bot.GetWebhookInfo()
|
||||
errors.Check(err)
|
||||
var info *tg.WebhookInfo
|
||||
info, err = bot.Bot.GetWebhookInfo()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if info.URL != "" {
|
||||
log.Ln("Deleting webhook...")
|
||||
_, err := bot.Bot.DeleteWebhook()
|
||||
errors.Check(err)
|
||||
_, err = bot.Bot.DeleteWebhook()
|
||||
return
|
||||
}
|
||||
|
||||
return bot.Bot.NewLongPollingChannel(&tg.GetUpdatesParameters{
|
||||
updates = bot.Bot.NewLongPollingChannel(&tg.GetUpdatesParameters{
|
||||
Offset: 0,
|
||||
Limit: 100,
|
||||
Timeout: 60,
|
||||
AllowedUpdates: models.AllowedUpdates,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
set, err := url.Parse(config.Config.GetString("telegram.webhook.set"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set := config.Config.GetString("telegram.webhook.set")
|
||||
listen := config.Config.GetString("telegram.webhook.listen")
|
||||
serve := config.Config.GetString("telegram.webhook.serve")
|
||||
|
||||
log.Ln(
|
||||
"Trying set webhook on address:",
|
||||
fmt.Sprint(set, listen, bot.Bot.AccessToken),
|
||||
fmt.Sprint(set.String(), bot.Bot.AccessToken),
|
||||
)
|
||||
|
||||
log.Ln("Creating new webhook...")
|
||||
webhook := tg.NewWebhook(fmt.Sprint(set, listen, bot.Bot.AccessToken), nil)
|
||||
webhook.MaxConnections = 40
|
||||
webhook.AllowedUpdates = models.AllowedUpdates
|
||||
params := tg.NewWebhook(fmt.Sprint(set, listen, bot.Bot.AccessToken), nil)
|
||||
params.MaxConnections = 40
|
||||
params.AllowedUpdates = models.AllowedUpdates
|
||||
|
||||
return bot.Bot.NewWebhookChannel(
|
||||
webhook, // params
|
||||
"", // certFile
|
||||
"", // keyFile
|
||||
set, // set
|
||||
fmt.Sprint(listen, bot.Bot.AccessToken), // listen
|
||||
serve, // serve
|
||||
updates = bot.Bot.NewWebhookChannel(
|
||||
set,
|
||||
params, // params
|
||||
"", // certFile
|
||||
"", // keyFile
|
||||
serve, // serve
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"time"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/config"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/config"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// ChannelPost checks ChannelPost update for forwarding content to bot users
|
||||
|
|
|
@ -4,18 +4,17 @@ import (
|
|||
"strconv"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/db"
|
||||
"github.com/toby3d/MyPackBot/internal/errors"
|
||||
"github.com/toby3d/MyPackBot/internal/helpers"
|
||||
"github.com/toby3d/MyPackBot/internal/i18n"
|
||||
"github.com/toby3d/MyPackBot/internal/models"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/utils"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// InlineQuery checks InlineQuery updates for answer with personal results
|
||||
func InlineQuery(inlineQuery *tg.InlineQuery) {
|
||||
fixedQuery, err := helpers.FixEmoji(inlineQuery.Query)
|
||||
fixedQuery, err := utils.FixEmoji(inlineQuery.Query)
|
||||
if err == nil {
|
||||
inlineQuery.Query = fixedQuery
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ func InlineQuery(inlineQuery *tg.InlineQuery) {
|
|||
},
|
||||
)
|
||||
|
||||
answer.SwitchPrivateMessageParameter = models.CommandHelp
|
||||
answer.SwitchPrivateMessageParameter = tg.CommandHelp
|
||||
}
|
||||
|
||||
answer.Results = nil
|
||||
|
|
|
@ -2,11 +2,11 @@ package updates
|
|||
|
||||
import (
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
"github.com/toby3d/MyPackBot/internal/actions"
|
||||
"github.com/toby3d/MyPackBot/internal/bot"
|
||||
"github.com/toby3d/MyPackBot/internal/commands"
|
||||
"github.com/toby3d/MyPackBot/internal/messages"
|
||||
tg "github.com/toby3d/telegram"
|
||||
"gitlab.com/toby3d/mypackbot/internal/actions"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/commands"
|
||||
"gitlab.com/toby3d/mypackbot/internal/messages"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// Message checks Message updates for answer to user commands, replies or sended
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package helpers
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// CancelButton helper just generate ReplyMarkup with cancel button
|
|
@ -1,4 +1,4 @@
|
|||
package helpers
|
||||
package utils
|
||||
|
||||
import (
|
||||
"golang.org/x/text/runes"
|
|
@ -1,8 +1,8 @@
|
|||
package helpers
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// MenuKeyboard helper just generate ReplyMarkup with menu buttons
|
|
@ -1,8 +1,8 @@
|
|||
package helpers
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/i18n"
|
||||
tg "github.com/toby3d/telegram"
|
||||
tg "gitlab.com/toby3d/telegram"
|
||||
)
|
||||
|
||||
// SwitchButton helper just generate ReplyMarkup with SelfSwitch button
|
32
main.go
32
main.go
|
@ -4,8 +4,12 @@ import (
|
|||
"flag"
|
||||
|
||||
log "github.com/kirillDanshin/dlog"
|
||||
_ "github.com/toby3d/MyPackBot/init"
|
||||
"github.com/toby3d/MyPackBot/internal/updates"
|
||||
"gitlab.com/toby3d/mypackbot/internal/bot"
|
||||
"gitlab.com/toby3d/mypackbot/internal/config"
|
||||
"gitlab.com/toby3d/mypackbot/internal/db"
|
||||
"gitlab.com/toby3d/mypackbot/internal/errors"
|
||||
"gitlab.com/toby3d/mypackbot/internal/i18n"
|
||||
"gitlab.com/toby3d/mypackbot/internal/updates"
|
||||
)
|
||||
|
||||
var flagWebhook = flag.Bool(
|
||||
|
@ -13,11 +17,33 @@ var flagWebhook = flag.Bool(
|
|||
"enable work via webhooks (required valid certificates)",
|
||||
)
|
||||
|
||||
// init prepare configuration and other things for successful start
|
||||
func init() {
|
||||
log.Ln("Initializing...")
|
||||
|
||||
// Preload localization strings
|
||||
err := i18n.Open("i18n/")
|
||||
errors.Check(err)
|
||||
|
||||
// Preload configuration file
|
||||
config.Open("configs/config.yaml")
|
||||
|
||||
// Open database or create new one
|
||||
db.Open("stickers.db")
|
||||
|
||||
// Create bot with credentials from config
|
||||
bot.Bot, err = bot.New(config.Config.GetString("telegram.token"))
|
||||
errors.Check(err)
|
||||
}
|
||||
|
||||
// main function is a general function for work of this bot
|
||||
func main() {
|
||||
flag.Parse() // Parse flagWebhook
|
||||
|
||||
for update := range updates.Channel(*flagWebhook) {
|
||||
channel, err := updates.Channel(*flagWebhook)
|
||||
errors.Check(err)
|
||||
|
||||
for update := range channel {
|
||||
log.D(update)
|
||||
switch {
|
||||
case update.IsInlineQuery():
|
||||
|
|
Loading…
Reference in a new issue