@@ -119,13 +119,12 @@ func init() {
119119 })
120120
121121 // 设置openai api key
122- engine .OnRegex ("set chatgpt apiKey (.*)" , robot .OnlyPrivate , robot .AdminPermission ).SetBlock (true ).Handle (func (ctx * robot.Ctx ) {
122+ engine .OnRegex ("set chatgpt api[K|k]ey (.*)" , robot .OnlyPrivate , robot .AdminPermission ).SetBlock (true ).Handle (func (ctx * robot.Ctx ) {
123123 keys := strings .Split (ctx .State ["regex_matched" ].([]string )[1 ], ";" )
124124 failedKeys := make ([]string , 0 )
125125 for i := range keys {
126126 data := ApiKey {Key : keys [i ]}
127127 if err := db .Orm .Table ("apikey" ).Where (& data ).FirstOrCreate (& data ).Error ; err != nil {
128- ctx .ReplyTextAndAt ("设置apiKey失败" )
129128 failedKeys = append (failedKeys , keys [i ])
130129 continue
131130 }
@@ -154,6 +153,22 @@ func init() {
154153 }
155154 ctx .ReplyTextAndAt (fmt .Sprintf ("插件 - ChatGPT\n %s" , apiKeyMsg ))
156155 })
156+
157+ engine .OnRegex ("del chatgpt api[K|k]ey (.*)" , robot .OnlyPrivate , robot .AdminPermission ).SetBlock (true ).Handle (func (ctx * robot.Ctx ) {
158+ keys := strings .Split (ctx .State ["regex_matched" ].([]string )[1 ], ";" )
159+ failedKeys := make ([]string , 0 )
160+ for i := range keys {
161+ if err := db .Orm .Table ("apikey" ).Where ("key = ?" , keys [i ]).Delete (& ApiKey {}).Error ; err != nil {
162+ failedKeys = append (failedKeys , keys [i ])
163+ continue
164+ }
165+ }
166+ if len (failedKeys ) > 0 {
167+ ctx .ReplyText (fmt .Sprintf ("以下apiKey删除失败: %v" , failedKeys ))
168+ return
169+ }
170+ ctx .ReplyText ("apiKey删除成功" )
171+ })
157172}
158173
159174func askChatGPT (question string ) (string , error ) {
0 commit comments