2022-10-10 03:15:53 +00:00
|
|
|
const chalk = require("chalk");
|
|
|
|
|
|
|
|
const {addCommand} = require("../lib/command");
|
|
|
|
const {startPrompt} = require("../lib/prompt");
|
|
|
|
const {listUsers} = require("./listUsers");
|
|
|
|
|
|
|
|
function startDM(user) {
|
|
|
|
startPrompt(":msg> ", async function (input) {
|
|
|
|
if (input == "") {
|
2023-05-31 03:03:44 +00:00
|
|
|
console.log(`\n<message not sent to ${user.username}>`);
|
2022-10-10 03:15:53 +00:00
|
|
|
} else {
|
|
|
|
try {
|
2023-05-31 03:03:44 +00:00
|
|
|
const channel = await comcord.client.getDMChannel(user.id);
|
2022-10-10 03:15:53 +00:00
|
|
|
await channel.createMessage({content: input});
|
2023-05-31 03:03:44 +00:00
|
|
|
console.log(chalk.bold.green(`\n<message sent to ${user.username}>`));
|
2022-10-10 03:15:53 +00:00
|
|
|
} catch (err) {
|
2023-05-31 03:03:44 +00:00
|
|
|
console.log(`\n<failed to send message: ${err.message}>`);
|
2022-10-10 03:15:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addCommand("s", "send private", function () {
|
|
|
|
console.log("Provide a RECIPIENT");
|
|
|
|
startPrompt(":to> ", function (who) {
|
|
|
|
let target;
|
|
|
|
for (const user of comcord.client.users.values()) {
|
2023-05-31 03:03:44 +00:00
|
|
|
if (user.username == who) {
|
2022-10-10 03:15:53 +00:00
|
|
|
target = user;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
console.log("");
|
|
|
|
startDM(target);
|
|
|
|
} else {
|
|
|
|
listUsers();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
addCommand("a", "answer a send", function () {
|
|
|
|
if (comcord.state.lastDM) {
|
2023-05-31 03:03:44 +00:00
|
|
|
console.log(
|
|
|
|
chalk.bold.green(`<answering ${comcord.state.lastDM.username}>`)
|
|
|
|
);
|
2022-10-10 03:15:53 +00:00
|
|
|
startDM(comcord.state.lastDM);
|
|
|
|
} else {
|
|
|
|
// FIXME: figure out the actual message in com
|
|
|
|
console.log("<no one to answer>");
|
|
|
|
}
|
|
|
|
});
|