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-10-02 18:11:08 +00:00
|
|
|
const DiscordRPC = require("discord-rpc");
|
|
|
|
|
|
|
|
const CLIENT_ID = "1026163285877325874";
|
2022-08-28 00:14:10 +00:00
|
|
|
|
2022-08-27 23:27:05 +00:00
|
|
|
const token = process.argv[2];
|
2022-08-28 00:14:10 +00:00
|
|
|
|
2022-08-28 23:59:33 +00:00
|
|
|
process.title = "comcord";
|
|
|
|
|
2022-08-28 22:01:31 +00:00
|
|
|
global.comcord = {
|
|
|
|
state: {
|
2022-10-02 16:25:59 +00:00
|
|
|
startTime: Date.now(),
|
2022-08-28 22:01:31 +00:00
|
|
|
currentGuild: null,
|
|
|
|
currentChannel: null,
|
|
|
|
nameLength: 2,
|
|
|
|
inPrompt: false,
|
|
|
|
messageQueue: [],
|
|
|
|
lastChannel: new Map(),
|
2022-10-02 16:25:59 +00:00
|
|
|
afk: false,
|
2022-08-28 22:01:31 +00:00
|
|
|
},
|
|
|
|
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;
|
2022-10-02 18:11:08 +00:00
|
|
|
const rpc = new DiscordRPC.Client({transport: "ipc"});
|
|
|
|
comcord.rpc = rpc;
|
2022-08-28 22:01:31 +00:00
|
|
|
|
|
|
|
const {finalizePrompt} = require("./lib/prompt");
|
|
|
|
const {processMessage, processQueue} = require("./lib/messages");
|
2022-10-02 18:11:08 +00:00
|
|
|
const {updatePresence} = require("./lib/presence");
|
2022-08-28 22:01:31 +00:00
|
|
|
|
|
|
|
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
|
2022-10-02 16:25:59 +00:00
|
|
|
require("./commands/afk");
|
2022-08-28 22:01:31 +00:00
|
|
|
|
|
|
|
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-10-02 16:25:59 +00:00
|
|
|
|
|
|
|
client.editStatus("online", [
|
|
|
|
{
|
2022-10-02 18:11:08 +00:00
|
|
|
application_id: CLIENT_ID,
|
2022-10-02 16:25:59 +00:00
|
|
|
name: "comcord",
|
|
|
|
timestamps: {
|
|
|
|
start: comcord.state.startTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
2022-10-02 18:11:08 +00:00
|
|
|
|
|
|
|
rpc
|
|
|
|
.login({
|
|
|
|
clientId: CLIENT_ID,
|
|
|
|
})
|
|
|
|
.catch(function () {});
|
2022-08-27 23:27:05 +00:00
|
|
|
});
|
2022-09-04 16:42:35 +00:00
|
|
|
client.on("error", function () {});
|
2022-08-27 23:27:05 +00:00
|
|
|
|
2022-10-02 19:17:31 +00:00
|
|
|
rpc.on("connected", function () {
|
2022-10-02 18:11:08 +00:00
|
|
|
updatePresence();
|
|
|
|
});
|
2022-10-02 19:17:31 +00:00
|
|
|
rpc.once("ready", function () {
|
|
|
|
rpc.transport.on("close", async function () {
|
|
|
|
try {
|
|
|
|
await rpc.transport.connect();
|
|
|
|
} catch (err) {
|
|
|
|
rpc.transport.emit("close");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-10-02 18:11:08 +00:00
|
|
|
rpc.on("error", function () {});
|
|
|
|
|
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-10-02 16:17:39 +00:00
|
|
|
processMessage(msg);
|
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 {
|
2022-10-02 16:17:39 +00:00
|
|
|
processMessage(msg);
|
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 {
|
2022-08-28 23:20:01 +00:00
|
|
|
if (key === "\b" || key === "\u007f") {
|
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-09-03 00:21:00 +00:00
|
|
|
key = key.replace("\u001b", "");
|
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");
|
2022-09-03 00:21:25 +00:00
|
|
|
|
|
|
|
const dateObj = new Date();
|
|
|
|
let sentTime = false;
|
|
|
|
|
|
|
|
const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
|
|
const months = [
|
|
|
|
"Jan",
|
|
|
|
"Feb",
|
|
|
|
"Mar",
|
|
|
|
"Apr",
|
|
|
|
"May",
|
|
|
|
"Jun",
|
|
|
|
"Jul",
|
|
|
|
"Aug",
|
|
|
|
"Sep",
|
|
|
|
"Oct",
|
|
|
|
"Nov",
|
|
|
|
"Dec",
|
|
|
|
];
|
|
|
|
|
|
|
|
setInterval(function () {
|
|
|
|
dateObj.setTime(Date.now());
|
|
|
|
|
|
|
|
const hour = dateObj.getUTCHours(),
|
|
|
|
minutes = dateObj.getUTCMinutes(),
|
|
|
|
seconds = dateObj.getUTCSeconds(),
|
|
|
|
day = dateObj.getUTCDate(),
|
|
|
|
month = dateObj.getUTCMonth(),
|
|
|
|
year = dateObj.getUTCFullYear(),
|
|
|
|
weekDay = dateObj.getUTCDay();
|
|
|
|
|
|
|
|
const timeString = `[${weekdays[weekDay]} ${day
|
|
|
|
.toString()
|
|
|
|
.padStart(2, "0")}-${months[month]}-${year
|
|
|
|
.toString()
|
|
|
|
.substring(2, 4)} ${hour.toString().padStart(2, "0")}:${minutes
|
|
|
|
.toString()
|
|
|
|
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}]`;
|
|
|
|
|
|
|
|
if (minutes % 15 == 0 && seconds < 2 && !sentTime) {
|
|
|
|
if (comcord.state.inPrompt == true) {
|
|
|
|
comcord.state.messageQueue.push({time: true, content: timeString});
|
|
|
|
} else {
|
|
|
|
console.log(timeString);
|
|
|
|
}
|
|
|
|
sentTime = true;
|
|
|
|
} else if (seconds > 2 && sentTime) {
|
|
|
|
sentTime = false;
|
|
|
|
}
|
|
|
|
}, 500);
|