Skip to content
This repository was archived by the owner on Feb 16, 2025. It is now read-only.

Commit 2c603c3

Browse files
authored
Merge pull request #16 from graynk/bump-and-reply
Bump versions, reply everywhere to support topics
2 parents 2008e16 + 53e6e60 commit 2c603c3

File tree

7 files changed

+823
-57
lines changed

7 files changed

+823
-57
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18-bullseye as build
1+
FROM golang:1.19-bullseye as build
22
WORKDIR /go/src/distortioner
33
COPY app .
44
RUN go test ./...

app/distorters/animation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func DistortVideo(filename, output string, progressChan chan string) {
3838
if err != nil {
3939
progressChan <- Failed
4040
return
41-
} else if duration > 30 {
41+
} else if duration > 60 {
4242
progressChan <- TooLong
4343
return
4444
}

app/distortioner.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

109110
func (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

113114
func (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 {
195196
func (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 += "\nYou 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

288289
func (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

296297
func 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 {

app/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module github.com/graynk/distortioner
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/google/uuid v1.3.0
7-
github.com/mattn/go-sqlite3 v1.14.13
7+
github.com/mattn/go-sqlite3 v1.14.16
88
github.com/pkg/errors v0.9.1
9-
github.com/stretchr/testify v1.7.1
10-
go.uber.org/zap v1.21.0
11-
gopkg.in/telebot.v3 v3.0.0
9+
github.com/stretchr/testify v1.8.0
10+
go.uber.org/zap v1.23.0
11+
gopkg.in/telebot.v3 v3.1.2
1212
)
1313

1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
1616
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
go.uber.org/atomic v1.9.0 // indirect
17+
go.uber.org/atomic v1.10.0 // indirect
1818
go.uber.org/multierr v1.8.0 // indirect
19-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
19+
gopkg.in/yaml.v3 v3.0.1 // indirect
2020
)

0 commit comments

Comments
 (0)