koishi-plugin-fenglu-mouth 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Context, Schema } from "koishi";
2
+ export declare const name = "fenglu-mouth";
3
+ export declare const inject: {
4
+ required: string[];
5
+ optional: string[];
6
+ };
7
+ export declare const usage = "\n<h1>\u4FF8\u7984\u67E5\u8BE2</h1>\n\n<p>\u76EE\u524D\u4EC5\u6D4B\u8BD5\u4E86 <b>Onebot</b> \u534F\u8BAE</p>\n\n<p>\u4ED3\u5E93\u5730\u5740\uFF1A<a href=\"https://github.com/snowwolfair/fenglu-mouth\">https://github.com/snowwolfair/fenglu-mouth</a></p>\n\n<p style=\"color: #f39c12;\">\u63D2\u4EF6\u4F7F\u7528\u95EE\u9898 / Bug\u53CD\u9988 / \u5EFA\u8BAE \u8BF7 \u6DFB\u52A0\u4F01\u9E45\u7FA4 <b style=\"color: #bd73fa;\">156529412</b> \u6216\u5728\u4ED3\u5E93\u4E2D\u53D1 <a href=\"https://github.com/snowwolfair/daynew/issues\" >issue</a> </p>\n\n<p>\u7075\u611F\u6765\u6E90\u4E8E\u8BE5\u6897\u56FE </p>\n<img src=\"https://github.com/snowwolfair/fenglu-mouth/blob/master/src/asset/chart.jpg\" alt=\"chart\" />\n\n<h2>\u98DF\u7528\u65B9\u6CD5</h2>\n<p> \u5728\u7FA4\u5185\u53D1\u9001\u547D\u4EE4 <b style=\"color: #08b402ff;\">elu</b> \u6216 <b style=\"color: #08b402ff;\">\u67E5\u8BE2\u4FF8\u7984</b> , \u7136\u540E\u6839\u636E\u63D0\u793A\u8F93\u5165\u5DE5\u8D44\u5373\u53EF\u67E5\u8BE2\u4FF8\u7984</p>\n<hr>\n<p> \u76EE\u524D\u4EC5\u652F\u6301\u4F7F\u7528 <b>https://www.goldapi.io</b> \u63D0\u4F9B\u7684 api \u6E90</p>\n<p> \u82E5\u9700\u8981\u4F7F\u7528\u5176\u4ED6 api \u6E90\uFF0C\u8BF7\u901A\u8FC7 <b style=\"color: #bd73fa;\">QQ</b> \u6216\u8005 <b style=\"color: #bd73fa;\">\u63D0\u4EA4issue </b> \u6DFB\u52A0</p>\n";
8
+ export declare const Config: Schema;
9
+ export declare function apply(ctx: Context, config: any): void;
package/lib/index.js ADDED
@@ -0,0 +1,235 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Config: () => Config,
24
+ apply: () => apply,
25
+ inject: () => inject,
26
+ name: () => name,
27
+ usage: () => usage
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+ var import_koishi = require("koishi");
31
+ var name = "fenglu-mouth";
32
+ var inject = {
33
+ required: ["database"],
34
+ optional: ["adapter-onebot"]
35
+ };
36
+ var usage = `
37
+ <h1>俸禄查询</h1>
38
+
39
+ <p>目前仅测试了 <b>Onebot</b> 协议</p>
40
+
41
+ <p>仓库地址:<a href="https://github.com/snowwolfair/fenglu-mouth">https://github.com/snowwolfair/fenglu-mouth</a></p>
42
+
43
+ <p style="color: #f39c12;">插件使用问题 / Bug反馈 / 建议 请 添加企鹅群 <b style="color: #bd73fa;">156529412</b> 或在仓库中发 <a href="https://github.com/snowwolfair/daynew/issues" >issue</a> </p>
44
+
45
+ <p>灵感来源于该梗图 </p>
46
+ <img src="https://github.com/snowwolfair/fenglu-mouth/blob/master/src/asset/chart.jpg" alt="chart" />
47
+
48
+ <h2>食用方法</h2>
49
+ <p> 在群内发送命令 <b style="color: #08b402ff;">elu</b> 或 <b style="color: #08b402ff;">查询俸禄</b> , 然后根据提示输入工资即可查询俸禄</p>
50
+ <hr>
51
+ <p> 目前仅支持使用 <b>https://www.goldapi.io</b> 提供的 api 源</p>
52
+ <p> 若需要使用其他 api 源,请通过 <b style="color: #bd73fa;">QQ</b> 或者 <b style="color: #bd73fa;">提交issue </b> 添加</p>
53
+ `;
54
+ var Config = import_koishi.Schema.intersect([
55
+ import_koishi.Schema.object({
56
+ api: import_koishi.Schema.object({
57
+ list: import_koishi.Schema.array(import_koishi.Schema.string().default("").description("api源key")).default([]).description("api key列表")
58
+ }).description("贵金属源配置")
59
+ }),
60
+ import_koishi.Schema.object({
61
+ conver: import_koishi.Schema.object({
62
+ dynasty: import_koishi.Schema.union(["秦朝", "东汉", "唐朝", "清朝"]).default("秦朝").description(
63
+ "朝代(仅明清使用银两结算俸禄,故只有选择清朝时才会计算对应的官职)"
64
+ ),
65
+ metal: import_koishi.Schema.union(["金", "银"]).default("金").description("金属"),
66
+ currency: import_koishi.Schema.union(["人民币", "美元", "欧元", "英镑", "日元"]).default("人民币").description("货币")
67
+ }).description("转化配置")
68
+ })
69
+ ]);
70
+ var transformDynasty = [
71
+ {
72
+ key: "秦朝",
73
+ value: "QING",
74
+ transform: 16.14
75
+ },
76
+ {
77
+ key: "东汉",
78
+ value: "HAN",
79
+ transform: 15
80
+ },
81
+ {
82
+ key: "唐朝",
83
+ value: "TANG",
84
+ transform: 40
85
+ },
86
+ {
87
+ key: "清朝",
88
+ value: "MING",
89
+ transform: 37.3
90
+ }
91
+ ];
92
+ var transformMetal = [
93
+ {
94
+ key: "金价",
95
+ value: "XAU"
96
+ },
97
+ {
98
+ key: "银",
99
+ value: "XAG"
100
+ }
101
+ ];
102
+ var transformCurrency = [
103
+ {
104
+ key: "人民币",
105
+ value: "USD"
106
+ },
107
+ {
108
+ key: "美元",
109
+ value: "USD"
110
+ },
111
+ {
112
+ key: "欧元",
113
+ value: "EUR"
114
+ },
115
+ {
116
+ key: "英镑",
117
+ value: "GBP"
118
+ },
119
+ {
120
+ key: "日元",
121
+ value: "JPY"
122
+ }
123
+ ];
124
+ function QINGofficial(emolument) {
125
+ if (emolument < 5.25) {
126
+ return "不入流,担任职位:驿丞、闸官";
127
+ }
128
+ if (5.25 <= emolument && emolument < 5.52) {
129
+ return "从九品,担任职位:典史、吏目";
130
+ }
131
+ if (5.52 <= emolument && emolument < 6.67) {
132
+ return "正九品,担任职位:主簿、巡检";
133
+ }
134
+ if (6.67 <= emolument && emolument < 7.5) {
135
+ return "正八品,担任职位:司务、县丞";
136
+ }
137
+ if (7.5 <= emolument && emolument < 10) {
138
+ return "正七品,担任职位:知府、国子监助教";
139
+ }
140
+ if (10 <= emolument && emolument < 13.33) {
141
+ return "正六品,担任职位:主事、翰林院修撰";
142
+ }
143
+ if (13.33 <= emolument && emolument < 17.5) {
144
+ return "正五品,担任职位:御史、六部郎中";
145
+ }
146
+ if (17.5 <= emolument && emolument < 21.67) {
147
+ return "正四品,担任职位:翰林院侍读、国子监祭酒";
148
+ }
149
+ if (21.67 <= emolument && emolument < 25.83) {
150
+ return "正三品,担任职位:按察使、大理寺少卿";
151
+ }
152
+ if (25.83 <= emolument && emolument < 30) {
153
+ return "正二品,担任职位:六部侍郎、内务府总管";
154
+ }
155
+ if (emolument >= 30) {
156
+ return "正一品,担任职位:大学士、六部尚书";
157
+ }
158
+ return "您的工资为资深等级";
159
+ }
160
+ __name(QINGofficial, "QINGofficial");
161
+ function apply(ctx, config) {
162
+ const APIList = config.api.list;
163
+ const dynasty = transformDynasty.find(
164
+ (item) => item.key == config.conver.dynasty
165
+ );
166
+ const metal = transformMetal.find((item) => item.key == config.conver.metal)?.value || "XAU";
167
+ const currency = transformCurrency.find((item) => item.key == config.conver.currency)?.value || "USD";
168
+ ctx.command("elu").action(async ({ session }) => {
169
+ try {
170
+ const userId = session.userId;
171
+ const user = session.user;
172
+ await session.send("请输入您的工资(/月):");
173
+ let salary = await session.prompt();
174
+ if (!salary) return "输入超时。";
175
+ if (isNaN(Number(salary))) return "请输入一个数字。";
176
+ let salaryNum = Number(salary);
177
+ if (config.conver.currency == "人民币") {
178
+ salaryNum = Number((salaryNum / 7).toFixed(2));
179
+ }
180
+ const emolument = await sendEmolument(
181
+ ctx,
182
+ APIList,
183
+ salaryNum,
184
+ dynasty,
185
+ metal,
186
+ currency
187
+ );
188
+ const official = QINGofficial(Number(emolument));
189
+ if (metal == "XAG" && dynasty.value == "MING") {
190
+ await session.send(
191
+ `您在 ${dynasty.key}的 每月俸禄为: ${emolument} 两 ${config.conver.metal}子
192
+ 官至${official}`
193
+ );
194
+ } else {
195
+ await session.send(
196
+ `您在 ${dynasty.key}的 每月俸禄为: ${emolument} 两 ${config.conver.metal}子`
197
+ );
198
+ }
199
+ } catch (err) {
200
+ console.error("请求失败:", err);
201
+ }
202
+ }).alias("查询俸禄");
203
+ }
204
+ __name(apply, "apply");
205
+ async function sendEmolument(ctx, APIList, salaryNum, dynasty, metal, currency) {
206
+ for (const api of APIList) {
207
+ try {
208
+ var url = "https://www.goldapi.io/api/" + metal + "/" + currency;
209
+ const res = await ctx.http("get", url, {
210
+ headers: {
211
+ "x-access-token": api,
212
+ "Content-Type": "application/json"
213
+ }
214
+ });
215
+ const data = res.data;
216
+ const { price_gram_24k } = data;
217
+ let price = price_gram_24k.toFixed(2);
218
+ price = (dynasty.transform * price).toFixed(2);
219
+ const emolument = (salaryNum / price).toFixed(2);
220
+ return emolument;
221
+ } catch (err) {
222
+ console.error("请求失败:", err);
223
+ }
224
+ }
225
+ return "❌ 获取贵金属资讯失败,请稍后再试。";
226
+ }
227
+ __name(sendEmolument, "sendEmolument");
228
+ // Annotate the CommonJS export names for ESM import in node:
229
+ 0 && (module.exports = {
230
+ Config,
231
+ apply,
232
+ inject,
233
+ name,
234
+ usage
235
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-fenglu-mouth",
3
- "description": "",
4
- "version": "0.0.1",
3
+ "description": "Emolument Change Plugin",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -9,9 +9,9 @@
9
9
  "dist"
10
10
  ],
11
11
  "license": "MIT",
12
- "homepage": "https://github.com/snowwolfair/daynew",
12
+ "homepage": "https://github.com/snowwolfair/fenglu-mouth",
13
13
  "bugs": {
14
- "url": "https://github.com/snowwolfair/daynew/issues"
14
+ "url": "https://github.com/snowwolfair/fenglu-mouth/issues"
15
15
  },
16
16
  "scripts": {},
17
17
  "keywords": [
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "koishi": {
29
29
  "description": {
30
- "en": "Daily 60s News Plugin",
30
+ "en": "Emolument Change Plugin",
31
31
  "zh": "俸禄转换插件"
32
32
  },
33
33
  "service": {