From e05ff3dbef27691838eea2a490e6b8243e4a515f Mon Sep 17 00:00:00 2001 From: Virginia Senioria <91khr@users.noreply.github.com> Date: Wed, 6 Sep 2023 10:45:22 +0800 Subject: [PATCH] chore prettier: prettier the world with new config --- src/index.ts | 2 +- src/init.ts | 2 +- src/lib/app.ts | 37 ++++++------------- src/lib/command.ts | 23 +++--------- src/lib/db.js | 5 +-- src/lib/file_lock.ts | 2 +- src/plugins/bot_on_off/index.ts | 2 +- src/plugins/chengyu/index.ts | 50 ++++++++++---------------- src/plugins/feed/index.ts | 63 ++++++--------------------------- src/plugins/help/index.ts | 6 +--- src/plugins/hitokoto/index.ts | 10 ++---- src/plugins/rand/index.js | 14 ++------ src/plugins/set_title/index.ts | 16 +++------ src/plugins/slashbot/index.ts | 2 +- src/plugins/tarot/index.ts | 10 ++---- src/plugins/todo/index.ts | 18 ++++------ src/plugins/waife/index.ts | 49 +++++++++---------------- src/types/app.ts | 6 +--- src/util/fatal_error.ts | 5 +-- tsconfig.json | 42 ++++++++++------------ typedoc.json | 8 +---- 21 files changed, 109 insertions(+), 263 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9b57491..951c7eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,4 +22,4 @@ function reload() { }); } -reload(); \ No newline at end of file +reload(); diff --git a/src/init.ts b/src/init.ts index da00873..ea8a896 100644 --- a/src/init.ts +++ b/src/init.ts @@ -81,4 +81,4 @@ function setBotCommand() { app.bot!.setMyCommands(botCommands); } -setBotCommand(); \ No newline at end of file +setBotCommand(); diff --git a/src/lib/app.ts b/src/lib/app.ts index 5016c93..d2bc59b 100644 --- a/src/lib/app.ts +++ b/src/lib/app.ts @@ -5,11 +5,7 @@ import yaml from 'js-yaml'; import std from '@/util/std.js'; import fatalError from '@/util/fatal_error.js'; import db from '@/lib/db.js'; -import { - registCommand, - registGlobalMessageHandle, - registReplyHandle, -} from '@/lib/command.js'; +import { registCommand, registGlobalMessageHandle, registReplyHandle } from '@/lib/command.js'; import { App } from '@/types/app.js'; import { YamlConfig } from '@/types/config.js'; import process from '@/lib/process.js'; @@ -44,8 +40,8 @@ export class Application implements App { this._configExample = ''; console.warn( chalk.yellow( - 'No config.example.yml found. This program will not be able to provide a config example.', - ), + 'No config.example.yml found. This program will not be able to provide a config example.' + ) ); } } @@ -56,34 +52,23 @@ export class Application implements App { console.log(this.config); console.log('---------------'); console.log('Initializing bot ...'); - if ( - this.config.platform.settings[this.config.platform.enabled] === undefined - ) { - console.log( - `未找到平台${this.config.platform.enabled}的配置,请检查config.yml`, - ); + if (this.config.platform.settings[this.config.platform.enabled] === undefined) { + console.log(`未找到平台${this.config.platform.enabled}的配置,请检查config.yml`); process.exit(-1); } - console.log( - `Launching bot at Platform[${this.config.platform.enabled}]...`, - ); + console.log(`Launching bot at Platform[${this.config.platform.enabled}]...`); - const createBot = ( - await import(`../bridges/${this.config.platform.enabled}/index.js`) - ).createBot as CreateBot; + const createBot = (await import(`../bridges/${this.config.platform.enabled}/index.js`)) + .createBot as CreateBot; try { - this._bot = createBot( - this.config.platform.settings[this.config.platform.enabled], - ); + this._bot = createBot(this.config.platform.settings[this.config.platform.enabled]); if (!this._bot) { throw 'bot is undefined'; } } catch (err) { console.log(`-------${chalk.red('[ERROR]')}--------`); - console.log( - 'Launching bot failed. Please check the error information below:', - ); + console.log('Launching bot failed. Please check the error information below:'); console.error(err); process.exit(-1); } @@ -140,7 +125,7 @@ export class Application implements App { console.log('请正确配置config.yml. 本程序将自动退出.'); } process.exit(0); - }, + } ); return; } diff --git a/src/lib/command.ts b/src/lib/command.ts index 10233e8..cb1bf82 100644 --- a/src/lib/command.ts +++ b/src/lib/command.ts @@ -15,11 +15,7 @@ const replyHandles: ReplyHandleConfig[] = []; */ let on_off_mode: (app: App, msg: Message) => boolean = () => true; -export type commandHandleFunction = ( - app: App, - message: Message, - message_text?: string, -) => void; +export type commandHandleFunction = (app: App, message: Message, message_text?: string) => void; export type handleFunction = (app: App, message: Message) => void; export interface _HandleConfigBase_ { @@ -41,7 +37,6 @@ export interface _HandleConfigBase_ { description?: BotCommand['description']; } - export interface CommandHandleConfig extends _HandleConfigBase_ { handle: commandHandleFunction; /** @@ -126,11 +121,7 @@ export interface canUseCommandResult { * @param cmd 命令名(string) * @returns 是否允许运行 */ -export function canUseCommand( - app: App, - message: Message, - cmd: string, -): canUseCommandResult { +export function canUseCommand(app: App, message: Message, cmd: string): canUseCommandResult { if ( commands[cmd].premission === 'sysAdmin' && !(message.from?.id && app.config.bot_sysadmin_id.includes(message.from?.id)) @@ -161,9 +152,7 @@ export function canUseCommand( */ export function commandParser(app: App, message: Message) { if (message.text?.startsWith(app.config.command_style)) { - const matched = message.text - .substring(app.config.command_style.length) - .match(/[^\s@]+/); + const matched = message.text.substring(app.config.command_style.length).match(/[^\s@]+/); if (!matched) { return; } @@ -194,7 +183,7 @@ export function commandParser(app: App, message: Message) { */ export function getCommands(): { [key: string]: CommandHandleConfig; - } { +} { return commands; } @@ -218,9 +207,7 @@ export function getReplyHandles(): ReplyHandleConfig[] { * 注册bot on off mode管理器 * @param func 一个函数,调用后返回当前bot处于打开还是关闭状态 */ -export function botOnOffRegister( - func: (app: App, message: Message) => boolean, -) { +export function botOnOffRegister(func: (app: App, message: Message) => boolean) { on_off_mode = func; } diff --git a/src/lib/db.js b/src/lib/db.js index bc0d167..0410c0c 100644 --- a/src/lib/db.js +++ b/src/lib/db.js @@ -155,10 +155,7 @@ class ChatDB extends DB { */ user(uid) { if (!this._user_caches[uid]) { - this._user_caches[uid] = new Proxy( - new GroupUserDB(this._chatId, uid), - GroupUserDB.handler, - ); + this._user_caches[uid] = new Proxy(new GroupUserDB(this._chatId, uid), GroupUserDB.handler); } return this._user_caches[uid]; } diff --git a/src/lib/file_lock.ts b/src/lib/file_lock.ts index c2a6a83..51fabd0 100644 --- a/src/lib/file_lock.ts +++ b/src/lib/file_lock.ts @@ -91,7 +91,7 @@ class functionQueue { export async function writeFileSafe( file: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, - options?: fs.WriteFileOptions, + options?: fs.WriteFileOptions ) { fileLocks.find(String(file)).push(() => { fs.writeFileSync(file, data, options); diff --git a/src/plugins/bot_on_off/index.ts b/src/plugins/bot_on_off/index.ts index 5cd4514..2e808f9 100644 --- a/src/plugins/bot_on_off/index.ts +++ b/src/plugins/bot_on_off/index.ts @@ -15,7 +15,7 @@ const bot_status: commandHandleFunction = (app, msg) => { msg.chat.id, db.chat(msg.chat.id).turned_off ? `${app.config?.bot_name}关机中` - : `${app.config?.bot_name}开机中`, + : `${app.config?.bot_name}开机中` ); }; diff --git a/src/plugins/chengyu/index.ts b/src/plugins/chengyu/index.ts index aa92dab..adf45e0 100644 --- a/src/plugins/chengyu/index.ts +++ b/src/plugins/chengyu/index.ts @@ -69,15 +69,10 @@ function gameEnded(msg: Message): boolean { // 从starter获取随机成语开局 function setRandomChenyu(msg: Message, starter?: string): string { console.log(starter); - if ( - starter === '' || - starter === undefined || - cylist[starter] === undefined - ) { + if (starter === '' || starter === undefined || cylist[starter] === undefined) { return setRandomChenyu(msg, py[Math.floor(Math.random() * py.length)]); } else { - const find: string = - cylist[starter][Math.floor(Math.random() * cylist[starter].length)]; + const find: string = cylist[starter][Math.floor(Math.random() * cylist[starter].length)]; if (!getJielongStatus(msg)) { clearJielongStatus(msg); } @@ -120,9 +115,9 @@ function getJielongInfo(msg: Message): string { } uList.sort((a, b) => Number(b.score) - Number(a.score)); for (let i = 0; i < uList.length; i++) { - res += `\n第${numToChinese(i + 1)}名: @${uList[i].username} ${ - uList[i].score - }分,最多连击${uList[i].combo}次`; + res += `\n第${numToChinese(i + 1)}名: @${uList[i].username} ${uList[i].score}分,最多连击${ + uList[i].combo + }次`; } return res; } else { @@ -136,15 +131,12 @@ const startJielong: commandHandleFunction = (app, msg, starter) => { msg.chat.id, `现在正在游戏哦,上一个成语是 ${getJielongStatus(msg).stcy},请接:${ getJielongStatus(msg).st - }\n场上情况:${getJielongInfo(msg)}`, + }\n场上情况:${getJielongInfo(msg)}` ); } else { if (starter?.length && starter?.length >= 3) { if (cy[starter] === undefined) { - app.bot?.sendMessage( - msg.chat.id, - `这个成语是什么,${app.config?.bot_name}不知道哦OoO`, - ); + app.bot?.sendMessage(msg.chat.id, `这个成语是什么,${app.config?.bot_name}不知道哦OoO`); return; } db.chat(msg.chat.id).jielong_status = { @@ -157,10 +149,7 @@ const startJielong: commandHandleFunction = (app, msg, starter) => { userStatus: {}, // 用户得分信息 startAt: Number(new Date()), // 开始时间 }; - app.bot?.sendMessage( - msg.chat.id, - `游戏开始!请接 ${getJielongStatus(msg)?.st}`, - ); + app.bot?.sendMessage(msg.chat.id, `游戏开始!请接 ${getJielongStatus(msg)?.st}`); } else { db.chat(msg.chat.id).jielong_status = { started: true, @@ -173,9 +162,8 @@ const startJielong: commandHandleFunction = (app, msg, starter) => { setRandomChenyu(msg); app.bot?.sendMessage( msg.chat.id, - `游戏开始,${app.config - ?.bot_name}来给出第一个成语吧:${getJielongStatus(msg) - ?.stcy},请接 ${getJielongStatus(msg)?.st}`, + `游戏开始,${app.config?.bot_name}来给出第一个成语吧:${getJielongStatus(msg) + ?.stcy},请接 ${getJielongStatus(msg)?.st}` ); } } @@ -185,7 +173,7 @@ const stopJielong: commandHandleFunction = (app, msg) => { if (getJielongStatus(msg)?.started) { app.bot?.sendMessage( msg.chat.id, - `接龙被 @${msg.from?.username} 结束!\n最终情况:${getJielongInfo(msg)}`, + `接龙被 @${msg.from?.username} 结束!\n最终情况:${getJielongInfo(msg)}` ); try { db.chat(msg.chat.id).jielong_status = { @@ -202,8 +190,9 @@ const stopJielong: commandHandleFunction = (app, msg) => { const newMessageHandle: handleFunction = (app, msg) => { if (getJielongStatus(msg)?.started && msg.text && cy[msg.text]) { if (gameEnded(msg)) { - const res: string = `成语接龙结束啦!${app.config - ?.bot_name}来宣布结果:${getJielongInfo(msg)}`; + const res: string = `成语接龙结束啦!${app.config?.bot_name}来宣布结果:${getJielongInfo( + msg + )}`; app.bot?.sendMessage(msg.chat.id, res); db.chat(msg.chat.id).jielong_status = {}; return; @@ -234,8 +223,7 @@ const newMessageHandle: handleFunction = (app, msg) => { combo: 1, }; } - userStatus[msg.from?.id].score = - Number(userStatus[msg.from?.id].score) + 1; + userStatus[msg.from?.id].score = Number(userStatus[msg.from?.id].score) + 1; // 判断combo if (!getJielongStatus(msg).combo) { getJielongStatus(msg).combo = 0; @@ -247,7 +235,7 @@ const newMessageHandle: handleFunction = (app, msg) => { if (lastJielonger) { userStatus[lastJielonger].combo = Math.max( Number(userStatus[lastJielonger].combo), - Number(getJielongStatus(msg).combo), + Number(getJielongStatus(msg).combo) ); } getJielongStatus(msg).combo = 1; @@ -259,16 +247,14 @@ const newMessageHandle: handleFunction = (app, msg) => { if (Number(getJielongStatus(msg).combo) <= 2) { app.bot?.sendMessage( msg.chat.id, - `接龙成功!${getName(msg)} 分数+1。\n下一个开头:${ - getJielongStatus(msg).st - }`, + `接龙成功!${getName(msg)} 分数+1。\n下一个开头:${getJielongStatus(msg).st}` ); } else { app.bot?.sendMessage( msg.chat.id, `${getName(msg)} ${getJielongStatus(msg).combo} 连击!\n下一个开头:${ getJielongStatus(msg).st - }`, + }` ); } } diff --git a/src/plugins/feed/index.ts b/src/plugins/feed/index.ts index b9b6bba..13e73ed 100644 --- a/src/plugins/feed/index.ts +++ b/src/plugins/feed/index.ts @@ -5,10 +5,7 @@ // 回复,回复时间,加好感度数,是否判断为吃过 const food_data: [ string[], - ( - | [string, number, number, boolean][] - | (() => [string, number, number, boolean][]) - ), + [string, number, number, boolean][] | (() => [string, number, number, boolean][]), ][] = [ [ ['冰淇淋', '雪糕'], @@ -18,17 +15,7 @@ const food_data: [ ], ], [ - [ - '天赋党', - '家长党', - '双性党', - '中奖党', - '年龄党', - '小朋友', - '欣然', - '某只小朋友', - '柴柴', - ], + ['天赋党', '家长党', '双性党', '中奖党', '年龄党', '小朋友', '欣然', '某只小朋友', '柴柴'], function () { const eat = [ '煲汤吃掉', @@ -79,18 +66,9 @@ const food_data: [ [['企鹅'], [['和小朋友一起炖了!(', 500, 2, true]]], [['琳酱'], [['我才不吃自己呢!', 500, 0.02, false]]], [['linca', '锦心', '零卡'], [['锦心那么可爱,不吃锦心w', 500, 0.02, false]]], - [ - ['seni', 'senioria', '刺猬', '小刺猬'], - [['seni那么可爱,不吃seniw', 500, 0.02, false]], - ], - [ - ['dringsim', 'Dringsim'], - [['Dringsim那么可爱,不吃Dringsimw', 500, 0.02, false]], - ], - [ - ['F2+B2', 'FFBB', 'F²+B²', '年明时分', '年明'], - [['好感度过高,不忍心吃x', 500, 0.02, false]], - ], + [['seni', 'senioria', '刺猬', '小刺猬'], [['seni那么可爱,不吃seniw', 500, 0.02, false]]], + [['dringsim', 'Dringsim'], [['Dringsim那么可爱,不吃Dringsimw', 500, 0.02, false]]], + [['F2+B2', 'FFBB', 'F²+B²', '年明时分', '年明'], [['好感度过高,不忍心吃x', 500, 0.02, false]]], [['藻云'], [['藻云那么可爱,不吃藻云w', 500, 0.02, false]]], [ [ @@ -542,22 +520,10 @@ const food_data: [ [['投喂成功!', 500, 2, true]], ], [ - [ - '高等数学', - '家暴党', - '线性代数', - '数学分析', - '数论', - '三角函数', - '微积分', - '', - ], + ['高等数学', '家暴党', '线性代数', '数学分析', '数论', '三角函数', '微积分', ''], [['猫猫听完死了', 500, 0, false]], ], - [ - ['昏睡红茶', '野兽先辈', '田所浩二'], - [['啊啊啊啊啊啊啊啊啊啊啊(吼叫', 500, 1, true]], - ], + [['昏睡红茶', '野兽先辈', '田所浩二'], [['啊啊啊啊啊啊啊啊啊啊啊(吼叫', 500, 1, true]]], [['锟斤铐'], [['烫烫烫烫烫烫烫烫烫烫烫!!', 500, 0, false]]], [ ['鸡鸡', 'jb', '鸡巴', '奶子', '核弹', '铀-235', '毒药', '屎', 'bug'], @@ -566,8 +532,7 @@ const food_data: [ ]; // Preprocess food data -const food_map: Map [string, number, number, boolean][]> = - new Map(); +const food_map: Map [string, number, number, boolean][]> = new Map(); // eslint-disable-next-line prefer-const for (let [names, fn] of food_data) { if (fn instanceof Array) { @@ -609,10 +574,7 @@ const init: PluginInit = (app) => { return; } if (!msgTxt) { - App.bot?.sendMessage( - msg.chat.id, - `要给${App.config?.bot_name}吃什么呢?`, - ); + App.bot?.sendMessage(msg.chat.id, `要给${App.config?.bot_name}吃什么呢?`); } else { const replies = generate_feed_food(msgTxt); for (const [reply, delay, love] of replies) { @@ -620,12 +582,9 @@ const init: PluginInit = (app) => { () => App.bot?.sendMessage( msg.chat.id, - reply.replaceAll( - '', - `好感度${love > 0 ? '+' : ''}${love}`, - ), + reply.replaceAll('', `好感度${love > 0 ? '+' : ''}${love}`) ), - delay, + delay ); } } diff --git a/src/plugins/help/index.ts b/src/plugins/help/index.ts index dd18ec9..f6bc816 100644 --- a/src/plugins/help/index.ts +++ b/src/plugins/help/index.ts @@ -1,9 +1,5 @@ import { PluginInit } from '@/types/plugin.js'; -import { - canUseCommand, - getCommands, - getGlobalMessageHandles, -} from '../../lib/command.js'; +import { canUseCommand, getCommands, getGlobalMessageHandles } from '../../lib/command.js'; const init: PluginInit = (app) => { console.log('help loaded!'); diff --git a/src/plugins/hitokoto/index.ts b/src/plugins/hitokoto/index.ts index a402c98..a053b9d 100644 --- a/src/plugins/hitokoto/index.ts +++ b/src/plugins/hitokoto/index.ts @@ -22,13 +22,9 @@ const init: PluginInit = (app) => { const arg = msgTxt.split(' ').join('&c='); get_hitokoto(arg).then((res) => { console.log(res); - App.bot?.sendMessage( - msg.chat.id, - `${res.hitokoto} ${res.from ? '——' + res.from : ''}`, - { - reply_to_message_id: msg.message_id, - }, - ); + App.bot?.sendMessage(msg.chat.id, `${res.hitokoto} ${res.from ? '——' + res.from : ''}`, { + reply_to_message_id: msg.message_id, + }); }); }, description: '一言', diff --git a/src/plugins/rand/index.js b/src/plugins/rand/index.js index 99ee0db..0c3ab57 100644 --- a/src/plugins/rand/index.js +++ b/src/plugins/rand/index.js @@ -5,17 +5,12 @@ */ function rand(app, message, message_text) { const result = Math.floor(Math.random() * 101); - let username = message.from?.first_name - ? message.from?.first_name - : message.from?.username; + let username = message.from?.first_name ? message.from?.first_name : message.from?.username; if (message.from?.last_name) { username += ' ' + message.from?.last_name; } if (message_text) { - app.bot.sendMessage( - message.chat.id, - `${username} ${message_text} 的概率是: ${result}%`, - ); + app.bot.sendMessage(message.chat.id, `${username} ${message_text} 的概率是: ${result}%`); } else { app.bot.sendMessage(message.chat.id, `${username} 掷出了: ${result}`); } @@ -29,10 +24,7 @@ function rand(app, message, message_text) { function randnoid(app, message, message_text) { const result = Math.floor(Math.random() * 101); if (message_text) { - app.bot.sendMessage( - message.chat.id, - `${message_text} 的概率是: ${result}%`, - ); + app.bot.sendMessage(message.chat.id, `${message_text} 的概率是: ${result}%`); } } diff --git a/src/plugins/set_title/index.ts b/src/plugins/set_title/index.ts index 7f7a470..772d006 100644 --- a/src/plugins/set_title/index.ts +++ b/src/plugins/set_title/index.ts @@ -26,11 +26,7 @@ async function setTitle(app: App, msg: Message, title: string = '') { await app.bot.promoteChatMember(msg.chat.id, msg.from?.id, { can_pin_messages: true, }); - await app.bot.setChatAdministratorCustomTitle( - msg.chat.id, - msg.from?.id, - title, - ); + await app.bot.setChatAdministratorCustomTitle(msg.chat.id, msg.from?.id, title); app.bot.sendMessage(msg.chat.id, `设置成功,你现在是${title}了`, { reply_to_message_id: msg.message_id, }); @@ -49,13 +45,9 @@ async function setTitle(app: App, msg: Message, title: string = '') { errobj.message.includes('user is not an administrator') || errobj.message.includes('CHAT_ADMIN_REQUIRED') ) { - app.bot.sendMessage( - msg.chat.id, - `${app.config.bot_name}还没这个权限哦`, - { - reply_to_message_id: msg.message_id, - }, - ); + app.bot.sendMessage(msg.chat.id, `${app.config.bot_name}还没这个权限哦`, { + reply_to_message_id: msg.message_id, + }); return; } if (errobj.message.includes('ADMIN_RANK_EMOJI_NOT_ALLOWED')) { diff --git a/src/plugins/slashbot/index.ts b/src/plugins/slashbot/index.ts index 0b99214..10ad704 100644 --- a/src/plugins/slashbot/index.ts +++ b/src/plugins/slashbot/index.ts @@ -61,7 +61,7 @@ const rong = (app: App, msg: Message, msgTxt?: string, rev?: boolean) => { { parse_mode: 'HTML', reply_to_message_id: msg.message_id, - }, + } ); } } diff --git a/src/plugins/tarot/index.ts b/src/plugins/tarot/index.ts index 54923f3..56c57ab 100644 --- a/src/plugins/tarot/index.ts +++ b/src/plugins/tarot/index.ts @@ -20,15 +20,9 @@ const sendTarot: commandHandleFunction = (app, msg, txt) => { txt = '1'; } const tarots = getTarots(app, txt); - app.bot?.sendMessage( - msg.chat.id, - `${getName(msg)}最近遇到了什么烦心事吗?让琳酱给你算一算:`, - ); + app.bot?.sendMessage(msg.chat.id, `${getName(msg)}最近遇到了什么烦心事吗?让琳酱给你算一算:`); setTimeout(() => { - app.bot?.sendMessage( - msg.chat.id, - `${getName(msg)}抽到的牌组是:\n${tarots}`, - ); + app.bot?.sendMessage(msg.chat.id, `${getName(msg)}抽到的牌组是:\n${tarots}`); }, 3000); }; diff --git a/src/plugins/todo/index.ts b/src/plugins/todo/index.ts index a139004..8b1af78 100644 --- a/src/plugins/todo/index.ts +++ b/src/plugins/todo/index.ts @@ -4,11 +4,7 @@ import { PluginInit } from '@/types/plugin.js'; import { Message, User } from 'node-telegram-bot-api'; function getName(user: User): string { - let username: string = user.first_name - ? user.first_name - : user.username - ? user.username - : ''; + let username: string = user.first_name ? user.first_name : user.username ? user.username : ''; if (user.last_name) { username += ' ' + user.last_name; } @@ -37,7 +33,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { `需要至少两个参数哦,第一个参数是分钟,第二个参数是${app.config.bot_name}要提醒干什么事`, { reply_to_message_id: msg.message_id, - }, + } ); return; } @@ -50,7 +46,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { `需要至少两个参数哦,你还没告诉${app.config.bot_name}要多久之后提醒哦`, { reply_to_message_id: msg.message_id, - }, + } ); return; } else { @@ -59,7 +55,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { `需要至少两个参数哦,你还没有告诉琳酱${app.config.bot_name}要提醒干什么哦`, { reply_to_message_id: msg.message_id, - }, + } ); return; } @@ -72,7 +68,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { `你给${app.config.bot_name}的时间不对,不要调戏${app.config.bot_name}呀`, { reply_to_message_id: msg.message_id, - }, + } ); return; } @@ -83,7 +79,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { { parse_mode: 'HTML', reply_to_message_id: msg.message_id, - }, + } ); setTimeout( () => { @@ -91,7 +87,7 @@ const setTodo: commandHandleFunction = (app: App, msg: Message, msgTxt) => { reply_to_message_id: msg.message_id, }); }, - time * 60 * 1000, + time * 60 * 1000 ); } }; diff --git a/src/plugins/waife/index.ts b/src/plugins/waife/index.ts index a36cfbe..a4b1d44 100644 --- a/src/plugins/waife/index.ts +++ b/src/plugins/waife/index.ts @@ -6,11 +6,7 @@ import fs from 'fs'; import { spawn } from 'child_process'; function getName(user: User): string { - let username: string = user.first_name - ? user.first_name - : user.username - ? user.username - : ''; + let username: string = user.first_name ? user.first_name : user.username ? user.username : ''; if (user.last_name) { username += ' ' + user.last_name; } @@ -108,13 +104,9 @@ async function getWaife(app: App, msg: Message) { } const lst = await getWaifesList(app, msg); if (lst.length <= 1) { - app.bot.sendMessage( - msg.chat.id, - '抱歉,我还没从群里获取到足够多的人哦,请先回复我一些消息', - { - reply_to_message_id: msg.message_id, - }, - ); + app.bot.sendMessage(msg.chat.id, '抱歉,我还没从群里获取到足够多的人哦,请先回复我一些消息', { + reply_to_message_id: msg.message_id, + }); return; } let waife: User = lst[Math.floor(Math.random() * lst.length)]; @@ -124,25 +116,21 @@ async function getWaife(app: App, msg: Message) { cnt++; } if (waife.id === msg.from?.id) { - app.bot.sendMessage( - msg.chat.id, - '获取失败……理论上不会出现这个情况, 请查看bot代码', - { - reply_to_message_id: msg.message_id, - }, - ); + app.bot.sendMessage(msg.chat.id, '获取失败……理论上不会出现这个情况, 请查看bot代码', { + reply_to_message_id: msg.message_id, + }); return; } add_to_wife(app, msg, msg.from.id); const res = await app.bot.sendMessage( msg.chat.id, - `${htmlify('获取成功~ 你今天的群友老婆是')} ${htmlify(getName(waife))}`, + `${htmlify('获取成功~ 你今天的群友老婆是')} ${htmlify( + getName(waife) + )}`, { parse_mode: 'HTML', reply_to_message_id: msg.message_id, - }, + } ); app.db.chat(msg.chat.id).waifemap[msg.from?.id] = { msg_id: res.message_id, @@ -154,13 +142,13 @@ async function getWaife(app: App, msg: Message) { async function renderGraph(id: string, src: string): Promise { const [fname, outname] = [`${tmpdir()}/${id}.gv`, `${tmpdir()}/${id}.png`]; await new Promise((res, rej) => - fs.writeFile(fname, src, {encoding: 'utf-8'}, (err) => { + fs.writeFile(fname, src, { encoding: 'utf-8' }, (err) => { if (err) { rej(err); } else { res({}); } - }), + }) ); await new Promise((res, rej) => { const proc = spawn('dot', [fname, '-Tpng', '-o', outname]); @@ -179,7 +167,7 @@ async function renderGraph(id: string, src: string): Promise { } else { res(data); } - }), + }) ); } @@ -197,7 +185,7 @@ async function getWaifeGraph(app: App, msg: Message) { } const iduser = app.db.chat(msg.chat.id).iduserMap; const getNode = (user: User) => `${user.id}[label="${getName(user)}"]`; - const uidMap: {[key: string]: boolean} = {}; + const uidMap: { [key: string]: boolean } = {}; const txt = []; for (const id in wfMap) { if (wfMap[id]?.waife) { @@ -213,10 +201,7 @@ async function getWaifeGraph(app: App, msg: Message) { } } const src = - 'digraph G {\n' + - 'node[shape=box fontname="wqy-microhei"];\n' + - txt.join('\n') + - '\n}'; + 'digraph G {\n' + 'node[shape=box fontname="wqy-microhei"];\n' + txt.join('\n') + '\n}'; console.log(src); const qidao = await app.bot.sendMessage(msg.chat.id, '少女祈祷中', { reply_to_message_id: msg.message_id, @@ -257,4 +242,4 @@ const init: PluginInit = (app) => { }); }; -export { init }; \ No newline at end of file +export { init }; diff --git a/src/types/app.ts b/src/types/app.ts index 969d299..6cfcb57 100644 --- a/src/types/app.ts +++ b/src/types/app.ts @@ -1,10 +1,6 @@ import TelegramBot from 'node-telegram-bot-api'; import { YamlConfig } from './config.js'; -import { - registCommand, - registGlobalMessageHandle, - registReplyHandle, -} from '@/lib/command.js'; +import { registCommand, registGlobalMessageHandle, registReplyHandle } from '@/lib/command.js'; import { Std } from '@/util/std.js'; export interface App { diff --git a/src/util/fatal_error.ts b/src/util/fatal_error.ts index 2364849..b78b5cb 100644 --- a/src/util/fatal_error.ts +++ b/src/util/fatal_error.ts @@ -3,10 +3,7 @@ * @param error The error * @param message The message to output */ -export default function logFatalError( - error: unknown, - message: string | undefined, -) { +export default function logFatalError(error: unknown, message: string | undefined) { if (message) { console.log('---------------'); console.log(`致命错误:${message}`); diff --git a/tsconfig.json b/tsconfig.json index e0dc69f..a44286f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ // "disableSolutionSearching": true, /* 在编辑时选择项目退出多项目引用检查。 */ // "disableReferencedProjectLoad": true, /* 减少 TypeScript 自动加载的项目数。 */ /* 语言和环境 */ - "target": "ES2021", /* 为发出的 JavaScript 设置 JavaScript 语言版本并包含兼容的库声明。 */ + "target": "ES2021" /* 为发出的 JavaScript 设置 JavaScript 语言版本并包含兼容的库声明。 */, // "lib": [], /* 指定一组描述目标运行时环境的捆绑库声明文件。 */ // "jsx": "preserve", /* 指定生成的 JSX 代码。 */ // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ @@ -22,18 +22,14 @@ // "useDefineForClassFields": true, /* 发出符合 ECMAScript 标准的类字段。 */ // "moduleDetection": "auto", /* 控制用于检测模块格式 JS 文件的方法。 */ /* 模块 */ - "module": "NodeNext", /* 指定生成的模块代码。 */ + "module": "NodeNext" /* 指定生成的模块代码。 */, // "rootDir": "./src", /* 指定源文件中的根文件夹。 */ - "moduleResolution": "NodeNext", /* 指定 TypeScript 如何从给定的模块说明符查找文件。 */ - "baseUrl": ".", /* 指定基目录以解析非相关模块名称。 */ + "moduleResolution": "NodeNext" /* 指定 TypeScript 如何从给定的模块说明符查找文件。 */, + "baseUrl": "." /* 指定基目录以解析非相关模块名称。 */, "paths": { - "@": [ - "src" - ], - "@/*": [ - "src/*" - ], - }, /* 指定一组将导入重新映射到其他查找位置的条目。 */ + "@": ["src"], + "@/*": ["src/*"] + } /* 指定一组将导入重新映射到其他查找位置的条目。 */, // "rootDirs": [], /* 允许在解析模块时将多个文件夹视为一个文件夹。 */ // "typeRoots": [], /* 指定多个行为类似于 “./node_modules/@types” 的文件夹。 */ // "types": [], /* 指定要包含的类型包名称,而无需在源文件中引用。 */ @@ -43,21 +39,21 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - "resolveJsonModule": true, /* 启用导入 .json 文件。 */ + "resolveJsonModule": true /* 启用导入 .json 文件。 */, // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* 禁止 “import”、“require” 或 “” 扩展 TypeScript 应添加到项目的文件数。 */ /* JavaScript 支持 */ - "allowJs": true, /* 允许 JavaScript 文件成为程序的一部分。使用 “checkJS” 选项从这些文件中获取错误。 */ + "allowJs": true /* 允许 JavaScript 文件成为程序的一部分。使用 “checkJS” 选项从这些文件中获取错误。 */, // "checkJs": true, /* 在已检查类型的 JavaScript 文件中启用错误报告。 */ // "maxNodeModuleJsDepth": 1, /* 指定用于从 “node_modules” 检查 JavaScript 文件的最大文件夹深度。仅适用于 “allowJs”。 */ /* 发出 */ // "declaration": true, /* 从项目的 TypeScript 和 JavaScript 文件生成 .d.ts 文件。 */ // "declarationMap": true, /* 为 d.ts 文件创建源映射。 */ // "emitDeclarationOnly": true, /* 仅输出 d.ts 文件,而不输出 JavaScript 文件。 */ - "sourceMap": true, /* 为发出的 JavaScript 文件创建源映射文件。 */ + "sourceMap": true /* 为发出的 JavaScript 文件创建源映射文件。 */, // "inlineSourceMap": true, /* 在发出的 JavaScript 中包括源映射文件。 */ // "outFile": "./", /* 指定将所有输出捆绑到一个 JavaScript 文件中的文件。如果 “declaration” 为 true,还要指定一个捆绑所有 .d.ts 输出的文件。 */ - "outDir": "./dist", /* 为所有已发出的文件指定输出文件夹。 */ + "outDir": "./dist" /* 为所有已发出的文件指定输出文件夹。 */, // "removeComments": true, /* 禁用发出注释。 */ // "noEmit": true, /* 禁用从编译发出文件。 */ // "importHelpers": true, /* 允许每个项目从 tslib 导入帮助程序函数一次,而不是将它们包含在每个文件中。 */ @@ -75,14 +71,14 @@ // "declarationDir": "./", /* 指定已生成声明文件的输出目录。 */ // "preserveValueImports": true, /* 保留 JavaScript 输出中未使用的导入值,否则将删除这些值。 */ /* 互操作约束 */ - "isolatedModules": true, /* 确保可以安全地转译每个文件,而无需依赖其他导入。 */ + "isolatedModules": true /* 确保可以安全地转译每个文件,而无需依赖其他导入。 */, // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - "allowSyntheticDefaultImports": true, /* 当模块没有默认导出时,允许“从 y 导入 x”。 */ - "esModuleInterop": true, /* 发出其他 JavaScript 以轻松支持导入 CommonJS 模块。这将启用 “allowSyntheticDefaultImports” 以实现类型兼容性。 */ + "allowSyntheticDefaultImports": true /* 当模块没有默认导出时,允许“从 y 导入 x”。 */, + "esModuleInterop": true /* 发出其他 JavaScript 以轻松支持导入 CommonJS 模块。这将启用 “allowSyntheticDefaultImports” 以实现类型兼容性。 */, // "preserveSymlinks": true, /* 禁用将符号链接解析为其实际路径。这会关联到节点中的同一标志。 */ - "forceConsistentCasingInFileNames": true, /* 确保导入中的大小写正确。 */ + "forceConsistentCasingInFileNames": true /* 确保导入中的大小写正确。 */, /* 类型检查 */ - "strict": true, /* 启用所有严格类型检查选项。 */ + "strict": true /* 启用所有严格类型检查选项。 */, // "noImplicitAny": true, /* 对具有隐式 “any” 类型的表达式和声明启用错误报告。 */ // "strictNullChecks": true, /* 进行类型检查时,请考虑 “null” 和 “undefined”。 */ // "strictFunctionTypes": true, /* 分配函数时,请检查以确保参数和返回值与子类型兼容。 */ @@ -105,7 +101,5 @@ // "skipDefaultLibCheck": true, /* 跳过 TypeScript 附带的类型检查 .d.ts 文件。 */ "skipLibCheck": true /* 跳过对所有 .d.ts 文件的类型检查。 */ }, - "include": [ - "./src" - ] -} \ No newline at end of file + "include": ["./src"] +} diff --git a/typedoc.json b/typedoc.json index c918171..9bde433 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,12 +1,6 @@ { // Comments are supported, like tsconfig.json - "entryPoints": [ - "src/index.ts", - "src/lib", - "src/bridges", - "src/types", - "src/util" - ], + "entryPoints": ["src/index.ts", "src/lib", "src/bridges", "src/types", "src/util"], "entryPointStrategy": "expand", "out": "docs" }