Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: send edit delete #4

Merged
merged 8 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
- run: go test -race -v ./...
15 changes: 15 additions & 0 deletions .github/workflows/_golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: golangci-lint

on:
workflow_call:

jobs:
golangci-lint:
name: run
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
- uses: golangci/golangci-lint-action@v4
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- uses: goreleaser/goreleaser-action@v1
go-version: '1.22'
- uses: goreleaser/goreleaser-action@v5
with:
args: release --clean
env:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/golangci-lint.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:

jobs:
go-test:
uses: ./.github/workflows/go-test.yml
uses: ./.github/workflows/_go-test.yml
golangci-lint:
uses: ./.github/workflows/golangci-lint.yml
uses: ./.github/workflows/_golangci-lint.yml
goreleaser:
needs:
- go-test
- golangci-lint
uses: ./.github/workflows/goreleaser.yml
uses: ./.github/workflows/_goreleaser.yml
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ on:

jobs:
go-test:
uses: ./.github/workflows/go-test.yml
uses: ./.github/workflows/_go-test.yml
golangci-lint:
uses: ./.github/workflows/golangci-lint.yml
uses: ./.github/workflows/_golangci-lint.yml
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.out
dist/
31 changes: 15 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
run:
timeout: 2m
modules-download-mode: readonly
go: 1.21
go: "1.22"

output:
format: colored-line-number
formats:
- format: colored-line-number
sort-results: true

linters-settings:
Expand All @@ -13,14 +14,10 @@ linters-settings:
statements: 50
varnamelen:
min-name-length: 2
cyclop:
max-complexity: 15
exhaustruct:
exclude:
- 'net/http\..*'
- github.com/a-kataev/tg.Chat
wsl:
allow-assign-and-anything: true
tagliatelle:
case:
rules:
Expand All @@ -44,6 +41,7 @@ linters:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- cyclop
## - deadcode # deprecated
- decorder
Expand All @@ -55,7 +53,6 @@ linters:
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
## - exhaustivestruct # deprecated
Expand All @@ -69,6 +66,7 @@ linters:
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gochecksumtype
- gocognit
- goconst
- gocritic
Expand All @@ -79,27 +77,29 @@ linters:
- gofmt
- gofumpt
- goheader
- goimports
## - golint # deprecated
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
## - ifshort # deprecated
- importas
- inamedparam
- ineffassign
- interfacebloat
## - interfacer # deprecated
- intrange
- ireturn
- lll
- loggercheck
- maintidx
- makezero
## - maligned # deprecated
- mirror
- misspell
- musttag
- nakedret
Expand All @@ -112,32 +112,31 @@ linters:
- nonamedreturns
## - nosnakecase # deprecated
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
## - scopelint # deprecated
- sqlclosecheck
- sloglint
- spancheck
- staticcheck
## - structcheck # deprecated
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
## - varcheck # deprecated
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl
- zerologlint
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @a-kataev
40 changes: 20 additions & 20 deletions cmd/tg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (
"github.com/a-kataev/tg"
)

func logFatal(log *slog.Logger, msg string) {
log.Error(msg)

os.Exit(1)
}

func main() {
fset := flag.NewFlagSet("", flag.ContinueOnError)
fset.SetOutput(io.Discard)
Expand All @@ -27,12 +33,6 @@ func main() {

log := slog.New(slog.NewJSONHandler(os.Stdout, nil))

logFatal := func(msg string) {
log.Error(msg)

os.Exit(1)
}

err := fset.Parse(os.Args[1:])
if err != nil {
if errors.Is(flag.ErrHelp, err) {
Expand All @@ -43,7 +43,7 @@ func main() {
os.Exit(1)
}

logFatal(err.Error())
logFatal(log, err.Error())
}

if *token == "" {
Expand All @@ -54,40 +54,40 @@ func main() {
stdin, err := io.ReadAll(io.LimitReader(os.Stdin, int64(tg.MaxTextSize)))
if err != nil {
if !errors.Is(err, io.EOF) {
logFatal(err.Error())
logFatal(log, err.Error())
}
}

*text = string(stdin)
}

tgb, err := tg.NewTG(*token)
client, err := tg.NewClient(*token)
if err != nil {
logFatal(err.Error())
logFatal(log, err.Error())
}

ctx := context.Background()

bot, err := tgb.GetMe(ctx)
bot, err := client.GetMe(ctx)
if err != nil {
logFatal(err.Error())
logFatal(log, err.Error())
}

log = log.With(slog.String("bot_name", bot.UserName))

msg, err := tgb.SendMessage(ctx, *chatID, *text,
tg.ChatParseMode(tg.ParseMode(*parseMode)),
tg.ChatMessageThreadID(*messageThreadID),
tg.ChatDisableWebPagePreview(*disableWebPagePreview),
tg.ChatDisableNotification(*disableNotification),
tg.ChatProtectContent(*protectContent),
msg, err := client.SendMessage(ctx, *chatID, *text,
tg.ParseModeSendOption(tg.ParseMode(*parseMode)),
tg.MessageThreadIDSendOption(*messageThreadID),
tg.DisableWebPagePreviewSendOption(*disableWebPagePreview),
tg.DisableNotificationSendOption(*disableNotification),
tg.ProtectContentSendOption(*protectContent),
)
if err != nil {
logFatal(err.Error())
logFatal(log, err.Error())
}

log.Info("Success send message",
slog.Int64("chat_id", *chatID),
slog.Int("message_id", msg.MessageID),
slog.Any("message_id", msg.MessageID),
)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/a-kataev/tg

go 1.21
go 1.22

require github.com/stretchr/testify v1.9.0

Expand Down
Loading