Skip to content

Commit

Permalink
💩👌 make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Aug 6, 2021
1 parent 3814d17 commit 932abcb
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 57 deletions.
44 changes: 44 additions & 0 deletions data/Diana/text.pb

Large diffs are not rendered by default.

51 changes: 3 additions & 48 deletions plugin_diana/bing.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions plugin_diana/text.go → plugin_diana/data/text.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package diana
package data

import (
"io"
Expand All @@ -13,7 +13,7 @@ const (

var (
compo Composition
array []string
Array []string
)

func init() {
Expand All @@ -23,13 +23,13 @@ func init() {
if err != nil {
panic(err)
}
if loadText() == nil {
array = compo.Array
if LoadText() == nil {
Array = compo.Array
}
}()
}

func loadText() error {
func LoadText() error {
if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) {
f, err := os.Open(pbfile)
if err == nil {
Expand All @@ -46,9 +46,9 @@ func loadText() error {
return nil
}

func addText(txt string) error {
func AddText(txt string) error {
if txt != "" {
array = append(array, txt)
compo.Array = append(compo.Array, txt)
data, err := compo.Marshal()
if err == nil {
if _, err := os.Stat(datapath); err == nil || os.IsExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion plugin_diana/text.pb.go → plugin_diana/data/text.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugin_diana/text.proto → plugin_diana/data/text.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package diana;
package data;

message composition {
repeated string array = 1;
Expand Down
44 changes: 44 additions & 0 deletions plugin_diana/tools/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package convert 转换txt到pb
package main

import (
"bufio"
"os"

"github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data"
)

var (
compo data.Composition
)

func init() {
compo.Array = make([]string, 0, 64)
}

// 参数:txt文件位置 pb文件位置
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
defer file.Close()

scanner := bufio.NewScanner(file)
// optionally, resize scanner's capacity for lines over 64K, see next example
for scanner.Scan() {
//fmt.Println(scanner.Text())
compo.Array = append(compo.Array, scanner.Text())
}

if err := scanner.Err(); err != nil {
panic(err)
}

data, _ := compo.Marshal()
f, err1 := os.OpenFile(os.Args[2], os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err1 == nil {
defer f.Close()
f.Write(data)
}
}
41 changes: 41 additions & 0 deletions plugin_diana/tools/text.txt

Large diffs are not rendered by default.

0 comments on commit 932abcb

Please sign in to comment.