-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
52 lines (46 loc) · 1.34 KB
/
index.ts
File metadata and controls
52 lines (46 loc) · 1.34 KB
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
import Devzat from "../dist";
const plugin = new Devzat({
address: process.env.DEVZAT_ADDRESS,
name: "Demo bot",
token: process.env.DEVZAT_TOKEN
});
const destruct = plugin.onMessageSend({
middleware: true,
once: false,
regex: /([A-Z])\w+/g // regex to match all words in title case
}, message => {
console.log("new message!", message);
if(message.msg === "DESTRUCT") {
destruct();
return "destructing";
}
if(!message.msg.startsWith("demo-bot ")) {
return message.msg + " TESTING";
}
});
plugin.onMessageSend({
middleware: false,
once: true
}, message => {
console.log("got a message once", message);
});
plugin.command({
name: "demo-bot",
argsInfo: "<msg | \"send-test\" | \"ephemeral-test\">",
info: "Ping the demo bot"
}, async invocation => {
console.log("got a command", invocation);
if(invocation.args === "send-test") {
setInterval(() => plugin.sendMessage({
room: "#main",
msg: "Hello world!"
}), 4000);
return "Set interval!";
} else if(invocation.args === "ephemeral-test") {
await plugin.sendMessage({
room: invocation.room,
msg: "Pong!",
ephemeralTo: invocation.from
});
} else return `Hello, ${invocation.from}! You said: ${invocation.args}`;
})