Split BaseRepository into non-guild and guild
BaseRepository includes all the non-guild-specific functionality, such as with() and getRelations(). BaseGuildRepository includes guild-specific functionality, such as getInstance().
This commit is contained in:
parent
1aa549e391
commit
d54897acdd
39 changed files with 162 additions and 156 deletions
|
@ -1,19 +1,20 @@
|
|||
export class BaseRepository {
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
|
||||
export class BaseGuildRepository extends BaseRepository {
|
||||
private static guildInstances: Map<string, any>;
|
||||
private nextRelations: string[];
|
||||
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId: string) {
|
||||
super();
|
||||
this.guildId = guildId;
|
||||
this.nextRelations = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cached instance of the inheriting class for the specified guildId,
|
||||
* or creates a new instance if one doesn't exist yet
|
||||
*/
|
||||
public static getInstance<T extends typeof BaseRepository>(this: T, guildId: string): InstanceType<T> {
|
||||
public static getGuildInstance<T extends typeof BaseGuildRepository>(this: T, guildId: string): InstanceType<T> {
|
||||
if (!this.guildInstances) {
|
||||
this.guildInstances = new Map();
|
||||
}
|
||||
|
@ -24,27 +25,4 @@ export class BaseRepository {
|
|||
|
||||
return this.guildInstances.get(guildId) as InstanceType<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Primes the specified relation(s) to be used in the next database operation.
|
||||
* Can be chained.
|
||||
*/
|
||||
public with(relations: string | string[]): this {
|
||||
if (Array.isArray(relations)) {
|
||||
this.nextRelations.push(...relations);
|
||||
} else {
|
||||
this.nextRelations.push(relations);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and resets the relations primed using with()
|
||||
*/
|
||||
protected getRelations(): string[] {
|
||||
const relations = this.nextRelations || [];
|
||||
this.nextRelations = [];
|
||||
return relations;
|
||||
}
|
||||
}
|
||||
|
|
30
src/data/BaseRepository.ts
Normal file
30
src/data/BaseRepository.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
export class BaseRepository {
|
||||
private nextRelations: string[];
|
||||
|
||||
constructor() {
|
||||
this.nextRelations = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Primes the specified relation(s) to be used in the next database operation.
|
||||
* Can be chained.
|
||||
*/
|
||||
public with(relations: string | string[]): this {
|
||||
if (Array.isArray(relations)) {
|
||||
this.nextRelations.push(...relations);
|
||||
} else {
|
||||
this.nextRelations.push(relations);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and resets the relations primed using with()
|
||||
*/
|
||||
protected getRelations(): string[] {
|
||||
const relations = this.nextRelations || [];
|
||||
this.nextRelations = [];
|
||||
return relations;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ import uuid from "uuid/v4"; // tslint:disable-line
|
|||
import moment from "moment-timezone";
|
||||
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { trimLines } from "../utils";
|
||||
import { SavedMessage } from "./entities/SavedMessage";
|
||||
import { Channel, Guild, User } from "eris";
|
||||
|
@ -16,7 +16,7 @@ const MESSAGE_ARCHIVE_HEADER_FORMAT = trimLines(`
|
|||
const MESSAGE_ARCHIVE_MESSAGE_FORMAT =
|
||||
"[#{channel.name}] [{user.id}] [{timestamp}] {user.username}#{user.discriminator}: {content}{attachments}";
|
||||
|
||||
export class GuildArchives extends BaseRepository {
|
||||
export class GuildArchives extends BaseGuildRepository {
|
||||
protected archives: Repository<ArchiveEntry>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { AutoReaction } from "./entities/AutoReaction";
|
||||
|
||||
export class GuildAutoReactions extends BaseRepository {
|
||||
export class GuildAutoReactions extends BaseGuildRepository {
|
||||
private autoReactions: Repository<AutoReaction>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
@ -13,8 +13,8 @@ export class GuildAutoReactions extends BaseRepository {
|
|||
async all(): Promise<AutoReaction[]> {
|
||||
return this.autoReactions.find({
|
||||
where: {
|
||||
guild_id: this.guildId
|
||||
}
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,15 +22,15 @@ export class GuildAutoReactions extends BaseRepository {
|
|||
return this.autoReactions.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
}
|
||||
channel_id: channelId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async removeFromChannel(channelId: string) {
|
||||
await this.autoReactions.delete({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
channel_id: channelId,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -40,17 +40,17 @@ export class GuildAutoReactions extends BaseRepository {
|
|||
this.autoReactions.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
channel_id: channelId,
|
||||
},
|
||||
{
|
||||
reactions
|
||||
}
|
||||
reactions,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await this.autoReactions.insert({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
reactions
|
||||
reactions,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Case } from "./entities/Case";
|
||||
import { CaseNote } from "./entities/CaseNote";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, In, Repository } from "typeorm";
|
||||
import { disableLinkPreviews } from "../utils";
|
||||
import { CaseTypes } from "./CaseTypes";
|
||||
|
@ -8,7 +8,7 @@ import moment = require("moment-timezone");
|
|||
|
||||
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
|
||||
|
||||
export class GuildCases extends BaseRepository {
|
||||
export class GuildCases extends BaseGuildRepository {
|
||||
private cases: Repository<Case>;
|
||||
private caseNotes: Repository<CaseNote>;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
||||
|
||||
export class GuildEvents extends BaseRepository {
|
||||
export class GuildEvents extends BaseGuildRepository {
|
||||
private queuedEventEmitter: QueuedEventEmitter;
|
||||
private pluginListeners: Map<string, Map<string, any[]>>;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import moment from "moment-timezone";
|
||||
import { Mute } from "./entities/Mute";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository, Brackets } from "typeorm";
|
||||
|
||||
export class GuildMutes extends BaseRepository {
|
||||
export class GuildMutes extends BaseGuildRepository {
|
||||
private mutes: Repository<Mute>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { NicknameHistoryEntry } from "./entities/NicknameHistoryEntry";
|
||||
import { sorter } from "../utils";
|
||||
|
||||
export const MAX_NICKNAME_ENTRIES_PER_USER = 10;
|
||||
|
||||
export class GuildNicknameHistory extends BaseRepository {
|
||||
export class GuildNicknameHistory extends BaseGuildRepository {
|
||||
private nicknameHistory: Repository<NicknameHistoryEntry>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { PersistedData } from "./entities/PersistedData";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
|
||||
export interface IPartialPersistData {
|
||||
|
@ -8,7 +8,7 @@ export interface IPartialPersistData {
|
|||
is_voice_muted?: boolean;
|
||||
}
|
||||
|
||||
export class GuildPersistedData extends BaseRepository {
|
||||
export class GuildPersistedData extends BaseGuildRepository {
|
||||
private persistedData: Repository<PersistedData>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
@ -20,8 +20,8 @@ export class GuildPersistedData extends BaseRepository {
|
|||
return this.persistedData.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
user_id: userId
|
||||
}
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,15 +36,15 @@ export class GuildPersistedData extends BaseRepository {
|
|||
await this.persistedData.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
user_id: userId
|
||||
user_id: userId,
|
||||
},
|
||||
finalData
|
||||
finalData,
|
||||
);
|
||||
} else {
|
||||
await this.persistedData.insert({
|
||||
...finalData,
|
||||
guild_id: this.guildId,
|
||||
user_id: userId
|
||||
user_id: userId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export class GuildPersistedData extends BaseRepository {
|
|||
async clear(userId: string) {
|
||||
await this.persistedData.delete({
|
||||
guild_id: this.guildId,
|
||||
user_id: userId
|
||||
user_id: userId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { PingableRole } from "./entities/PingableRole";
|
||||
|
||||
export class GuildPingableRoles extends BaseRepository {
|
||||
export class GuildPingableRoles extends BaseGuildRepository {
|
||||
private pingableRoles: Repository<PingableRole>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
@ -13,8 +13,8 @@ export class GuildPingableRoles extends BaseRepository {
|
|||
async all(): Promise<PingableRole[]> {
|
||||
return this.pingableRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId
|
||||
}
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ export class GuildPingableRoles extends BaseRepository {
|
|||
return this.pingableRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
}
|
||||
channel_id: channelId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ export class GuildPingableRoles extends BaseRepository {
|
|||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
}
|
||||
role_id: roleId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ export class GuildPingableRoles extends BaseRepository {
|
|||
await this.pingableRoles.delete({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
role_id: roleId,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ export class GuildPingableRoles extends BaseRepository {
|
|||
await this.pingableRoles.insert({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId,
|
||||
role_id: roleId
|
||||
role_id: roleId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { ReactionRole } from "./entities/ReactionRole";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
|
||||
export class GuildReactionRoles extends BaseRepository {
|
||||
export class GuildReactionRoles extends BaseGuildRepository {
|
||||
private reactionRoles: Repository<ReactionRole>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
@ -13,8 +13,8 @@ export class GuildReactionRoles extends BaseRepository {
|
|||
async all(): Promise<ReactionRole[]> {
|
||||
return this.reactionRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId
|
||||
}
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ export class GuildReactionRoles extends BaseRepository {
|
|||
return this.reactionRoles.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId
|
||||
}
|
||||
message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -32,15 +32,15 @@ export class GuildReactionRoles extends BaseRepository {
|
|||
where: {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId,
|
||||
emoji
|
||||
}
|
||||
emoji,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async removeFromMessage(messageId: string, emoji: string = null) {
|
||||
const criteria: any = {
|
||||
guild_id: this.guildId,
|
||||
message_id: messageId
|
||||
message_id: messageId,
|
||||
};
|
||||
|
||||
if (emoji) {
|
||||
|
@ -56,7 +56,7 @@ export class GuildReactionRoles extends BaseRepository {
|
|||
channel_id: channelId,
|
||||
message_id: messageId,
|
||||
emoji,
|
||||
role_id: roleId
|
||||
role_id: roleId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { Reminder } from "./entities/Reminder";
|
||||
|
||||
export class GuildReminders extends BaseRepository {
|
||||
export class GuildReminders extends BaseGuildRepository {
|
||||
private reminders: Repository<Reminder>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Brackets, getRepository, Repository } from "typeorm";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
|
||||
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
||||
import { GuildChannel, Message } from "eris";
|
||||
|
@ -36,7 +36,7 @@ async function cleanup() {
|
|||
// Start first cleanup 30 seconds after startup
|
||||
setTimeout(cleanup, 30 * 1000);
|
||||
|
||||
export class GuildSavedMessages extends BaseRepository {
|
||||
export class GuildSavedMessages extends BaseGuildRepository {
|
||||
private messages: Repository<SavedMessage>;
|
||||
protected toBePermanent: Set<string>;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { ScheduledPost } from "./entities/ScheduledPost";
|
||||
|
||||
export class GuildScheduledPosts extends BaseRepository {
|
||||
export class GuildScheduledPosts extends BaseGuildRepository {
|
||||
private scheduledPosts: Repository<ScheduledPost>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { SelfGrantableRole } from "./entities/SelfGrantableRole";
|
||||
|
||||
export class GuildSelfGrantableRoles extends BaseRepository {
|
||||
export class GuildSelfGrantableRoles extends BaseGuildRepository {
|
||||
private selfGrantableRoles: Repository<SelfGrantableRole>;
|
||||
|
||||
constructor(guildId) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { SlowmodeChannel } from "./entities/SlowmodeChannel";
|
||||
import { SlowmodeUser } from "./entities/SlowmodeUser";
|
||||
import moment from "moment-timezone";
|
||||
|
||||
export class GuildSlowmodes extends BaseRepository {
|
||||
export class GuildSlowmodes extends BaseGuildRepository {
|
||||
private slowmodeChannels: Repository<SlowmodeChannel>;
|
||||
private slowmodeUsers: Repository<SlowmodeUser>;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { Starboard } from "./entities/Starboard";
|
||||
import { StarboardMessage } from "./entities/StarboardMessage";
|
||||
|
||||
export class GuildStarboards extends BaseRepository {
|
||||
export class GuildStarboards extends BaseGuildRepository {
|
||||
private starboards: Repository<Starboard>;
|
||||
private starboardMessages: Repository<StarboardMessage>;
|
||||
|
||||
|
@ -17,8 +17,8 @@ export class GuildStarboards extends BaseRepository {
|
|||
return this.starboards.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
}
|
||||
channel_id: channelId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ export class GuildStarboards extends BaseRepository {
|
|||
return this.starboards.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
emoji
|
||||
}
|
||||
emoji,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ export class GuildStarboards extends BaseRepository {
|
|||
relations: this.getRelations(),
|
||||
where: {
|
||||
starboard_id: starboardId,
|
||||
message_id: messageId
|
||||
}
|
||||
message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ export class GuildStarboards extends BaseRepository {
|
|||
return this.starboardMessages.find({
|
||||
relations: this.getRelations(),
|
||||
where: {
|
||||
message_id: id
|
||||
}
|
||||
message_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -54,14 +54,14 @@ export class GuildStarboards extends BaseRepository {
|
|||
await this.starboardMessages.insert({
|
||||
starboard_id: starboardId,
|
||||
message_id: messageId,
|
||||
starboard_message_id: starboardMessageId
|
||||
starboard_message_id: starboardMessageId,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteStarboardMessage(starboardId, messageId): Promise<void> {
|
||||
await this.starboardMessages.delete({
|
||||
starboard_id: starboardId,
|
||||
message_id: messageId
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -71,14 +71,14 @@ export class GuildStarboards extends BaseRepository {
|
|||
channel_id: channelId,
|
||||
channel_whitelist: channelWhitelist ? channelWhitelist.join(",") : null,
|
||||
emoji,
|
||||
reactions_required: reactionsRequired
|
||||
reactions_required: reactionsRequired,
|
||||
});
|
||||
}
|
||||
|
||||
async delete(channelId: string): Promise<void> {
|
||||
await this.starboards.delete({
|
||||
guild_id: this.guildId,
|
||||
channel_id: channelId
|
||||
channel_id: channelId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Tag } from "./entities/Tag";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { TagResponse } from "./entities/TagResponse";
|
||||
|
||||
export class GuildTags extends BaseRepository {
|
||||
export class GuildTags extends BaseGuildRepository {
|
||||
private tags: Repository<Tag>;
|
||||
private tagResponses: Repository<TagResponse>;
|
||||
|
||||
|
@ -16,8 +16,8 @@ export class GuildTags extends BaseRepository {
|
|||
async all(): Promise<Tag[]> {
|
||||
return this.tags.find({
|
||||
where: {
|
||||
guild_id: this.guildId
|
||||
}
|
||||
guild_id: this.guildId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ export class GuildTags extends BaseRepository {
|
|||
return this.tags.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
tag
|
||||
}
|
||||
tag,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ export class GuildTags extends BaseRepository {
|
|||
.set({
|
||||
body,
|
||||
user_id: userId,
|
||||
created_at: () => "NOW()"
|
||||
created_at: () => "NOW()",
|
||||
})
|
||||
.where("guild_id = :guildId", { guildId: this.guildId })
|
||||
.andWhere("tag = :tag", { tag })
|
||||
|
@ -49,7 +49,7 @@ export class GuildTags extends BaseRepository {
|
|||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
tag,
|
||||
body
|
||||
body,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class GuildTags extends BaseRepository {
|
|||
async delete(tag) {
|
||||
await this.tags.delete({
|
||||
guild_id: this.guildId,
|
||||
tag
|
||||
tag,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ export class GuildTags extends BaseRepository {
|
|||
return this.tagResponses.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
command_message_id: messageId
|
||||
}
|
||||
command_message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -74,8 +74,8 @@ export class GuildTags extends BaseRepository {
|
|||
return this.tagResponses.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
response_message_id: messageId
|
||||
}
|
||||
response_message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ export class GuildTags extends BaseRepository {
|
|||
await this.tagResponses.insert({
|
||||
guild_id: this.guildId,
|
||||
command_message_id: cmdMessageId,
|
||||
response_message_id: responseMessageId
|
||||
response_message_id: responseMessageId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { UsernameHistoryEntry } from "./entities/UsernameHistoryEntry";
|
||||
import { sorter } from "../utils";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
|
||||
export const MAX_USERNAME_ENTRIES_PER_USER = 10;
|
||||
|
||||
export class UsernameHistory extends BaseRepository {
|
||||
private usernameHistory: Repository<UsernameHistoryEntry>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
constructor() {
|
||||
super();
|
||||
this.usernameHistory = getRepository(UsernameHistoryEntry);
|
||||
}
|
||||
|
||||
async getByUserId(userId): Promise<UsernameHistoryEntry[]> {
|
||||
return this.usernameHistory.find({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
order: {
|
||||
|
@ -29,7 +28,6 @@ export class UsernameHistory extends BaseRepository {
|
|||
getLastEntry(userId): Promise<UsernameHistoryEntry> {
|
||||
return this.usernameHistory.findOne({
|
||||
where: {
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
order: {
|
||||
|
|
|
@ -36,8 +36,8 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<IAutoReactionsPluginConf
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.autoReactions = GuildAutoReactions.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.autoReactions = GuildAutoReactions.getGuildInstance(this.guildId);
|
||||
|
||||
this.onMessageCreateFn = this.savedMessages.events.on("create", this.onMessageCreate.bind(this));
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ export class CasesPlugin extends ZeppelinPlugin<ICasesPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.cases = GuildCases.getInstance(this.guildId);
|
||||
this.archives = GuildArchives.getInstance(this.guildId);
|
||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ export class CensorPlugin extends ZeppelinPlugin<ICensorPluginConfig> {
|
|||
|
||||
onLoad() {
|
||||
this.serverLogs = new GuildLogs(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
|
||||
this.onMessageCreateFn = this.onMessageCreate.bind(this);
|
||||
this.onMessageUpdateFn = this.onMessageUpdate.bind(this);
|
||||
|
|
|
@ -93,9 +93,9 @@ export class LogsPlugin extends ZeppelinPlugin<ILogsPluginConfig> {
|
|||
|
||||
onLoad() {
|
||||
this.guildLogs = new GuildLogs(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.archives = GuildArchives.getInstance(this.guildId);
|
||||
this.cases = GuildCases.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||
|
||||
this.logListener = ({ type, data }) => this.log(type, data);
|
||||
this.guildLogs.on("log", this.logListener);
|
||||
|
|
|
@ -30,7 +30,7 @@ export class MessageSaverPlugin extends Plugin<IMessageSaverPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
}
|
||||
|
||||
@d.event("messageCreate", "guild", false)
|
||||
|
|
|
@ -75,8 +75,8 @@ export class ModActionsPlugin extends ZeppelinPlugin<IModActionsPluginConfig> {
|
|||
protected ignoredEvents: IIgnoredEvent[];
|
||||
|
||||
async onLoad() {
|
||||
this.mutes = GuildMutes.getInstance(this.guildId);
|
||||
this.cases = GuildCases.getInstance(this.guildId);
|
||||
this.mutes = GuildMutes.getGuildInstance(this.guildId);
|
||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||
this.serverLogs = new GuildLogs(this.guildId);
|
||||
|
||||
this.ignoredEvents = [];
|
||||
|
|
|
@ -99,8 +99,8 @@ export class MutesPlugin extends ZeppelinPlugin<IMutesPluginConfig> {
|
|||
}
|
||||
|
||||
protected onLoad() {
|
||||
this.mutes = GuildMutes.getInstance(this.guildId);
|
||||
this.cases = GuildCases.getInstance(this.guildId);
|
||||
this.mutes = GuildMutes.getGuildInstance(this.guildId);
|
||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||
this.serverLogs = new GuildLogs(this.guildId);
|
||||
|
||||
// Check for expired mutes every 5s
|
||||
|
|
|
@ -33,8 +33,8 @@ export class NameHistoryPlugin extends ZeppelinPlugin<INameHistoryPluginConfig>
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.nicknameHistory = GuildNicknameHistory.getInstance(this.guildId);
|
||||
this.usernameHistory = UsernameHistory.getInstance(null);
|
||||
this.nicknameHistory = GuildNicknameHistory.getGuildInstance(this.guildId);
|
||||
this.usernameHistory = new UsernameHistory();
|
||||
}
|
||||
|
||||
@d.command("names", "<userId:userid>")
|
||||
|
|
|
@ -30,7 +30,7 @@ export class PersistPlugin extends ZeppelinPlugin<IPersistPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.persistedData = GuildPersistedData.getInstance(this.guildId);
|
||||
this.persistedData = GuildPersistedData.getGuildInstance(this.guildId);
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ export class PingableRolesPlugin extends ZeppelinPlugin<IPingableRolesPluginConf
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.pingableRoles = GuildPingableRoles.getInstance(this.guildId);
|
||||
this.pingableRoles = GuildPingableRoles.getGuildInstance(this.guildId);
|
||||
|
||||
this.cache = new Map();
|
||||
this.timeouts = new Map();
|
||||
|
|
|
@ -43,8 +43,8 @@ export class PostPlugin extends ZeppelinPlugin<IPostPluginConfig> {
|
|||
private scheduledPostLoopTimeout;
|
||||
|
||||
onLoad() {
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.scheduledPosts = GuildScheduledPosts.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.scheduledPosts = GuildScheduledPosts.getGuildInstance(this.guildId);
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
|
||||
this.scheduledPostLoop();
|
||||
|
|
|
@ -64,8 +64,8 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<IReactionRolesPluginConf
|
|||
}
|
||||
|
||||
async onLoad() {
|
||||
this.reactionRoles = GuildReactionRoles.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.reactionRoles = GuildReactionRoles.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.reactionRemoveQueue = new Queue();
|
||||
this.pendingRoleChanges = new Map();
|
||||
this.pendingRefreshes = new Set();
|
||||
|
|
|
@ -46,7 +46,7 @@ export class RemindersPlugin extends ZeppelinPlugin<IRemindersPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.reminders = GuildReminders.getInstance(this.guildId);
|
||||
this.reminders = GuildReminders.getGuildInstance(this.guildId);
|
||||
this.tries = new Map();
|
||||
this.postDueRemindersLoop();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ export class SelfGrantableRolesPlugin extends ZeppelinPlugin<ISelfGrantableRoles
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.selfGrantableRoles = GuildSelfGrantableRoles.getInstance(this.guildId);
|
||||
this.selfGrantableRoles = GuildSelfGrantableRoles.getGuildInstance(this.guildId);
|
||||
}
|
||||
|
||||
@d.command("role remove", "<roleNames:string...>")
|
||||
|
|
|
@ -61,8 +61,8 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.slowmodes = GuildSlowmodes.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.slowmodes = GuildSlowmodes.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
this.clearInterval = setInterval(() => this.clearExpiredSlowmodes(), BOT_SLOWMODE_CLEAR_INTERVAL);
|
||||
|
||||
|
|
|
@ -128,9 +128,9 @@ export class SpamPlugin extends ZeppelinPlugin<ISpamPluginConfig> {
|
|||
|
||||
onLoad() {
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
this.archives = GuildArchives.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.mutes = GuildMutes.getInstance(this.guildId);
|
||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.mutes = GuildMutes.getGuildInstance(this.guildId);
|
||||
|
||||
this.recentActions = [];
|
||||
this.expiryInterval = setInterval(() => this.clearOldRecentActions(), 1000 * 60);
|
||||
|
|
|
@ -47,8 +47,8 @@ export class StarboardPlugin extends ZeppelinPlugin<IStarboardPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.starboards = GuildStarboards.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.starboards = GuildStarboards.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
|
||||
this.onMessageDeleteFn = this.onMessageDelete.bind(this);
|
||||
this.savedMessages.events.on("delete", this.onMessageDeleteFn);
|
||||
|
|
|
@ -55,9 +55,9 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig> {
|
|||
}
|
||||
|
||||
onLoad() {
|
||||
this.archives = GuildArchives.getInstance(this.guildId);
|
||||
this.tags = GuildTags.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||
this.tags = GuildTags.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
|
||||
this.onMessageCreateFn = this.onMessageCreate.bind(this);
|
||||
this.savedMessages.events.on("create", this.onMessageCreateFn);
|
||||
|
|
|
@ -8,7 +8,7 @@ export class UsernameSaver extends GlobalPlugin {
|
|||
protected usernameHistory: UsernameHistory;
|
||||
|
||||
async onLoad() {
|
||||
this.usernameHistory = UsernameHistory.getInstance(null);
|
||||
this.usernameHistory = new UsernameHistory();
|
||||
}
|
||||
|
||||
protected async updateUsername(user: User) {
|
||||
|
|
|
@ -136,9 +136,9 @@ export class UtilityPlugin extends ZeppelinPlugin<IUtilityPluginConfig> {
|
|||
|
||||
onLoad() {
|
||||
this.logs = new GuildLogs(this.guildId);
|
||||
this.cases = GuildCases.getInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getInstance(this.guildId);
|
||||
this.archives = GuildArchives.getInstance(this.guildId);
|
||||
this.cases = GuildCases.getGuildInstance(this.guildId);
|
||||
this.savedMessages = GuildSavedMessages.getGuildInstance(this.guildId);
|
||||
this.archives = GuildArchives.getGuildInstance(this.guildId);
|
||||
|
||||
if (activeReloads && activeReloads.has(this.guildId)) {
|
||||
activeReloads.get(this.guildId).createMessage(successMessage("Reloaded!"));
|
||||
|
|
Loading…
Add table
Reference in a new issue