mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
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
|
@ -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/dateFormats";
|
||||
import { DBDateFormat } from "../utils";
|
||||
|
||||
export class ApiLogins extends BaseRepository {
|
||||
private apiLogins: Repository<ApiLogin>;
|
||||
|
|
|
@ -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/dateFormats";
|
||||
import { DBDateFormat } from "../utils";
|
||||
|
||||
export class ApiUserInfo extends BaseRepository {
|
||||
private apiUserInfo: Repository<ApiUserInfoEntity>;
|
||||
|
|
|
@ -2,11 +2,10 @@ import { Case } from "./entities/Case";
|
|||
import { CaseNote } from "./entities/CaseNote";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, In, Repository } from "typeorm";
|
||||
import { disableLinkPreviews } from "../utils";
|
||||
import { DBDateFormat, 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;
|
||||
|
||||
|
|
48
backend/src/data/GuildMemberTimezones.ts
Normal file
48
backend/src/data/GuildMemberTimezones.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { MemberTimezone } from "./entities/MemberTimezone";
|
||||
import { getRepository, Repository } from "typeorm/index";
|
||||
import { connection } from "./db";
|
||||
|
||||
export class GuildMemberTimezones extends BaseGuildRepository {
|
||||
protected memberTimezones: Repository<MemberTimezone>;
|
||||
|
||||
constructor(guildId: string) {
|
||||
super(guildId);
|
||||
this.memberTimezones = getRepository(MemberTimezone);
|
||||
}
|
||||
|
||||
get(memberId: string) {
|
||||
return this.memberTimezones.findOne({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
});
|
||||
}
|
||||
|
||||
async set(memberId, timezone: string) {
|
||||
await connection.transaction(async entityManager => {
|
||||
const repo = entityManager.getRepository(MemberTimezone);
|
||||
const existingRow = await repo.findOne({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
});
|
||||
|
||||
if (existingRow) {
|
||||
await repo.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
},
|
||||
{
|
||||
timezone,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await repo.insert({
|
||||
guild_id: this.guildId,
|
||||
member_id: memberId,
|
||||
timezone,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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/dateFormats";
|
||||
import { DBDateFormat } from "../../utils";
|
||||
|
||||
const CLEAN_PER_LOOP = 50;
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { DAYS, MINUTES } from "../../utils";
|
||||
import { DAYS, DBDateFormat, 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.
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { getRepository, In } from "typeorm";
|
||||
import moment from "moment-timezone";
|
||||
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
|
||||
import { DAYS } from "../../utils";
|
||||
import { DAYS, DBDateFormat } from "../../utils";
|
||||
import { connection } from "../db";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||
const CLEAN_PER_LOOP = 500;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { getRepository, In } from "typeorm";
|
||||
import moment from "moment-timezone";
|
||||
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
|
||||
import { DAYS } from "../../utils";
|
||||
import { DAYS, DBDateFormat } from "../../utils";
|
||||
import { connection } from "../db";
|
||||
import { DBDateFormat } from "../../utils/dateFormats";
|
||||
|
||||
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||
const CLEAN_PER_LOOP = 500;
|
||||
|
|
14
backend/src/data/entities/MemberTimezone.ts
Normal file
14
backend/src/data/entities/MemberTimezone.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||
|
||||
@Entity("member_timezones")
|
||||
export class MemberTimezone {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
guild_id: string;
|
||||
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
member_id: string;
|
||||
|
||||
@Column() timezone: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue