Skip to content

Commit

Permalink
feat: 支持自定义指令名
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Mar 8, 2024
1 parent 6ece74c commit 72dbfa7
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 255 deletions.
17 changes: 11 additions & 6 deletions dbase/keyword/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type CreateParam struct {
Rd uint `json:"rd"`
Group string `binding:"required" json:"group"`
Roomid string `binding:"required" json:"roomid"`
Phrase string `binding:"required" json:"phrase"`
Target string `json:"target"`
Expand All @@ -19,6 +20,7 @@ type CreateParam struct {
func Create(data *CreateParam) (uint, error) {

item := &tables.Keyword{
Group: data.Group,
Roomid: data.Roomid,
Phrase: data.Phrase,
Target: data.Target,
Expand All @@ -42,6 +44,7 @@ func Update(data *UpdateParam) error {
Rd: data.Rd,
}).
Updates(tables.Keyword{
Group: data.Group,
Roomid: data.Roomid,
Phrase: data.Phrase,
Target: data.Target,
Expand All @@ -60,6 +63,7 @@ func Replace(data *ReplaceParam) error {

item, err := Fetch(&FetchParam{
Rd: data.Rd,
Group: data.Group,
Roomid: data.Roomid,
Phrase: data.Phrase,
})
Expand All @@ -79,8 +83,10 @@ func Replace(data *ReplaceParam) error {

type FetchParam struct {
Rd uint `json:"rd"`
Group string `json:"group"`
Roomid string `json:"roomid"`
Phrase string `json:"phrase"`
Target string `json:"target"`
}

func Fetch(data *FetchParam) (*tables.Keyword, error) {
Expand All @@ -90,6 +96,7 @@ func Fetch(data *FetchParam) (*tables.Keyword, error) {
result := dborm.Db.
Where(&tables.Keyword{
Rd: data.Rd,
Group: data.Group,
Roomid: data.Roomid,
Phrase: data.Phrase,
}).
Expand All @@ -114,6 +121,7 @@ func Delete(data *DeleteParam) error {
result := dborm.Db.
Where(&tables.Keyword{
Rd: data.Rd,
Group: data.Group,
Roomid: data.Roomid,
Phrase: data.Phrase,
}).
Expand All @@ -126,9 +134,8 @@ func Delete(data *DeleteParam) error {
// 获取关键词列表

type FetchAllParam struct {
Group string `json:"group"`
Roomid string `json:"roomid"`
Target string `json:"target"`
Level int32 `json:"level"`
}

func FetchAll(data *FetchAllParam) ([]*tables.Keyword, error) {
Expand All @@ -137,9 +144,8 @@ func FetchAll(data *FetchAllParam) ([]*tables.Keyword, error) {

result := dborm.Db.
Where(&tables.Keyword{
Group: data.Group,
Roomid: data.Roomid,
Target: data.Target,
Level: data.Level,
}).
Find(&items)

Expand All @@ -158,9 +164,8 @@ func Count(data *CountParam) (int64, error) {
result := dborm.Db.
Model(&tables.Keyword{}).
Where(&tables.Keyword{
Group: data.Group,
Roomid: data.Roomid,
Target: data.Target,
Level: data.Level,
}).
Count(&count)

Expand Down
6 changes: 3 additions & 3 deletions dbase/tables/chatroom.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package tables
// 群聊配置

type Chatroom struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Roomid string `gorm:"uniqueIndex" json:"roomid"` // 群聊 id
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Roomid string `json:"roomid" gorm:"uniqueIndex"` // 群聊 id
Name string `json:"name"` // 群聊名称
Level int32 `gorm:"default:-1" json:"level"` // 等级
Level int32 `json:"level" gorm:"default:-1"` // 等级
Remark string `json:"remark"` // 备注
JoinArgot string `json:"join_argot"` // 加群指令
PatReturn string `json:"pat_return"` // 响应拍拍我
Expand Down
4 changes: 2 additions & 2 deletions dbase/tables/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tables
// 联系人

type Contact struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Wxid string `gorm:"uniqueIndex json:wxid"` // 微信 id
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Wxid string `json:wxid" gorm:"uniqueIndex` // 微信 id
Code string `json:"code"` // 微信号
Remark string `json:"remark"` // 备注
Name string `json:"name"` // 微信昵称
Expand Down
2 changes: 1 addition & 1 deletion dbase/tables/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tables
// 计划任务

type Cronjob struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Name string `json:"name"` // 名称
Second string `json:"second"` // 秒
Minute string `json:"minute"` // 分
Expand Down
15 changes: 8 additions & 7 deletions dbase/tables/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package tables
// 关键词

type Keyword struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Roomid string `gorm:"uniqueIndex:r_phrase" json:"roomid"` // 群聊 id
Phrase string `gorm:"uniqueIndex:r_phrase" json:"phrase"` // 短语
Target string `gorm:"index;default:-" json:"target"` // 目标
Level int32 `gorm:"default:-1" json:"level"` // 等级
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Group string `json:"group" gorm:"uniqueIndex:t_r_phrase"` // 分组
Roomid string `json:"roomid" gorm:"uniqueIndex:t_r_phrase;default:-"` // 群聊 id
Phrase string `json:"phrase" gorm:"uniqueIndex:t_r_phrase"` // 短语
Target string `json:"target"` // 目标
Level int32 `json:"level" gorm:"default:-1"` // 等级
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
}
6 changes: 3 additions & 3 deletions dbase/tables/llmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package tables
// 大语言模型

type LLModel struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Mid string `gorm:"uniqueIndex" json:"mid"` // 模型 Id,用于生成模型切换指令
Level int32 `gorm:"default:-1" json:"level"` // 等级,用于限制用户访问
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Mid string `json:"mid" gorm:"uniqueIndex"` // 模型 Id,用于生成模型切换指令
Level int32 `json:"level" gorm:"default:-1"` // 等级,用于限制用户访问
Family string `json:"family"` // 模型家族,用于在指令中描述模型类型
Provider string `json:"provider"` // 服务商 [google, openai, xunfei]
Model string `json:"model"` // 模型,必须和服务商对应
Expand Down
32 changes: 16 additions & 16 deletions dbase/tables/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package tables
// 消息

type Message struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Id uint64 `gorm:"uniqueIndex" json:"id"` // 消息 id
IsSelf bool `json:"is_self"` // 是否自己发送的
IsGroup bool `json:"is_group"` // 是否群消息
Type uint32 `json:"type"` // 消息类型
Ts uint32 `json:"ts"` // 消息类型
Roomid string `json:"roomid"` // 群 id(如果是群消息的话)
Content string `json:"content"` // 消息内容
Sender string `json:"sender"` // 消息发送者
Sign string `json:"sign"` // Sign
Thumb string `json:"thumb"` // 缩略图
Extra string `json:"extra"` // 附加内容
Xml string `json:"xml"` // 消息 xml
Remark string `json:"remark"` // 备注,非微信字段
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Id uint64 `json:"id" gorm:"uniqueIndex"` // 消息 id
IsSelf bool `json:"is_self"` // 是否自己发送的
IsGroup bool `json:"is_group"` // 是否群消息
Type uint32 `json:"type"` // 消息类型
Ts uint32 `json:"ts"` // 消息类型
Roomid string `json:"roomid" gorm:"default:-"` // 群 id(如果是群消息的话)
Content string `json:"content"` // 消息内容
Sender string `json:"sender"` // 消息发送者
Sign string `json:"sign"` // Sign
Thumb string `json:"thumb"` // 缩略图
Extra string `json:"extra"` // 附加内容
Xml string `json:"xml"` // 消息 xml
Remark string `json:"remark"` // 备注,非微信字段
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
}
20 changes: 10 additions & 10 deletions dbase/tables/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package tables
// 用户配置

type Profile struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Wxid string `gorm:"index" json:"wxid"` // 微信 id
Roomid string `gorm:"index" json:"roomid"` // 群聊 id
Level int32 `gorm:"default:-1" json:"level"` // 等级
Remark string `json:"remark"` // 备注
AiArgot string `json:"ai_argot"` // 唤醒词
AiModel string `json:"ai_model"` // 会话模型
BanExpire int64 `json:"ban_expire"` // 拉黑截止时间
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
Rd uint `json:"rd" gorm:"primaryKey" ` // 主键
Wxid string `json:"wxid" gorm:"index"` // 微信 id
Roomid string `json:"roomid" gorm:"index;default:-"` // 群聊 id
Level int32 `json:"level" gorm:"default:-1"` // 等级
Remark string `json:"remark"` // 备注
AiArgot string `json:"ai_argot"` // 唤醒词
AiModel string `json:"ai_model"` // 会话模型
BanExpire int64 `json:"ban_expire"` // 拉黑截止时间
CreatedAt int64 `json:"created_at"` // 创建时间戳
UpdatedAt int64 `json:"updated_at"` // 最后更新时间戳
}
8 changes: 4 additions & 4 deletions dbase/tables/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package tables
// 全局配置

type Setting struct {
Rd uint `gorm:"primaryKey" json:"rd"` // 主键
Name string `gorm:"uniqueIndex" json:"name"` // 键
Type string `gorm:"default:string" json:"type"` // 类型
Group string `gorm:"index" json:"group"` // 分组
Rd uint `json:"rd" gorm:"primaryKey"` // 主键
Name string `json:"name" gorm:"uniqueIndex"` // 键
Type string `json:"type" gorm:"default:string"` // 类型
Group string `json:"group" gorm:"index"` // 分组
Value string `json:"value"` // 值
Title string `json:"title"` // 标题
Remark string `json:"remark"` // 备注
Expand Down
2 changes: 0 additions & 2 deletions httpd/wcfrest/receiver_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"

"github.com/opentdp/go-helper/logman"
"github.com/opentdp/go-helper/recovery"
"github.com/opentdp/go-helper/request"

"github.com/opentdp/wechat-rest/wcferry"
Expand All @@ -23,7 +22,6 @@ func (wc *Controller) enableUrlReceiver(url string) error {

if len(urlReceiverList) == 0 {
key, err := wc.EnrollReceiver(true, func(msg *wcferry.WxMsg) {
defer recovery.Handler()
ret := wcferry.ParseWxMsg(msg)
for u := range urlReceiverList {
logman.Info("call receiver", "url", u, "Id", ret.Id)
Expand Down
2 changes: 0 additions & 2 deletions httpd/wcfrest/receiver_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/gorilla/websocket"
"github.com/opentdp/go-helper/logman"
"github.com/opentdp/go-helper/recovery"

"github.com/opentdp/wechat-rest/wcferry"
)
Expand Down Expand Up @@ -37,7 +36,6 @@ func (wc *Controller) enableSocketReceiver(ws *websocket.Conn) error {

if len(socketReceiverList) == 0 {
key, err := wc.EnrollReceiver(true, func(msg *wcferry.WxMsg) {
defer recovery.Handler()
ret := wcferry.ParseWxMsg(msg)
for s := range socketReceiverList {
logman.Info("call receiver", "addr", s.RemoteAddr(), "Id", ret.Id)
Expand Down
Loading

0 comments on commit 72dbfa7

Please sign in to comment.