@@ -13,6 +13,7 @@ import (
1313
1414 "go.uber.org/zap"
1515 tb "gopkg.in/telebot.v3"
16+ "gopkg.in/telebot.v3/middleware"
1617
1718 "github.com/graynk/distortioner/distorters"
1819 "github.com/graynk/distortioner/stats"
@@ -107,7 +108,7 @@ func (d DistorterBot) handleRegularStickerDistortion(c tb.Context) error {
107108}
108109
109110func (d DistorterBot ) handleVideoStickerDistortion (c tb.Context ) error {
110- return c .Send ("You can go vote for this suggestion, for .webm stickers handling to become somewhat tolerable https://bugs.telegram.org/c/14858" )
111+ return c .Reply ("You can go vote for this suggestion, for .webm stickers handling to become somewhat tolerable https://bugs.telegram.org/c/14858" )
111112}
112113
113114func (d DistorterBot ) handleStickerDistortion (c tb.Context ) error {
@@ -176,9 +177,9 @@ func (d DistorterBot) handleVideoNoteDistortion(c tb.Context) error {
176177 failed := err != nil
177178 if failed {
178179 if progressMessage != nil && progressMessage .Text != distorters .TooLong {
180+ d .logger .Error (err )
179181 d .DoneMessageWithRepeater (b , progressMessage , failed )
180182 }
181- d .logger .Error (err )
182183 return
183184 }
184185 defer os .Remove (output )
@@ -195,7 +196,7 @@ func (d DistorterBot) handleVideoNoteDistortion(c tb.Context) error {
195196func (d DistorterBot ) handleVoiceDistortion (c tb.Context ) error {
196197 m := c .Message ()
197198 if m .Voice .FileSize > MaxSizeMb {
198- return c .Send ( m . Chat , distorters .TooBig )
199+ return c .Reply ( distorters .TooBig )
199200 }
200201 filename , err := tools .JustGetTheFile (c .Bot (), m )
201202 if err != nil {
@@ -222,7 +223,7 @@ func (d DistorterBot) handleReplyDistortion(c tb.Context) error {
222223 if m .FromGroup () {
223224 msg += "\n You might also need to make chat history visible for new members if your group is private."
224225 }
225- return c .Send (msg )
226+ return c .Reply (msg )
226227 }
227228 original := m .ReplyTo
228229 update := c .Update ()
@@ -255,7 +256,7 @@ func (d DistorterBot) handleStatRequest(c tb.Context, db *stats.DistortionerDB,
255256 stat , err := db .GetStat (period )
256257 if err != nil {
257258 d .logger .Error (err )
258- return c .Send (err .Error ())
259+ return c .Reply (err .Error ())
259260 }
260261 header := "Stats for the past %s"
261262 switch period {
@@ -282,15 +283,15 @@ _Photos_: %d
282283_Text messages_: %d
283284` ,
284285 stat .Sticker , stat .Animation , stat .Video , stat .VideoNote , stat .Voice , stat .Photo , stat .Text )
285- return c .Send (message + details , tb .ModeMarkdown )
286+ return c .Reply (message + details , tb .ModeMarkdown )
286287}
287288
288289func (d DistorterBot ) handleQueueStats (c tb.Context ) error {
289290 if c .Message ().Sender .ID != d .adminID {
290291 return nil
291292 }
292293 length , users := d .videoWorker .QueueStats ()
293- return c .Send (fmt .Sprintf ("Currently in queue: %d requests from %d users" , length , users ))
294+ return c .Reply (fmt .Sprintf ("Currently in queue: %d requests from %d users" , length , users ))
294295}
295296
296297func main () {
@@ -346,7 +347,7 @@ func main() {
346347 logger .Warn ("can't send anything at all" , zap .Int64 ("chat_id" , m .Chat .ID ))
347348 return false
348349 } else if (! permissions .CanSendMedia && tools .IsMedia (m .ReplyTo )) || (! permissions .CanSendOther && tools .IsNonMediaMedia (m .ReplyTo )) {
349- b .Send ( m . Chat , NotEnoughRights )
350+ b .Reply ( m , NotEnoughRights )
350351 return false
351352 }
352353 }
@@ -362,8 +363,9 @@ func main() {
362363 return
363364 }
364365
366+ b .Use (middleware .Recover ())
365367 b .Handle ("/start" , func (c tb.Context ) error {
366- return c .Send ("Send me a picture, a sticker, a voice message, a video[note] or a GIF and I'll distort it" )
368+ return c .Reply ("Send me a picture, a sticker, a voice message, a video[note] or a GIF and I'll distort it" )
367369 })
368370
369371 b .Handle ("/daily" , d .ApplyShutdownMiddleware (func (c tb.Context ) error {
0 commit comments