Skip to content

Commit

Permalink
fix: 初始化时没有data目录的问题,暂时注释余额功能及其他修复 (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
eryajf authored Apr 3, 2023
1 parent b9f6e10 commit 16a5541
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
6 changes: 6 additions & 0 deletions pkg/db/sqlite.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package db

import (
"os"

"github.com/eryajf/chatgpt-dingtalk/pkg/logger"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
Expand All @@ -24,6 +26,10 @@ func dbAutoMigrate() {
}

func ConnSqlite() *gorm.DB {
err := os.MkdirAll("data", 0755)
if err != nil {
return nil
}
db, err := gorm.Open(sqlite.Open("data/dingtalkbot.sqlite"), &gorm.Config{
// 禁用外键(指定外键时不会在mysql创建真实的外键约束)
DisableForeignKeyConstraintWhenMigrating: true,
Expand Down
30 changes: 18 additions & 12 deletions pkg/process/process_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,28 @@ func ProcessRequest(rmsg *dingbot.ReceiveMsg) error {
logger.Warning(fmt.Errorf("send message error: %v", err))
}
case "余额":
cacheMsg := public.UserService.GetUserMode("system_balance")
if cacheMsg == "" {
rst, err := public.GetBalance()
if err != nil {
logger.Warning(fmt.Errorf("get balance error: %v", err))
return err
}
t1 := time.Unix(int64(rst.Grants.Data[0].EffectiveAt), 0)
t2 := time.Unix(int64(rst.Grants.Data[0].ExpiresAt), 0)
cacheMsg = fmt.Sprintf("💵 已用: 💲%v\n💵 剩余: 💲%v\n⏳ 有效时间: 从 %v 到 %v\n", fmt.Sprintf("%.2f", rst.TotalUsed), fmt.Sprintf("%.2f", rst.TotalAvailable), t1.Format("2006-01-02 15:04:05"), t2.Format("2006-01-02 15:04:05"))
}

// cacheMsg := public.UserService.GetUserMode("system_balance")
// if cacheMsg == "" {
// rst, err := public.GetBalance()
// if err != nil {
// logger.Warning(fmt.Errorf("get balance error: %v", err))
// return err
// }
// t1 := time.Unix(int64(rst.Grants.Data[0].EffectiveAt), 0)
// t2 := time.Unix(int64(rst.Grants.Data[0].ExpiresAt), 0)
// cacheMsg = fmt.Sprintf("💵 已用: 💲%v\n💵 剩余: 💲%v\n⏳ 有效时间: 从 %v 到 %v\n", fmt.Sprintf("%.2f", rst.TotalUsed), fmt.Sprintf("%.2f", rst.TotalAvailable), t1.Format("2006-01-02 15:04:05"), t2.Format("2006-01-02 15:04:05"))
// }
cacheMsg := "官方暂时改写了余额接口,因此暂不提供查询余额功能!2023-04-03"
_, err := rmsg.ReplyToDingtalk(string(dingbot.TEXT), cacheMsg)
if err != nil {
logger.Warning(fmt.Errorf("send message error: %v", err))
}
case "查对话":
msg := "使用如下指令进行查询:\n\n---\n\n**#查对话 username:张三**\n\n---\n\n需要注意格式必须严格与上边一致,否则会查询失败\n\n只有钉钉管理员,程序系统管理员,与查自己的情况下,才会被允许"
_, err := rmsg.ReplyToDingtalk(string(dingbot.MARKDOWN), msg)
if err != nil {
logger.Warning(fmt.Errorf("send message error: %v", err))
}
default:
if public.FirstCheck(rmsg) {
return Do("串聊", rmsg)
Expand Down
4 changes: 3 additions & 1 deletion public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ var Welcome string = `# 发送信息
**重置**:重置上下文
**余额**:查询机器人所用OpenAI账号的余额
**余额**: ~~查询机器人所用OpenAI账号的余额~~ (暂不可用)
**模板**:查询机器人内置的快捷模板
**图片**:查看如何根据提示词生成图片
**查对话**:获取指定人员的对话历史
**帮助**:重新获取帮助信息
-----
Expand Down
3 changes: 2 additions & 1 deletion public/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func JudgeUsers(s string) bool {

// JudgeAdminUsers 判断用户是否为系统管理员
func JudgeAdminUsers(s string) bool {
if len(Config.AllowGroups) == 0 {
// 如果没有指定,则没有人是管理员
if len(Config.AdminUsers) == 0 {
return false
}
for _, v := range Config.AdminUsers {
Expand Down

0 comments on commit 16a5541

Please sign in to comment.