From 645ce837c6ca24564399bb1a0fd9b1f65675cab3 Mon Sep 17 00:00:00 2001 From: wuqinqiang <1185079673@qq.com> Date: Wed, 22 Feb 2023 00:20:41 +0800 Subject: [PATCH] Add before action for wordChainCmd --- README.md | 35 ++++++++++++++++++++++++++++++++++- cmd/games.go | 22 ++++++++++++++++++++++ db/sqlite/settings.go | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35686bb..6e4c45f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,37 @@ Hello Word是我在背单词的过程中想到的一个想法。在学习英语时,词汇量是非常重要的。仅仅死记硬背单词,没有语境感,效率是很低的。虽然一些应用程序可以根据单词的多个词义为单词组成一小段句子,稍微增强语境感。但是单词仍然过于零散。因此,我们是否可以将每天背诵的多个单词组合成一段小短文,以便复习这一批单词呢?这就是Hello Word的初衷。当然,ChatGPT API是实现这个想法的工具。 除此之外,还配套了几个周边小游戏。 + + +### 初始化 +#### 环境变量 + +```shell +HELLO_WORD_PATH # 默认不配置在 ~/.helloword +``` + +#### 配置文件 +配置文件在conf/conf.yml里。 +```yaml +gptToken: "xx" #要使用短语推送功能这个是必须的!!!可以先注册openai,然后到platform.openai.com平台申请key + +collector: + bbdc: # 不背单词cookie,配置了可以同步不背单词的生词表。 + cookie: + +# --------------------- Notification Configuration --------------------- +notify: # 通知配置,目前支持telegram,dingtalk,lark可以全配,那么所有平台都会推送一遍 + # telegram: + # token: xxxxxxx # Bot Token + # chat_id: -123456789 # Channel / Group ID + # dingtalk: + # webhook: "https://oapi.dingtalk.com/robot/send?access_token=xxxx" + # secret: "" # sign secret if set + lark: + webhook: "xx" +``` + + ### 单词短语推送器 指定单词数量,随机选择单词,生成一段小短文,推送到用户指定平台。 @@ -33,8 +64,10 @@ go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-num 使用 ```shell -go run main.go games chain +go run main.go games chain --files="CET4.txt,CET6.txt" ``` +**参数说明** +- files 可选,如上 ![example](./library/word_chain.png) diff --git a/cmd/games.go b/cmd/games.go index 437d48a..52e7468 100644 --- a/cmd/games.go +++ b/cmd/games.go @@ -7,6 +7,9 @@ import ( "os" "strings" + "github.com/wuqinqiang/helloword/collector" + "github.com/wuqinqiang/helloword/collector/file" + "github.com/wuqinqiang/helloword/games" "github.com/wuqinqiang/helloword/dao" @@ -24,6 +27,25 @@ var GamesCmd = &cli.Command{ var wordChainCmd = &cli.Command{ Name: "chain", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "files", + Usage: "传入要导入的Library目录下的单词文件。例如你可以导入一个文件 damon --files=CET4.txt" + + "或者多个文件用逗号隔开,damon --files=CET4.txt,CET6.txt", + }, + }, + Before: func(cctx *cli.Context) error { + var collectors []collector.Collector + files := "CET4.txt" + if cctx.String("files") != "" { + files = cctx.String("files") + } + + collectors = append(collectors, file.New(files)) + importer := collector.NewImporter(collectors...) + + return importer.Import(cctx.Context) + }, Action: func(cctx *cli.Context) error { list, err := dao.NewWord().GetList(cctx.Context) diff --git a/db/sqlite/settings.go b/db/sqlite/settings.go index a1579ba..0d71485 100644 --- a/db/sqlite/settings.go +++ b/db/sqlite/settings.go @@ -39,7 +39,7 @@ type Settings struct { func New(path string) *Settings { settings := DefaultSettings if path == "" { - path = "~/.bridge" + path = "~/.helloword" } settings.path = path return settings