Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
toby3d committed Jan 19, 2018
2 parents 5d2bb60 + 7443022 commit ad3e7db
Show file tree
Hide file tree
Showing 39 changed files with 734 additions and 439 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ fmt:

# Build localization files with separated untranslated strings
translation:
goi18n merge -format yaml -sourceLanguage en-us -outdir ./i18n/ ./i18n/*
goi18n merge -format yaml -sourceLanguage en -outdir ./i18n/ ./i18n/*/*

# Build localization files and merge untranslated strings
localization:
make translation
goi18n -format yaml -sourceLanguage en-us -outdir ./i18n/ ./i18n/*.all.yaml \
goi18n -format yaml -sourceLanguage en -outdir ./i18n/ ./i18n/*.all.yaml \
./i18n/*.untranslated.yaml
31 changes: 31 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
97 changes: 42 additions & 55 deletions add.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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"
)

func commandAdd(msg *tg.Message, pack bool) {
bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)

T, err := switchLocale(msg.From.LanguageCode)
errCheck(err)

_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
errCheck(err)

reply := tg.NewMessage(msg.Chat.ID, T("reply_add_sticker"))
reply.ParseMode = tg.ModeMarkdown
reply.ReplyMarkup = getCancelButton(T)

err = dbChangeUserState(msg.From.ID, stateAddSticker)
errCheck(err)
Expand All @@ -30,21 +32,44 @@ func commandAdd(msg *tg.Message, pack bool) {
}

func actionAdd(msg *tg.Message, pack bool) {
bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
if msg.Sticker == nil {
return
}

T, err := switchLocale(msg.From.LanguageCode)
errCheck(err)

_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
errCheck(err)

reply := tg.NewMessage(msg.Chat.ID, T("success_add_sticker"))
reply.ParseMode = tg.ModeMarkdown

switch {
case pack && msg.Sticker.SetName == "":
reply.Text = T("error_empty_add_pack", map[string]interface{}{
"AddStickerCommand": cmdAddSticker,
})
case pack && msg.Sticker.SetName != "":
set, err := bot.GetStickerSet(msg.Sticker.SetName)
if !pack {
var exist bool
sticker := msg.Sticker
exist, err = dbAddSticker(
msg.From.ID, sticker.SetName, sticker.FileID, sticker.Emoji,
)
errCheck(err)

if exist {
reply.Text = T("error_already_add_sticker")
}

reply.ReplyMarkup = getCancelButton(T)
_, err = bot.SendMessage(reply)
errCheck(err)
return
}

reply.Text = T("error_empty_add_pack", map[string]interface{}{
"AddStickerCommand": cmdAddSticker,
})

if msg.Sticker.SetName != "" {
var set *tg.StickerSet
set, err = bot.GetStickerSet(msg.Sticker.SetName)
errCheck(err)

log.Ln("SetTitle:", set.Title)
Expand All @@ -54,64 +79,26 @@ func actionAdd(msg *tg.Message, pack bool) {

allExists := true
for _, sticker := range set.Stickers {
exists, err := dbAddSticker(
msg.From.ID,
sticker.SetName,
sticker.FileID,
sticker.Emoji,
var exist bool
exist, err = dbAddSticker(
msg.From.ID, sticker.SetName, sticker.FileID, sticker.Emoji,
)
errCheck(err)

if !exists {
if !exist {
allExists = false
}
}

log.Ln("All exists?", allExists)

if allExists {
reply.Text = T("error_already_add_pack", map[string]interface{}{
"SetTitle": set.Title,
})
} else {
markup := tg.NewInlineKeyboardMarkup(
tg.NewInlineKeyboardRow(
tg.NewInlineKeyboardButtonSwitch(
T("button_share"),
" ",
),
),
)
reply.ReplyMarkup = &markup
}
default:
exists, err := dbAddSticker(
msg.From.ID,
msg.Sticker.SetName,
msg.Sticker.FileID,
msg.Sticker.Emoji,
)
errCheck(err)

if exists {
reply.Text = T("error_already_add_sticker")
}

if msg.Sticker.Emoji == "" {
msg.Sticker.Emoji = " "
}

markup := tg.NewInlineKeyboardMarkup(
tg.NewInlineKeyboardRow(
tg.NewInlineKeyboardButtonSwitch(
T("button_share"),
msg.Sticker.Emoji,
),
),
)
reply.ReplyMarkup = &markup
}

reply.ReplyMarkup = getCancelButton(T)
_, err = bot.SendMessage(reply)
errCheck(err)
}
15 changes: 10 additions & 5 deletions cancel.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package main

import tg "github.com/toby3d/telegram" // My Telegram bindings
import tg "github.com/toby3d/telegram"

func commandCancel(msg *tg.Message) {
bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)

T, err := switchLocale(msg.From.LanguageCode)
errCheck(err)

state, err := dbGetUserState(msg.From.ID)
errCheck(err)

_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
errCheck(err)

var text string
switch state {
case stateAddSticker:
text = T("cancel_add_sticker")
case stateAddPack:
text = T("cancel_add_pack")
case stateDelete:
text = T("cancel_del")
case stateDeleteSticker:
text = T("cancel_del_sticker")
case stateDeletePack:
text = T("cancel_del_pack")
case stateReset:
text = T("cancel_reset")
default:
Expand All @@ -29,6 +32,8 @@ func commandCancel(msg *tg.Message) {
errCheck(err)

reply := tg.NewMessage(msg.Chat.ID, text)
reply.ReplyMarkup = getMenuKeyboard(T)

_, err = bot.SendMessage(reply)
errCheck(err)
}
27 changes: 15 additions & 12 deletions commands.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ 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"
)

const (
cmdAddPack = "addPack"
cmdAddSticker = "addSticker"
cmdCancel = "cancel"
cmdHelp = "help"
cmdDelete = "del"
cmdReset = "reset"
cmdStart = "start"
cmdAddPack = "addPack"
cmdAddSticker = "addSticker"
cmdCancel = "cancel"
cmdHelp = "help"
cmdDeleteSticker = "delSticker"
cmdDeletePack = "delPack"
cmdReset = "reset"
cmdStart = "start"
)

func commands(msg *tg.Message) {
log.Ln("Received a", msg.Command(), "command")
log.Ln("command:", msg.Command())
switch strings.ToLower(msg.Command()) {
case strings.ToLower(cmdStart):
commandStart(msg)
Expand All @@ -28,8 +29,10 @@ func commands(msg *tg.Message) {
commandAdd(msg, false)
case strings.ToLower(cmdAddPack):
commandAdd(msg, true)
case strings.ToLower(cmdDelete):
commandDelete(msg)
case strings.ToLower(cmdDeleteSticker):
commandDelete(msg, false)
case strings.ToLower(cmdDeletePack):
commandDelete(msg, true)
case strings.ToLower(cmdReset):
commandReset(msg)
case strings.ToLower(cmdCancel):
Expand Down
Loading

0 comments on commit ad3e7db

Please sign in to comment.