Skip to content

Commit 6938f05

Browse files
committed
fix: pkg name err
1 parent 3c4ca52 commit 6938f05

File tree

20 files changed

+304
-55
lines changed

20 files changed

+304
-55
lines changed

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
module Yui
1+
module github.com/opq-osc/Yui
22

33
go 1.19
44

55
require (
66
github.com/charmbracelet/log v0.2.1
77
github.com/ethereum/go-ethereum v1.11.6
8+
github.com/go-toolsmith/astcopy v1.1.0
89
github.com/google/uuid v1.3.0
910
github.com/imroc/req/v3 v3.33.2
1011
github.com/knqyf263/go-plugin v0.7.1-0.20230420183704-82cf9090ca1e
1112
github.com/mailru/easyjson v0.7.7
13+
github.com/manifoldco/promptui v0.9.0
1214
github.com/mcoo/OPQBot v0.2.2-0.20230415115049-02b00e2cf9e1
1315
github.com/opq-osc/OPQBot/v2 v2.0.0-20230427091225-f73faded2e3b
1416
github.com/robfig/cron/v3 v3.0.1
@@ -26,6 +28,7 @@ require (
2628
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
2729
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
2830
github.com/charmbracelet/lipgloss v0.7.1 // indirect
31+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
2932
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
3033
github.com/fsnotify/fsnotify v1.6.0 // indirect
3134
github.com/go-logfmt/logfmt v0.6.0 // indirect
@@ -72,6 +75,7 @@ require (
7275
github.com/yusufpapurcu/wmi v1.2.2 // indirect
7376
golang.org/x/crypto v0.4.0 // indirect
7477
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect
78+
golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 // indirect
7579
golang.org/x/mod v0.10.0 // indirect
7680
golang.org/x/net v0.9.0 // indirect
7781
golang.org/x/sys v0.7.0 // indirect

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

33
import (
4-
_ "Yui/config"
5-
"Yui/cron"
6-
"Yui/opq"
7-
"Yui/plugin"
84
"context"
95
"github.com/charmbracelet/log"
6+
_ "github.com/opq-osc/Yui/config"
7+
"github.com/opq-osc/Yui/cron"
8+
"github.com/opq-osc/Yui/opq"
9+
"github.com/opq-osc/Yui/plugin"
1010
"github.com/spf13/viper"
1111
)
1212

plugin/S/S.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package S
44

55
import (
6-
"Yui/proto"
76
"context"
87
"github.com/opq-osc/OPQBot/v2/events"
8+
"github.com/opq-osc/Yui/proto"
99
)
1010

1111
func LogInfo(ctx context.Context, msg string) {

plugin/S/S_host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package S
44

55
import (
6-
"Yui/opq"
76
"github.com/opq-osc/OPQBot/v2/apiBuilder"
87
"github.com/opq-osc/OPQBot/v2/events"
8+
"github.com/opq-osc/Yui/opq"
99
)
1010

1111
func GetApi(event events.IEvent) apiBuilder.IMainFunc {

plugin/admin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package plugin
22

33
import (
4-
"Yui/plugin/S"
5-
"Yui/plugin/meta"
6-
"Yui/plugin/repository"
7-
"Yui/session"
84
"context"
95
"fmt"
106
"github.com/opq-osc/OPQBot/v2/events"
7+
"github.com/opq-osc/Yui/plugin/S"
8+
"github.com/opq-osc/Yui/plugin/meta"
9+
"github.com/opq-osc/Yui/plugin/repository"
10+
"github.com/opq-osc/Yui/session"
1111
"github.com/spf13/cast"
1212
"github.com/spf13/viper"
1313
"strings"

plugin/builder/cmd/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
44
package cmd
55

66
import (
7-
"Yui/plugin/meta"
87
"bytes"
98
"crypto/ecdsa"
109
"crypto/rand"
@@ -14,6 +13,7 @@ import (
1413
"encoding/hex"
1514
"encoding/json"
1615
"github.com/ethereum/go-ethereum/crypto"
16+
"github.com/opq-osc/Yui/plugin/meta"
1717
"github.com/spf13/cobra"
1818
"github.com/spf13/viper"
1919
"io"

plugin/builder/cmd/new.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"encoding/json"
8+
"github.com/manifoldco/promptui"
9+
"github.com/opq-osc/Yui/plugin/meta"
10+
"github.com/spf13/cobra"
11+
"os"
12+
"os/exec"
13+
"path/filepath"
14+
"strings"
15+
)
16+
17+
// newCmd represents the new command
18+
var newCmd = &cobra.Command{
19+
Use: "new",
20+
Short: "创建一个新的插件",
21+
Long: `创建一个新的插件`,
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
prompt := promptui.Prompt{
24+
Label: "plugin name",
25+
}
26+
var err error
27+
pluginInfo := &meta.PluginMeta{}
28+
pluginInfo.PluginName, err = prompt.Run()
29+
if err != nil {
30+
return err
31+
}
32+
prompt = promptui.Prompt{Label: "plugin description"}
33+
pluginInfo.Description, err = prompt.Run()
34+
if err != nil {
35+
return err
36+
}
37+
prompt = promptui.Prompt{Label: "author"}
38+
pluginInfo.Author, err = prompt.Run()
39+
if err != nil {
40+
return err
41+
}
42+
prompt = promptui.Prompt{Label: "author url"}
43+
pluginInfo.Url, err = prompt.Run()
44+
if err != nil {
45+
return err
46+
}
47+
err = os.MkdirAll(pluginInfo.PluginName, 0777)
48+
if err != nil {
49+
return err
50+
}
51+
goFile = strings.ReplaceAll(goFile, "{{.pluginName}}", pluginInfo.PluginName)
52+
err = os.WriteFile(filepath.Join(pluginInfo.PluginName, pluginInfo.PluginName+".go"), []byte(goFile), 0777)
53+
if err != nil {
54+
return err
55+
}
56+
GoCmd := exec.Command("go", "mod", "init", pluginInfo.PluginName)
57+
GoCmd.Dir = "./" + pluginInfo.PluginName
58+
GoCmd.Stderr = os.Stderr
59+
err = GoCmd.Run()
60+
if err != nil {
61+
return err
62+
}
63+
GoCmd = exec.Command("go", "mod", "tidy")
64+
GoCmd.Dir = "./" + pluginInfo.PluginName
65+
GoCmd.Stderr = os.Stderr
66+
err = GoCmd.Run()
67+
if err != nil {
68+
return err
69+
}
70+
metaInfo, err := json.Marshal(pluginInfo)
71+
if err != nil {
72+
return err
73+
}
74+
err = os.WriteFile(filepath.Join(pluginInfo.PluginName, "meta.json"), []byte(metaInfo), 0777)
75+
if err != nil {
76+
return err
77+
}
78+
return nil
79+
},
80+
}
81+
82+
func init() {
83+
rootCmd.AddCommand(newCmd)
84+
85+
// Here you will define your flags and configuration settings.
86+
87+
// Cobra supports Persistent Flags which will work for this command
88+
// and all subcommands, e.g.:
89+
// newCmd.PersistentFlags().String("foo", "", "A help for foo")
90+
91+
// Cobra supports local flags which will only run when this command
92+
// is called directly, e.g.:
93+
// newCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
94+
}
95+
96+
var goFile = `//go:build tinygo.wasm
97+
98+
package main
99+
100+
import (
101+
"github.com/opq-osc/Yui/plugin/meta"
102+
"github.com/opq-osc/Yui/proto"
103+
"context"
104+
"github.com/knqyf263/go-plugin/types/known/emptypb"
105+
)
106+
107+
type {{.pluginName}} struct {
108+
}
109+
110+
func (p {{.pluginName}}) OnRemoteCallEvent(ctx context.Context, req *proto.RemoteCallReq) (*proto.RemoteCallReply, error) {
111+
//TODO implement me
112+
panic("implement me")
113+
}
114+
115+
func (p {{.pluginName}}) OnCronEvent(ctx context.Context, req *proto.CronEventReq) (*emptypb.Empty, error) {
116+
return &emptypb.Empty{}, nil
117+
}
118+
119+
func (p {{.pluginName}}) OnFriendMsg(ctx context.Context, msg *proto.CommonMsg) (*emptypb.Empty, error) {
120+
return &emptypb.Empty{}, nil
121+
}
122+
123+
func (p {{.pluginName}}) OnPrivateMsg(ctx context.Context, msg *proto.CommonMsg) (*emptypb.Empty, error) {
124+
return &emptypb.Empty{}, nil
125+
}
126+
127+
func (p {{.pluginName}}) OnGroupMsg(ctx context.Context, msg *proto.CommonMsg) (*emptypb.Empty, error) {
128+
return &emptypb.Empty{}, nil
129+
}
130+
func (p {{.pluginName}}) Unload(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) {
131+
return &emptypb.Empty{}, nil
132+
133+
}
134+
func (p {{.pluginName}}) Init(ctx context.Context, _ *emptypb.Empty) (*proto.InitReply, error) {
135+
return &proto.InitReply{
136+
Ok: true,
137+
Message: "Success",
138+
}, nil
139+
}
140+
141+
func main() {
142+
proto.RegisterEvent({{.pluginName}}{})
143+
}
144+
`

plugin/builder/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/*
22
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package main
65

7-
import "Yui/plugin/builder/cmd"
6+
import "github.com/opq-osc/Yui/plugin/builder/cmd"
87

98
func main() {
109
cmd.Execute()

plugin/callOPQApi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package plugin
22

33
import (
4-
"Yui/opq"
5-
"Yui/plugin/meta"
6-
"Yui/proto"
74
"context"
85
"fmt"
96
"github.com/opq-osc/OPQBot/v2/apiBuilder"
7+
"github.com/opq-osc/Yui/opq"
8+
"github.com/opq-osc/Yui/plugin/meta"
9+
"github.com/opq-osc/Yui/proto"
1010
)
1111

1212
func (p *Plugin) SendFriendMsg(ctx context.Context, request *proto.MsgReq) (*proto.SendReply, error) {

plugin/httpApi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package plugin
22

33
import (
4-
"Yui/plugin/meta"
5-
"Yui/proto"
64
"context"
75
"fmt"
86
"github.com/charmbracelet/log"
97
"github.com/imroc/req/v3"
8+
"github.com/opq-osc/Yui/plugin/meta"
9+
"github.com/opq-osc/Yui/proto"
1010
"github.com/spf13/viper"
1111
)
1212

0 commit comments

Comments
 (0)