-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pibragimov
committed
Jun 3, 2024
1 parent
85a7370
commit 16ec1b8
Showing
11 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,5 +169,5 @@ dmypy.json | |
.terragrunt-cache | ||
.terraform | ||
|
||
/core/service/analitics/.test-* | ||
**/.test-* | ||
/fun_telegram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.11.62 | ||
v1.11.63 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters