123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import { addCoins, getUserData, removeCoins } from "../lib/economy.js";
- import { param, plugins, runcod } from "../lib/decorators.js";
- import { GroupMessage, PrivateFriendMessage, PrivateGroupMessage } from "node-napcat-ts/dist/Interfaces.js";
- import path from "path";
- import { fileURLToPath } from "url";
- import { ParamType } from "../interface/plugin.js";
- import { IsAdmin } from "../lib/Permission.js";
- @plugins({
- name: "经济系统", //插件名称,用于显示在菜单中
- version: "1.0.0", //插件版本号,用于显示在菜单中
- describe: "官方经济插件", //插件描述,用于显示在菜单中
- author: "枫叶秋林",//插件作者,用于显示在菜单中
- help: { //插件帮助信息,用于显示在菜单中
- enabled: true, //是否启用帮助信息
- description: "显示帮助信息" //帮助信息描述
- }
- })
- export class ecomony {
- @runcod(["info","个人信息"], "获取个人金币信息")
- async ecomonyInfo(
- context: PrivateFriendMessage | PrivateGroupMessage | GroupMessage
- ) {
- const { economy } = await getUserData(context?.sender?.user_id?.toString())
- const __dirname = path.dirname(fileURLToPath(import.meta.url)); //获取当前文件的目录名
- return {
- nickname: context?.sender?.nickname??"未知",
- coins: economy.coins,
- logs: economy.logs,
- avatar: `http://q1.qlogo.cn/g?b=qq&nk=${context?.sender?.user_id??0}&s=640`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..', 'resources', 'ecomony', 'info.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- },
- toString() { //重写toString方法,用于返回文本内容,启用sendText时将发送文本内容,不启用时将发送图片内容,图片发送失败时发送文字内容
- let logsString = "";
- economy.logs.forEach(log => {
- logsString += `类型: ${log.type} 数量: ${log.amount} 原因: ${log.reason} 时间: ${log.date}\n`;
- });
- return `
- 金币: ${economy.coins}\n
- ------明细记录----
- ${logsString}
- `;
- }
- }
- }
- @runcod(["add", "增加"], "增加金币")
- async addecomony(
- @param("QQ号", ParamType.Number,) userid: string,
- @param("数量", ParamType.Number) amount: number,
- @param("原因", ParamType.String,'管理员增加',true) reason: string,
- context: PrivateFriendMessage | PrivateGroupMessage | GroupMessage
- ) {
- const __dirname = path.dirname(fileURLToPath(import.meta.url)); //获取当前文件的目录名
- try {
- if (!IsAdmin(context.sender.user_id)) {
- return {
- msgtype: 'error',
- ecomsg: `无权限,无法增加金币`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..','resources', 'ecomony','msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- height: 600,// 模板高度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- }
- }
- }
- addCoins(context.sender.user_id.toString(),amount,reason)
- const newcoins = (await getUserData(userid)).economy.coins
- return {
- msgtype: 'success',
- ecomsg: `增加成功! 金币 +${amount}, 当前数量: ${newcoins}`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..', 'resources', 'ecomony', 'msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- },
- toString() { //重写toString方法,用于返回文本内容,启用sendText时将发送文本内容,不启用时将发送图片内容,图片发送失败时发送文字内容
- return `
- 增加成功\n
- 数量: ${amount}\n
- 原因: ${reason}\n
- 时间: ${new Date().toLocaleString()}\n
- `;
- }
- }
- } catch (error) {
- return {
- type: 'error',
- ecomsg: `增加失败! 原因: ${(error as Error).message??'未知错误'}`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..', 'resources', 'ecomony', 'msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- },
- toString() { //重写toString方法,用于返回文本内容,启用sendText时将发送文本内容,不启用时将发送图片内容,图片发送失败时发送文字内容
- return `
- 增加成功\n
- 数量: ${amount}\n
- 原因: ${reason}\n
- 时间: ${new Date().toLocaleString()}\n
- `;
- }
- }
- }
-
- }
- @runcod(["reduce", "减少"], "减少金币")
- async reduceecomony(
- @param("QQ号", ParamType.Number,) userid: string,
- @param("数量", ParamType.Number) amount: number,
- @param("原因", ParamType.String,'管理员减少',true) reason: string,
- context: PrivateFriendMessage | PrivateGroupMessage | GroupMessage
- ){
- const __dirname = path.dirname(fileURLToPath(import.meta.url)); //获取当前文件的目录名
- try {
- if (!IsAdmin(context.sender.user_id)) {
- return {
- msgtype: 'error',
- ecomsg: `无权限,无法减少金币`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..','resources', 'ecomony','msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- height: 400,// 模板高度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- }
- }
- }
- removeCoins(context.sender.user_id.toString(),-amount,reason)
- const newcoins = (await getUserData(userid)).economy.coins
- return {
- msgtype:'success',
- ecomsg: `减少成功! 金币 -${amount}, 当前数量: ${newcoins}`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..','resources', 'ecomony','msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- height: 400,// 模板高度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- }
- }
- }
- catch (error) {
- return {
- msgtype: 'error',
- ecomsg: `减少失败! 原因: ${(error as Error).message??'未知错误'}`,
- template: {
- enabled: true,
- sendText: false,
- path: path.resolve(__dirname, '..','resources', 'ecomony','msg.html'),//模版路径,推荐按规范放置在resources目录下
- render: {//浏览器默认参数设置,用于打开浏览器的设置
- width: 800, // 模板宽度
- height: 400,// 模板高度
- type: 'png',// 模板类型
- quality: 100,// 模板质量
- fullPage: false,// 是否全屏
- background: true// 是否背景
- }
- }
- }
- }
- }
- }
|