-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
75 lines (64 loc) · 1.73 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
import { CustomFile } from "$grm";
import { Buffer } from "$grm-deps";
import { bold, CommandHandler, fmt, Module, updateMessage } from "$xor";
import { GTR } from "https://deno.land/x/[email protected]/mod.ts";
const i = new GTR();
const gtr: Module = {
name: "gtr",
handlers: [
new CommandHandler(
"t",
async ({ event, args, input }) => {
if (!input) {
return;
}
const result = await i.translate(input, {
targetLang: args[0],
sourceLang: args[1],
});
await updateMessage(event, result.lang);
await event.message.reply({ message: result.trans });
},
),
new CommandHandler(
"s",
async ({ event, args, input }) => {
const targetLang = args[0];
if (!input || !targetLang) {
return;
}
const b = Buffer.from(
await (await i.tts(input, { targetLang }))
.arrayBuffer(),
);
const file = new CustomFile(
"s.mp3",
b.byteLength,
"",
b,
);
await event.message.reply({ file });
},
),
new CommandHandler(
"d",
async ({ event, input }) => {
if (!input) {
return;
}
const lang = await i.detect(input);
await updateMessage(event, lang);
},
),
],
help: fmt`${bold("Introduction")}
Translate messages and convert text to speech.
${bold("Commands")}
- t (<target_lang>) (<source_lang>)
Takes the input as <source_lang> or detect it if not provided, and then translates it to <target_lang> or en if not provided.
- s <target_lang>
Converts the input in <target_lang> to speech.
- d
Detects the language of the input.`,
};
export default gtr;