From 05325a555300ede5dc9c810a09be29111a830076 Mon Sep 17 00:00:00 2001 From: BST_luo <36332288+BSTluo@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:30:26 +0800 Subject: [PATCH 1/3] Delete function/word directory --- function/word/api/Driver/api/index.ts | 181 ---- function/word/api/Driver/index.ts | 285 ------- .../api/Function/Config/regList/iirose.ts | 6 - function/word/api/Function/execute/index.ts | 208 ----- function/word/api/Function/initiative/test.ts | 5 - function/word/api/main.ts | 800 ------------------ function/word/index.ts | 177 ---- function/word/package.json | 71 -- 8 files changed, 1733 deletions(-) delete mode 100644 function/word/api/Driver/api/index.ts delete mode 100644 function/word/api/Driver/index.ts delete mode 100644 function/word/api/Function/Config/regList/iirose.ts delete mode 100644 function/word/api/Function/execute/index.ts delete mode 100644 function/word/api/Function/initiative/test.ts delete mode 100644 function/word/api/main.ts delete mode 100644 function/word/index.ts delete mode 100644 function/word/package.json diff --git a/function/word/api/Driver/api/index.ts b/function/word/api/Driver/api/index.ts deleted file mode 100644 index 3d224e4..0000000 --- a/function/word/api/Driver/api/index.ts +++ /dev/null @@ -1,181 +0,0 @@ -// 导入函数包 -import { funcPack } from '../../Function/execute/index' -// 导入配置包 -import { config } from '../../Function/Config/conventional/index' -// 左边界符号配置 -const leftBoundarySymbol = config.pars.leftBoundarySymbol -// 右边界符号配置 -const rightBoundarySymbol = config.pars.rightBoundarySymbol - -// ----------------------------------------------------------------------------------- -// -// 上方是配置,下方是嵌套解析语句的 -// -// ----------------------------------------------------------------------------------- - -// 判断$后面是否有标识 -const isMark = (input: string[]) => { - const message = input[0] + input[1] - if (Object.keys(funcPack).indexOf(message) > -1) { - return true - } else { - return false - } -} - -// 核心递归解析语句 -const pers2 = (inText: string[]): any => { - const outArr = [] - const T = inText - - while (T.length > 0) { - const a = T.splice(0, 1)[0] - if (a[0] === leftBoundarySymbol && isMark(T)) { - outArr.push(pers2(T)) - } else if (a[0] === rightBoundarySymbol && !isMark(T)) { - return outArr - } else { - outArr.push(a[0]) - } - } - - return outArr -} - -// ----------------------------------------------------------------------------------- -// -// 上方是嵌套解析语句的,下方是输出合理结构的 -// -// ----------------------------------------------------------------------------------- - -// 合并同类项 -const makePar = (data: any[]): any => { - const inArr = data - const outArr = [] - let index = 0 - - while (inArr.length > 0) { - const a = inArr.shift() // 取出传入数组的第一项 - if (Array.isArray(a)) { - outArr.push(makePar(a)) - index = outArr.length - } else if (a === ' ') { - outArr.push(' ') - index = outArr.length - } else { - if (!outArr[index]) { outArr[index] = '' } - outArr[index] = outArr[index] + a - } - } - - return outArr -} - -// 生成最终结果 -const generateResults = (in2: any[]) => { - const inArr = in2 - const Arr = [] - const outArr = [] - - for (let i1 = 0; i1 < inArr.length; i1++) { - if (inArr[i1] === ' ') { Arr.push(i1) } - } - - let index = 0 - outArr[0] = inArr[0] - for (let i2 = 1; i2 < inArr.length; i2++) { - if (Arr.indexOf(i2) > -1) { index++ } - if (inArr[i2] !== ' ') { - if (!outArr[index]) { outArr[index] = [] } - - if (Array.isArray(inArr[i2])) { - outArr[index].push(generateResults(inArr[i2])) - } else { - outArr[index].push(inArr[i2]) - } - } - } - - for (let i3 = 1; i3 < outArr.length; i3++) { - if (outArr[i3].length === 1) { - outArr[i3] = outArr[i3][0] - } - } - - return outArr -} - -// 获取结果 -const getResult = (arrIn: string) => { - const wordOrigin = arrIn.split('') - const Merge = makePar(pers2(wordOrigin)) - - const result = [] - while (Merge.length > 0) { - const intermediateVariable = Merge.shift() - if (Array.isArray(intermediateVariable)) { - result.push(generateResults(intermediateVariable)) - } else { - result.push(intermediateVariable) - } - } - return result -} - -// ----------------------------------------------------------------------------------- -// -// 上方是输出合理结构的,下方是对应到函数包的 -// -// ----------------------------------------------------------------------------------- - -// 解析出数组 -export const interpreter = (inData: string, playData: { [key: string]: string }): any => { - const inArr = getResult(inData) - const outArr = [] - try { - while (inArr.length > 0) { - const a = inArr.shift() - - if (Array.isArray(a)) { - outArr.push(ArrayInterpreter(a, playData)) - } else { - outArr.push(a) - } - } - return outArr - } catch (err: any) { - console.log(err) - return `[Word-Driver] ${err.message}` - } -} - -// 将数组进行递归处理 -const ArrayInterpreter = (needInterpreterArr: any[], playData: { [key: string]: string }) => { - let inArr: any = needInterpreterArr - - for (let i = 0; i < inArr.length; i++) { - if (Array.isArray(inArr[i])) { - inArr[i] = ArrayInterpreter(inArr[i], playData) - } - } - - if (Object.keys(funcPack).indexOf(inArr[0]) > -1) { - if (!funcPack[inArr[0]]) { return } - - let o = funcPack[inArr[0]](inArr, playData) - if (!o) { o = '' } - return o - } else { - inArr = inArr.join('') - } - - return inArr -} - -export const next = () => { - return new Error('[Word-Driver] next') -} - -export const error = (text: string) => { - return new Error(`[Word-Driver] error ${text}`) -} diff --git a/function/word/api/Driver/index.ts b/function/word/api/Driver/index.ts deleted file mode 100644 index 84fc67e..0000000 --- a/function/word/api/Driver/index.ts +++ /dev/null @@ -1,285 +0,0 @@ -import * as fs from 'fs' -import * as path from 'path' -import * as api from '../Tools/index' -import { messageReg } from '../Function/Config/regList/index' -import { interpreter } from './api/index' -import md5 from 'md5' - -/** -* 返回一个文件的json对象 -* @param list 词库文件目录(wordConfig/userData/wordList/recycleBin) -* @param name 词库文件名 -* @return 词库json对象 -*/ -const getjson = (list: string, name: string) => { return api.command.getjson(dir, list, name) } - -/** -* 将词库json对象存储在文件内 -* @param list 词库文件目录 -* @param name 词库文件名 -* @param file 词库json对象 -*/ -// const update = (list: string, name: string, file: object) => { return api.command.update(dir, list, name, file) } - -/** - * 生成随机数 - * @param n 区间a - * @param m 区间b - * @returns 结果 - */ -const random = (n: number, m: number) => { return api.command.random(n, m) } - -// 定义词库缓存变量的类型 -type wordCacheType = { - passive: { [key: string]: string[] } - keys: string[], - wordList: string[], - recycleBinList: string[], - initiative: { [key: string]: string[] } -} - -let wordCache: wordCacheType - -let dir: string - -export default class { - /** - * 配置基础信息 - * @param cache - * @param dataDir - */ - constructor (cache: wordCacheType, dataDir: string) { - wordCache = cache - dir = dataDir - } - - /** - * 开始被动查找问 - * @param q 源问 - * @param playerData 当前玩家数据 - * @returns 结果 - */ - mainStart (q: string, playerData: { [key: string]: any }) { - playerData.data = {} - playerData.data[playerData.mid] = api.command.getjson(dir, 'userData', playerData.mid) - - if (wordCache.passive[q]) { - const value = this.Change(joint(wordCache.passive[q], q), playerData) - - Object.keys(playerData.data).forEach(item => { - api.command.update(dir, 'userData', item, playerData.data[item]) - }) - - return value - } // 无替换的话 - - const arrCache = messageReg() - while (arrCache.item.test(q)) { - for (const a of arrCache.list) { - const reg: RegExp = a[0] - const txt: string = a[1] - const index: string = a[2] - - const cache = q.match(reg) - if (cache) { - q = q.replace(reg, txt) - playerData[index] = q[1] - } - - if (wordCache.passive[q]) { - // wordCache.passive[q]是词库的表接下来要去那些表将他们拼接起来 - const value = this.Change(joint(wordCache.passive[q], q), playerData) - - Object.keys(playerData.data).forEach(item => { - api.command.update(dir, 'userData', item, playerData.data[item]) - }) - - return value - } - } - } - } - - Change (resultArr: { [key: string]: string[] }, playData: { [key: string]: any }) { - // 拷贝原数组 - const inArr = JSON.parse(JSON.stringify(resultArr)) - - // 开始解析,若返回值为[Word-Driver] next则表示随机重新解析 - while (Object.keys(inArr).length > 0) { - const index = random(0, Object.keys(inArr).length - 1) - - const key = Object.keys(inArr)[index]// 选择哪个词库 - const a = inArr[key] - - if (a.length < 0) { break } - - playData.cache = key - - const now = a.splice(random(0, a.length - 1), 1) - const value = this.start(now[0], playData) - - if (/\[Word-Driver\]\s(next|error)/.test(value)) { - return value - } - } - - return '' - } - - /** - * 主动词库解析 - * @param q 主动词库触发词 - * @param playerData 传入数据 - * @returns 结果 - */ - initiativeStart (q: string, playerData: { [key: string]: any }) { - if (!wordCache.initiative[q]) { return } - - playerData.data = {} - playerData.data[playerData.mid] = api.command.getjson(dir, 'userData', playerData.mid) - - // 苏苏的随机数生成姬 - const random = (n: number, m: number) => { return Math.floor(Math.random() * (m - n + 1) + n) } - - const main = wordCache.initiative[q].concat() - - // for (const a of main) { - // outArr.push(this.start(a, playerData)) - // } // 全主动解析 - - while (main.length > 0) { - const messageOrigin = main.splice(random(0, main.length - 1), 1) - - const out = this.start(messageOrigin[0], playerData) - if (out !== '[Word-Driver] next') { - Object.keys(playerData.data).forEach(item => { - api.command.update(dir, 'userData', item, playerData.data[item]) - }) - - return out - } - } - // 解析随机一句 - } - - /** - * 开始解析某回答 - * @param a - * @param playData - * @returns - */ - start (a: string, playData: { [key: string]: any }) { - // 修改消息唯一标识 - playData.messageId = md5(a) - - let out = interpreter(a, playData) - - if (Array.isArray(out)) { out = out.join('') } - - // 完成后从这边应用整个playData.data的数据 - return out - } - - /** - * 查看某个物品的排行榜 - * @param itemName 物品名称 - * @param str { header:输出玩家名的前缀 ,body:输出玩家名的后缀 } - * @returns 排行榜 - */ - itemList (itemName: string, dbName: string, str?: { header: string, body: string }, mk?: boolean) { - const userData = fs.readdirSync(path.join(dir, './word/userData')) - const tempArr:{[key: string]: string[]} = {} - const outArr = mk ? ['# 排行榜', '|序号|ID|数量|', '|:--|:--|:--|'] : ['[词库核心] 物品排行榜:', ''] - let number = 0 - const repository = (getjson('wordList', dbName).cache) ? getjson('wordList', dbName).cache : null - const header = (str) ? str.header : '' - const body = (str) ? str.body : '' - - if (!repository) return - - userData.forEach(value => { - const nameMatch = value ? value.match(/([\s\S]+?)\.json/) : null - const name = nameMatch ? nameMatch[1] : null - if (!name) { return } - - const data = (getjson('userData', name).repository) ? getjson('userData', name).repository : null - if (!data) { return } - - const itemValue = (data[itemName] && typeof data[itemName] === 'number') ? data[itemName] : 0 - - // 基础的获取玩家数据好了,接下来就是写排行榜 - if (!tempArr[itemValue]) { tempArr[itemValue] = [] } - tempArr[itemValue].push(name) - }) - const list = Object.keys(tempArr).sort(func) - - list.forEach(value => { - number++ - if (mk) { outArr.push(`${number} | ${header}${tempArr[value]}${body} | ${value}`) } - if (!mk) { outArr.push(`${number}. ${header}${tempArr[value]}${body} ${value}`) } - }) - - return outArr.join('\n') - } - - /* - readPack(dbName: string) { } // 查看xxx词库背包 - readOtherPack() { } //查看某人xxx词库背包 - */ -} - -/** - * 拼接多个词库的关键词数组 - * @param list 库表 - * @param q 处理后的关键词 - * @returns 结果 - */ -const joint = (list: string[], q: string) => { - const outArr: { [key: string]: string[] } = {} - - for (const a of list) { - const word = getjson('wordList', a) - // outArr = word.main[q].concat(outArr) - - outArr[a] = word.main[q] - } - return outArr -} - -const func = (a: string, b: string) => { - return Number(a) - Number(b) -} -/* - wordCacheObj = { - passive: { 触发词: [所拥有的词库] } - keys : [所有的触发词], - wordList : [所有的库名称], - recycleBinList: [回收站列表], - initiative: { 主动触发词:[所拥有的词库] } - } -*/ - -/* - { - main:{ // 基础存储 }, - author: [ // 编写者 ], - backpack: [ // 标记物品? ], - cache: '存储库名', - initiative: { // 主动词库 }, - function: { // js代码 } - } -*/ - -/* -playData = { - mid: '' - mname: '', - yid: '', - yname: '' -} -*/ -/* -suerData = { - 存储库名:{item: num/arr/string} -} -*/ diff --git a/function/word/api/Function/Config/regList/iirose.ts b/function/word/api/Function/Config/regList/iirose.ts deleted file mode 100644 index dfa9c09..0000000 --- a/function/word/api/Function/Config/regList/iirose.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const regList: [RegExp, string, string][] = [ - [/\s*\[\*([\s\S]+)\*\]\s*/, '(@)', 'yname'], // 对方昵称 - [/\s*\[@([\s\S]+)@\]\s*/, '(id)', 'yid'], // 对方id - [/<([\s\S]+)>/, '<语>', 'text'], - [/\s*(\d+)\s*/, '(数)', 'number'] -] diff --git a/function/word/api/Function/execute/index.ts b/function/word/api/Function/execute/index.ts deleted file mode 100644 index 6a1cb26..0000000 --- a/function/word/api/Function/execute/index.ts +++ /dev/null @@ -1,208 +0,0 @@ -import * as api from '../../Tools/index' -import { config } from '../../Function/Config/conventional' -import * as word from '../../index' -// next() 代表此条词库执行失败,申请换一条 -import { next, error } from '../../Driver/api/index' - -const dir = config.dir - -// 苏苏的随机数生成姬 -const random = (n: number, m: number) => { return Math.floor(Math.random() * (m - n + 1) + n) } - -// 函数包 -export const funcPack:any = { - 测试: (inData: any, playData: any) => { - console.log(inData) - console.log(playData) - // 当发现有测试语句的时候会触发这个 - return inData[1] - }, - 添加: (inData: any, playData: any) => { - const cache = playData.cache - const reg = /([\s\S]+?)~([\s\S]+?)/ - const main = inData[1] - let num = inData[2] - const who = inData[3] ? inData[3] : playData.mid - - // 在缓存的玩家数据如果不存在的话,读取,并初始化它 - /* - { - 存储格名: {} - } - */ - if (!playData.data[who]) { playData.data[who] = api.command.getjson(dir, 'userData', who) } - if (!playData.data[who][cache]) { playData.data[who][cache] = {} } - - const mData = playData.data[who][cache] - if (!mData[main]) { mData[main] = 0 } - - if (num.includes('all')) { num.replace('all', mData[main]) } - - if (reg.test(num)) { - const value = num.match(reg) - num = random(Number(value[1]), Number(value[2])) - } - - mData[main] = mData[main] + Number(num) - - return num - }, - // $减少 物品名称 数量(可以为xx~xx,或者是all) 为谁减少$ - 减少: (inData: any, playData: any) => { - const cache = playData.cache - const reg = /([\s\S]+?)~([\s\S]+?)/ - const main = inData[1] - let num = inData[2] - const who = inData[3] ? inData[3] : playData.mid - - // 在缓存的玩家数据如果不存在的话,读取,并初始化它 - /* - { - 存储格子a: { - 小鱼干: 10, - 大鱼干: 20 - }, - 存储格子b: { - 丹药: 114514 - } - } - */ - if (!playData.data[who]) { playData.data[who] = api.command.getjson(dir, 'userData', who) } - if (!playData.data[who][cache]) { playData.data[who][cache] = {} } - const mData = playData.data[who][cache] - - if (!mData[main]) { mData[main] = 0 } - - if (num.includes('all')) { num.replace('all', mData[main]) } - - if (reg.test(num)) { - const value = num.match(reg) - num = random(Number(value[1]), Number(value[2])) - } - - mData[main] = mData[main] - Number(num) - if (mData[main] > 0) { return num } - return error(`你的物品${main}不足`) - }, - 数值: (inData: any, playData: any) => { - const cache = playData.cache - const itemName = inData[1] - const who = inData[2] ? inData[2] : playData.mid - - if (!playData.data[who]) { playData.data[who] = api.command.getjson(dir, 'userData', who) } - if (!playData.data[who][cache]) { playData.data[who][cache] = {} } - const mData = playData.data[who][cache] - - return mData[itemName] - }, - 概率: (inData: any, playData: any) => { - const value = inData[1] - - if (random(0, 100) <= value) { - return '' - } else { - return next() - } - }, - 延迟: (inData: any, playData: any) => { - const cache = playData.cache - const cdTime = inData[1] - const nowTime = Date.now() - const overTime = nowTime + cdTime - const who = inData[2] ? inData[2] : playData.mid - - // 任务延迟也是分格存储 - const playConfigTemp = api.command.getjson(dir, 'wordConfig', who) - if (!playConfigTemp.time) { playConfigTemp.time = {} } - if (!playConfigTemp.time[cache]) { playConfigTemp.time[cache] = {} } - - // 获取当前问的cd - let timeTemp = playConfigTemp.time[playData.messageId] - - if (!timeTemp) { timeTemp = 0 } - - if (timeTemp <= nowTime) { - // 如果存储的cd比现在的时间低 - // 重启cd,并执行它 - timeTemp = overTime - - return '' - } else { - return next() - } - }, - 鉴权: (inData: any, playData: any) => { - const witchPerssion = inData[1] - const who = inData[2] ? inData[2] : playData.mid - - if (word.permissions.have(witchPerssion, who)) { - return '' - } else { - return next() - } - }, - 随机: (inData: any, playData: any) => { - return random(Number(inData[1]), Number(inData[2])) - }, - 判断: (inData: any, playData: any) => { - const who = inData[4] ? inData[4] : playData.mid - const cache = playData.cache - const itemName = inData[1] - const relationship = inData[2] - const number = inData[3] - - if (!playData.data[who]) { playData.data[who] = api.command.getjson(dir, 'userData', who) } - if (!playData.data[who][cache]) { playData.data[who][cache] = {} } - - const mData = playData.data[who][cache] - if (relationship === '>' && mData[itemName] > Number(number)) { return '' } - if (relationship === '<' && mData[itemName] < Number(number)) { return '' } - if (relationship === '=' && mData[itemName] === Number(number)) { return '' } - if (relationship === '<>' && mData[itemName] !== Number(number)) { return '' } - if (relationship === '==' && mData[itemName] === number) { return '' } - - return next() - }, - 我I: (inData: any, playData: any) => { - return playData.mid - }, - 我N: (inData: any, playData: any) => { - return playData.mname - }, - 你I: (inData: any, playData: any) => { - return playData.yid - }, - 你N: (inData: any, playData: any) => { - return playData.yname - } - - // 音频 - // 视频 - // 禁言 - // 踢人 - // 黑名 - // 切除 - // 创建延迟器 - // 被动 - // 计算 - - // 武器 - // 法器 - // 足具 - // 法防 - // 物防 -} - -/* -playData = { - cache: '存储格子', - mid: '触发者id', - mname: '触发者的昵称', - yid: '语法中的对方id', - yname: '语法中的对方昵称', - messageId: '问句的md5', - data: { - 唯一标识: {玩家信息} - } -} -*/ diff --git a/function/word/api/Function/initiative/test.ts b/function/word/api/Function/initiative/test.ts deleted file mode 100644 index a5718a9..0000000 --- a/function/word/api/Function/initiative/test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { initiative } from '../../index' - -setInterval(() => { - initiative('每隔2秒', {}) -}) diff --git a/function/word/api/main.ts b/function/word/api/main.ts deleted file mode 100644 index b35a045..0000000 --- a/function/word/api/main.ts +++ /dev/null @@ -1,800 +0,0 @@ -import fs from 'fs' -import path from 'path' - -export default class word { - where:any - dir:any - wordData:any - userData:any - nickname:string - - // 苏苏的随机数生成姬 - random = (n: number, m: number): number => { return Math.floor(Math.random() * (m - n + 1) + n) } - - /** - * 返回一个文件的json对象 - * @param list 词库文件目录(wordconfig/userData/wordData) - * @param name 词库文件名 - * @return 词库json对象 - */ - getjson = (list:string, name:string) => { - const wordPath = path.join(this.dir, `./word/${list}/${name}.json`) - if (!fs.existsSync(wordPath)) { - fs.writeFileSync(wordPath, '{}') - } - - return JSON.parse(fs.readFileSync(wordPath).toString()) - } - - /** - * 将词库json对象存储在文件内 - * @param list 词库文件目录 - * @param name 词库文件名 - * @param file 词库json对象 - */ - update = (list:string, name:string, file:any) => { - try { - fs.writeFileSync(path.join(this.dir, `./word/${list}/${name}.json`), JSON.stringify(file, null, 3)) - } catch (error) { - } - } - - /** - * 获取词库json对象 - * @return 词库json对象 - */ - getword = () => { - const fileName = path.join(this.dir, './word/wordData') - const list = fs.readdirSync(fileName) - const data:any = {} - list.forEach(function (item, index) { - const word = JSON.parse(fs.readFileSync(fileName + `/${item}`).toString()) - for (let i = 0; i < Object.keys(word).length; i++) { - if (!data[Object.keys(word)[i]]) { - data[Object.keys(word)[i]] = [] - } - data[Object.keys(word)[i]] = data[Object.keys(word)[i]].concat(word[Object.keys(word)[i]]) - } - }) - return data - } - - /** - * 初始化词库对象 - * @dir 指定词库存储根目录 - * @uid 机器人主人 - * @nick 机器人昵称 - */ - constructor (dir:string, uid:string, nick:string) { - this.dir = dir - try { fs.mkdirSync(path.join(dir, 'word')) } catch (err) { } - try { fs.mkdirSync(path.join(dir, 'word/wordData')) } catch (err) { } - try { fs.mkdirSync(path.join(dir, 'word/userData')) } catch (err) { } - try { fs.mkdirSync(path.join(dir, 'word/wordconfig')) } catch (err) { } - const adminlist = this.getjson('wordconfig', 'adminlist') - if (!adminlist.admin) { // admin高级权限 - adminlist.admin = [uid] - } - this.update('wordconfig', 'adminlist', adminlist) - this.nickname = nick - } - - /** - * 添加词库 - * @param q 指定触发词 - * @param a 指定触发后的回复 - * @param m 指定编辑者数据json:{uid:"id",name:"昵称"} - * @return 返回为字符串,成功/失败 - */ - add (q:string, a:string, m:any) { - // 获取json对象后判断key是否存在,不存在则定义为数组,若存在则为数组添加元素,并存储它 - const uid = m.uid - let listName = '' - const list = this.getjson('wordconfig', 'userlist') - if (Object.prototype.hasOwnProperty.call(list, uid)) { - listName = list[uid] - } else { - listName = '默认' - } - - const word = this.getjson('wordData', listName) - if (word[q] == null) { - word[q] = [] - } - if (word[q][a]) return (` [ 词库核心 ] 该词条已存在于词库【${listName}】,序号为【${word[q].indexOf(a) + 1}】`) - const num = word[q].push(a) - this.update('wordData', listName, word) - return (` [ 词库核心 ] 添加成功,已添加到词库【${listName}】,序号为【${num}】`) - } - - /** - * 删除词库 - * @param q 指定触发词 - * @param num 指定第几条回复(若为'all'则删除整个词条) - * @param m 指定编辑者数据json:{uid:"id",name:"昵称"} - * @return 返回为字符串,成功/失败 - */ - del (q:string, num:string, m:any) { - const id = m.uid - // 获取json对象后,删除其中的一项,若删除后数组为空则删除key,存储数组 - const ku = this.getjson('wordconfig', 'userlist') - let word - let outList = '' - if (ku[id]) { - outList = ku[id] - word = this.getjson('wordData', ku[id]) - } else { - outList = '默认' - word = this.getjson('wordData', '默认') - } - if (!word[q]) { return ' [ 词库核心 ] 并未在当前库中找到相应的关键词' } - if (num === 'all') { - delete word[q] - } else { - word[q].splice(Number(num) - 1, 1) - if (!word[q].length) { - delete word[q] - } - } - - this.update('wordData', outList, word) - return (` [ 词库核心 ] 删除成功,词库【${outList}】,处理成功`) - } - - /** - * 获取触发词的位置 - * @param q 被寻找的触发词 - * @return 返回为搜索结果(字符串) - */ - getas (q:string) { - try { - const fileName = path.join(this.dir, './word/wordData') - const list = fs.readdirSync(fileName) - const qList:any = [] - list.forEach(function (item, index) { - const word = JSON.parse(fs.readFileSync(path.join(fileName + `/${item}`)).toString()) - if (word[q]) { - const name = item.match(/(.*).json/) - if (name) { - qList.push(name[1]) - } - } - }) - return (` [ 词库核心 ] 相关询问存储于【${qList.join(' , ')}】词库中`) - } catch (err) { - return ' [词库核心] 啊哦...好像产生了未知错误....快告诉开发者...!' - } - } - - /** - * 获取回复词的位置 - * @param a 被寻找的回复词 - * @return 返回为搜索结果(字符串) - */ - getqs (a:string) { - try { - const fileName = path.join(this.dir, './word/wordData') - const list = fs.readdirSync(fileName) - const aDataList:any = [] - list.forEach(function (item, index) { - const word = JSON.parse(fs.readFileSync(path.join(fileName + `/${item}`)).toString()) - const name = item.match(/(.*).json/) - if (name) { - for (let i = 0; i < Object.keys(word).length; i++) { - if (word[Object.keys(word)[i]].indexOf(a) >= 0) { - aDataList.push(`词库【${name[1]}】 : 问【${Object.keys(word)[i]}】 序号:【${word[Object.keys(word)[i]].indexOf(a) + 1}】`) - } - } - } - }) - return (` [ 词库核心 ] 相关询问存储于\n ${aDataList.join('\n')}`) - } catch (err) { - return ' [词库核心] 啊哦...好像产生了未知错误....快告诉开发者...!' - } - } - - /** - * 获取问的表 - * @param q 显示的库 - * @param m 查询者数据json:{uid:"id",name:"昵称"} - * @return 返回为搜索结果(字符串) - */ - alist (q:string, m:any) { - const ku = this.getjson('wordconfig', 'userlist') - let word - let outList = '' - if (ku[m.uid]) { - outList = ku[m.uid] - word = this.getjson('wordData', ku[m.uid]) - } else { - outList = '默认' - word = this.getjson('wordData', '默认') - } - - if (word[q]) { - let out = '' - word[q].forEach(function (item:any, index:any) { - out = out + `\n${index + 1}. ` + item - }) - return ` [词库核心] 查询到以下回答:\n\n\n ${out}` - } else { - return ` [ 词库核心 ] 库【 ${outList} 】 无法查询到此回答,请确定该词条存在或进入其他库查询` - } - } - - /** - * 词库解析 - * @param rawq 需要回复的触发词 - * @param m 触发者的数据json:{uid:'id',name:'昵称'} - * @return 返回为回复结果 - */ - start (rawq:string, m:any) { - const uid:string = m.uid - const userName:string = m.username - // 将唯一标识转换为id - let wd = '' - let tid:any - let tname:any - const numdata = [] - let q = rawq - // 将各种情况的唯一标识转换为id - if (q.match(/^\[@(.*?)@\]\s*/)) { - tid = q.match(/^\[@(.*?)@\]\s*/) - } - if (q.match(/\s*\[@(.*?)@\]$/)) { - tid = q.match(/\s*\[@(.*?)@\]$/) - } - if (q.match(/\s*\[@(.*?)@\]\s*/)) { - tid = q.match(/\s*\[@(.*?)@\]\s*/) - } - if (q.match(/^\[@(.*?)@\]$/)) { - tid = q.match(/^\[@(.*?)@\]$/) - } - let tha:any = null - if (tid) { - tha = tid[1] - q = q.replace(tid[0], '(id)') // 我tm终于转换好了 - } - - // 将各种情况的艾特转换为@ - if (q.match(/^\[\*(.*?)\*\]\s*/)) { - tname = q.match(/^\[\*(.*?)\*\]\s*/) - } - if (q.match(/\s*\[\*(.*?)\*\]$/)) { - tname = q.match(/\s\[\*(.*?)\*\]$/) - } - if (q.match(/\s*\[\*(.*?)\*\]\s*/)) { - tname = q.match(/\s*\[\*(.*?)\*\]\s*/) - } - if (q.match(/^\[\*(.*?)\*\]$/)) { - tname = q.match(/^\[\*(.*?)\*\]$/) - } - let name = '' - if (tname) { - name = tname[1] - q = q.replace(tname[0], '(@)') // 我tm终于转换好了 - } - - // 将数字替换为(数) - while (q.match(/(\d+)/)) { - const reg = q.match(/(\d+)/) - if (reg) { - numdata.push(reg[1]) - q = q.replace(reg[0], '(数)') - } - } - - // 获取全部的词库 - if (this.getword()[rawq]) { - const num = this.random(0, this.getword()[rawq].length - 1) - wd = this.getword()[rawq][num] - console.log(` 【 词库核心 】 已触发词库 【${rawq}】 `) - } else if (this.getword()[q]) { - const num = this.random(0, this.getword()[q].length - 1) - wd = this.getword()[q][num] - console.log(` 【 词库核心 】 已触发词库 【${q}】 `) - } else { - return null - } - - try { - // 将$数$替换为数 - while (wd.match(/\$数(.*?)\$/)) { - const reg = wd.match(/\$数(.*?)\$/) - if (reg) { - const index = Number(reg[1]) - 1 - wd = wd.replace(reg[0], String(numdata[index])) - } - } - - // 将$id$变为发送人id - while (wd.match(/\$id\$/)) { - if (wd.match(/\$id\$/)) { - const over = wd.match(/\$id\$/) - if (over) { - wd = wd.replace(over[0], uid) - } - } - } - - // 将$发$变为发送者名字 - while (wd.match(/\$发\$/)) { - if (wd.match(/\$发\$/)) { - const over = wd.match(/\$发\$/) - if (over) { - wd = wd.replace(over[0], userName) - } - } - } - - // 将$@$变为问中的@ - while (wd.match(/\$@\$/)) { - if (wd.match(/\$@\$/)) { - const over = wd.match(/\$@\$/) - try { - if (over) { - wd = wd.replace(over[0], name) - } - } catch (err) { - return ` 【 词库核心 】 [${q}] 无法获取对应数据` - } - } - } - - // 将$称$变为机器人昵称 - while (wd.match(/\$称\$/)) { - if (wd.match(/\$称\$/)) { - const over = wd.match(/\$称\$/) - try { - if (over) { - wd = wd.replace(over[0], this.nickname) - } - } catch (err) { - return ` 【 词库核心 】 [${q}] 无法获取对应数据` - } - } - } - - // 将$xx~xx$替换为随机数 - while (wd.match(/\$(\d+)~(\d+)\$/)) { - const reg = wd.match(/\$(\d+)~(\d+)\$/) - if (reg) { - wd = wd.replace(reg[0], String(this.random(Number(reg[1]), Number(reg[2])))) - } - } - - // 优先获取属性 `物品名 目标` - while (wd.match(/`(.*?)`/)) { - const end = wd.match(/`(.*?)`/) - if (end) { - const endData = end[1].split(' ') - let mubiao = '' - if (endData.length === 2) { - mubiao = (endData[1] === 'that') ? (tha) : (endData[1]) - } else { - mubiao = uid - } - const data = this.getjson('userData', mubiao) - if (endData[0].substring(0, 2) === '武器' || endData[0].substring(0, 2) === '防具') { - if (endData[0].substring(2, 3)) { - if (endData[0].substring(2, 3) === '名') { wd = wd.replace(end[0], data[endData[0].substring(0, 2)].name) } - if (endData[0].substring(2, 3) === '值') { wd = wd.replace(end[0], data[endData[0].substring(0, 2)].value) } - } - } else if (endData[0].substring(0, 3) === 'str') { - const name = endData[0].replace('str', '') - if (!data[name]) { data[name] = [] } - const listData = name.split(':') - if (listData.length === 1) { - wd = wd.replace(end[0], data[name].join(',')) - } else { - const ran = listData[1].split('~') - if (ran.length === 1) { - wd = wd.replace(end[0], data[listData[0]][Number(listData[1]) - 1]) - } else { - wd = (ran[1] !== 'all') ? (wd.replace(end[0], data[listData[0]][this.random(Number(ran[0]), Number(ran[1])) - 1])) : (wd.replace(end[0], data[listData[0]][this.random(Number(ran[0]), data[listData[0]].length) - 1])) - } - } - } else { - const out = Number((data[endData[0]]) ? data[endData[0]] : 0) - wd = wd.replace(end[0], String(out)) - } - } - } - - // 延迟 - while (wd.match(/\^(\d+)\s(.*?)\^/)) { - const load = wd.match(/\^(\d+)\s(.*?)\^/) - if (load) { - const now = Date.parse(new Date().toString()) / 1000 - const nowlist = this.getjson('wordconfig', 'timelist') - if (!nowlist[uid]) { nowlist[uid] = {} } - if (!nowlist[uid][load[2]]) { - nowlist[uid][load[2]] = Number(now + Number(load[1])) - wd = wd.replace(load[0], load[2]) - } else { - if (nowlist[uid][load[2]] > now) { - return ` 【 词库核心: ${userName} 】 ${q} 任务未完成...` - } else { - nowlist[uid][load[2]] = Number(now + Number(load[1])) - wd = wd.replace(load[0], load[2]) - } - } - this.update('wordconfig', 'timelist', nowlist) - } - } - - // 判断管理员命令 - while (wd.match(/{(.*?)}/)) { - if (wd.match(/{(.*?)}/)) { - const over = wd.match(/{(.*?)}/) - try { - if (over) { - const admin = this.getjson('wordconfig', 'adminlist') - if (admin.admin.indexOf(uid) >= 0) { - wd = wd.replace(over[0], over[1]) - } else { - wd = wd.replace(over[0], '') - } - } - } catch (err) { - return ` 【 词库核心 】 [${q}] 无法获取对应数据` - } - } - } - - // 开始解析判断 ?物品名<>=<>数量 语句? - while (wd.match(/\?(.*?)\s(.*?)\s(.*?)\s(.*?)\?/)) { - const first = wd.match(/\?(.*?)\s(.*?)\s(.*?)\s(.*?)\?/) - if (first) { - const mData = this.getjson('userData', uid) - let out = '' - if (first[2] === '<' && mData[first[1]] < Number(first[3])) { out = first[4] } - if (first[2] === '>' && mData[first[1]] > Number(first[3])) { out = first[4] } - if (first[2] === '=' && mData[first[1]] === Number(first[3])) { out = first[4] } - if (first[2] === '<>' && mData[first[1]] !== Number(first[3])) { out = first[4] } - wd = wd.replace(first[0], out) - } - } - - // 开始解析概率 %30 语句% - while (wd.match(/%(.*?)\s(.*?)%/)) { - const next1 = wd.match(/%(.*?)\s(.*?)%/) - if (next1) { - const num = this.random(0, 100) - if (num < Number(next1[1])) { - wd = wd.replace(next1[0], next1[2]) - } else { - wd = wd.replace(next1[0], '什么都木有') - } - } - } - - // 收集本次干了啥,失败则恢复 - const things:any = {} - let thingnum = 0 - // 开始解析减少 -物品名 数量 目标/that- - while (wd.match(/-(.*?)-/)) { - const third = wd.match(/-(.*?)-/) - if (third) { - let outNumber:number - const mData = third[1].split(' ') - let mubiao = '' - if (mData.length >= 3) { // 如果有3个参数 - mubiao = (mData[2] === 'that' && tha) ? (tha) : (mData[2]) - } else { - mubiao = uid - } - const user = this.getjson('userData', mubiao) - if (mData[0].substring(0, 2) === '武器' || mData[0].substring(0, 2) === '防具') { - if (!user[mData[0].substring(0, 2)]) { user[mData[0].substring(0, 2)] = { name: '', value: 0 } } - const name = user[mData[0].substring(0, 2)].name - thingnum++ - things[String(thingnum)] = [mubiao, mData[0].substring(0, 2), user[mData[0].substring(0, 2)], 'other1'] - if (mData[1].search('~') >= 0) { - const num = mData[1].split('~') - outNumber = this.random(Number(num[0]), Number(num[1])) - } else { - outNumber = (mData[1] === 'all') ? (user[mData[0].substring(0, 2)].name) : (Number(mData[1])) - } - user[mData[0].substring(0, 2)].value = user[mData[0].substring(0, 2)].value - outNumber - if (!user[mData[0].substring(0, 2)].value || user[mData[0].substring(0, 2)].value <= 0) { delete user[mData[0].substring(0, 2)] } - this.update('userData', mubiao, user) - if (user[mData[0].substring(0, 2)]) { wd = wd.replace(third[0], String(user[mData[0].substring(0, 2)].value)) } - if (!user[mData[0].substring(0, 2)]) { wd = wd.replace(third[0], name) } - } else if (mData[0].substring(0, 3) === 'str') { - const name = mData[0].replace('str', '') - if (!user[name]) { user[name] = [] } - if (mData[1] === 'all') { - thingnum++ - things[String(thingnum)] = [mubiao, mData[0].substring(0, 2), user[mData[0].substring(0, 2)], 'other1'] - delete user[name] - wd = wd.replace(third[0], '无') - } else if (user[name].indexOf(mData[1]) >= 0) { - thingnum++ - things[String(thingnum)] = [mubiao, mData[0].substring(0, 2), user[mData[0].substring(0, 2)], 'other1'] - user[name].splice(user[name].indexOf(mData[1]), 1) - if (!user[name].length) { delete user[name] } - wd = wd.replace(third[0], mData[1]) - } else { - this.losserr(things) - return ` [ 词库核心 ] 【${userName}】 似乎失败了...唔..好像没有物品【${name}】` - } - this.update('userData', mubiao, user) - } else { - if (!user[mData[0]]) { user[mData[0]] = 0 } - if (mData[1].search('~') >= 0) { - const num = mData[1].split('~') - outNumber = this.random(Number(num[0]), Number(num[1])) - } else { - outNumber = (mData[1] === 'all') ? (user[mData[0]]) : (Number(mData[1])) - } - user[mData[0]] = (user[mData[0]] * 1000 - outNumber * 1000) / 1000 - if (user[mData[0]] < 0) { - this.losserr(things) - return ` [ 词库核心 ] 【${userName}】 似乎失败了...唔..好像物品【${mData[0]}】不够` - } - thingnum++ - things[String(thingnum)] = [mubiao, mData[0], outNumber, '-'] - this.update('userData', mubiao, user) - wd = wd.replace(third[0], String(outNumber)) - } - } - } - - // 开始解析添加 +物品名 数量 目标/that+ - while (wd.match(/\+(.*?)\+/)) { - const second = wd.match(/\+(.*?)\+/) - if (second) { - const mData = second[1].split(' ') - let mubiao = '' - if (mData.length >= 3) { - mubiao = (mData[2] === 'that' && tha) ? (tha) : (mData[2]) - } else { - mubiao = uid - } - const user = this.getjson('userData', mubiao) - if (mData[0].substring(0, 2) === '武器' || mData[0].substring(0, 2) === '防具') { - if (!user[mData[0].substring(0, 2)]) { user[mData[0].substring(0, 2)] = { name: '', value: 0 } } - const name = mData[0].replace(mData[0].substring(0, 2), '') - thingnum++ - things[String(thingnum)] = [mubiao, [mData[0].substring(0, 2), name], user[mData[0].substring(0, 2)], 'other1'] - const outnum = Number((mData[1].search('~') >= 0) ? (this.random(Number(mData[1].split('~')[0]), Number(mData[1].split('~')[1]))) : Number(mData[1])) - if (outnum > user[mData[0].substring(0, 2)].value) { - user[mData[0].substring(0, 2)] = { - name: name, - value: outnum - } - this.update('userData', mubiao, user) - wd = wd.replace(second[0], `${name},强度${outnum}`) - } else { - return ' [词库核心] 当前背包内的武器可能更好哦~新装备已被丢弃' - } - } else if (mData[0].substring(0, 3) === 'str') { - const name = mData[0].replace('str', '') - if (!user[name]) { user[name] = [] } - thingnum++ - things[String(thingnum)] = [mubiao, name, user[name], 'other2'] - if (user[name].indexOf(mData[1]) === -1) { - user[name].push(String(mData[1])) - } - this.update('userData', mubiao, user) - wd = wd.replace(second[0], String(mData[1])) - } else { - if (!user[mData[0]]) { user[mData[0]] = 0 } - let outNumber = 0 - if (mData[1] === 'all') { - outNumber = user[mData[0]] - } else { - outNumber = (mData[1].search('~') >= 0) ? (this.random(Number(mData[1].split('~')[0]), Number(mData[1].split('~')[1]))) : Number(mData[1]) - } - user[mData[0]] = (outNumber * 1000 + user[mData[0]] * 1000) / 1000 - this.update('userData', mubiao, user) - thingnum++ - things[String(thingnum)] = [mubiao, mData[0], outNumber, '+'] - wd = wd.replace(second[0], String(outNumber)) - } - } - } - - // 获取属性 #物品名 目标# - while (wd.match(/#(.*?)#/)) { - const end = wd.match(/#(.*?)#/) - if (end) { - const endData = end[1].split(' ') - let mubiao = '' - if (endData.length === 2) { - mubiao = (endData[1] === 'that') ? (tha) : (endData[1]) - } else { - mubiao = uid - } - const data = this.getjson('userData', mubiao) - if (endData[0].substring(0, 2) === '武器' || endData[0].substring(0, 2) === '防具') { - if (endData[0].substring(2, 3)) { - if (endData[0].substring(2, 3) === '名') { wd = wd.replace(end[0], data[endData[0].substring(0, 2)].name) } - if (endData[0].substring(2, 3) === '值') { wd = wd.replace(end[0], data[endData[0].substring(0, 2)].value) } - } - } else if (endData[0].substring(0, 3) === 'str') { - const name = endData[0].replace('str', '') - if (!data[name]) { data[name] = [] } - const listData = name.split(':') - if (listData.length === 1) { - wd = wd.replace(end[0], data[name].join(',')) - } else { - const ran = listData[1].split('~') - if (ran.length === 1) { - wd = wd.replace(end[0], data[listData[0]][Number(listData[1]) - 1]) - } else { - wd = (ran[1] !== 'all') ? (wd.replace(end[0], data[listData[0]][this.random(Number(ran[0]), Number(ran[1])) - 1])) : (wd.replace(end[0], data[listData[0]][this.random(Number(ran[0]), data[listData[0]].length) - 1])) - } - } - } else { - const out = Number((data[endData[0]]) ? data[endData[0]] : 0) - wd = wd.replace(end[0], String(out)) - } - } - } - - // 将$换$变为 - while (wd.match(/\$换\$/)) { - if (wd.match(/\$换\$/)) { - const over = wd.match(/\$换\$/) - if (over) { - wd = wd.replace(over[0], '\n') - } - } - } - } catch (err) { - return ` [词库核心] 问:【${q}】词条【${wd}】 \n\n发生致命解析错误,请查看当前解析词条中符号是否为英文,若无法解决请联系开发者` - } - if (wd) { - return wd - } - } - - /** - * 选择编辑词库 - * @param db 设置被编辑词库 - * @param m 设置人数据json:{uid:"id",name:"昵称"} - * @return 返回为回复结果(成功/失败) - */ - in (db:string, m:any) { - const uid = m.uid - const list = this.getjson('wordconfig', 'userlist') - list[uid] = db - this.update('wordconfig', 'userlist', list) - return ` [词库核心] 设置成功,接下来您添加的词库将添加至【${db}】词库` - } - - /** - * 恢复编辑默认词库 - * @param m 设置人数据json:{uid:"id",name:"昵称"} - * @return 返回为回复结果(成功/失败) - */ - out (m:any) { - const uid = m.uid - const list = this.getjson('wordconfig', 'userlist') - try { - delete list[uid] - this.update('wordconfig', 'userlist', list) - return ' [词库核心] 设置成功,将添加至【默认】词库' - } catch (err) { return ' [词库核心] 设置失败' } - } - - /** - * 获取库的表 - * @return 返回为搜索结果(字符串) - */ - list () { - const fileName = path.join(this.dir, './word/wordData') - const list = fs.readdirSync(fileName) - const kulist:any = [] - list.forEach(function (item, index) { - const name = item.match(/(.*).json/) - if (name) { - kulist.push(name[1]) - } - } - ) - return ` [词库核心] 当前拥有这些库:【${kulist.join(' , ')}】` - } - - /** - * 获取库内的问表 - * @name 库名(字符串) - * @return 返回为搜索结果(字符串) - */ - qlist (name:string) { - const word = this.getjson('wordData', name) - const outlist = [] - for (let i = 0; i < Object.keys(word).length; i++) { - outlist.push(`${i + 1}. ${Object.keys(word)[i]}`) - } - return ` [词库核心] 搜索到的库内含有以下的触发词 : \n\n ${outlist.join('\n')}` - } - - // 反馈减少的错误 - losserr = (things:any) => { - for (let n = Object.keys(things).length; n > 0; n--) { - const json = things[n] - const data = this.getjson('userData', json[0]) - if (json[3] === '-') { data[json[1]] = data[json[1]] + json[2] } - if (json[3] === '+') { data[json[1]] = data[json[1]] - json[2] } - if (json[3] === 'other1') { data[json[1]] = json[2] } - if (json[3] === 'other2') { data[json[1]] = json[2] } - this.update('userData', json[0], data) - } - } - - /** - * 增加词库管理员 - * @name 唯一标识(字符串) - * @return 返回为结果(字符串) - */ - op (name:string) { - let id = '' - const a = name.match(/\s*\[@(.*?)@\]\s*/) - if (a) { - id = a[1] - } - const adminlist = this.getjson('wordconfig', 'adminlist') - if (adminlist.admin.indexOf(id) < 0) { - adminlist.admin.push(id) - } - this.update('wordconfig', 'adminlist', adminlist) - return ' [词库核心] 词库管理员设置成功...!' - } - - /** - * 去除词库管理员 - * @name 唯一标识(字符串) - * @return 返回为结果(字符串) - */ - deop (name:string) { - let id = '' - const a = name.match(/\s*\[@(.*?)@\]\s*/) - if (a) { - id = a[1] - } - const adminlist = this.getjson('wordconfig', 'adminlist') - if (adminlist.admin.indexOf(id) >= 0) { - adminlist.admin.splice(adminlist.admin.indexOf(id), 1) - } - this.update('wordconfig', 'adminlist', adminlist) - return ' [词库核心] 词库管理员取消成功...!' - } - - /** - * 查询排行榜 - * @itemName 查询的物品(字符串),切记只能查询物品,不能查询文字 - * @return 返回为结果(字符串) - */ - leaderboard (itemName:string) { - try { - const pathName = path.join(this.dir, './word/userData') - const list = fs.readdirSync(pathName) - const dataList:any = {} - list.forEach(function (item, index) { - const word = JSON.parse(fs.readFileSync(path.join(pathName + `/${item}`)).toString()) - const str = item.match(/(.*).json/) - if (str) { - if (word[itemName]) { - dataList[`${word[itemName]}`] = str[1] - } - } - }) - const test = Object.keys(dataList).map(function (item:any) { - return Number(item) - }) - test.sort(function (a:number, b:number) { return b - a }) - let out = '' - let num = 0 - test.forEach(function (item, index) { - num++ - out = out + `\n${num} : 【${dataList[test[num - 1]]}】 - ${test[num - 1]}` - }) - return (` [ 词库核心 ] 相关询问存储于\n ${out}`) - } catch (err) { - return ' [词库核心] 啊哦...好像产生了未知错误....快告诉开发者...!' - } - } -} diff --git a/function/word/index.ts b/function/word/index.ts deleted file mode 100644 index 577560a..0000000 --- a/function/word/index.ts +++ /dev/null @@ -1,177 +0,0 @@ -<<<<<<< HEAD -import * as word from './api/index' -import config from '../../config' -======= -import Word from './api/main' ->>>>>>> parent of 4743efd ( deleted: function/JustForFun/index.ts) -import * as api from '../../lib/api' -import config from '../../config' -import per from '../permission/permission' -import fs from 'fs' -import path from 'path' -import axios from 'axios' - -try { - fs.mkdirSync(path.join(api.Data, 'word/wordData')) -} catch (err) {} - -try { - fs.mkdirSync(path.join(api.Data, 'word/userData')) -} catch (err) {} - -try { - fs.mkdirSync(path.join(api.Data, 'word/wordconfig')) -} catch (err) {} - -// 指定词库数据库根目录 -const word = new Word(api.Data, config.app.master_uid, config.app.nickname) - -// 主词库(公屏触发) -api.Event.on('PrivateMessage', msg => { - if (per.users.hasPermission(msg.uid, 'word.kick')) return // 不响应已经被踢出的人 - if (msg.username === config.account.username) return // 不响应自己发送的消息 - const wd: string = msg.message.trim() - const reply = api.method.sendPrivateMessage // 定义发送文本的函数 - const out = word.start(wd, msg) - if (out) { - reply(msg.uid, out) - } -} -) - -// 主词库(公屏触发) -api.Event.on('PublicMessage', msg => { - if (per.users.hasPermission(msg.uid, 'word.kick')) return // 不响应已经被踢出的人 - if (msg.username === config.account.username) return // 不响应自己发送的消息 - const wd: string = msg.message.trim() - const reply = api.method.sendPublicMessage // 定义发送文本的函数 - const out = word.start(wd, msg) - if (out) { - reply(out) - } -} -) - -// 添加问答√ -api.command(/^\.问(.*?)答(.*)$/, 'word.add', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.add') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.add(m[1], m[2], e)) -} -) - -// 删除问答√ -api.command(/^\.删(.*?)序号(.*)$/, 'word.del', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.del') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.del(m[1], m[2], e)) -} -) - -// 查看问(包含指定文字的问,需要显示是哪个库的√ -api.command(/^\.问表(.*?)$/, 'word.qwhere', async (m, e, reply) => { - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - api.method.sendPrivateMessage(e.uid, word.getas(m[1])) -} -) - -// 查看答 (包含指定文字的答,需要显示是哪个库的√ -api.command(/^\.答表(.*?)$/, 'word.awhere', async (m, e, reply) => { - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - api.method.sendPrivateMessage(e.uid, word.getqs(m[1])) -} -) - -// 设置为第几个词库 -api.command(/^\.入库(.*?)$/, 'word.in', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.in') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - - reply(word.in(m[1], e)) -} -) - -api.command(/^\.出库$/, 'word.out', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.out') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.out(e)) -} -) - -api.command(/^\.表(.*)$/, 'word.list.a', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.find') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - api.method.sendPrivateMessage(e.uid, word.alist(m[1], e)) -} -) - -api.command(/^\.库表$/, 'word.list', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.find') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - api.method.sendPrivateMessage(e.uid, word.list()) -} -) - -api.command(/^\.栈(.*)$/, 'word.list.q', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.find') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - api.method.sendPrivateMessage(e.uid, word.qlist(m[1])) -} -) - -api.command(/^\.wop(.*)$/, 'word.admin.add', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.admin.add') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.op(m[1])) -} -) - -api.command(/^\.wdeop(.*)$/, 'word.admin.del', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.admin.del') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.deop(m[1])) -} -) - -api.command(/^\.(.*)天梯$/, 'word.list.data', async (m, e, reply) => { - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - reply(word.leaderboard(m[1])) -} -) - -api.command(/^.上传(.*)$/, 'word.upload', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.upload') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - const up = word.getjson('wordData', m[1]) - if (JSON.stringify(up) !== '{}') { - try { - const response = await axios.post('https://word.bstluo.top/new.php', up) - reply(` [词库核心] ${response.data}`) - } catch (error) { - reply('投稿失败,请联系管理员手动进行投稿') - } - } -}) - -api.command(/^.下载(.*):(.*)$/, 'word.download', async (m, e, reply) => { - if (!per.users.hasPermission(e.uid, 'word.edit.download') && !per.users.hasPermission(e.uid, 'permission.word')) return // 不响应没有权限的人,@后期改为能设置config文件内决定是否开启这一条 - if (per.users.hasPermission(e.uid, 'word.kick')) return // 不响应已经被踢出的人 - try { - const response = await axios.post('https://word.bstluo.top/read.php', { - id: m[1] - }) - word.update('wordData', m[2], response.data) - reply(' [词库核心] 下载成功') - } catch (error) { - console.log(error) - reply('下载失败,请联系管理员手动进行投稿') - } -}) -/** - * 导出,导入词库功能 - * 以node POST给服务器然后导出为直链 - * 导入为下载直链 - * 每隔一天清空一次缓存 - * - * 删除一句、全部删除 -*/ diff --git a/function/word/package.json b/function/word/package.json deleted file mode 100644 index 7c3077e..0000000 --- a/function/word/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "word", - "id": "word", - "main": "index", - "author": { - "name": "春风萧落", - "github": "BSTluo", - "iirose": "春风萧落" - }, - "intro": [ - "【词库2.0】", - "本次更新优化了写法,修改了一些无用的功能,可以在私聊触发词库", - "使用文档:https://docs.bstluo.top/#/词库使用", - "开发词库文档:https://docs.bstluo.top/#/词库开发", - "", - "权限节点:", - "word.edit.add 添加词库的权限", - "word.edit.del 删除词库的权限", - "word.kick 禁止使用词库的权限", - "word.edit.in 编辑选中库的权限", - "word.edit.out 编辑默认库的权限", - "word.edit.find 查看词库内容的权限", - "word.admin.del 删除词库管理员权限", - "word.admin.add 添加词库管理员权限", - "word.edit.upload 上传词库的权限", - "word.edit.download 下载内容的权限" - ], - "commands": [{ - "cmd": ".问<触发词>答<回答>", - "helper": "当机器人检测到信息<触发词>的时候发送<回答>" - },{ - "cmd": ".删<触发词>序号<第几个问>", - "helper": "删除某一个序号的答,序号为all的时候删除该问" - },{ - "cmd": ".问表<触发词>", - "helper": "查询某个问题处于哪个库,结果发送至私聊" - },{ - "cmd": ".答表<触发词>", - "helper": "查询某个答处于哪个库以及哪个触发词下,结果发送至私聊" - },{ - "cmd": ".入库<库名>", - "helper": "设定接下来添加的词放入指定库" - },{ - "cmd": ".出库", - "helper": "设定接下来添加的词放入默认库" - },{ - "cmd": ".表<触发词>", - "helper": "查看此触发词在当前库内的回答表" - },{ - "cmd": ".库表", - "helper": "查看词库内存储着哪些库" - },{ - "cmd": ".栈<触发词>", - "helper": "查看某个库的所有触发词" - },{ - "cmd": ".wop<唯一标识>", - "helper": "将某人设定为op" - },{ - "cmd": ".wdeop<唯一标识>", - "helper": "取消某人的op" - },{ - "cmd": ".<物品名称>天梯", - "helper": "查看某个物品的排行榜" - },{ - "cmd": ".上传<库名>", - "helper": "上传库到服务器(会不定期清理)" - },{ - "cmd": ".下载<词库码>:<保存为的库名>", - "helper": "从服务器下载库,切记,它会覆盖本地的库" - }] -} \ No newline at end of file From a8c4a79f7a5252bc31f4d199abbd99305dcf77fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=97=B4=E8=8B=8F=E8=8B=8F?= Date: Fri, 9 Feb 2024 13:35:27 +0000 Subject: [PATCH 2/3] fix: remove merge conflict marker --- index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.ts b/index.ts index ded3c33..35eaab2 100644 --- a/index.ts +++ b/index.ts @@ -29,8 +29,4 @@ process.on('uncaughtException', (err: any, origin: any) => { process.exit(127) }) -<<<<<<< HEAD -init() -======= -init() ->>>>>>> parent of 4743efd ( deleted: function/JustForFun/index.ts) +init() \ No newline at end of file From e8c40fd497ad6a69180a7cafb6e8d7f0549c9f97 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Fri, 9 Feb 2024 13:35:40 +0000 Subject: [PATCH 3/3] [CodeFactor] Apply fixes to commit a8c4a79 [ci skip] [skip ci] --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 35eaab2..ee433ea 100644 --- a/index.ts +++ b/index.ts @@ -29,4 +29,4 @@ process.on('uncaughtException', (err: any, origin: any) => { process.exit(127) }) -init() \ No newline at end of file +init()