2022-08-27 23:27:05 +00:00
|
|
|
const Eris = require("eris");
|
2022-08-28 00:14:10 +00:00
|
|
|
const chalk = require("chalk");
|
|
|
|
|
2022-08-27 23:27:05 +00:00
|
|
|
const token = process.argv[2];
|
2022-08-28 00:14:10 +00:00
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
global.comcord = {
|
|
|
|
state: {
|
|
|
|
currentGuild: null,
|
|
|
|
currentChannel: null,
|
|
|
|
nameLength: 2,
|
|
|
|
inPrompt: false,
|
|
|
|
messageQueue: [],
|
|
|
|
lastChannel: new Map(),
|
|
|
|
},
|
|
|
|
commands: {},
|
2022-08-28 00:49:02 +00:00
|
|
|
};
|
2022-08-27 23:27:05 +00:00
|
|
|
const client = new Eris("Bot " + token, {
|
|
|
|
defaultImageFormat: "png",
|
|
|
|
defaultImageSize: 1024,
|
|
|
|
intents: Eris.Constants.Intents.all,
|
|
|
|
});
|
2022-08-28 22:01:31 +00:00
|
|
|
comcord.client = client;
|
|
|
|
|
|
|
|
const {finalizePrompt} = require("./lib/prompt");
|
|
|
|
const {processMessage, processQueue} = require("./lib/messages");
|
|
|
|
|
|
|
|
require("./commands/quit");
|
|
|
|
require("./commands/clear");
|
|
|
|
require("./commands/help");
|
|
|
|
const {sendMode} = require("./commands/send");
|
|
|
|
require("./commands/emote");
|
|
|
|
const {listGuilds} = require("./commands/listGuilds");
|
|
|
|
require("./commands/switchGuild"); // loads listChannels and listUsers
|
|
|
|
require("./commands/switchChannel"); //loads listUsers
|
|
|
|
require("./commands/history"); // includes extended history
|
|
|
|
|
|
|
|
process.stdin.setRawMode(true);
|
|
|
|
process.stdin.resume();
|
|
|
|
process.stdin.setEncoding("utf8");
|
2022-08-27 23:27:05 +00:00
|
|
|
|
|
|
|
client.once("ready", function () {
|
|
|
|
console.log(
|
2022-08-28 00:14:10 +00:00
|
|
|
"Logged in as: " +
|
|
|
|
chalk.yellow(
|
|
|
|
`${client.user.username}#${client.user.discriminator} (${client.user.id})`
|
|
|
|
)
|
2022-08-27 23:27:05 +00:00
|
|
|
);
|
2022-08-28 22:01:31 +00:00
|
|
|
comcord.state.nameLength = client.user.username.length + 2;
|
2022-08-28 01:53:55 +00:00
|
|
|
|
|
|
|
listGuilds();
|
2022-08-27 23:27:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
client.on("messageCreate", function (msg) {
|
2022-08-28 02:13:25 +00:00
|
|
|
if (msg.author.id === client.user.id) return;
|
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
if (msg.channel.id == comcord.state.currentChannel) {
|
|
|
|
if (comcord.state.inPrompt) {
|
|
|
|
comcord.state.messageQueue.push(msg);
|
2022-08-27 23:27:05 +00:00
|
|
|
} else {
|
2022-08-28 00:14:10 +00:00
|
|
|
if (msg.content.indexOf("\n") > -1) {
|
|
|
|
const lines = msg.content.split("\n");
|
2022-08-28 02:43:00 +00:00
|
|
|
for (const index in lines) {
|
|
|
|
const line = lines[index];
|
2022-08-28 00:14:10 +00:00
|
|
|
processMessage({
|
2022-08-28 02:13:25 +00:00
|
|
|
name: msg.author.username,
|
2022-08-28 00:14:10 +00:00
|
|
|
bot: msg.author.bot,
|
|
|
|
content: line,
|
2022-08-28 15:12:26 +00:00
|
|
|
attachments: index == lines.length - 1 ? msg.attachments : [],
|
2022-08-28 02:57:40 +00:00
|
|
|
reply: index == 0 ? msg.referencedMessage : null,
|
2022-08-28 00:14:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
processMessage({
|
2022-08-28 02:13:25 +00:00
|
|
|
name: msg.author.username,
|
2022-08-28 00:14:10 +00:00
|
|
|
bot: msg.author.bot,
|
|
|
|
content: msg.content,
|
2022-08-28 02:43:00 +00:00
|
|
|
attachments: msg.attachments,
|
2022-08-28 02:57:40 +00:00
|
|
|
reply: msg.referencedMessage,
|
2022-08-28 02:43:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
client.on("messageUpdate", function (msg, old) {
|
|
|
|
if (msg.author.id === client.user.id) return;
|
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
if (msg.channel.id == comcord.state.currentChannel) {
|
2022-08-28 02:43:00 +00:00
|
|
|
if (msg.content == old.content) return;
|
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
if (comcord.state.inPrompt) {
|
|
|
|
comcord.state.messageQueue.push(msg);
|
2022-08-28 02:43:00 +00:00
|
|
|
} else {
|
|
|
|
if (msg.content.indexOf("\n") > -1) {
|
|
|
|
const lines = msg.content.split("\n");
|
|
|
|
for (const index in lines) {
|
|
|
|
const line = lines[index];
|
|
|
|
processMessage({
|
|
|
|
name: msg.author.username,
|
|
|
|
bot: msg.author.bot,
|
2022-08-28 15:12:26 +00:00
|
|
|
content: line + (index == lines.length - 1 ? " (edited)" : ""),
|
|
|
|
attachments: index == lines.length - 1 ? msg.attachments : [],
|
2022-08-28 02:57:40 +00:00
|
|
|
reply: index == 0 ? msg.referencedMessage : null,
|
2022-08-28 02:43:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
processMessage({
|
|
|
|
name: msg.author.username,
|
|
|
|
bot: msg.author.bot,
|
|
|
|
content: msg.content + " (edited)",
|
|
|
|
attachments: msg.attachments,
|
2022-08-28 02:57:40 +00:00
|
|
|
reply: msg.referencedMessage,
|
2022-08-28 00:14:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
process.stdin.on("data", async function (key) {
|
|
|
|
if (comcord.state.inPrompt) {
|
2022-08-28 03:22:06 +00:00
|
|
|
if (key === "\r") {
|
2022-08-28 22:01:31 +00:00
|
|
|
await finalizePrompt();
|
|
|
|
processQueue();
|
2022-08-28 03:22:06 +00:00
|
|
|
} else {
|
|
|
|
if (key === "\b") {
|
2022-08-28 22:01:31 +00:00
|
|
|
if (comcord.state.promptInput.length > 0) {
|
|
|
|
process.stdout.moveCursor(-1);
|
|
|
|
process.stdout.write(" ");
|
|
|
|
process.stdout.moveCursor(-1);
|
|
|
|
comcord.state.promptInput = comcord.state.promptInput.substring(
|
|
|
|
0,
|
|
|
|
comcord.state.promptInput.length - 1
|
|
|
|
);
|
2022-08-28 03:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-28 22:01:31 +00:00
|
|
|
process.stdout.write(key);
|
|
|
|
comcord.state.promptInput += key;
|
2022-08-28 03:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-28 00:14:10 +00:00
|
|
|
} else {
|
2022-08-28 22:01:31 +00:00
|
|
|
if (comcord.commands[key]) {
|
|
|
|
comcord.commands[key].callback();
|
|
|
|
} else {
|
|
|
|
sendMode();
|
2022-08-27 23:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.connect();
|
2022-08-28 00:49:02 +00:00
|
|
|
|
|
|
|
console.log("COMcord (c)left 2022");
|
|
|
|
console.log("Type 'h' for Commands");
|