-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.js
More file actions
60 lines (51 loc) · 2.1 KB
/
Copy pathcommands.js
File metadata and controls
60 lines (51 loc) · 2.1 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
53
54
55
56
57
58
59
60
/*
commands.js
Includes event handlers and message sending methods for both Discord and Telegram.
(C) Adam Gincel 2018
*/
const fs = require("fs");
const prefixes = JSON.parse(fs.readFileSync("./prefix.json", "utf8"));
const p = prefixes.telegram;
async function genericSendMessage(text, platformObject, bots) {
if (platformObject.platform == "telegram") {
return await bots.telegram.sendMessage(platformObject.chatID, text, {parse_mode: "Markdown"});
} else {
return await platformObject.message.channel.send(text);
}
}
async function genericEditMessage(text, platformObject, messageToEdit, bots) {
if (platformObject.platform == "telegram") {
return await bots.telegram.editMessageText(text, {chat_id: platformObject.chatID, message_id: messageToEdit.message_id, parse_mode: "Markdown"});
} else {
return await messageToEdit.edit(text);
}
}
function isCommand(args, name) {
return args[0] == p + name;
}
async function handle(text, args, platformObject, bots) {
//passthrough functions so you don't have to send redundant info each and every time
async function sendMessage (messageText) {
return await genericSendMessage(messageText, platformObject, bots);
}
async function editMessage(newText, messageToEdit) {
return await genericEditMessage(newText, platformObject, messageToEdit, bots);
}
function command(name) {
return isCommand(args, name);
}
//command replies
if (command("ping")) {
return await sendMessage("Hello, I am online.");
} else if (command("help")) {
let s = "Command Help:\n\n";
let prefix = platformObject.platform == "telegram" ? prefixes.telegram : prefixes.discord;
s += prefix + "ping - Check if the bot is online.\n";
s += prefix + "edittest - Send a message, then instantly edit it.\n";
return await sendMessage(s);
} else if (command("edittest")) {
let messageToEdit = await sendMessage("Hi, you shouldn't see this text for long.");
return await editMessage("You should see this message!", messageToEdit);
}
}
module.exports.handle = handle;