🚚 Moving to GitLab

This commit is contained in:
Maxim Lebedev 2018-06-24 22:37:20 +05:00
parent ade07764c0
commit c086448a32
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
35 changed files with 240 additions and 213 deletions

View File

@ -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
-->

View File

@ -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?
-->

View File

@ -2,10 +2,10 @@ package actions
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Action function check Message update on commands, sended stickers or other // Action function check Message update on commands, sended stickers or other

View File

@ -2,13 +2,13 @@ package actions
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Add action add sticker or set to user's pack // Add action add sticker or set to user's pack
@ -24,7 +24,7 @@ func Add(msg *tg.Message, pack bool) {
errors.Check(err) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("success_add_sticker")) reply := tg.NewMessage(msg.Chat.ID, T("success_add_sticker"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
if !pack { if !pack {
var exist bool var exist bool
@ -36,7 +36,7 @@ func Add(msg *tg.Message, pack bool) {
reply.Text = T("error_already_add_sticker") reply.Text = T("error_already_add_sticker")
} }
reply.ReplyMarkup = helpers.CancelButton(T) reply.ReplyMarkup = utils.CancelButton(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
return 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) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
} }

View File

@ -2,12 +2,12 @@ package actions
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Delete action remove sticker or set from user's pack // Delete action remove sticker or set from user's pack
@ -23,8 +23,8 @@ func Delete(msg *tg.Message, pack bool) {
errors.Check(err) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("success_del_sticker")) reply := tg.NewMessage(msg.Chat.ID, T("success_del_sticker"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.CancelButton(T) reply.ReplyMarkup = utils.CancelButton(T)
var notExist bool var notExist bool
if pack { if pack {

View File

@ -1,12 +1,12 @@
package actions package actions
import ( import (
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Error action send error reply about invalid user request // Error action send error reply about invalid user request
@ -25,8 +25,8 @@ func Error(msg *tg.Message) {
"DeletePackCommand": models.CommandDeletePack, "DeletePackCommand": models.CommandDeletePack,
}), }),
) )
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)

View File

@ -3,13 +3,13 @@ package actions
import ( import (
"strings" "strings"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Reset action checks key phrase and reset user's pack // 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")) { if !strings.EqualFold(msg.Text, T("key_phrase")) {
reply := tg.NewMessage(msg.Chat.ID, T("error_reset_phrase")) reply := tg.NewMessage(msg.Chat.ID, T("error_reset_phrase"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
@ -37,8 +37,8 @@ func Reset(msg *tg.Message) {
errors.Check(err) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("success_reset")) reply := tg.NewMessage(msg.Chat.ID, T("success_reset"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
} }

View File

@ -1,11 +1,11 @@
package bot package bot
import tg "github.com/toby3d/telegram" import tg "gitlab.com/toby3d/telegram"
// Bot is a main object of Telegram bot // Bot is a main object of Telegram bot
var Bot *tg.Bot var Bot *tg.Bot
// New just create new bot by configuration credentials // 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) return tg.New(accessToken)
} }

View File

@ -2,13 +2,13 @@ package commands
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Add command prepare user for adding some stickers or sets to his pack // 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) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("reply_add_sticker")) reply := tg.NewMessage(msg.Chat.ID, T("reply_add_sticker"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.CancelButton(T) reply.ReplyMarkup = utils.CancelButton(T)
err = db.DB.ChangeUserState(msg.From, models.StateAddSticker) err = db.DB.ChangeUserState(msg.From, models.StateAddSticker)
errors.Check(err) errors.Check(err)

View File

@ -1,13 +1,13 @@
package commands package commands
import ( import (
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Cancel just cancel current user operation // Cancel just cancel current user operation
@ -41,7 +41,7 @@ func Cancel(msg *tg.Message) {
errors.Check(err) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, text) reply := tg.NewMessage(msg.Chat.ID, text)
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)

View File

@ -2,17 +2,17 @@ package commands
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Command check's got user command // Command check's got user command
func Command(msg *tg.Message) { func Command(msg *tg.Message) {
log.Ln("command:", msg.Command()) log.Ln("command:", msg.Command())
switch { switch {
case msg.IsCommandEqual(models.CommandStart): case msg.IsCommandEqual(tg.CommandStart):
Start(msg) Start(msg)
case msg.IsCommandEqual(models.CommandHelp): case msg.IsCommandEqual(tg.CommandHelp):
Help(msg) Help(msg)
case msg.IsCommandEqual(models.CommandAddSticker): case msg.IsCommandEqual(models.CommandAddSticker):
Add(msg, false) Add(msg, false)

View File

@ -1,13 +1,13 @@
package commands package commands
import ( import (
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Delete prepare user to remove some stickers or sets from his pack // 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) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("error_empty_del")) 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) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
return return
} }
reply := tg.NewMessage(msg.Chat.ID, T("reply_del_sticker")) reply := tg.NewMessage(msg.Chat.ID, T("reply_del_sticker"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.CancelButton(T) reply.ReplyMarkup = utils.CancelButton(T)
err = db.DB.ChangeUserState(msg.From, models.StateDeleteSticker) err = db.DB.ChangeUserState(msg.From, models.StateDeleteSticker)
errors.Check(err) errors.Check(err)
@ -53,7 +53,7 @@ func Delete(msg *tg.Message, pack bool) {
errors.Check(err) errors.Check(err)
reply = tg.NewMessage(msg.Chat.ID, T("reply_switch_button")) 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) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
} }

View File

@ -1,13 +1,13 @@
package commands package commands
import ( import (
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Help just send instructions about bot usage // Help just send instructions about bot usage
@ -32,8 +32,8 @@ func Help(msg *tg.Message) {
"Username": bot.Bot.Username, "Username": bot.Bot.Username,
}), }),
) )
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)

View File

@ -1,13 +1,13 @@
package commands package commands
import ( import (
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Reset prepare user to reset his pack // Reset prepare user to reset his pack
@ -26,8 +26,8 @@ func Reset(msg *tg.Message) {
errors.Check(err) errors.Check(err)
reply := tg.NewMessage(msg.Chat.ID, T("error_already_reset")) reply := tg.NewMessage(msg.Chat.ID, T("error_already_reset"))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
return return
@ -40,8 +40,8 @@ func Reset(msg *tg.Message) {
"KeyPhrase": T("key_phrase"), "KeyPhrase": T("key_phrase"),
"CancelCommand": models.CommandCancel, "CancelCommand": models.CommandCancel,
})) }))
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.CancelButton(T) reply.ReplyMarkup = utils.CancelButton(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)
} }

