test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //PLUGIN test.ts
  2. import { coins, param, plugins, runcod, schedule } from '../lib/decorators.js';
  3. import path from 'path';
  4. import 'reflect-metadata';
  5. import { fileURLToPath } from 'node:url';
  6. import { qqBot } from '../app.js';
  7. import botlogger from '../lib/logger.js';
  8. import { ParamType } from '../interface/plugin.js';
  9. @plugins({
  10. easycmd: true,//是否启用简易命令,启用将将命令注册为<命令名称>,不启用将注册为#<插件名称> <命令名称>
  11. name: "测试插件", //插件名称,用于显示在菜单中
  12. version: "1.0.0", //插件版本号,用于显示在菜单中
  13. describe: "测试功能", //插件描述,用于显示在菜单中
  14. author: "枫叶秋林",//插件作者,用于显示在菜单中
  15. help: { //插件帮助信息,用于显示在菜单中
  16. enabled: true, //是否启用帮助信息
  17. description: "显示帮助信息" //帮助信息描述
  18. }
  19. })
  20. export class test {
  21. constructor() {
  22. //构造函数内可以再次注册qqBot的事件
  23. qqBot.on('message', async (event) => {
  24. event.message.forEach(async (message) => {
  25. if (message.type === 'text') {
  26. if (message.data.text === '自测') {
  27. await event.quick_action([{
  28. type: 'text',
  29. data: { text: `插件加载事件测试` }
  30. }]);
  31. }
  32. }
  33. })
  34. })
  35. botlogger.info("测试插件加载成功")
  36. }
  37. @runcod(
  38. ["param"], //命令名称,用于触发命令
  39. "参数实例" //命令描述,用于显示在默认菜单中
  40. )//命令装饰器,用于注册命令
  41. async param(
  42. @param("参数1", ParamType.String) param1: string,//参数装饰器,用于解析参数
  43. @param("参数2", ParamType.Number,999,true) param2: number,//参数装饰器,用于解析参数
  44. ): Promise<any> {
  45. if (!param1 || !param2) {
  46. return "请输入正确的参数格式: #test param <字符串> <数字>";//返回错误信息,用于显示在菜单中
  47. }
  48. const __dirname = path.dirname(fileURLToPath(import.meta.url)); //获取当前文件的目录名
  49. // 返回带模板的响应
  50. return {
  51. param1,//参数1,用于显示在菜单中
  52. param2,//参数2,用于显示在菜单中
  53. template: { // 模板配置,用于发送图片内容
  54. enabled: true,//是否启用模板,启用将发送图片内容
  55. sendText: false,//是否发送文本,启用将发送文本内容,如果都启用则发送两条消息
  56. path: path.resolve(__dirname, '..', 'resources', 'test', 'param.html'),//模版路径,推荐按规范放置在resources目录下
  57. render: {//浏览器默认参数设置,用于打开浏览器的设置
  58. width: 600, // 模板宽度
  59. height: 300,// 模板高度
  60. type: 'png',// 模板类型
  61. quality: 100,// 模板质量
  62. fullPage: false,// 是否全屏
  63. background: true// 是否背景
  64. }
  65. },
  66. toString() { //重写toString方法,用于返回文本内容,启用sendText时将发送文本内容,不启用时将发送图片内容,图片发送失败时发送文字内容
  67. return `参数1(字符串): ${param1}\n参数2(数字): ${param2}`;
  68. }
  69. };
  70. }
  71. @runcod(["remove"], "移除金币")//命令装饰器,用于注册命令
  72. @coins(
  73. 10,//金币数量
  74. 'remove',//类别 add为增加金币,remove为减少金币
  75. ) //经济修饰词,用于减少金币
  76. async remove(){
  77. return `移除成功`;
  78. }
  79. @schedule('* */30 * * * *') // 每30分钟执行一次
  80. async testschedule() {
  81. // botlogger.info("定时任务测试")
  82. }
  83. }