diff --git a/go.mod b/go.mod index 9f82f68..f55c040 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.5 require ( github.com/dustin/go-humanize v1.0.1 // indirect - github.com/fogleman/gg v1.3.0 // indirect + github.com/fogleman/gg v1.3.0 github.com/glebarez/go-sqlite v1.22.0 // indirect github.com/go-telegram/bot v1.5.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect diff --git a/src/captcha.go b/src/captcha.go new file mode 100644 index 0000000..08ff44e --- /dev/null +++ b/src/captcha.go @@ -0,0 +1,29 @@ +package main + +import ( + "embed" + "image/color" + + "github.com/fogleman/gg" +) + +var ( + res embed.FS +) + +func GenCaptcha() { + dc := gg.NewContext(400, 300) + gd := gg.NewLinearGradient(0, 0, 400, 300) + gd.AddColorStop(0, color.RGBA{189, 24, 229, 255}) + gd.AddColorStop(1, color.RGBA{27, 21, 123, 255}) + dc.SetFillStyle(gd) + dc.DrawRectangle(0, 0, 400, 300) + dc.Fill() + dc.SetRGBA(0, 0, 0, 0.05) + dc.SetLineWidth(27) + for i := 0.0; i < 20; i += 1 { + dc.DrawLine(i * 70, -100, i * 70 - 500, 400) + dc.Stroke() + } + dc.SavePNG("grad.png") +} diff --git a/src/handlers.go b/src/handlers.go index d63c2cb..139bb5f 100644 --- a/src/handlers.go +++ b/src/handlers.go @@ -89,20 +89,20 @@ func handleNewJoined(ctx context.Context, b *bot.Bot, u *models.Update) { ChatID: u.Message.Chat.ID, UserID: user.ID, Permissions: &models.ChatPermissions{ - CanSendMessages: false, - CanSendAudios: false, - CanSendDocuments: false, - CanSendPhotos: false, - CanSendVideos: false, - CanSendVideoNotes: false, - CanSendVoiceNotes: false, - CanSendPolls: false, - CanSendOtherMessages: false, + CanSendMessages: false, + CanSendAudios: false, + CanSendDocuments: false, + CanSendPhotos: false, + CanSendVideos: false, + CanSendVideoNotes: false, + CanSendVoiceNotes: false, + CanSendPolls: false, + CanSendOtherMessages: false, CanAddWebPagePreviews: false, - CanChangeInfo: false, - CanInviteUsers: false, - CanPinMessages: false, - CanManageTopics: false, + CanChangeInfo: false, + CanInviteUsers: false, + CanPinMessages: false, + CanManageTopics: false, }, }) if err != nil { @@ -148,7 +148,6 @@ func handlePrivateStartCaptcha(ctx context.Context, b *bot.Bot, u *models.Update return } } - if captcha.CorrectAnswer == 0 { captcha.CorrectAnswer = 42 msg, err := b.SendMessage(ctx, &bot.SendMessageParams{ @@ -197,8 +196,8 @@ func handlePrivateCaptcha(ctx context.Context, b *bot.Bot, u *models.Update) { } if ban_minutes > 0 { - b.SendMessage(ctx, &bot.SendMessageParams{ChatID: msg.From.ID, Text:text}) - _, err := db.Exec("update captchas set blocked_until = $2 where id = $1", captcha.Id, time.Now().Add(time.Minute * time.Duration(ban_minutes)).Unix()) + b.SendMessage(ctx, &bot.SendMessageParams{ChatID: msg.From.ID, Text: text}) + _, err := db.Exec("update captchas set blocked_until = $2 where id = $1", captcha.Id, time.Now().Add(time.Minute*time.Duration(ban_minutes)).Unix()) if err != nil { log.Println("Can't block user from captcha: ", err) } @@ -206,20 +205,20 @@ func handlePrivateCaptcha(ctx context.Context, b *bot.Bot, u *models.Update) { } _, err = b.RestrictChatMember(ctx, &bot.RestrictChatMemberParams{ChatID: captcha.ChatID, UserID: captcha.UserID, Permissions: &models.ChatPermissions{ - CanSendMessages: true, - CanSendAudios: true, - CanSendDocuments: true, - CanSendPhotos: true, - CanSendVideos: true, - CanSendVideoNotes: true, - CanSendVoiceNotes: true, - CanSendPolls: true, - CanSendOtherMessages: true, + CanSendMessages: true, + CanSendAudios: true, + CanSendDocuments: true, + CanSendPhotos: true, + CanSendVideos: true, + CanSendVideoNotes: true, + CanSendVoiceNotes: true, + CanSendPolls: true, + CanSendOtherMessages: true, CanAddWebPagePreviews: true, - CanChangeInfo: true, - CanInviteUsers: true, - CanPinMessages: true, - CanManageTopics: true, + CanChangeInfo: true, + CanInviteUsers: true, + CanPinMessages: true, + CanManageTopics: true, }}) if err != nil { log.Println("Can't unrestrict user: ", err) diff --git a/src/main.go b/src/main.go index 3895d22..b4492c8 100644 --- a/src/main.go +++ b/src/main.go @@ -14,6 +14,7 @@ import ( ) func main() { + GenCaptcha() ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel()