Skip to content

Commit 81fbfad

Browse files
authored
Merge pull request #7 from miscord-dev/add-uconv-latin
Add uconv latin
2 parents 588eca1 + aa6c404 commit 81fbfad

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

.github/workflows/goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
-
2020
name: Set up Go
2121
uses: actions/setup-go@v4
22+
with:
23+
go-version-file: ./go.mod
2224
-
2325
name: Run GoReleaser
2426
uses: goreleaser/goreleaser-action@v5

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ WORKDIR /app/
99
ADD . .
1010
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o /palog .
1111

12-
FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch
12+
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.19
1313
COPY --from=builder /palog /palog
14+
RUN apk add --no-cache icu
1415

1516
ENTRYPOINT ["/palog"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ Broadcast messages that someone joined/left the game.
1212

1313
## Known issues
1414
* If the message is split via whitespaces, `Broadcast` sends only the first segment
15+
* CKJ characters are corrupted
16+
* https://github.com/miscord-dev/palog/issues/6

main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"log/slog"
66
"os"
7+
"os/exec"
8+
"strings"
79
"time"
810

911
"github.com/miscord-dev/palog/pkg/palrcon"
@@ -18,6 +20,8 @@ var (
1820

1921
timeoutRaw = os.Getenv("TIMEOUT")
2022
timeout time.Duration
23+
24+
uconvLatin = os.Getenv("UCONV_LATIN") != "false"
2125
)
2226

2327
func init() {
@@ -45,6 +49,28 @@ func init() {
4549
}
4650
}
4751

52+
func escapeString(s string) string {
53+
s = strings.ReplaceAll(s, " ", "_")
54+
55+
if !uconvLatin {
56+
return s
57+
}
58+
59+
var out strings.Builder
60+
cmd := exec.Command("uconv", "-x", "latin")
61+
cmd.Stdin = strings.NewReader(s)
62+
cmd.Stderr = os.Stderr
63+
cmd.Stdout = &out
64+
65+
err := cmd.Run()
66+
if err != nil {
67+
slog.Error("failed to run uconv", "error", err)
68+
return s
69+
}
70+
71+
return strings.TrimSpace(out.String())
72+
}
73+
4874
func main() {
4975
palRCON := palrcon.NewPalRCON(rconEndpoint, rconPassword)
5076
palRCON.SetTimeout(timeout)
@@ -66,6 +92,8 @@ func main() {
6692
}
6793

6894
retriedBoarcast := func(message string) error {
95+
message = escapeString(message)
96+
6997
var err error
7098
for i := 0; i < 10; i++ {
7199
err = palRCON.Broadcast(message)

0 commit comments

Comments
 (0)