mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Finish preliminary rework, ready to test
This commit is contained in:
parent
57893e7f76
commit
d0a1beb809
177 changed files with 854 additions and 707 deletions
|
@ -8,6 +8,7 @@ import { PostPluginType } from "../types";
|
|||
import { parseScheduleTime } from "./parseScheduleTime";
|
||||
import { postMessage } from "./postMessage";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { Message, Channel, TextChannel } from "discord.js";
|
||||
|
||||
const MIN_REPEAT_TIME = 5 * MINUTES;
|
||||
const MAX_REPEAT_TIME = Math.pow(2, 32);
|
||||
|
@ -27,22 +28,30 @@ export async function actualPostCmd(
|
|||
} = {},
|
||||
) {
|
||||
if (!(targetChannel instanceof TextChannel)) {
|
||||
msg.channel.createMessage(errorMessage("Channel is not a text channel"));
|
||||
msg.channel.send(errorMessage("Channel is not a text channel"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (content == null && msg.attachments.length === 0) {
|
||||
msg.channel.createMessage(errorMessage("Message content or attachment required"));
|
||||
if (content == null && msg.attachments.size === 0) {
|
||||
msg.channel.send(errorMessage("Message content or attachment required"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.repeat) {
|
||||
if (opts.repeat < MIN_REPEAT_TIME) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Minimum time for -repeat is ${humanizeDuration(MIN_REPEAT_TIME)}`);
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
`Minimum time for -repeat is ${humanizeDuration(MIN_REPEAT_TIME)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (opts.repeat > MAX_REPEAT_TIME) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Max time for -repeat is ${humanizeDuration(MAX_REPEAT_TIME)}`);
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
`Max time for -repeat is ${humanizeDuration(MAX_REPEAT_TIME)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +62,7 @@ export async function actualPostCmd(
|
|||
// Schedule the post to be posted later
|
||||
postAt = await parseScheduleTime(pluginData, msg.author.id, opts.schedule);
|
||||
if (!postAt) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid schedule time");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid schedule time");
|
||||
return;
|
||||
}
|
||||
} else if (opts.repeat) {
|
||||
|
@ -70,17 +79,17 @@ export async function actualPostCmd(
|
|||
|
||||
// Invalid time
|
||||
if (!repeatUntil) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid time specified for -repeat-until");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid time specified for -repeat-until");
|
||||
return;
|
||||
}
|
||||
if (repeatUntil.isBefore(moment.utc())) {
|
||||
sendErrorMessage(pluginData, msg.channel, "You can't set -repeat-until in the past");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "You can't set -repeat-until in the past");
|
||||
return;
|
||||
}
|
||||
if (repeatUntil.isAfter(MAX_REPEAT_UNTIL)) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
"Unfortunately, -repeat-until can only be at most 100 years into the future. Maybe 99 years would be enough?",
|
||||
);
|
||||
return;
|
||||
|
@ -88,18 +97,26 @@ export async function actualPostCmd(
|
|||
} else if (opts["repeat-times"]) {
|
||||
repeatTimes = opts["repeat-times"];
|
||||
if (repeatTimes <= 0) {
|
||||
sendErrorMessage(pluginData, msg.channel, "-repeat-times must be 1 or more");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "-repeat-times must be 1 or more");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (repeatUntil && repeatTimes) {
|
||||
sendErrorMessage(pluginData, msg.channel, "You can only use one of -repeat-until or -repeat-times at once");
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
"You can only use one of -repeat-until or -repeat-times at once",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts.repeat && !repeatUntil && !repeatTimes) {
|
||||
sendErrorMessage(pluginData, msg.channel, "You must specify -repeat-until or -repeat-times for repeated messages");
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
"You must specify -repeat-until or -repeat-times for repeated messages",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -114,7 +131,7 @@ export async function actualPostCmd(
|
|||
// Save schedule/repeat information in DB
|
||||
if (postAt) {
|
||||
if (postAt < moment.utc()) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Post can't be scheduled to be posted in the past");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Post can't be scheduled to be posted in the past");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,7 +140,7 @@ export async function actualPostCmd(
|
|||
author_name: `${msg.author.username}#${msg.author.discriminator}`,
|
||||
channel_id: targetChannel.id,
|
||||
content,
|
||||
attachments: msg.attachments,
|
||||
attachments: msg.attachments.array(),
|
||||
post_at: postAt
|
||||
.clone()
|
||||
.tz("Etc/UTC")
|
||||
|
@ -162,7 +179,7 @@ export async function actualPostCmd(
|
|||
|
||||
// When the message isn't scheduled for later, post it immediately
|
||||
if (!opts.schedule) {
|
||||
await postMessage(pluginData, targetChannel, content, msg.attachments, opts["enable-mentions"]);
|
||||
await postMessage(pluginData, targetChannel, content, msg.attachments.array(), opts["enable-mentions"]);
|
||||
}
|
||||
|
||||
if (opts.repeat) {
|
||||
|
@ -197,6 +214,6 @@ export async function actualPostCmd(
|
|||
}
|
||||
|
||||
if (targetChannel.id !== msg.channel.id || opts.schedule || opts.repeat) {
|
||||
sendSuccessMessage(pluginData, msg.channel, successMessage);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, successMessage);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue