Skip to content

Commit

Permalink
auto: autocommit
Browse files Browse the repository at this point in the history
  • Loading branch information
pibragimov committed Jun 3, 2024
1 parent 85a7370 commit 16ec1b8
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ dmypy.json
.terragrunt-cache
.terraform

/core/service/analitics/.test-*
**/.test-*
/fun_telegram
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.11.62
v1.11.63
1 change: 0 additions & 1 deletion core/presentation/telegram/regrule_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (r *Presentation) regruleCommandHandler(
}

if regToDelete, ok := input.Ops[FlagRegRuleDelete.Long]; ok {
println(regToDelete)
err := r.redisRepository.DelRegRules(ctx, update.EffectiveChat().GetID(), regToDelete)
if err != nil {
return errors.Wrap(err, "failed to delete")
Expand Down
10 changes: 9 additions & 1 deletion core/presentation/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"time"

"github.com/teadove/fun_telegram/core/service/tex"

"github.com/celestix/gotgproto/dispatcher/handlers/filters"
"github.com/glebarez/sqlite"

Expand Down Expand Up @@ -49,6 +51,7 @@ type Presentation struct {
resourceService *resource.Service
analiticsService *analitics.Service
jobService *job.Service
texService *tex.Service
}

func NewProtoClient(ctx context.Context) (*gotgproto.Client, error) {
Expand Down Expand Up @@ -278,7 +281,12 @@ func MustNewTelegramPresentation(
},
"anime-detect": {
executor: presentation.animeDetectionCommandHandler,
description: resource.CommandRestartDescription,
description: resource.CommandAnimeDetectDescription,
},
"tex": {
executor: presentation.texCommandHandler,
description: resource.CommandTexDescription,
example: "Найс! $f(x) = \\frac{\\sqrt{x +20}}{2\\pi} +\\hbar \\sum y\\partial y$",
},
}

Expand Down
51 changes: 51 additions & 0 deletions core/presentation/telegram/tex_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package telegram

import (
"bytes"

"github.com/celestix/gotgproto/ext"
"github.com/gotd/td/telegram/message"
"github.com/gotd/td/telegram/uploader"
"github.com/pkg/errors"
"github.com/teadove/fun_telegram/core/service/tex"
)

func (r *Presentation) texCommandHandler(
ctx *ext.Context,
update *ext.Update,
input *input,
) error {
if input.Text == "" {
err := r.replyIfNotSilent(ctx, update, input, "Text should not be empty")
if err != nil {
return errors.Wrap(err, "failed to reply")
}
}

var buf bytes.Buffer

err := r.texService.Draw(tex.DrawInput{
Write: &buf,
Expr: input.Text,
Size: 50,
DPI: 90,
})
if err != nil {
return errors.Wrap(err, "failed to draw")
}

imgUploader := uploader.NewUploader(ctx.Raw)

file, err := imgUploader.FromBytes(ctx, "tex-image.png", buf.Bytes())
if err != nil {
return errors.Wrap(err, "failed to upload img")
}

_, err = ctx.Sender.To(update.EffectiveChat().GetInputPeer()).
Album(ctx, message.UploadedPhoto(file))
if err != nil {
return errors.Wrap(err, "failed to send album")
}

return nil
}
10 changes: 8 additions & 2 deletions core/service/resource/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
CommandKandinskyFlagNegativePromptDescription
CommandLocationDescription

CommandTexDescription

CommandUploadStatsDescription

CommandDumpStatsDescription
Expand Down Expand Up @@ -199,6 +201,10 @@ var localizer = map[Code]map[Locale]string{
Ru: "получить аналитическое описание данного чата",
En: "get stats of this chat",
},
CommandTexDescription: {
Ru: "скомпилировать LaTeX выражение и выдать в формате PNG",
En: "compile LaTeX expression and return it in PNG format",
},
CommandUploadStatsDescription: {
Ru: "загрузить статистику из этого чата",
En: "uploads stats from this chat",
Expand Down Expand Up @@ -234,8 +240,8 @@ var localizer = map[Code]map[Locale]string{
CommandRestartSuccess: {Ru: "Перезагрузка успешна!", En: "Restart success!"},
CommandRestartDescription: {Ru: "перезагружает бота", En: "restarts bot"},
CommandAnimeDetectDescription: {
Ru: "проверяет, является ли отвеченный стикер/картинка аниме",
En: "check if replied sticker/image is anime",
Ru: "проверяет, является ли отвеченный стикер/картинка аниме. Используйте !chat -e=anime-detections, чтобы включить автоматическую проверку на аниме",
En: "check if replied sticker/image is anime. To toggle auto anime detection: !chat -e=anime-detections",
},
CommandStatsFlagTZDescription: {
Ru: "временной офсет по UTC",
Expand Down
24 changes: 24 additions & 0 deletions core/service/tex/draw_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tex

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestUnit_TexServic_Draw_Ok(t *testing.T) {
f, err := os.Create(".test-output.png")
require.NoError(t, err)
defer f.Close()

service := Service{}
err = service.Draw(DrawInput{
Write: f,
Expr: "Найс! $f(x) = \\frac{\\sqrt{x +20}}{2\\pi} +\\hbar \\sum y\\partial y$",
Size: 50,
DPI: 90,
})

require.NoError(t, err)
}
28 changes: 28 additions & 0 deletions core/service/tex/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tex

import (
"io"

"github.com/go-latex/latex/drawtex/drawimg"
"github.com/go-latex/latex/mtex"
"github.com/pkg/errors"
)

type Service struct{}

type DrawInput struct {
Write io.Writer

Expr string
Size float64
DPI float64
}

func (r *Service) Draw(input DrawInput) error {
err := mtex.Render(drawimg.NewRenderer(input.Write), input.Expr, input.Size, input.DPI, nil)
if err != nil {
return errors.Wrap(err, "failed to draw")
}

return nil
}
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
fun_storage__mongo_db_url: "mongodb://mongodb:27017"
fun_storage__clickhouse_url: "clickhouse:9000"
fun_ds_supplier_url: "http://ds:8000"
image: ghcr.io/teadove/fun-telegram:v1.11.62
image: ghcr.io/teadove/fun-telegram:v1.11.63
volumes:
- ".mtproto:/.mtproto"
- ".env:/.env"
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-faster/jx v1.1.0 // indirect
github.com/go-faster/xor v1.0.0 // indirect
github.com/go-latex/latex v0.0.0-20231108140139-5c1ce85aa4ea // indirect
github.com/go-pdf/fpdf v0.9.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gotd/ige v0.2.2 // indirect
github.com/gotd/neo v0.1.5 // indirect
Expand Down Expand Up @@ -78,6 +82,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/image v0.14.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
Expand Down Expand Up @@ -284,7 +285,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2
github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U=
github.com/go-latex/latex v0.0.0-20231108140139-5c1ce85aa4ea h1:DfZQkvEbdmOe+JK2TMtBM+0I9GSdzE2y/L1/AmD8xKc=
github.com/go-latex/latex v0.0.0-20231108140139-5c1ce85aa4ea/go.mod h1:Y7Vld91/HRbTBm7JwoI7HejdDB0u+e9AUBO9MB7yuZk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-pdf/fpdf v0.9.0 h1:PPvSaUuo1iMi9KkaAn90NuKi+P4gwMedWPHhj8YlJQw=
github.com/go-pdf/fpdf v0.9.0/go.mod h1:oO8N111TkmKb9D7VvWGLvLJlaZUQVPM+6V42pp3iV4Y=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
Expand All @@ -307,6 +312,7 @@ github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -750,6 +756,8 @@ golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+o
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down

0 comments on commit 16ec1b8

Please sign in to comment.