mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +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 { generateHello } from '../utils/randomMessage.js'
|
||||||
import { segment } from 'oicq'
|
import { segment } from 'oicq'
|
||||||
import { generateAudio } from '../utils/tts.js'
|
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 {
|
export class Entertainment extends plugin {
|
||||||
constructor (e) {
|
constructor (e) {
|
||||||
super({
|
super({
|
||||||
|
|
@ -16,6 +19,10 @@ export class Entertainment extends plugin {
|
||||||
reg: '^#(chatgpt|ChatGPT)打招呼',
|
reg: '^#(chatgpt|ChatGPT)打招呼',
|
||||||
fnc: 'sendMessage',
|
fnc: 'sendMessage',
|
||||||
permission: 'master'
|
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) {
|
async sendMessage (e) {
|
||||||
let groupId = e.msg.replace(/^#(chatgpt|ChatGPT)打招呼/, '')
|
let groupId = e.msg.replace(/^#(chatgpt|ChatGPT)打招呼/, '')
|
||||||
groupId = parseInt(groupId)
|
groupId = parseInt(groupId)
|
||||||
|
|
|
||||||
69304
resources/emojiData.json
Normal file
69304
resources/emojiData.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -69,7 +69,8 @@ const defaultConfig = {
|
||||||
chatglmBaseUrl: 'http://localhost:8080',
|
chatglmBaseUrl: 'http://localhost:8080',
|
||||||
allowOtherMode: true,
|
allowOtherMode: true,
|
||||||
sydneyContext: '',
|
sydneyContext: '',
|
||||||
version: 'v2.3.3'
|
emojiBaseURL: 'https://www.gstatic.com/android/keyboard/emojikitchen',
|
||||||
|
version: 'v2.3.4'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
let config = {}
|
let config = {}
|
||||||
|
|
|
||||||
20
utils/emoj/index.js
Normal file
20
utils/emoj/index.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Config } from '../config.js'
|
||||||
|
|
||||||
|
function googleRequestUrlEmojiFilename (combo) {
|
||||||
|
return `${googleRequestUrlEmojiPart(
|
||||||
|
combo.leftEmoji
|
||||||
|
)}_${googleRequestUrlEmojiPart(combo.rightEmoji)}.png`
|
||||||
|
}
|
||||||
|
|
||||||
|
function googleRequestUrlEmojiPart (emoji) {
|
||||||
|
return emoji
|
||||||
|
.split('-')
|
||||||
|
.map((part) => `u${part.toLowerCase()}`)
|
||||||
|
.join('-')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function googleRequestUrl (combo) {
|
||||||
|
return `${Config.emojiBaseURL}/${combo.date}/${googleRequestUrlEmojiPart(
|
||||||
|
combo.leftEmoji
|
||||||
|
)}/${googleRequestUrlEmojiFilename(combo)}`
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue