kokkoro-plugin-kfc 3.0.1 → 3.0.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # kokkoro-plugin-kfc
2
2
 
3
- vivo 50
3
+ 肯德基网络梗,随机获取一条疯狂星期四文案。
4
4
 
5
5
  ## 安装
6
6
 
@@ -26,4 +26,17 @@ bun add kokkoro-plugin-kfc
26
26
 
27
27
  北京时间每周四,消息中出现「麦当劳」、「金拱门」、「华莱士」、「汉堡王」、「德克士」或「塔斯汀」时,也会随机返回一条疯狂星期四文案。
28
28
 
29
+ > [!WARNING]
30
+ > 快捷方式会在整段消息中查找关键词,因此链接地址中包含 `v50` 或 `kfc` 时也可能触发插件。该问题将在后续版本中优化。
31
+
29
32
  群聊需要开启「获取群内全部消息」权限。
33
+
34
+ ## API
35
+
36
+ 其他插件可以从 `service` 入口导入 `fetchCrazyThursday()`。该函数返回疯狂星期四接口的完整响应:
37
+
38
+ ```typescript
39
+ import { fetchCrazyThursday } from 'kokkoro-plugin-kfc/service';
40
+
41
+ const result = await fetchCrazyThursday();
42
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kokkoro-plugin-kfc",
3
- "version": "3.0.1",
4
- "description": "vivo 50",
3
+ "version": "3.0.2",
4
+ "description": "肯德基网络梗,随机获取一条疯狂星期四文案。",
5
5
  "keywords": [
6
6
  "bot",
7
7
  "kokkoro",
@@ -17,12 +17,15 @@
17
17
  "license": "MIT",
18
18
  "author": "Yuki <admin@yuki.sh>",
19
19
  "type": "module",
20
- "exports": "./src/index.ts",
20
+ "exports": {
21
+ ".": "./src/index.ts",
22
+ "./service": "./src/service.ts"
23
+ },
21
24
  "files": [
22
25
  "src"
23
26
  ],
24
27
  "peerDependencies": {
25
- "@kokkoro/core": "^3.1.3",
28
+ "@kokkoro/core": "^3.1.4",
26
29
  "typescript": "^6.0.3"
27
30
  }
28
31
  }
package/src/index.ts CHANGED
@@ -1,12 +1,8 @@
1
- import { useCommand } from '@kokkoro/core';
1
+ import { useCommand, useLogger } from '@kokkoro/core';
2
2
 
3
- interface CrazyThursday {
4
- readonly success: boolean;
5
- readonly message: string;
6
- readonly text: string;
7
- }
3
+ import { fetchCrazyThursday, KFC_API } from './service';
8
4
 
9
- const KFC_API = new URL('https://kfc.yuki.sh');
5
+ const logger = useLogger();
10
6
 
11
7
  const PAYMENT = /(?:vivo|[v微]\s*(?:我|me)?)\s*(?:50|五十)/i;
12
8
  const KFC = /(?:肯德基|kfc)/i;
@@ -20,17 +16,6 @@ const WEEKDAY_FORMAT = new Intl.DateTimeFormat('en-US', {
20
16
  weekday: 'long',
21
17
  });
22
18
 
23
- async function getCrazyThursday() {
24
- const response = await fetch(KFC_API);
25
-
26
- if (!response.ok) {
27
- throw new Error(`接口请求失败,状态码 ${response.status}`);
28
- }
29
- const { success, message, text } = <CrazyThursday>await response.json();
30
-
31
- return success ? text : message;
32
- }
33
-
34
19
  function shouldTrigger(content: string) {
35
20
  if (KEYWORDS.some(pattern => pattern.test(content))) {
36
21
  return true;
@@ -39,9 +24,16 @@ function shouldTrigger(content: string) {
39
24
  }
40
25
 
41
26
  export default () => {
42
- useCommand('/疯狂星期四', context => {
27
+ useCommand('/疯狂星期四', async context => {
43
28
  if (shouldTrigger(context.content)) {
44
- return getCrazyThursday();
29
+ logger.debug('发送疯狂星期四请求', { method: 'GET', url: KFC_API });
30
+
31
+ const result = await fetchCrazyThursday();
32
+
33
+ logger.debug('收到疯狂星期四响应', result);
34
+ logger.info('已获取疯狂星期四文案');
35
+
36
+ return result.success ? result.text : result.message;
45
37
  }
46
38
  }).shortcut(SHORTCUT);
47
39
  };
package/src/service.ts ADDED
@@ -0,0 +1,17 @@
1
+ export interface CrazyThursday {
2
+ readonly success: boolean;
3
+ readonly message: string;
4
+ readonly text: string;
5
+ }
6
+
7
+ export const KFC_API = 'https://kfc.yuki.sh';
8
+
9
+ /** 请求随机的疯狂星期四文案,并返回完整的接口响应。 */
10
+ export async function fetchCrazyThursday(): Promise<CrazyThursday> {
11
+ const response = await fetch(KFC_API);
12
+
13
+ if (!response.ok) {
14
+ throw new Error(`接口请求失败,状态码 ${response.status}`);
15
+ }
16
+ return <CrazyThursday>await response.json();
17
+ }