Skip to content

Commit

Permalink
Merge branch 'FloatTech:master' into master
Browse files Browse the repository at this point in the history
Jiang-Red authored Dec 14, 2022
2 parents 5201ab8 + 913f01d commit 0fcdf38
Showing 8 changed files with 102 additions and 75 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -29,4 +29,5 @@ jobs:
- name: Create Pull Request
if: ${{ !github.head_ref }}
continue-on-error: true
uses: peter-evans/create-pull-request@v4
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,17 +15,17 @@

[![go](https://goreportcard.com/badge/github.com/FloatTech/ZeroBot-Plugin?style=flat-square&logo=go)](https://goreportcard.com/badge/github.com/FloatTech/ZeroBot-Plugin)
[![onebot](https://img.shields.io/badge/onebot-v11-black?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://t.me/zerobotplugin)
[![zerobot](https://img.shields.io/badge/zerobot-v1.5.1-black?style=flat-square&logo=go)](https://github.com/wdvxdr1123/ZeroBot)
[![zerobot](https://img.shields.io/badge/zerobot-v1.6.6-black?style=flat-square&logo=go)](https://github.com/wdvxdr1123/ZeroBot)
[![license](https://img.shields.io/github/license/FloatTech/ZeroBot-Plugin.svg?style=flat-square&logo=gnu)](https://raw.githubusercontent.com/FloatTech/ZeroBot-Plugin/master/LICENSE)
[![tencent-qq](https://img.shields.io/badge/group-1048452984-red?style=flat-square&logo=tencent-qq)](https://jq.qq.com/?_wv=1027&k=QMb7x1mM)
[![telegram](https://img.shields.io/badge/Telegram-click%20me-informational?style=flat-square&logo=telegram)](https://t.me/zerobotplugin)

本项目符合 [OneBot](https://github.com/howmanybots/onebot) 标准,可基于以下项目与机器人框架/平台进行交互
| 项目地址 | 平台 | 核心作者 |
| --- | --- | --- |
| [Mrs4s/go-cqhttp](https://github.com/Mrs4s/go-cqhttp) | [MiraiGo](https://github.com/Mrs4s/MiraiGo) | Mrs4s |
| [yyuueexxiinngg/cqhttp-mirai](https://github.com/yyuueexxiinngg/cqhttp-mirai) | [Mirai](https://github.com/mamoe/mirai) | yyuueexxiinngg |
| [takayama-lily/onebot](https://github.com/takayama-lily/onebot) | [OICQ](https://github.com/takayama-lily/oicq) | takayama |
| [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) | [MiraiGo](https://github.com/Mrs4s/MiraiGo) | Mrs4s |
| [onebot-kotlin](https://github.com/yyuueexxiinngg/onebot-kotlin) | [Mirai](https://github.com/mamoe/mirai) | yyuueexxiinngg |
| [oicq/http-api](https://github.com/takayama-lily/oicq/tree/master/http-api) | [OICQ](https://github.com/takayama-lily/oicq) | takayama |

[![Star Trend](https://api.star-history.com/svg?repos=FloatTech/ZeroBot-Plugin&type=Timeline)](https://seladb.github.io/StarTrack-js/#/preload?r=FloatTech,ZeroBot-Plugin)

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ go 1.19
require (
github.com/Baidu-AIP/golang-sdk v1.1.1
github.com/Coloured-glaze/gg v1.3.4
github.com/FloatTech/AnimeAPI v1.6.1-0.20221211044824-a4c95321af15
github.com/FloatTech/AnimeAPI v1.6.1-0.20221214084932-8c0223841d43
github.com/FloatTech/floatbox v0.0.0-20221210051813-4bd44af40c60
github.com/FloatTech/sqlite v1.5.7
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
github.com/FloatTech/zbpctrl v1.5.3-0.20221210051848-740ab7bd6ec3
github.com/FloatTech/zbputils v1.6.1-0.20221210052030-50f19ddfae6f
github.com/FloatTech/zbputils v1.6.1-0.20221212090658-d0de5338e354
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
github.com/antchfx/htmlquery v1.2.5
@@ -25,7 +25,7 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/jinzhu/gorm v1.9.16
github.com/jozsefsallai/gophersauce v1.0.1
github.com/lucas-clemente/quic-go v0.31.0
github.com/lucas-clemente/quic-go v0.31.1
github.com/mroth/weightedrand v1.0.0
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.22.11
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/Coloured-glaze/gg v1.3.4 h1:l31zIF/HaVwkzjrj+A56RGQoSKyKuR1IWtIrqXGFStI=
github.com/Coloured-glaze/gg v1.3.4/go.mod h1:Ih5NLNNDHOy3RJbB0EPqGTreIzq/H02TGThIagh8HJg=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/FloatTech/AnimeAPI v1.6.1-0.20221211044824-a4c95321af15 h1:/AMRe7SDCqrE0674bz6FakI/UqaxTUbBjbDs+p/ARh8=
github.com/FloatTech/AnimeAPI v1.6.1-0.20221211044824-a4c95321af15/go.mod h1:Sp8rOoJkMq/X0XIqrhcH9fuFTF/HuLDBL26NkA1FEGA=
github.com/FloatTech/AnimeAPI v1.6.1-0.20221214084932-8c0223841d43 h1:a0Hl8o6sYaepeuFZ3rboCM3Wh+sikKhsFm6pFmtyom8=
github.com/FloatTech/AnimeAPI v1.6.1-0.20221214084932-8c0223841d43/go.mod h1:Ri2Qa0552braxZVsk+axbBHL6UIWkGqQRETiIT9QTXI=
github.com/FloatTech/floatbox v0.0.0-20221210051813-4bd44af40c60 h1:S4KfcdK6LdOa0+TTyacHYOZ8aWkR6YbvlnI6GWe66Jc=
github.com/FloatTech/floatbox v0.0.0-20221210051813-4bd44af40c60/go.mod h1:/k2zxRJtAJ17w9fSpc7xf2QjPDTUBmqhBsOGyHVyX0U=
github.com/FloatTech/rendercard v0.0.2-0.20221128165614-a41216d2422e h1:7bF01RHsYS99Zp+OWfob1W/Cymho6fcggoRSpiuiYB8=
@@ -16,8 +16,8 @@ github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJG
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/FloatTech/zbpctrl v1.5.3-0.20221210051848-740ab7bd6ec3 h1:dxARTVta2i48OOYa0xMRzWTO0lr6bM4M6JmQWLkHdNE=
github.com/FloatTech/zbpctrl v1.5.3-0.20221210051848-740ab7bd6ec3/go.mod h1:KFfMTzItP5usfnUYs7cFWjk89dzjtdO1eI+B1BVQNig=
github.com/FloatTech/zbputils v1.6.1-0.20221210052030-50f19ddfae6f h1:l+MzleQkVkEdGFOfmxuPL5gGLd+d8za7m4g+AyQ+qeA=
github.com/FloatTech/zbputils v1.6.1-0.20221210052030-50f19ddfae6f/go.mod h1:S7M4oH9MM8DRmIOHfTcpUpIW9KbmWht9Y6zkZLtaeKE=
github.com/FloatTech/zbputils v1.6.1-0.20221212090658-d0de5338e354 h1:vXchiNmu44lc7ECePl2ypreJhq8M7PDOdeP47hmmKqE=
github.com/FloatTech/zbputils v1.6.1-0.20221212090658-d0de5338e354/go.mod h1:S7M4oH9MM8DRmIOHfTcpUpIW9KbmWht9Y6zkZLtaeKE=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
@@ -126,8 +126,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lucas-clemente/quic-go v0.31.0 h1:MfNp3fk0wjWRajw6quMFA3ap1AVtlU+2mtwmbVogB2M=
github.com/lucas-clemente/quic-go v0.31.0/go.mod h1:0wFbizLgYzqHqtlyxyCaJKlE7bYgE6JQ+54TLd/Dq2g=
github.com/lucas-clemente/quic-go v0.31.1 h1:O8Od7hfioqq0PMYHDyBkxU2aA7iZ2W9pjbrWuja2YR4=
github.com/lucas-clemente/quic-go v0.31.1/go.mod h1:0wFbizLgYzqHqtlyxyCaJKlE7bYgE6JQ+54TLd/Dq2g=
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
2 changes: 1 addition & 1 deletion kanban/banner.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@ package kanban

// Banner ...
var Banner = "* OneBot + ZeroBot + Golang\n" +
"* Version v1.6.0 - 2022-12-10 13:57:05 +0800 CST\n" +
"* Version v1.6.1-beta2 - 2022-12-14 21:39:15 +0800 CST\n" +
"* Copyright © 2020 - 2022 FloatTech. All Rights Reserved.\n" +
"* Project: https://github.com/FloatTech/ZeroBot-Plugin"
65 changes: 25 additions & 40 deletions plugin/ai_reply/ai_tts.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@ package aireply
import (
"errors"
"net/url"
"sync"

"github.com/RomiChan/syncx"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"

"github.com/FloatTech/AnimeAPI/aireply"
@@ -58,7 +59,7 @@ func setReplyMode(ctx *zero.Ctx, name string) error {
if !ok {
return errors.New("no such plugin")
}
return m.SetData((m.GetData(gid)&^0xff)|(gid&0xff), index)
return m.SetData(gid, (m.GetData(index)&^0xff)|(index&0xff))
}

var chats *aireply.ChatGPT
@@ -99,9 +100,8 @@ var ttsModes = func() []string {
}()

type ttsmode struct {
sync.Mutex `json:"-"`
APIKey string // APIKey is for genshin vits
mode map[int64]int64 `json:"-"` // mode grp index
APIKey string // APIKey is for genshin vits
mode syncx.Map[int64, int64] `json:"-"` // mode grp index
}

func list(list []string, num int) string {
@@ -119,44 +119,32 @@ func list(list []string, num int) string {

func newttsmode() *ttsmode {
t := &ttsmode{}
t.Lock()
defer t.Unlock()
m, ok := control.Lookup("tts")
t.mode = make(map[int64]int64, 2*len(genshin.SoundList))
t.mode[defaultttsindexkey] = 0
t.mode = syncx.Map[int64, int64]{}
t.mode.Store(defaultttsindexkey, 0)
if ok {
index := m.GetData(defaultttsindexkey)
msk := index & 0xff
if msk >= 0 && (msk < int64(len(genshin.SoundList)) || msk == baiduttsindex || msk == mockingbirdttsindex) {
t.mode[defaultttsindexkey] = index
t.mode.Store(defaultttsindexkey, index)
}
}
return t
}

func (t *ttsmode) getAPIKey(ctx *zero.Ctx) string {
if t.APIKey == "" {
t.Lock()
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
}
_ = m.Manager.GetExtra(gid, &t)
t.Unlock()
_ = m.Manager.GetExtra(-1, &t)
logrus.Debugln("[tts] get api key:", t.APIKey)
}
return url.QueryEscape(t.APIKey)
}

func (t *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], grp int64, key string) error {
t.Lock()
defer t.Unlock()
err := m.Manager.SetExtra(grp, &key)
if err != nil {
return err
}
func (t *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], key string) error {
t.APIKey = key
return nil
_ = m.Manager.Response(-1)
return m.Manager.SetExtra(-1, t)
}

func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt int) error {
@@ -186,9 +174,7 @@ func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt
}
}
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
t.Lock()
defer t.Unlock()
t.mode[gid] = index
t.mode.Store(gid, index)
return m.SetData(gid, (m.GetData(gid)&^0xffff00)|((index<<8)&0xff00)|((int64(baiduper)<<16)&0x0f0000)|((int64(mockingsynt)<<20)&0xf00000))
}

@@ -197,21 +183,19 @@ func (t *ttsmode) getSoundMode(ctx *zero.Ctx) (tts.TTS, error) {
if gid == 0 {
gid = -ctx.Event.UserID
}
t.Lock()
defer t.Unlock()
i, ok := t.mode[gid]
i, ok := t.mode.Load(gid)
if !ok {
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
i = m.GetData(gid) >> 8
}
m := i & 0xff
if m < 0 || (m >= int64(len(genshin.SoundList)) && m != baiduttsindex && m != mockingbirdttsindex) {
i = t.mode[defaultttsindexkey]
i, _ = t.mode.Load(defaultttsindexkey)
m = i & 0xff
}
mode := ttsModes[m]
ins, ok := ttsins[mode]
if !ok {
if !ok || ins == nil {
switch mode {
case "百度":
ins = baidutts.NewBaiduTTS(int(i&0x0f00) >> 8)
@@ -222,8 +206,13 @@ func (t *ttsmode) getSoundMode(ctx *zero.Ctx) (tts.TTS, error) {
return nil, err
}
default: // 原神
ins = genshin.NewGenshin(int(m), t.getAPIKey(ctx))
ttsins[mode] = ins
k := t.getAPIKey(ctx)
if k != "" {
ins = genshin.NewGenshin(int(m), t.getAPIKey(ctx))
ttsins[mode] = ins
} else {
return nil, errors.New("no valid speaker")
}
}
}
return ins, nil
@@ -234,8 +223,6 @@ func (t *ttsmode) resetSoundMode(ctx *zero.Ctx) error {
if gid == 0 {
gid = -ctx.Event.UserID
}
t.Lock()
defer t.Unlock()
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
index := m.GetData(defaultttsindexkey)
return m.SetData(gid, (m.GetData(gid)&0xff)|((index&^0xff)<<8)) // 重置数据
@@ -263,12 +250,10 @@ func (t *ttsmode) setDefaultSoundMode(name string, baiduper, mockingsynt int) er
return errors.New("语音人物" + name + "未注册index")
}
}
t.Lock()
defer t.Unlock()
m, ok := control.Lookup("tts")
if !ok {
return errors.New("[tts] service not found")
}
t.mode[defaultttsindexkey] = index
t.mode.Store(defaultttsindexkey, index)
return m.SetData(defaultttsindexkey, (index&0xff)|((int64(baiduper)<<8)&0x0f00)|((int64(mockingsynt)<<12)&0xf000))
}
73 changes: 59 additions & 14 deletions plugin/ai_reply/main.go
Original file line number Diff line number Diff line change
@@ -28,14 +28,14 @@ func init() { // 插件主体
"- 设置语音模式[原神人物/百度/拟声鸟] 数字(百度/拟声鸟模式)\n" +
"- 设置默认语音模式[原神人物/百度/拟声鸟] 数字(百度/拟声鸟模式)\n" +
"- 恢复成默认语音模式\n" +
"- 为群 xxx 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
"- 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
"当前适用的原神人物含有以下:\n" + list(genshin.SoundList[:], 5),
})

enr := control.Register("aireply", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: true,
Brief: "人工智能回复",
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱|ChatGPT]\n- 设置 ChatGPT SessionToken xxx\n- 重置ChatGPT连接",
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱|ChatGPT]\n- 设置 ChatGPT SessionToken xxx\n- 设置 ChatGPT UA xxx\n- 设置 ChatGPT CF xxx\n- 重置ChatGPT连接",
PrivateDataFolder: "aireply",
})

@@ -64,19 +64,28 @@ func init() { // 插件主体
})

chatgptfile := enr.DataFolder() + "chatgpt.txt"
uafile := enr.DataFolder() + "ua.txt"
cffile := enr.DataFolder() + "cf.txt"
cfg := &chatgpt.Config{
UA: chatgpt.UA,
RefreshInterval: time.Hour,
Timeout: time.Minute,
}
data, err := os.ReadFile(chatgptfile)
if err == nil {
cfg.SessionToken = binary.BytesToString(data)
chats = aireply.NewChatGPT(cfg)
data, err = os.ReadFile(uafile)
if err == nil {
cfg.UA = binary.BytesToString(data)
data, err = os.ReadFile(cffile)
if err == nil {
cfg.CFClearance = binary.BytesToString(data)
}
}
}
chats = aireply.NewChatGPT(cfg)
go func() {
for range time.NewTicker(time.Hour).C {
if chats == nil {
if chats == nil || cfg.SessionToken == "" {
continue
}
err := os.WriteFile(chatgptfile, binary.StringToBytes(cfg.SessionToken), 0644)
@@ -99,16 +108,49 @@ func init() { // 插件主体
ctx.SendChain(message.Text("ERROR: ", err))
return
}
chats = aireply.NewChatGPT(&chatgpt.Config{
UA: chatgpt.UA,
SessionToken: token,
RefreshInterval: time.Hour,
Timeout: time.Minute,
})
cfg.SessionToken = token
ctx.SendChain(message.Text("设置成功"))
})

enr.OnRegex(`^设置\s*ChatGPT\s*UA\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
ua := ctx.State["regex_matched"].([]string)[1]
f, err := os.Create(uafile)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
defer f.Close()
_, err = f.WriteString(ua)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
cfg.UA = ua
ctx.SendChain(message.Text("设置成功"))
})

enr.OnRegex(`^设置\s*ChatGPT\s*CF\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
cf := ctx.State["regex_matched"].([]string)[1]
f, err := os.Create(cffile)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
defer f.Close()
_, err = f.WriteString(cf)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
cfg.CFClearance = cf
ctx.SendChain(message.Text("设置成功"))
})

enr.OnFullMatch("重置ChatGPT连接").SetBlock(true).Handle(func(ctx *zero.Ctx) {
if chats == nil {
ctx.SendChain(message.Text("ERROR: chats 为空"))
return
}
err := chats.Reset(ctx.Event.UserID)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
@@ -154,23 +196,27 @@ func init() { // 插件主体
}
}
// 保存设置
logrus.Debugln("[tts] t.setSoundMode( ctx", param, n, n, ")")
err = t.setSoundMode(ctx, param, n, n)
if err != nil {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(err))
return
}
if banner, ok := genshin.TestRecord[param]; ok {
logrus.Debugln("[tts] banner:", banner, "get sound mode...")
// 设置验证
speaker, err := t.getSoundMode(ctx)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
logrus.Debugln("[tts] got sound mode, speaking...")
rec, err := speaker.Speak(ctx.Event.UserID, func() string { return banner })
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
logrus.Debugln("[tts] sending...")
if id := ctx.SendChain(message.Record(rec).Add("cache", 0)); id.ID() == 0 {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("无法发送测试语音,请重试。"))
return
@@ -216,9 +262,8 @@ func init() { // 插件主体
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功,当前为", speaker))
})

ent.OnRegex(`^为群\s*(-?\d+)\s*设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
grp, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
err := t.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), grp, ctx.State["regex_matched"].([]string)[2])
ent.OnRegex(`^设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
err := t.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), ctx.State["regex_matched"].([]string)[1])
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
10 changes: 3 additions & 7 deletions plugin/moegoe/main.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/AnimeAPI/tts/genshin"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
@@ -16,7 +17,6 @@ import (
const (
jpapi = "https://moegoe.azurewebsites.net/api/speak?text=%s&id=%d"
krapi = "https://moegoe.azurewebsites.net/api/speakkr?text=%s&id=%d"
cnapi = "https://genshin.azurewebsites.net/api/speak?format=mp3&text=%s&id=%d&code=%s"
)

var speakers = map[string]uint{
@@ -57,15 +57,11 @@ func init() {
var key struct {
APIKey string
}
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
}
err := c.Manager.GetExtra(gid, &key)
err := c.Manager.GetExtra(-1, &key)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Record(fmt.Sprintf(cnapi, url.QueryEscape(text), id, url.QueryEscape(key.APIKey))))
ctx.SendChain(message.Record(fmt.Sprintf(genshin.CNAPI, id, url.QueryEscape(text), url.QueryEscape(key.APIKey))))
})
}

0 comments on commit 0fcdf38

Please sign in to comment.