Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HalcyonAlcedo committed Dec 4, 2023
2 parents ef1423d + fac0863 commit d795e8e
Show file tree
Hide file tree
Showing 13 changed files with 1,878 additions and 348 deletions.
4 changes: 2 additions & 2 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ export class chatgpt extends plugin {
if (!msg || e.msg?.startsWith('#')) {
return false
}
if ((e.isGroup || e.group_id) && !(e.atme || e.atBot)) {
if ((e.isGroup || e.group_id) && !(e.atme || e.atBot || (e.at === e.self_id))) {
return false
}
if (e.user_id == getUin(e)) return false
Expand Down Expand Up @@ -1652,7 +1652,7 @@ export class chatgpt extends plugin {
opt.groupId = e.group_id
opt.qq = e.sender.user_id
opt.nickname = e.sender.card
opt.groupName = e.group.name
opt.groupName = e.group.name || e.group_name
opt.botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname
let master = (await getMasterQQ())[0]
if (master && e.group) {
Expand Down
112 changes: 58 additions & 54 deletions apps/entertainment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { translate, translateLangSupports } from '../utils/translate.js'
import AzureTTS from '../utils/tts/microsoft-azure.js'
import VoiceVoxTTS from '../utils/tts/voicevox.js'
import { URL } from 'node:url'
import { getBots } from '../utils/bot.js'

let useSilk = false
try {
Expand Down Expand Up @@ -350,7 +351,7 @@ ${translateLangLabels}
let groupId = e.msg.replace(/^#chatgpt打招呼/, '')
logger.info(groupId)
groupId = parseInt(groupId)
if (groupId && !e.bot.getGroupList().get(groupId)) {
if (groupId && !e.bot.gl.get(groupId)) {
await e.reply('机器人不在这个群里!')
return
}
Expand Down Expand Up @@ -379,74 +380,77 @@ ${translateLangLabels}
continue
}
let groupId = parseInt(element)
if (this.e.bot.getGroupList().get(groupId)) {
// 打招呼概率
if (Math.floor(Math.random() * 100) < Config.helloProbability) {
let message = await generateHello()
logger.info(`打招呼给群聊${groupId}:` + message)
if (Config.defaultUseTTS) {
let audio
const [defaultVitsTTSRole, defaultAzureTTSRole, defaultVoxTTSRole] = [Config.defaultTTSRole, Config.azureTTSSpeaker, Config.voicevoxTTSSpeaker]
let ttsSupportKinds = []
if (Config.azureTTSKey) ttsSupportKinds.push(1)
if (Config.ttsSpace) ttsSupportKinds.push(2)
if (Config.voicevoxSpace) ttsSupportKinds.push(3)
if (!ttsSupportKinds.length) {
logger.warn('没有配置任何语音服务!')
return false
}
const randomIndex = Math.floor(Math.random() * ttsSupportKinds.length)
switch (ttsSupportKinds[randomIndex]) {
case 1 : {
const isEn = AzureTTS.supportConfigurations.find(config => config.code === defaultAzureTTSRole)?.language.includes('en')
if (isEn) {
message = (await translate(message, '英')).replace('\n', '')
}
audio = await AzureTTS.generateAudio(message, {
defaultAzureTTSRole
})
break
let bots = this.e ? [this.e.bot] : getBots()
for (let bot of bots) {
if (bot.gl?.get(groupId)) {
// 打招呼概率
if (Math.floor(Math.random() * 100) < Config.helloProbability) {
let message = await generateHello()
logger.info(`打招呼给群聊${groupId}:` + message)
if (Config.defaultUseTTS) {
let audio
const [defaultVitsTTSRole, defaultAzureTTSRole, defaultVoxTTSRole] = [Config.defaultTTSRole, Config.azureTTSSpeaker, Config.voicevoxTTSSpeaker]
let ttsSupportKinds = []
if (Config.azureTTSKey) ttsSupportKinds.push(1)
if (Config.ttsSpace) ttsSupportKinds.push(2)
if (Config.voicevoxSpace) ttsSupportKinds.push(3)
if (!ttsSupportKinds.length) {
logger.warn('没有配置任何语音服务!')
return false
}
case 2 : {
if (Config.autoJapanese) {
const randomIndex = Math.floor(Math.random() * ttsSupportKinds.length)
switch (ttsSupportKinds[randomIndex]) {
case 1 : {
const isEn = AzureTTS.supportConfigurations.find(config => config.code === defaultAzureTTSRole)?.language.includes('en')
if (isEn) {
message = (await translate(message, '英')).replace('\n', '')
}
audio = await AzureTTS.generateAudio(message, {
defaultAzureTTSRole
})
break
}
case 2 : {
if (Config.autoJapanese) {
try {
message = await translate(message, '日')
} catch (err) {
logger.error(err)
}
}
try {
message = await translate(message, '日')
audio = await generateVitsAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
} catch (err) {
logger.error(err)
}
break
}
try {
audio = await generateVitsAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
} catch (err) {
logger.error(err)
case 3 : {
message = (await translate(message, '日')).replace('\n', '')
try {
audio = await VoiceVoxTTS.generateAudio(message, {
speaker: defaultVoxTTSRole
})
} catch (err) {
logger.error(err)
}
break
}
break
}
case 3 : {
message = (await translate(message, '日')).replace('\n', '')
try {
audio = await VoiceVoxTTS.generateAudio(message, {
speaker: defaultVoxTTSRole
})
} catch (err) {
logger.error(err)
}
break
if (useSilk) {
await this.e.bot.sendGroupMsg(groupId, await uploadRecord(audio))
} else {
await this.e.bot.sendGroupMsg(groupId, segment.record(audio))
}
}
if (useSilk) {
await this.e.bot.sendGroupMsg(groupId, await uploadRecord(audio))
} else {
await this.e.bot.sendGroupMsg(groupId, segment.record(audio))
await this.e.bot.sendGroupMsg(groupId, message)
}
} else {
await this.e.bot.sendGroupMsg(groupId, message)
logger.info(`时机未到,这次就不打招呼给群聊${groupId}了`)
}
} else {
logger.info(`时机未到,这次就不打招呼给群聊${groupId}了`)
logger.warn('机器人不在要发送的群组里,忽略群。同时建议检查配置文件修改要打招呼的群号。' + groupId)
}
} else {
logger.warn('机器人不在要发送的群组里,忽略群。同时建议检查配置文件修改要打招呼的群号。' + groupId)
}
}
}
Expand Down
109 changes: 109 additions & 0 deletions apps/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,25 @@ export class ChatgptManagement extends plugin {
reg: '^#chatgpt(开启|关闭)智能模式$',
fnc: 'switchSmartMode',
permission: 'master'
},
{
reg: '^#chatgpt模型列表$',
fnc: 'viewAPIModel'
},
{
reg: '^#chatgpt设置(API|api)模型$',
fnc: 'setAPIModel',
permission: 'master'
},
{
reg: '^#chatgpt设置(API|api)反代$',
fnc: 'setOpenAiBaseUrl',
permission: 'master'
},
{
reg: '^#chatgpt设置星火模型$',
fnc: 'setXinghuoModel',
permission: 'master'
}
]
})
Expand Down Expand Up @@ -1435,4 +1454,94 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await e.reply('好的,已经关闭智能模式')
}
}

async viewAPIModel (e) {
const contents = [
'仅列出部分模型以供参考',
'gpt-3.5-turbo',
'gpt-3.5-turbo-0301',
'gpt-3.5-turbo-0613',
'gpt-3.5-turbo-1106',
'gpt-3.5-turbo-16k',
'gpt-3.5-turbo-16k-0613',
'gpt-4',
'gpt-4-32k',
'gpt-4-1106-preview'
]
let modelList = []
contents.forEach(value => {
// console.log(value)
modelList.push(value)
})
await this.e.reply(makeForwardMsg(e, modelList, '模型列表'))
}

async setAPIModel (e) {
this.setContext('saveAPIModel')
await this.reply('请发送API模型', true)
return false
}

async saveAPIModel () {
if (!this.e.msg) return
let token = this.e.msg
Config.model = token
await this.reply('API模型设置成功', true)
this.finish('saveAPIModel')
}

async setOpenAiBaseUrl (e) {
this.setContext('saveOpenAiBaseUrl')
await this.reply('请发送API反代', true)
return false
}

async saveOpenAiBaseUrl () {
if (!this.e.msg) return
let token = this.e.msg
// console.log(token.startsWith('http://') || token.startsWith('https://'))
if (token.startsWith('http://') || token.startsWith('https://')) {
Config.openAiBaseUrl = token
await this.reply('API反代设置成功', true)
this.finish('saveOpenAiBaseUrl')
return
}
await this.reply('你的输入不是一个有效的URL,请检查是否含有http://或https://', true)
this.finish('saveOpenAiBaseUrl')
}

async setXinghuoModel (e) {
this.setContext('saveXinghuoModel')
await this.reply('1:星火V1.5\n2:星火V2\n3:星火V3\n4:星火助手')
await this.reply('请发送序号', true)
return false
}

async saveXinghuoModel (e) {
if (!this.e.msg) return
let token = this.e.msg
let ver
switch (token) {
case '3':
ver = 'V3'
Config.xhmode = 'apiv3'
break
case '2':
ver = 'V2'
Config.xhmode = 'apiv2'
break
case '1':
ver = 'V1.5'
Config.xhmode = 'api'
break
case '4':
ver = '助手'
Config.xhmode = 'assistants'
break
default:
break
}
await this.reply(`已成功切换到星火${ver}`, true)
this.finish('saveXinghuoModel')
}
}
49 changes: 3 additions & 46 deletions guoba.support.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function supportGuoba () {
{
field: 'model',
label: 'OpenAI 模型',
bottomHelpMessage: 'gpt-4, gpt-4-0613, gpt-4-32k, gpt-4-32k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0613, gpt-3.5-turbo-16k-0613。默认为gpt-3.5-turbo,gpt-4需账户支持',
bottomHelpMessage: 'gpt-4, gpt-4-0613, gpt-4-1106, gpt-4-32k, gpt-4-32k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0613, gpt-3.5-turbo-1106, gpt-3.5-turbo-16k-0613。默认为gpt-3.5-turbo,gpt-4需账户支持',
component: 'Input'
},
{
Expand Down Expand Up @@ -456,7 +456,7 @@ export function supportGuoba () {
{
field: 'sydneyWebsocketUseProxy',
label: '对话使用sydney反代',
bottomHelpMessage: '【一般情况无需也不建议开启】默认情况下仅创建对话走反代,对话时仍然直连微软。开启本选项将使对话过程也走反,需反代支持',
bottomHelpMessage: '默认情况下仅创建对话走反代,对话时仍然直连微软。开启本选项将使对话过程也走反代,需反代支持。默认开启',
component: 'Switch'
},
{
Expand Down Expand Up @@ -505,40 +505,6 @@ export function supportGuoba () {
bottomHelpMessage: '使用GPT-4,注意试用配额较低,如果用不了就关掉',
component: 'Switch'
},
{
label: '以下为浏览器方式的配置.(Deprecated)',
component: 'Divider'
},
{
field: 'username',
label: '用户名',
bottomHelpMessage: 'OpenAI用户名。',
component: 'Input'
},
{
field: 'password',
label: '密码',
bottomHelpMessage: 'OpenAI密码。',
component: 'InputPassword'
},
{
field: 'UA',
label: '浏览器UA',
bottomHelpMessage: '模拟浏览器UA,无特殊需求保持默认即可',
component: 'InputTextArea'
},
{
field: 'headless',
label: '无头模式',
bottomHelpMessage: '无界面的服务器可以开启,但遇到验证码时可能无法使用。(实测很容易卡住,几乎不可用)',
component: 'Switch'
},
{
field: 'chromePath',
label: 'Chrome路径',
bottomHelpMessage: '为空使用默认puppeteer的chromium,也可以传递自己本机安装的Chrome可执行文件地址,提高通过率。windows可以是‘C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe’,linux通过which查找路径',
component: 'Input'
},
{
label: '以下为Slack Claude方式的配置',
component: 'Divider'
Expand Down Expand Up @@ -625,16 +591,6 @@ export function supportGuoba () {
bottomHelpMessage: '等待响应的超时时间,单位为秒,默认为120。如果不使用反代而是使用代理可以适当调低。',
component: 'InputNumber'
},
{
label: '以下为ChatGLM方式的配置',
component: 'Divider'
},
{
field: 'chatglmBaseUrl',
label: 'ChatGLM API地址',
bottomHelpMessage: '如 http://localhost:8080',
component: 'Input'
},
{
label: '以下为星火方式的配置',
component: 'Divider'
Expand All @@ -649,6 +605,7 @@ export function supportGuoba () {
{ label: '体验版', value: 'web' },
{ label: '讯飞星火认知大模型V1.5', value: 'api' },
{ label: '讯飞星火认知大模型V2.0', value: 'apiv2' },
{ label: '讯飞星火认知大模型V3.0', value: 'apiv3' },
{ label: '讯飞星火助手', value: 'assistants' }
]
}
Expand Down
Loading

0 comments on commit d795e8e

Please sign in to comment.