View File

@ -4,13 +4,13 @@ import (
"strings" "strings"
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/utils"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Start just send introduction about bot to user // Start just send introduction about bot to user
@ -23,7 +23,7 @@ func Start(msg *tg.Message) {
if msg.HasCommandArgument() { if msg.HasCommandArgument() {
log.Ln("Received a", msg.Command(), "command with", msg.CommandArgument(), "argument") 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) Help(msg)
return return
} }
@ -39,8 +39,8 @@ func Start(msg *tg.Message) {
"ID": bot.Bot.ID, "ID": bot.Bot.ID,
}), }),
) )
reply.ParseMode = tg.ModeMarkdown reply.ParseMode = tg.StyleMarkdown
reply.ReplyMarkup = helpers.MenuKeyboard(T) reply.ReplyMarkup = utils.MenuKeyboard(T)
_, err = bot.Bot.SendMessage(reply) _, err = bot.Bot.SendMessage(reply)
errors.Check(err) errors.Check(err)

View File

@ -5,8 +5,8 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// AddSticker add sticker FileID, Emoji and SetName meta for UserID // AddSticker add sticker FileID, Emoji and SetName meta for UserID

View File

@ -5,7 +5,7 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// ChangeUserState change current user state on input state. // ChangeUserState change current user state on input state.

View File

@ -6,8 +6,8 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// DeletePack remove all keys for UserID which contains input SetName // DeletePack remove all keys for UserID which contains input SetName

View File

@ -5,8 +5,8 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// DeleteSticker just remove specified sticker key from database. // DeleteSticker just remove specified sticker key from database.

View File

@ -5,8 +5,8 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
"github.com/toby3d/MyPackBot/internal/models" "gitlab.com/toby3d/mypackbot/internal/models"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// UserState return current state for UserID // UserState return current state for UserID

View File

@ -7,7 +7,7 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "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 // GetUserStickers return array of saved stickers for input UserID and his total count

View File

