Skip to content

Commit 62ce22e

Browse files
feat: update mjx
1 parent 99a6817 commit 62ce22e

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/commands.js

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const MO_COMMAND = {
1313
description: '摸鱼办',
1414
};
1515

16+
export const MJX_COMMAND = {
17+
name: 'mjx',
18+
description: '买家秀随机一图',
19+
};
20+
1621
export const AI_TEXT_COMMAND = {
1722
name: 'ai_text',
1823
description: 'AI 文本',

src/register.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SE_COMMAND, MO_COMMAND, AI_TEXT_COMMAND } from './commands.js';
1+
import { SE_COMMAND, MO_COMMAND, MJX_COMMAND } from './commands.js';
22
import dotenv from 'dotenv';
33
import process from 'node:process';
44

@@ -34,7 +34,7 @@ const response = await fetch(url, {
3434
Authorization: `Bot ${token}`,
3535
},
3636
method: 'PUT',
37-
body: JSON.stringify([SE_COMMAND, MO_COMMAND]),
37+
body: JSON.stringify([SE_COMMAND, MO_COMMAND, MJX_COMMAND]),
3838
});
3939

4040
if (response.ok) {

src/server.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
InteractionType,
99
verifyKey,
1010
} from 'discord-interactions';
11-
import { SE_COMMAND, MO_COMMAND, AI_TEXT_COMMAND } from './commands.js';
11+
import { SE_COMMAND, MO_COMMAND, MJX_COMMAND, AI_TEXT_COMMAND } from './commands.js';
1212
import { Ai } from '@cloudflare/ai'
1313

1414
class JsonResponse extends Response {
@@ -65,7 +65,7 @@ router.post('/', async (request, env) => {
6565
}
6666
});
6767
const url = await response.json();
68-
console.log('Get url: ' + url);
68+
console.log('SE_COMMAND url: ' + url);
6969
return new JsonResponse({
7070
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
7171
data: {
@@ -74,12 +74,7 @@ router.post('/', async (request, env) => {
7474
});
7575
}
7676
case MO_COMMAND.name.toLowerCase(): {
77-
const response = await fetch(env.MOYU_URL, {
78-
"headers": {
79-
"accept": "*/*",
80-
},
81-
"method": "GET"
82-
});
77+
const response = await fetch(env.MOYU_URL);
8378
const text = await response.text();
8479
return new JsonResponse({
8580
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
@@ -88,6 +83,22 @@ router.post('/', async (request, env) => {
8883
},
8984
});
9085
}
86+
case MJX_COMMAND.name.toLowerCase(): {
87+
const response = await fetch(env.UOMG_URL, {
88+
method: 'GET',
89+
headers: {
90+
"Content-Type": "application/json",
91+
}
92+
});
93+
const data = await response.json();
94+
console.log('MJX_COMMAND data: ' + data);
95+
return new JsonResponse({
96+
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
97+
data: {
98+
content: data["imgurl"],
99+
},
100+
});
101+
}
91102
case AI_TEXT_COMMAND.name.toLowerCase(): {
92103
if (!interaction.data.content) {
93104
return new JsonResponse({

wrangler.toml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ routes = [
88
[vars]
99
API_URL = "https://awsl.api.awsl.icu"
1010
MOYU_URL = "https://moyu.awsl.icu/api/moyu_txt"
11+
UOMG_URL = "https://api.uomg.com/api/rand.img3?format=json"
12+
1113

1214
# [secrets]
1315
# DISCORD_TOKEN

0 commit comments

Comments
 (0)