mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
feat: emoji合成
This commit is contained in:
parent
1432723de5
commit
f4a740a6a8
4 changed files with 69372 additions and 2 deletions
|
|
@ -3,7 +3,10 @@ import { Config } from '../utils/config.js'
|
|||
import { generateHello } from '../utils/randomMessage.js'
|
||||
import { segment } from 'oicq'
|
||||
import { generateAudio } from '../utils/tts.js'
|
||||
|
||||
import fs from 'fs'
|
||||
import { googleRequestUrl } from '../utils/emoj/index.js'
|
||||
import fetch from 'node-fetch'
|
||||
import { mkdirs } from '../utils/common.js'
|
||||
export class Entertainment extends plugin {
|
||||
constructor (e) {
|
||||
super({
|
||||
|
|
@ -16,6 +19,10 @@ export class Entertainment extends plugin {
|
|||
reg: '^#(chatgpt|ChatGPT)打招呼',
|
||||
fnc: 'sendMessage',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]){2}',
|
||||
fnc: 'combineEmoj'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -29,6 +36,44 @@ export class Entertainment extends plugin {
|
|||
]
|
||||
}
|
||||
|
||||
async combineEmoj (e) {
|
||||
console.log(e.msg)
|
||||
logger.info('combine')
|
||||
const _path = process.cwd()
|
||||
const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/resources/emojiData.json`)
|
||||
const data = fs.readFileSync(fullPath)
|
||||
let emojDataJson = JSON.parse(data)
|
||||
let left = e.msg.codePointAt(0).toString(16).toLowerCase()
|
||||
let right = e.msg.codePointAt(2).toString(16).toLowerCase()
|
||||
logger.mark(`合成emoji:${left} ${right}`)
|
||||
let url
|
||||
if (emojDataJson[right]) {
|
||||
let find = emojDataJson[right].find(item => item.leftEmoji === left)
|
||||
if (find) {
|
||||
url = googleRequestUrl(find)
|
||||
}
|
||||
}
|
||||
if (!url && emojDataJson[left]) {
|
||||
let find = emojDataJson[left].find(item => item.leftEmoji === right)
|
||||
if (find) {
|
||||
url = googleRequestUrl(find)
|
||||
}
|
||||
}
|
||||
if (!url) {
|
||||
await e.reply('不支持合成', true)
|
||||
return true
|
||||
}
|
||||
let response = await fetch(url)
|
||||
mkdirs('data/chatgpt/emoji')
|
||||
let resultFileLoc = `data/chatgpt/emoji/${left}_${right}.jpg`
|
||||
const resultBlob = await response.blob()
|
||||
const resultArrayBuffer = await resultBlob.arrayBuffer()
|
||||
const resultBuffer = Buffer.from(resultArrayBuffer)
|
||||
await fs.writeFileSync(resultFileLoc, resultBuffer)
|
||||
await e.reply(segment.image(fs.createReadStream(resultFileLoc)), true)
|
||||
return true
|
||||
}
|
||||
|
||||
async sendMessage (e) {
|
||||
let groupId = e.msg.replace(/^#(chatgpt|ChatGPT)打招呼/, '')
|
||||
groupId = parseInt(groupId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue