mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Add support for server-specific timezone and date format settings
This commit is contained in:
parent
ddbbc543c2
commit
c67a1df11d
51 changed files with 326 additions and 168 deletions
|
@ -5,7 +5,7 @@ import crypto from "crypto";
|
|||
import moment from "moment-timezone";
|
||||
// tslint:disable-next-line:no-submodule-imports
|
||||
import uuidv4 from "uuid/v4";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { DBDateFormat } from "../utils/dateFormats";
|
||||
|
||||
export class ApiLogins extends BaseRepository {
|
||||
private apiLogins: Repository<ApiLogin>;
|
||||
|
@ -65,8 +65,9 @@ export class ApiLogins extends BaseRepository {
|
|||
id: loginId,
|
||||
token: hashedToken,
|
||||
user_id: userId,
|
||||
logged_in_at: moment().format(DBDateFormat),
|
||||
expires_at: moment()
|
||||
logged_in_at: moment.utc().format(DBDateFormat),
|
||||
expires_at: moment
|
||||
.utc()
|
||||
.add(1, "day")
|
||||
.format(DBDateFormat),
|
||||
});
|
||||
|
@ -81,7 +82,7 @@ export class ApiLogins extends BaseRepository {
|
|||
return this.apiLogins.update(
|
||||
{ id: loginId },
|
||||
{
|
||||
expires_at: moment().format(DBDateFormat),
|
||||
expires_at: moment.utc().format(DBDateFormat),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ApiUserInfo as ApiUserInfoEntity, ApiUserInfoData } from "./entities/Ap
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { connection } from "./db";
|
||||
import moment from "moment-timezone";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { DBDateFormat } from "../utils/dateFormats";
|
||||
|
||||
export class ApiUserInfo extends BaseRepository {
|
||||
private apiUserInfo: Repository<ApiUserInfoEntity>;
|
||||
|
@ -26,7 +26,7 @@ export class ApiUserInfo extends BaseRepository {
|
|||
const repo = entityManager.getRepository(ApiUserInfoEntity);
|
||||
|
||||
const existingInfo = await repo.findOne({ where: { id } });
|
||||
const updatedAt = moment().format(DBDateFormat);
|
||||
const updatedAt = moment.utc().format(DBDateFormat);
|
||||
|
||||
if (existingInfo) {
|
||||
await repo.update({ id }, { data, updated_at: updatedAt });
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
|
||||
"MEMBER_MUTE_REJOIN": "⚠ Reapplied active mute for {userMention(member)} on rejoin",
|
||||
|
||||
"SCHEDULED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {date} at {time} (UTC)",
|
||||
"SCHEDULED_REPEATED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {date} at {time} (UTC), repeated {repeatDetails}",
|
||||
"SCHEDULED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {datetime}",
|
||||
"SCHEDULED_REPEATED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} on {datetime}, repeated {repeatDetails}",
|
||||
"REPEATED_MESSAGE": "⏰ {userMention(author)} scheduled a message to be posted to {channelMention(channel)} {repeatDetails}",
|
||||
"POSTED_SCHEDULED_MESSAGE": "\uD83D\uDCE8 Posted scheduled message (`{messageId}`) to {channelMention(channel)} as scheduled by {userMention(author)}",
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ export class GuildArchives extends BaseGuildRepository {
|
|||
*/
|
||||
async create(body: string, expiresAt: moment.Moment = null): Promise<string> {
|
||||
if (!expiresAt) {
|
||||
expiresAt = moment().add(DEFAULT_EXPIRY_DAYS, "days");
|
||||
expiresAt = moment.utc().add(DEFAULT_EXPIRY_DAYS, "days");
|
||||
}
|
||||
|
||||
const result = await this.archives.insert({
|
||||
|
@ -78,7 +78,7 @@ export class GuildArchives extends BaseGuildRepository {
|
|||
|
||||
const line = await renderTemplate(MESSAGE_ARCHIVE_MESSAGE_FORMAT, {
|
||||
id: msg.id,
|
||||
timestamp: moment(msg.posted_at).format("YYYY-MM-DD HH:mm:ss"),
|
||||
timestamp: moment.utc(msg.posted_at).format("YYYY-MM-DD HH:mm:ss"),
|
||||
content: msg.data.content,
|
||||
user,
|
||||
channel,
|
||||
|
@ -89,7 +89,9 @@ export class GuildArchives extends BaseGuildRepository {
|
|||
}
|
||||
|
||||
async createFromSavedMessages(savedMessages: SavedMessage[], guild: Guild, expiresAt = null) {
|
||||
if (expiresAt == null) expiresAt = moment().add(DEFAULT_EXPIRY_DAYS, "days");
|
||||
if (expiresAt == null) {
|
||||
expiresAt = moment.utc().add(DEFAULT_EXPIRY_DAYS, "days");
|
||||
}
|
||||
|
||||
const headerStr = await renderTemplate(MESSAGE_ARCHIVE_HEADER_FORMAT, { guild });
|
||||
const msgLines = await this.renderLinesFromSavedMessages(savedMessages, guild);
|
||||
|
|
|
@ -6,6 +6,7 @@ import { disableLinkPreviews } from "../utils";
|
|||
import { CaseTypes } from "./CaseTypes";
|
||||
import moment = require("moment-timezone");
|
||||
import { connection } from "./db";
|
||||
import { DBDateFormat } from "../utils/dateFormats";
|
||||
|
||||
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
|
||||
|
||||
|
@ -158,6 +159,7 @@ export class GuildCases extends BaseGuildRepository {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO: Move this to the cases plugin, use server timezone + date formats
|
||||
getSummaryText(theCase: Case) {
|
||||
const firstNote = theCase.notes[0];
|
||||
let reason = firstNote ? firstNote.body : "";
|
||||
|
@ -172,7 +174,7 @@ export class GuildCases extends BaseGuildRepository {
|
|||
|
||||
reason = disableLinkPreviews(reason);
|
||||
|
||||
const timestamp = moment(theCase.created_at).format("YYYY-MM-DD");
|
||||
const timestamp = moment.utc(theCase.created_at, DBDateFormat).format("YYYY-MM-DD");
|
||||
let line = `\`[${timestamp}]\` \`Case #${theCase.case_number}\` __${CaseTypes[theCase.type]}__ ${reason}`;
|
||||
if (theCase.notes.length > 1) {
|
||||
line += ` *(+${theCase.notes.length - 1} ${theCase.notes.length === 2 ? "note" : "notes"})*`;
|
||||
|
|
|
@ -36,7 +36,8 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
|
||||
async addMute(userId, expiryTime): Promise<Mute> {
|
||||
const expiresAt = expiryTime
|
||||
? moment()
|
||||
? moment
|
||||
.utc()
|
||||
.add(expiryTime, "ms")
|
||||
.format("YYYY-MM-DD HH:mm:ss")
|
||||
: null;
|
||||
|
@ -52,7 +53,8 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
|
||||
async updateExpiryTime(userId, newExpiryTime) {
|
||||
const expiresAt = newExpiryTime
|
||||
? moment()
|
||||
? moment
|
||||
.utc()
|
||||
.add(newExpiryTime, "ms")
|
||||
.format("YYYY-MM-DD HH:mm:ss")
|
||||
: null;
|
||||
|
|
|
@ -182,7 +182,7 @@ export class GuildSavedMessages extends BaseGuildRepository {
|
|||
* If any messages were marked as deleted, also emits the deleteBulk event.
|
||||
*/
|
||||
async markBulkAsDeleted(ids) {
|
||||
const deletedAt = moment().format("YYYY-MM-DD HH:mm:ss");
|
||||
const deletedAt = moment.utc().format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
await this.messages
|
||||
.createQueryBuilder()
|
||||
|
|
|
@ -67,7 +67,8 @@ export class GuildSlowmodes extends BaseGuildRepository {
|
|||
const slowmode = await this.getChannelSlowmode(channelId);
|
||||
if (!slowmode) return;
|
||||
|
||||
const expiresAt = moment()
|
||||
const expiresAt = moment
|
||||
.utc()
|
||||
.add(slowmode.slowmode_seconds, "seconds")
|
||||
.format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { connection } from "../db";
|
|||
import { getRepository, In } from "typeorm";
|
||||
import { Config } from "../entities/Config";
|
||||
import moment from "moment-timezone";
|
||||
import { DBDateFormat } from "../../utils";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
const CLEAN_PER_LOOP = 50;
|
||||
|
||||
|
@ -13,7 +13,8 @@ export async function cleanupConfigs() {
|
|||
let rows;
|
||||
|
||||
// >1 month old: 1 config retained per month
|
||||
const oneMonthCutoff = moment()
|
||||
const oneMonthCutoff = moment
|
||||
.utc()
|
||||
.subtract(30, "days")
|
||||
.format(DBDateFormat);
|
||||
do {
|
||||
|
@ -53,7 +54,8 @@ export async function cleanupConfigs() {
|
|||
} while (rows.length === CLEAN_PER_LOOP);
|
||||
|
||||
// >2 weeks old: 1 config retained per day
|
||||
const twoWeekCutoff = moment()
|
||||
const twoWeekCutoff = moment
|
||||
.utc()
|
||||
.subtract(2, "weeks")
|
||||
.format(DBDateFormat);
|
||||
do {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { DAYS, DBDateFormat, MINUTES } from "../../utils";
|
||||
import { DAYS, MINUTES } from "../../utils";
|
||||
import { getRepository, In } from "typeorm";
|
||||
import { SavedMessage } from "../entities/SavedMessage";
|
||||
import moment from "moment-timezone";
|
||||
import { connection } from "../db";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
/**
|
||||
* How long message edits, deletions, etc. will include the original message content.
|
||||
|
@ -18,13 +19,16 @@ export async function cleanupMessages(): Promise<number> {
|
|||
|
||||
const messagesRepository = getRepository(SavedMessage);
|
||||
|
||||
const deletedAtThreshold = moment()
|
||||
const deletedAtThreshold = moment
|
||||
.utc()
|
||||
.subtract(DELETED_MESSAGE_RETENTION_PERIOD, "ms")
|
||||
.format(DBDateFormat);
|
||||
const postedAtThreshold = moment()
|
||||
const postedAtThreshold = moment
|
||||
.utc()
|
||||
.subtract(RETENTION_PERIOD, "ms")
|
||||
.format(DBDateFormat);
|
||||
const botPostedAtThreshold = moment()
|
||||
const botPostedAtThreshold = moment
|
||||
.utc()
|
||||
.subtract(BOT_MESSAGE_RETENTION_PERIOD, "ms")
|
||||
.format(DBDateFormat);
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { getRepository, In } from "typeorm";
|
||||
import moment from "moment-timezone";
|
||||
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
|
||||
import { DAYS, DBDateFormat } from "../../utils";
|
||||
import { DAYS } from "../../utils";
|
||||
import { connection } from "../db";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||
const CLEAN_PER_LOOP = 500;
|
||||
|
@ -11,7 +12,8 @@ export async function cleanupNicknames(): Promise<number> {
|
|||
let cleaned = 0;
|
||||
|
||||
const nicknameHistoryRepository = getRepository(NicknameHistoryEntry);
|
||||
const dateThreshold = moment()
|
||||
const dateThreshold = moment
|
||||
.utc()
|
||||
.subtract(NICKNAME_RETENTION_PERIOD, "ms")
|
||||
.format(DBDateFormat);
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { getRepository, In } from "typeorm";
|
||||
import moment from "moment-timezone";
|
||||
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
|
||||
import { DAYS, DBDateFormat } from "../../utils";
|
||||
import { DAYS } from "../../utils";
|
||||
import { connection } from "../db";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||
const CLEAN_PER_LOOP = 500;
|
||||
|
@ -11,7 +12,8 @@ export async function cleanupUsernames(): Promise<number> {
|
|||
let cleaned = 0;
|
||||
|
||||
const usernameHistoryRepository = getRepository(UsernameHistoryEntry);
|
||||
const dateThreshold = moment()
|
||||
const dateThreshold = moment
|
||||
.utc()
|
||||
.subtract(USERNAME_RETENTION_PERIOD, "ms")
|
||||
.format(DBDateFormat);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue