Add time_and_date plugin. Use it for timezones and date formats around the bot.
This commit is contained in:
parent
cffb0dbd6b
commit
4ae8cf85a3
67 changed files with 543 additions and 177 deletions
|
@ -6,6 +6,7 @@ import { postDueRemindersLoop } from "./utils/postDueRemindersLoop";
|
|||
import { RemindCmd } from "./commands/RemindCmd";
|
||||
import { RemindersCmd } from "./commands/RemindersCmd";
|
||||
import { RemindersDeleteCmd } from "./commands/RemindersDeleteCmd";
|
||||
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
const defaultOptions: PluginOptions<RemindersPluginType> = {
|
||||
config: {
|
||||
|
@ -27,6 +28,7 @@ export const RemindersPlugin = zeppelinPlugin<RemindersPluginType>()("reminders"
|
|||
prettyName: "Reminders",
|
||||
},
|
||||
|
||||
dependencies: [TimeAndDatePlugin],
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@ import { convertDelayStringToMS, messageLink } from "src/utils";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { remindersCommand } from "../types";
|
||||
import { getGuildTz, inGuildTz } from "../../../utils/timezones";
|
||||
import { getDateFormat } from "../../../utils/dateFormats";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
export const RemindCmd = remindersCommand({
|
||||
trigger: ["remind", "remindme"],
|
||||
|
@ -18,8 +17,10 @@ export const RemindCmd = remindersCommand({
|
|||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
const now = moment.utc();
|
||||
const tz = getGuildTz(pluginData);
|
||||
const tz = await timeAndDate.getMemberTz(msg.author.id);
|
||||
|
||||
let reminderTime: moment.Moment;
|
||||
if (args.time.match(/^\d{4}-\d{1,2}-\d{1,2}$/)) {
|
||||
|
@ -62,7 +63,10 @@ export const RemindCmd = remindersCommand({
|
|||
|
||||
const msUntilReminder = reminderTime.diff(now);
|
||||
const timeUntilReminder = humanizeDuration(msUntilReminder, { largest: 2, round: true });
|
||||
const prettyReminderTime = inGuildTz(pluginData, reminderTime).format(getDateFormat(pluginData, "pretty_datetime"));
|
||||
const prettyReminderTime = (await timeAndDate.inMemberTz(msg.author.id, reminderTime)).format(
|
||||
pluginData.getPlugin(TimeAndDatePlugin).getDateFormat("pretty_datetime"),
|
||||
);
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { remindersCommand } from "../types";
|
||||
import { sendErrorMessage } from "src/pluginUtils";
|
||||
import { createChunkedMessage, sorter } from "src/utils";
|
||||
import { createChunkedMessage, DBDateFormat, sorter } from "src/utils";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { inGuildTz } from "../../../utils/timezones";
|
||||
import { DBDateFormat, getDateFormat } from "../../../utils/dateFormats";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
export const RemindersCmd = remindersCommand({
|
||||
trigger: "reminders",
|
||||
|
@ -17,6 +16,8 @@ export const RemindersCmd = remindersCommand({
|
|||
return;
|
||||
}
|
||||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
reminders.sort(sorter("remind_at"));
|
||||
const longestNum = (reminders.length + 1).toString().length;
|
||||
const lines = Array.from(reminders.entries()).map(([i, reminder]) => {
|
||||
|
@ -25,9 +26,9 @@ export const RemindersCmd = remindersCommand({
|
|||
const target = moment.utc(reminder.remind_at, "YYYY-MM-DD HH:mm:ss");
|
||||
const diff = target.diff(moment.utc());
|
||||
const result = humanizeDuration(diff, { largest: 2, round: true });
|
||||
const prettyRemindAt = inGuildTz(pluginData, moment.utc(reminder.remind_at, DBDateFormat)).format(
|
||||
getDateFormat(pluginData, "pretty_datetime"),
|
||||
);
|
||||
const prettyRemindAt = timeAndDate
|
||||
.inGuildTz(moment.utc(reminder.remind_at, DBDateFormat))
|
||||
.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
return `\`${paddedNum}.\` \`${prettyRemindAt} (${result})\` ${reminder.body}`;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue