Skip to content

Commit

Permalink
perf: perfect ntfy
Browse files Browse the repository at this point in the history
  • Loading branch information
starudream committed Sep 5, 2024
1 parent 65a487c commit 03c67f8
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 77 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sign-Task

<div style="text-align: center;">

![golang](https://img.shields.io/github/actions/workflow/status/starudream/sign-task/golang.yml?style=for-the-badge&logo=github&label=golang)
![release](https://img.shields.io/github/v/release/starudream/sign-task?style=for-the-badge)
![license](https://img.shields.io/github/license/starudream/sign-task?style=for-the-badge)

![sign-task](https://socialify.git.ci/starudream/sign-task/image?font=Inter&forks=1&issues=1&language=1&name=1&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Auto)

</div>

## [License](./LICENSE)
15 changes: 10 additions & 5 deletions pkg/cfg/config_keys
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
$.version
$.time

$.rr
$.rr.key

$.tt
$.tt.key
$.geetest
$.geetest.cron
$.geetest.cron.disable
$.geetest.cron.spec
$.geetest.cron.startup
$.geetest.cron.jitter
$.geetest.rr
$.geetest.rr.key
$.geetest.tt
$.geetest.tt.key

$.douyu
$.douyu.cron
Expand Down
13 changes: 6 additions & 7 deletions pkg/cfg/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ var options = []yaml.EncodeOption{
yaml.UseLiteralStyleIfMultiline(true),
yaml.WithComment(yaml.CommentMap{
"$": []*yaml.Comment{yaml.HeadComment("", " https://github.com/starudream/sign-task", "")},
"$.rr": []*yaml.Comment{yaml.HeadComment(" 人人打码", " http://www.rrocr.com")},
"$.tt": []*yaml.Comment{yaml.HeadComment(" 套套打码", " http://www.ttocr.com")},
"$.douyu": []*yaml.Comment{yaml.HeadComment(" 斗鱼", " https://www.douyu.com")},
"$.kuro": []*yaml.Comment{yaml.HeadComment(" 库街区", " https://www.kurobbs.com")},
"$.miyoushe": []*yaml.Comment{yaml.HeadComment(" 米游社", " https://www.miyoushe.com")},
"$.skland": []*yaml.Comment{yaml.HeadComment(" 森空岛", " https://www.skland.com")},
"$.tieba": []*yaml.Comment{yaml.HeadComment(" 百度贴吧", " https://tieba.baidu.com")},
"$.geetest": []*yaml.Comment{yaml.HeadComment(" 打码")},
"$.douyu": []*yaml.Comment{yaml.HeadComment(" 斗鱼")},
"$.kuro": []*yaml.Comment{yaml.HeadComment(" 库街区")},
"$.miyoushe": []*yaml.Comment{yaml.HeadComment(" 米游社")},
"$.skland": []*yaml.Comment{yaml.HeadComment(" 森空岛")},
"$.tieba": []*yaml.Comment{yaml.HeadComment(" 百度贴吧")},
"$.log": []*yaml.Comment{yaml.HeadComment(" 日志", " https://pkg.go.dev/github.com/starudream/go-lib/core/v2/config/global#Config")},
"$.ntfy": []*yaml.Comment{yaml.HeadComment(" 通知", " https://pkg.go.dev/github.com/starudream/go-lib/ntfy/v2#Config")},
}),
Expand Down
12 changes: 4 additions & 8 deletions pkg/douyu/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ var (
execRefreshCmd = cobra.NewCommand(func(c *cobra.Command) {
c.Use = "refresh <account phone>"
c.Short = "Exec refresh"
c.RunE = func(cmd *cobra.Command, args []string) (err error) {
rf := job.Refresh(config.GetAccountOrFirst(args...))
fmt.Println(rf.String())
return
c.Run = func(cmd *cobra.Command, args []string) {
fmt.Println(job.Refresh(config.GetAccountOrFirst(args...)).String())
}
})

execRenewalCmd = cobra.NewCommand(func(c *cobra.Command) {
c.Use = "renewal <account phone>"
c.Short = "Exec renewal"
c.RunE = func(cmd *cobra.Command, args []string) (err error) {
rn := job.Renewal(config.GetAccountOrFirst(args...))
fmt.Println(rn.String())
return
c.Run = func(cmd *cobra.Command, args []string) {
fmt.Println(job.Renewal(config.GetAccountOrFirst(args...)).String())
}
})
)
Expand Down
12 changes: 3 additions & 9 deletions pkg/douyu/douyu.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package douyu

import (
"fmt"

"github.com/starudream/sign-task/pkg/cron"
"github.com/starudream/sign-task/pkg/douyu/config"
"github.com/starudream/sign-task/pkg/douyu/job"
Expand All @@ -16,8 +14,6 @@ func init() {
type douyu struct {
}

var _ cron.Job = (*douyu)(nil)

func (douyu) Name() string {
return "douyu"
}
Expand All @@ -28,10 +24,8 @@ func (j douyu) Do() {
}
}

func (douyu) do(account config.Account) {
rf := job.Refresh(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, rf))
func (j douyu) do(a config.Account) {
util.NtfyJob(j, a.GetKey(), job.Refresh(a).String())

rn := job.Renewal(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, rn))
util.NtfyJob(j, a.GetKey(), job.Renewal(a).String())
}
38 changes: 38 additions & 0 deletions pkg/geetest/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package geetest

import (
"fmt"

"github.com/starudream/sign-task/pkg/cron"
"github.com/starudream/sign-task/util"
)

func init() {
cron.Register(geetest{})
}

type geetest struct{}

func (geetest) Name() string {
return "geetest"
}

func (j geetest) Do() {
if TTKey() != "" {
point, err := TTPoint(&V3Param{})
if err != nil {
util.NtfyJob(j, "套套", fmt.Sprintf("执行失败(%s)", err))
} else {
util.NtfyJob(j, "套套", fmt.Sprintf("剩余点数:%s", point))
}
}

if RRKey() != "" {
point, err := RRPoint(&V3Param{})
if err != nil {
util.NtfyJob(j, "人人", fmt.Sprintf("执行失败(%s)", err))
} else {
util.NtfyJob(j, "人人", fmt.Sprintf("剩余点数:%d", point))
}
}
}
2 changes: 1 addition & 1 deletion pkg/geetest/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type rrConfig struct {
var rr = rrConfig{}

func init() {
_ = config.Unmarshal("rr", &rr)
_ = config.Unmarshal("geetest.rr", &rr)
}

func RRKey() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/geetest/tt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var tt = ttConfig{
}

func init() {
_ = config.Unmarshal("tt", &tt)
_ = config.Unmarshal("geetest.tt", &tt)
}

func TTKey() string {
Expand Down
6 changes: 2 additions & 4 deletions pkg/kuro/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ var (
c.Use = "game <account phone>"
c.Short = "Sign game"
c.Run = func(cmd *cobra.Command, args []string) {
sg := job.SignGame(config.GetAccountOrFirst(args...))
fmt.Println(sg.String())
fmt.Println(job.SignGame(config.GetAccountOrFirst(args...)).String())
}
})

signForumCmd = cobra.NewCommand(func(c *cobra.Command) {
c.Use = "forum <account phone>"
c.Short = "Sign forum"
c.Run = func(cmd *cobra.Command, args []string) {
sf := job.SignForum(config.GetAccountOrFirst(args...))
fmt.Println(sf.String())
fmt.Println(job.SignForum(config.GetAccountOrFirst(args...)).String())
}
})
)
Expand Down
12 changes: 3 additions & 9 deletions pkg/kuro/kuro.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package kuro

import (
"fmt"

"github.com/starudream/sign-task/pkg/cron"
"github.com/starudream/sign-task/pkg/kuro/config"
"github.com/starudream/sign-task/pkg/kuro/job"
Expand All @@ -15,8 +13,6 @@ func init() {

type kuro struct{}

var _ cron.Job = (*kuro)(nil)

func (kuro) Name() string {
return "kuro"
}
Expand All @@ -27,10 +23,8 @@ func (j kuro) Do() {
}
}

func (kuro) do(account config.Account) {
sg := job.SignGame(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sg))
func (j kuro) do(a config.Account) {
util.NtfyJob(j, a.GetKey(), job.SignGame(a).String())

sf := job.SignForum(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sf))
util.NtfyJob(j, a.GetKey(), job.SignForum(a).String())
}
6 changes: 2 additions & 4 deletions pkg/miyoushe/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ var (
if err != nil {
return err
}
sg := job.SignGame(account)
fmt.Println(sg.String())
fmt.Println(job.SignGame(account).String())
return
}
})
Expand All @@ -34,8 +33,7 @@ var (
c.Use = "forum <account phone>"
c.Short = "Sign forum"
c.Run = func(cmd *cobra.Command, args []string) {
sf := job.SignForum(config.GetAccountOrFirst(args...))
fmt.Println(sf.String())
fmt.Println(job.SignForum(config.GetAccountOrFirst(args...)).String())
}
})
)
Expand Down
14 changes: 5 additions & 9 deletions pkg/miyoushe/miyoushe.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ func init() {
type miyoushe struct {
}

var _ cron.Job = (*miyoushe)(nil)

func (miyoushe) Name() string {
return "miyoushe"
}
Expand All @@ -28,16 +26,14 @@ func (j miyoushe) Do() {
}
}

func (miyoushe) do(account config.Account) {
account, err := job.Refresh(account)
func (j miyoushe) do(a config.Account) {
a, err := job.Refresh(a)
if err != nil {
util.Ntfy(fmt.Sprintf("%s 执行失败(%s)", account.Phone, err))
util.NtfyJob(j, a.GetKey(), fmt.Sprintf("执行失败(%s)", err))
return
}

sg := job.SignGame(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sg))
util.NtfyJob(j, a.GetKey(), job.SignGame(a).String())

sf := job.SignForum(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sf))
util.NtfyJob(j, a.GetKey(), job.SignForum(a).String())
}
3 changes: 1 addition & 2 deletions pkg/skland/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ var (
if err != nil {
return err
}
sg := job.SignGame(account)
fmt.Println(sg.String())
fmt.Println(job.SignGame(account).String())
return
}
})
Expand Down
11 changes: 4 additions & 7 deletions pkg/skland/skland.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ func init() {

type skland struct{}

var _ cron.Job = (*skland)(nil)

func (skland) Name() string {
return "skland"
}
Expand All @@ -27,13 +25,12 @@ func (j skland) Do() {
}
}

func (skland) do(account config.Account) {
account, err := job.Refresh(account)
func (j skland) do(a config.Account) {
a, err := job.Refresh(a)
if err != nil {
util.Ntfy(fmt.Sprintf("%s 执行失败(%s)", account.Phone, err))
util.NtfyJob(j, a.GetKey(), fmt.Sprintf("执行失败(%s)", err))
return
}

sg := job.SignGame(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sg))
util.NtfyJob(j, a.GetKey(), job.SignGame(a).String())
}
3 changes: 1 addition & 2 deletions pkg/tieba/cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ var (
c.Use = "forum <account phone>"
c.Short = "Sign forum"
c.Run = func(cmd *cobra.Command, args []string) {
sf := job.SignForum(config.GetAccountOrFirst(args...))
fmt.Println(sf.String())
fmt.Println(job.SignForum(config.GetAccountOrFirst(args...)).String())
}
})
)
Expand Down
9 changes: 2 additions & 7 deletions pkg/tieba/tieba.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tieba

import (
"fmt"

"github.com/starudream/sign-task/pkg/cron"
"github.com/starudream/sign-task/pkg/tieba/config"
"github.com/starudream/sign-task/pkg/tieba/job"
Expand All @@ -16,8 +14,6 @@ func init() {
type tieba struct {
}

var _ cron.Job = (*tieba)(nil)

func (tieba) Name() string {
return "tieba"
}
Expand All @@ -28,7 +24,6 @@ func (j tieba) Do() {
}
}

func (tieba) do(account config.Account) {
sf := job.SignForum(account)
util.Ntfy(fmt.Sprintf("%s %s", account.Phone, sf))
func (j tieba) do(a config.Account) {
util.NtfyJob(j, a.GetKey(), job.SignForum(a).String())
}
2 changes: 0 additions & 2 deletions pkg/xiaoheihe/xiaoheihe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ func init() {
type xiaoheihe struct {
}

var _ cron.Job = (*xiaoheihe)(nil)

func (xiaoheihe) Name() string {
return "xiaoheihe"
}
Expand Down
7 changes: 7 additions & 0 deletions util/ntfy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package util
import (
"context"
"errors"
"fmt"

"github.com/starudream/go-lib/core/v2/slog"
"github.com/starudream/go-lib/ntfy/v2"

"github.com/starudream/sign-task/pkg/cron"
)

func Ntfy(text string) {
Expand All @@ -14,3 +17,7 @@ func Ntfy(text string) {
slog.Error("notify error: %v", err)
}
}

func NtfyJob(j cron.Job, k, s string) {
Ntfy(fmt.Sprintf("[%s] %s\n%s", j.Name(), k, s))
}

0 comments on commit 03c67f8

Please sign in to comment.