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

Commit 6ade04c

Browse files
committed
♻️ Refactoring codewith adding some small features
Remove linter warnings, changed inline-feed-button command, added message with switch-button. Also, fixed #1
1 parent 1f53b75 commit 6ade04c

16 files changed

+111
-78
lines changed

add.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
5-
tg "github.com/toby3d/telegram" // My Telegram bindings
4+
log "github.com/kirillDanshin/dlog"
5+
tg "github.com/toby3d/telegram"
66
)
77

88
func commandAdd(msg *tg.Message, pack bool) {
@@ -45,14 +45,31 @@ func actionAdd(msg *tg.Message, pack bool) {
4545
reply := tg.NewMessage(msg.Chat.ID, T("success_add_sticker"))
4646
reply.ParseMode = tg.ModeMarkdown
4747

48-
switch {
49-
case pack &&
50-
msg.Sticker.SetName == "":
51-
reply.Text = T("error_empty_add_pack", map[string]interface{}{
52-
"AddStickerCommand": cmdAddSticker,
53-
})
54-
case pack &&
55-
msg.Sticker.SetName != "":
48+
if !pack {
49+
var exist bool
50+
exist, err = dbAddSticker(
51+
msg.From.ID,
52+
msg.Sticker.SetName,
53+
msg.Sticker.FileID,
54+
msg.Sticker.Emoji,
55+
)
56+
errCheck(err)
57+
58+
if exist {
59+
reply.Text = T("error_already_add_sticker")
60+
}
61+
62+
reply.ReplyMarkup = getCancelButton(T)
63+
_, err = bot.SendMessage(reply)
64+
errCheck(err)
65+
return
66+
}
67+
68+
reply.Text = T("error_empty_add_pack", map[string]interface{}{
69+
"AddStickerCommand": cmdAddSticker,
70+
})
71+
72+
if msg.Sticker.SetName != "" {
5673
var set *tg.StickerSet
5774
set, err = bot.GetStickerSet(msg.Sticker.SetName)
5875
errCheck(err)
@@ -85,19 +102,6 @@ func actionAdd(msg *tg.Message, pack bool) {
85102
"SetTitle": set.Title,
86103
})
87104
}
88-
default:
89-
var exist bool
90-
exist, err = dbAddSticker(
91-
msg.From.ID,
92-
msg.Sticker.SetName,
93-
msg.Sticker.FileID,
94-
msg.Sticker.Emoji,
95-
)
96-
errCheck(err)
97-
98-
if exist {
99-
reply.Text = T("error_already_add_sticker")
100-
}
101105
}
102106

103107
reply.ReplyMarkup = getCancelButton(T)

cancel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import tg "github.com/toby3d/telegram" // My Telegram bindings
3+
import tg "github.com/toby3d/telegram"
44

55
func commandCancel(msg *tg.Message) {
66
T, err := switchLocale(msg.From.LanguageCode)

commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"strings"
55

6-
// log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
7-
tg "github.com/toby3d/telegram" // My Telegram bindings
6+
// log "github.com/kirillDanshin/dlog"
7+
tg "github.com/toby3d/telegram"
88
)
99

1010
const (

delete.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
5-
tg "github.com/toby3d/telegram" // My Telegram bindings
4+
log "github.com/kirillDanshin/dlog"
5+
tg "github.com/toby3d/telegram"
66
)
77

88
func commandDelete(msg *tg.Message, pack bool) {
@@ -42,6 +42,14 @@ func commandDelete(msg *tg.Message, pack bool) {
4242

4343
_, err = bot.SendMessage(reply)
4444
errCheck(err)
45+
46+
_, err = bot.SendChatAction(msg.Chat.ID, tg.ActionTyping)
47+
errCheck(err)
48+
49+
reply = tg.NewMessage(msg.Chat.ID, T("reply_switch_button"))
50+
reply.ReplyMarkup = getSwitchButton(T)
51+
_, err = bot.SendMessage(reply)
52+
errCheck(err)
4553
}
4654

4755
func actionDelete(msg *tg.Message, pack bool) {

help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
import tg "github.com/toby3d/telegram" // My Telegram bindings
3+
import tg "github.com/toby3d/telegram"
44

55
func commandHelp(msg *tg.Message) {
66
T, err := switchLocale(msg.From.LanguageCode)

helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func getCancelButton(T i18n.TranslateFunc) *tg.ReplyKeyboardMarkup {
4444
)
4545
}
4646

47+
func getSwitchButton(T i18n.TranslateFunc) *tg.InlineKeyboardMarkup {
48+
return tg.NewInlineKeyboardMarkup(
49+
tg.NewInlineKeyboardRow(
50+
tg.NewInlineKeyboardButtonSwitchSelf(T("button_inline_select"), " "),
51+
),
52+
)
53+
}
54+
4755
func fixEmoji(raw string) (string, error) {
4856
result, _, err := transform.String(skinRemover, raw)
4957
return result, err

i18n/en.all.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ button_add_sticker:
44
other: ➕ Add sticker
55
button_cancel:
66
other: ❌ Cancel
7-
button_del:
8-
other: Select sticker for remove
97
button_del_pack:
108
other: "\U0001F5D1 Delete pack"
119
button_del_sticker:
1210
other: "\U0001F5D1 Delete sticker"
13-
button_inline_add:
14-
one: You have {{.Count}} sticker. Add one more?
15-
other: You have {{.Count}} stickers. Add one more?
1611
button_inline_empty:
1712
other: Your pack is empty
1813
button_inline_nothing:
19-
other: Not found stickers for {{.Query}}, add one?
14+
other: Not found stickers for {{.Query}}
15+
button_inline_search:
16+
one: You have {{.Count}} sticker
17+
other: You have {{.Count}} stickers
18+
button_inline_select:
19+
other: Select sticker
2020
button_reset:
2121
other: "\U0001F525 Reset pack"
2222
button_share:
@@ -37,7 +37,9 @@ error_already_add_pack:
3737
other: All stickers from *{{.SetTitle}}* pack is already in yours.
3838
error_already_add_sticker:
3939
other: This sticker is already in your pack.
40-
error_already_del:
40+
error_already_del_pack:
41+
other: Maybe this pack is already removed from yours.
42+
error_already_del_sticker:
4143
other: Maybe this sticker is already removed from your pack.
4244
error_already_reset:
4345
other: There is nothing to reset, pack is already empty.
@@ -70,7 +72,7 @@ reply_del_pack:
7072
reply_del_sticker:
7173
other: Send an existing stickers from your pack for removing it.
7274
reply_help:
73-
other: |-
75+
other: |
7476
/{{.AddStickerCommand}} - add a single sticker to your pack
7577
/{{.AddPackCommand}} - add a full other pack to your pack
7678
/{{.DeleteStickerCommand}} - remove a single sticker from your pack
@@ -90,6 +92,9 @@ reply_start:
9092
Hello, I'm the [@{{.Username}}](tg://user?id={{.ID}})!
9193
I can create your personal pack with stickers from others packs.
9294
Without limits and installing. In any chat. For free.
95+
reply_switch_button:
96+
other: This button will help you quickly call your pack to select the sticker you
97+
want.
9398
success_add_pack:
9499
other: The sticker pack *{{.SetTitle}}* was successfully added to yours!
95100
success_add_sticker:

i18n/en/en.buttons.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
button_inline_empty:
22
other: Your pack is empty
33
button_inline_nothing:
4-
other: Not found stickers for {{.Query}}, add one?
5-
button_inline_add:
6-
one: You have {{.Count}} sticker. Add one more?
7-
other: You have {{.Count}} stickers. Add one more?
8-
button_del:
9-
other: Select sticker for remove
4+
other: Not found stickers for {{.Query}}
5+
button_inline_search:
6+
one: You have {{.Count}} sticker
7+
other: You have {{.Count}} stickers
8+
button_inline_select:
9+
other: Select sticker
1010
button_share:
1111
other: Use your stickers pack!
1212
button_add_sticker:

i18n/en/en.errors.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ error_already_add_sticker:
22
other: This sticker is already in your pack.
33
error_already_add_pack:
44
other: All stickers from *{{.SetTitle}}* pack is already in yours.
5-
error_already_del:
5+
error_already_del_sticker:
66
other: Maybe this sticker is already removed from your pack.
7+
error_already_del_pack:
8+
other: Maybe this pack is already removed from yours.
79
error_already_reset:
810
other: There is nothing to reset, pack is already empty.
911
error_reset_phrase:

i18n/en/en.replies.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ reply_help:
2626
/{{.ResetCommand}} - remove all stickers from your pack
2727
/{{.CancelCommand}} - cancel the current operation
2828
29-
To view and send stickers from your pack, just type `@{{.Username}}` (and space) in any chat.
29+
To view and send stickers from your pack, just type `@{{.Username}}` (and space) in any chat.
30+
reply_switch_button:
31+
other: This button will help you quickly call your pack to select the sticker you want.

0 commit comments

Comments
 (0)