@ -7,7 +7,7 @@ import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// ResetUser just drop out all stickers keys for input UserID // ResetUser just drop out all stickers keys for input UserID

31
internal/db/user_state.go Normal file
View 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
}

View File

@ -2,7 +2,7 @@ package i18n
import ( import (
"github.com/nicksnyder/go-i18n/i18n" "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 // SwitchTo try load locales by input language codes and return TranslateFunc

View File

@ -3,11 +3,11 @@ package messages
import ( import (
"strings" "strings"
"github.com/toby3d/MyPackBot/internal/actions" "gitlab.com/toby3d/mypackbot/internal/actions"
"github.com/toby3d/MyPackBot/internal/commands" "gitlab.com/toby3d/mypackbot/internal/commands"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/i18n"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Message checks user message on response, stickers, reset key phrase, else do // Message checks user message on response, stickers, reset key phrase, else do

View File

@ -1,17 +1,15 @@
package models package models
import tg "github.com/toby3d/telegram" import tg "gitlab.com/toby3d/telegram"
// Commands... represents available and supported bot commands // Commands... represents available and supported bot commands
const ( const (
CommandAddPack = "addPack" CommandAddPack = "addPack"
CommandAddSticker = "addSticker" CommandAddSticker = "addSticker"
CommandCancel = "cancel" CommandCancel = "cancel"
CommandHelp = "help"
CommandDeleteSticker = "delSticker" CommandDeleteSticker = "delSticker"
CommandDeletePack = "delPack" CommandDeletePack = "delPack"
CommandReset = "reset" CommandReset = "reset"
CommandStart = "start"
) )
// State... represents current state of user action // State... represents current state of user action

View File

@ -2,58 +2,67 @@ package updates
import ( import (
"fmt" "fmt"
"net/url"
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/config" "gitlab.com/toby3d/mypackbot/internal/config"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/models"
"github.com/toby3d/MyPackBot/internal/models" tg "gitlab.com/toby3d/telegram"
tg "github.com/toby3d/telegram"
) )
// Channel return webhook or long polling channel with bot updates // 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...") log.Ln("Preparing channel for updates...")
if !webhookMode { if !webhookMode {
log.Ln("Use LongPolling updates") log.Ln("Use LongPolling updates")
info, err := bot.Bot.GetWebhookInfo() var info *tg.WebhookInfo
errors.Check(err) info, err = bot.Bot.GetWebhookInfo()
if err != nil {
return
}
if info.URL != "" { if info.URL != "" {
log.Ln("Deleting webhook...") log.Ln("Deleting webhook...")
_, err := bot.Bot.DeleteWebhook() _, err = bot.Bot.DeleteWebhook()
errors.Check(err) return
} }
return bot.Bot.NewLongPollingChannel(&tg.GetUpdatesParameters{ updates = bot.Bot.NewLongPollingChannel(&tg.GetUpdatesParameters{
Offset: 0, Offset: 0,
Limit: 100, Limit: 100,
Timeout: 60, Timeout: 60,
AllowedUpdates: models.AllowedUpdates, 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") listen := config.Config.GetString("telegram.webhook.listen")
serve := config.Config.GetString("telegram.webhook.serve") serve := config.Config.GetString("telegram.webhook.serve")
log.Ln( log.Ln(
"Trying set webhook on address:", "Trying set webhook on address:",
fmt.Sprint(set, listen, bot.Bot.AccessToken), fmt.Sprint(set.String(), bot.Bot.AccessToken),
) )
log.Ln("Creating new webhook...") log.Ln("Creating new webhook...")
webhook := tg.NewWebhook(fmt.Sprint(set, listen, bot.Bot.AccessToken), nil) params := tg.NewWebhook(fmt.Sprint(set, listen, bot.Bot.AccessToken), nil)
webhook.MaxConnections = 40 params.MaxConnections = 40
webhook.AllowedUpdates = models.AllowedUpdates params.AllowedUpdates = models.AllowedUpdates
return bot.Bot.NewWebhookChannel( updates = bot.Bot.NewWebhookChannel(
webhook, // params set,
"", // certFile params, // params
"", // keyFile "", // certFile
set, // set "", // keyFile
fmt.Sprint(listen, bot.Bot.AccessToken), // listen serve, // serve
serve, // serve
) )
return
} }

View File

@ -4,11 +4,11 @@ import (
"time" "time"
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/config" "gitlab.com/toby3d/mypackbot/internal/config"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// ChannelPost checks ChannelPost update for forwarding content to bot users // ChannelPost checks ChannelPost update for forwarding content to bot users

View File

@ -4,18 +4,17 @@ import (
"strconv" "strconv"
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/db" "gitlab.com/toby3d/mypackbot/internal/db"
"github.com/toby3d/MyPackBot/internal/errors" "gitlab.com/toby3d/mypackbot/internal/errors"
"github.com/toby3d/MyPackBot/internal/helpers" "gitlab.com/toby3d/mypackbot/internal/i18n"
"github.com/toby3d/MyPackBot/internal/i18n" "gitlab.com/toby3d/mypackbot/internal/utils"
"github.com/toby3d/MyPackBot/internal/models" tg "gitlab.com/toby3d/telegram"
tg "github.com/toby3d/telegram"
) )
// InlineQuery checks InlineQuery updates for answer with personal results // InlineQuery checks InlineQuery updates for answer with personal results
func InlineQuery(inlineQuery *tg.InlineQuery) { func InlineQuery(inlineQuery *tg.InlineQuery) {
fixedQuery, err := helpers.FixEmoji(inlineQuery.Query) fixedQuery, err := utils.FixEmoji(inlineQuery.Query)
if err == nil { if err == nil {
inlineQuery.Query = fixedQuery inlineQuery.Query = fixedQuery
} }
@ -61,7 +60,7 @@ func InlineQuery(inlineQuery *tg.InlineQuery) {
}, },
) )
answer.SwitchPrivateMessageParameter = models.CommandHelp answer.SwitchPrivateMessageParameter = tg.CommandHelp
} }
answer.Results = nil answer.Results = nil

View File

@ -2,11 +2,11 @@ package updates
import ( import (
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
"github.com/toby3d/MyPackBot/internal/actions" "gitlab.com/toby3d/mypackbot/internal/actions"
"github.com/toby3d/MyPackBot/internal/bot" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/commands" "gitlab.com/toby3d/mypackbot/internal/commands"
"github.com/toby3d/MyPackBot/internal/messages" "gitlab.com/toby3d/mypackbot/internal/messages"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// Message checks Message updates for answer to user commands, replies or sended // Message checks Message updates for answer to user commands, replies or sended

View File

@ -1,8 +1,8 @@
package helpers package utils
import ( import (
"github.com/nicksnyder/go-i18n/i18n" "github.com/nicksnyder/go-i18n/i18n"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// CancelButton helper just generate ReplyMarkup with cancel button // CancelButton helper just generate ReplyMarkup with cancel button

View File

@ -1,4 +1,4 @@
package helpers package utils
import ( import (
"golang.org/x/text/runes" "golang.org/x/text/runes"

View File

@ -1,8 +1,8 @@
package helpers package utils
import ( import (
"github.com/nicksnyder/go-i18n/i18n" "github.com/nicksnyder/go-i18n/i18n"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// MenuKeyboard helper just generate ReplyMarkup with menu buttons // MenuKeyboard helper just generate ReplyMarkup with menu buttons

View File

@ -1,8 +1,8 @@
package helpers package utils
import ( import (
"github.com/nicksnyder/go-i18n/i18n" "github.com/nicksnyder/go-i18n/i18n"
tg "github.com/toby3d/telegram" tg "gitlab.com/toby3d/telegram"
) )
// SwitchButton helper just generate ReplyMarkup with SelfSwitch button // SwitchButton helper just generate ReplyMarkup with SelfSwitch button

32
main.go
View File

@ -4,8 +4,12 @@ import (
"flag" "flag"
log "github.com/kirillDanshin/dlog" log "github.com/kirillDanshin/dlog"
_ "github.com/toby3d/MyPackBot/init" "gitlab.com/toby3d/mypackbot/internal/bot"
"github.com/toby3d/MyPackBot/internal/updates" "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( var flagWebhook = flag.Bool(
@ -13,11 +17,33 @@ var flagWebhook = flag.Bool(
"enable work via webhooks (required valid certificates)", "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 // main function is a general function for work of this bot
func main() { func main() {
flag.Parse() // Parse flagWebhook 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) log.D(update)
switch { switch {
case update.IsInlineQuery(): case update.IsInlineQuery():