-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
84 lines (73 loc) · 2.37 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Api } from "$grm";
import { CommandHandler, updateMessage } from "$xor";
export default {
name: "paste",
handlers: [
new CommandHandler(
"paste",
async ({ client, event }) => {
const reply = await event.message.getReplyMessage();
const media = reply?.media;
if (!reply || (!media && !reply?.message)) {
await updateMessage(event, "Reply to a text message or a text file.");
return;
}
let content: string;
if (
media instanceof Api.MessageMediaDocument &&
media.document instanceof Api.Document &&
(["video/mpeg", "video/mp2t"].includes(media.document.mimeType) ||
media.document.mimeType.startsWith("text/") ||
media.document.mimeType.startsWith("application/")) &&
media.document.size.lt(65537)
) {
const result = await client.downloadMedia(media);
if (!result) {
await updateMessage(event, "Failed to download the text file.");
return;
}
content = typeof result === "string" ? result : result.toString();
} else {
if (reply?.message) {
content = reply.message;
} else {
await updateMessage(event, "Invalid data");
return;
}
}
const response = await fetch("https://nekobin.com/api/documents", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content: content }),
});
if (!response.ok) {
await client.sendMessage(event.chatId!, {
replyTo: event.message.id,
message: `Error: ${response.status} ${response.statusText}`,
linkPreview: false,
});
return;
}
const data = await response.json();
if (!data.ok) {
await client.sendMessage(event.chatId!, {
replyTo: event.message.id,
message: `Error: ${data.error}`,
linkPreview: false,
});
return;
}
await client.sendMessage(event.chatId!, {
replyTo: reply.id,
message: `https://nekobin.com/${data.result.key}`,
linkPreview: false,
});
},
),
],
help: `
**Introduction**
Paste messages and text files to nekobin.com.
**Commands**
- paste`,
};