mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
4a6cad2e4e
6 changed files with 79 additions and 71 deletions
|
|
@ -803,7 +803,7 @@ export class chatgpt extends plugin {
|
||||||
if (!msg || e.msg?.startsWith('#')) {
|
if (!msg || e.msg?.startsWith('#')) {
|
||||||
return false
|
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
|
return false
|
||||||
}
|
}
|
||||||
if (e.user_id == getUin(e)) return false
|
if (e.user_id == getUin(e)) return false
|
||||||
|
|
@ -1639,7 +1639,7 @@ export class chatgpt extends plugin {
|
||||||
opt.groupId = e.group_id
|
opt.groupId = e.group_id
|
||||||
opt.qq = e.sender.user_id
|
opt.qq = e.sender.user_id
|
||||||
opt.nickname = e.sender.card
|
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
|
opt.botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname
|
||||||
let master = (await getMasterQQ())[0]
|
let master = (await getMasterQQ())[0]
|
||||||
if (master && e.group) {
|
if (master && e.group) {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { translate, translateLangSupports } from '../utils/translate.js'
|
||||||
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
||||||
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
||||||
import { URL } from 'node:url'
|
import { URL } from 'node:url'
|
||||||
|
import { getBots } from '../utils/bot.js'
|
||||||
|
|
||||||
let useSilk = false
|
let useSilk = false
|
||||||
try {
|
try {
|
||||||
|
|
@ -350,7 +351,7 @@ ${translateLangLabels}
|
||||||
let groupId = e.msg.replace(/^#chatgpt打招呼/, '')
|
let groupId = e.msg.replace(/^#chatgpt打招呼/, '')
|
||||||
logger.info(groupId)
|
logger.info(groupId)
|
||||||
groupId = parseInt(groupId)
|
groupId = parseInt(groupId)
|
||||||
if (groupId && !e.bot.getGroupList().get(groupId)) {
|
if (groupId && !e.bot.gl.get(groupId)) {
|
||||||
await e.reply('机器人不在这个群里!')
|
await e.reply('机器人不在这个群里!')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -379,74 +380,77 @@ ${translateLangLabels}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let groupId = parseInt(element)
|
let groupId = parseInt(element)
|
||||||
if (this.e.bot.getGroupList().get(groupId)) {
|
let bots = this.e ? [this.e.bot] : getBots()
|
||||||
// 打招呼概率
|
for (let bot of bots) {
|
||||||
if (Math.floor(Math.random() * 100) < Config.helloProbability) {
|
if (bot.gl?.get(groupId)) {
|
||||||
let message = await generateHello()
|
// 打招呼概率
|
||||||
logger.info(`打招呼给群聊${groupId}:` + message)
|
if (Math.floor(Math.random() * 100) < Config.helloProbability) {
|
||||||
if (Config.defaultUseTTS) {
|
let message = await generateHello()
|
||||||
let audio
|
logger.info(`打招呼给群聊${groupId}:` + message)
|
||||||
const [defaultVitsTTSRole, defaultAzureTTSRole, defaultVoxTTSRole] = [Config.defaultTTSRole, Config.azureTTSSpeaker, Config.voicevoxTTSSpeaker]
|
if (Config.defaultUseTTS) {
|
||||||
let ttsSupportKinds = []
|
let audio
|
||||||
if (Config.azureTTSKey) ttsSupportKinds.push(1)
|
const [defaultVitsTTSRole, defaultAzureTTSRole, defaultVoxTTSRole] = [Config.defaultTTSRole, Config.azureTTSSpeaker, Config.voicevoxTTSSpeaker]
|
||||||
if (Config.ttsSpace) ttsSupportKinds.push(2)
|
let ttsSupportKinds = []
|
||||||
if (Config.voicevoxSpace) ttsSupportKinds.push(3)
|
if (Config.azureTTSKey) ttsSupportKinds.push(1)
|
||||||
if (!ttsSupportKinds.length) {
|
if (Config.ttsSpace) ttsSupportKinds.push(2)
|
||||||
logger.warn('没有配置任何语音服务!')
|
if (Config.voicevoxSpace) ttsSupportKinds.push(3)
|
||||||
return false
|
if (!ttsSupportKinds.length) {
|
||||||
}
|
logger.warn('没有配置任何语音服务!')
|
||||||
const randomIndex = Math.floor(Math.random() * ttsSupportKinds.length)
|
return false
|
||||||
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 : {
|
const randomIndex = Math.floor(Math.random() * ttsSupportKinds.length)
|
||||||
if (Config.autoJapanese) {
|
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 {
|
try {
|
||||||
message = await translate(message, '日')
|
audio = await generateVitsAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
try {
|
case 3 : {
|
||||||
audio = await generateVitsAudio(message, defaultVitsTTSRole, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)')
|
message = (await translate(message, '日')).replace('\n', '')
|
||||||
} catch (err) {
|
try {
|
||||||
logger.error(err)
|
audio = await VoiceVoxTTS.generateAudio(message, {
|
||||||
|
speaker: defaultVoxTTSRole
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
case 3 : {
|
if (useSilk) {
|
||||||
message = (await translate(message, '日')).replace('\n', '')
|
await this.e.bot.sendGroupMsg(groupId, await uploadRecord(audio))
|
||||||
try {
|
} else {
|
||||||
audio = await VoiceVoxTTS.generateAudio(message, {
|
await this.e.bot.sendGroupMsg(groupId, segment.record(audio))
|
||||||
speaker: defaultVoxTTSRole
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(err)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (useSilk) {
|
|
||||||
await this.e.bot.sendGroupMsg(groupId, await uploadRecord(audio))
|
|
||||||
} else {
|
} else {
|
||||||
await this.e.bot.sendGroupMsg(groupId, segment.record(audio))
|
await this.e.bot.sendGroupMsg(groupId, message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.e.bot.sendGroupMsg(groupId, message)
|
logger.info(`时机未到,这次就不打招呼给群聊${groupId}了`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info(`时机未到,这次就不打招呼给群聊${groupId}了`)
|
logger.warn('机器人不在要发送的群组里,忽略群。同时建议检查配置文件修改要打招呼的群号。' + groupId)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logger.warn('机器人不在要发送的群组里,忽略群。同时建议检查配置文件修改要打招呼的群号。' + groupId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,8 @@
|
||||||
import { UserInfo, AddUser } from './user_data.js'
|
import { UserInfo, AddUser } from './user_data.js'
|
||||||
import { randomString, getUserData, getMasterQQ, getUin } from '../../utils/common.js'
|
import { randomString, getUserData, getMasterQQ, getUin } from '../../utils/common.js'
|
||||||
|
import { getBots } from '../../utils/bot.js';
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import path from 'path';
|
||||||
function getBots () {
|
|
||||||
if (Bot.uin === 88888) {
|
|
||||||
// 找适配器
|
|
||||||
let adapters = Bot.adapter
|
|
||||||
return adapters?.map(uin => Bot[uin])
|
|
||||||
} else if (Bot.adapter && Bot.adapter.length > 0) {
|
|
||||||
let bots = [Bot]
|
|
||||||
Bot.adapter.forEach(uin => {
|
|
||||||
bots.push(Bot[uin])
|
|
||||||
})
|
|
||||||
return bots
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function User (fastify, options) {
|
async function User (fastify, options) {
|
||||||
// 登录
|
// 登录
|
||||||
|
|
|
||||||
15
utils/bot.js
Normal file
15
utils/bot.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
export function getBots () {
|
||||||
|
if (Bot.uin === 88888) {
|
||||||
|
// 找适配器
|
||||||
|
let adapters = Bot.adapter
|
||||||
|
return adapters?.map(uin => Bot[uin])
|
||||||
|
} else if (Bot.adapter && Bot.adapter.length > 0) {
|
||||||
|
let bots = [Bot]
|
||||||
|
Bot.adapter.forEach(uin => {
|
||||||
|
bots.push(Bot[uin])
|
||||||
|
})
|
||||||
|
return bots
|
||||||
|
} else {
|
||||||
|
return [Bot]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ export class ClaudeAIClient {
|
||||||
attachments,
|
attachments,
|
||||||
completion: {
|
completion: {
|
||||||
incremental: true,
|
incremental: true,
|
||||||
model: 'claude-2',
|
model: 'claude-2.1',
|
||||||
prompt: text,
|
prompt: text,
|
||||||
timezone: 'Asia/Hong_Kong'
|
timezone: 'Asia/Hong_Kong'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -848,6 +848,7 @@ export function getMaxModelTokens (model = 'gpt-3.5-turbo') {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUin (e) {
|
export function getUin (e) {
|
||||||
|
if (e?.self_id) return e.self_id
|
||||||
if (e?.bot?.uin) return e.bot.uin
|
if (e?.bot?.uin) return e.bot.uin
|
||||||
if (Array.isArray(Bot.uin)) {
|
if (Array.isArray(Bot.uin)) {
|
||||||
if (Config.trssBotUin && Bot.uin.indexOf(Config.trssBotUin) > -1) { return Config.trssBotUin } else {
|
if (Config.trssBotUin && Bot.uin.indexOf(Config.trssBotUin) > -1) { return Config.trssBotUin } else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue