3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Turn on strict TS compilation. Fix up and tweak types accordingly.

This commit is contained in:
Dragory 2020-11-09 20:03:57 +02:00
parent 690955a399
commit 629002b8d9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
172 changed files with 720 additions and 534 deletions

View file

@ -37,7 +37,7 @@ export class GuildArchives extends BaseGuildRepository {
.execute();
}
async find(id: string): Promise<ArchiveEntry> {
async find(id: string): Promise<ArchiveEntry | undefined> {
return this.archives.findOne({
where: { id },
relations: this.getRelations(),
@ -56,7 +56,7 @@ export class GuildArchives extends BaseGuildRepository {
/**
* @returns ID of the created entry
*/
async create(body: string, expiresAt: moment.Moment = null): Promise<string> {
async create(body: string, expiresAt?: moment.Moment): Promise<string> {
if (!expiresAt) {
expiresAt = moment.utc().add(DEFAULT_EXPIRY_DAYS, "days");
}
@ -71,7 +71,7 @@ export class GuildArchives extends BaseGuildRepository {
}
protected async renderLinesFromSavedMessages(savedMessages: SavedMessage[], guild: Guild) {
const msgLines = [];
const msgLines: string[] = [];
for (const msg of savedMessages) {
const channel = guild.channels.get(msg.channel_id);
const user = { ...msg.data.author, id: msg.user_id };
@ -88,7 +88,7 @@ export class GuildArchives extends BaseGuildRepository {
return msgLines;
}
async createFromSavedMessages(savedMessages: SavedMessage[], guild: Guild, expiresAt = null) {
async createFromSavedMessages(savedMessages: SavedMessage[], guild: Guild, expiresAt?: moment.Moment) {
if (expiresAt == null) {
expiresAt = moment.utc().add(DEFAULT_EXPIRY_DAYS, "days");
}
@ -105,6 +105,10 @@ export class GuildArchives extends BaseGuildRepository {
const messagesStr = msgLines.join("\n");
const archive = await this.find(archiveId);
if (archive == null) {
throw new Error("Archive not found");
}
archive.body += "\n" + messagesStr;
await this.archives.update({ id: archiveId }, { body: archive.body });

View file

@ -18,7 +18,7 @@ export class GuildAutoReactions extends BaseGuildRepository {
});
}
async getForChannel(channelId: string): Promise<AutoReaction> {
async getForChannel(channelId: string): Promise<AutoReaction | undefined> {
return this.autoReactions.findOne({
where: {
guild_id: this.guildId,

View file

@ -29,7 +29,7 @@ export class GuildCases extends BaseGuildRepository {
});
}
async find(id: number): Promise<Case> {
async find(id: number): Promise<Case | undefined> {
return this.cases.findOne({
relations: this.getRelations(),
where: {
@ -39,7 +39,7 @@ export class GuildCases extends BaseGuildRepository {
});
}
async findByCaseNumber(caseNumber: number): Promise<Case> {
async findByCaseNumber(caseNumber: number): Promise<Case | undefined> {
return this.cases.findOne({
relations: this.getRelations(),
where: {
@ -49,7 +49,7 @@ export class GuildCases extends BaseGuildRepository {
});
}
async findLatestByModId(modId: string): Promise<Case> {
async findLatestByModId(modId: string): Promise<Case | undefined> {
return this.cases.findOne({
relations: this.getRelations(),
where: {
@ -62,7 +62,7 @@ export class GuildCases extends BaseGuildRepository {
});
}
async findByAuditLogId(auditLogId: string): Promise<Case> {
async findByAuditLogId(auditLogId: string): Promise<Case | undefined> {
return this.cases.findOne({
relations: this.getRelations(),
where: {
@ -113,7 +113,7 @@ export class GuildCases extends BaseGuildRepository {
case_number: () => `(SELECT IFNULL(MAX(case_number)+1, 1) FROM cases AS ma2 WHERE guild_id = ${this.guildId})`,
});
return this.find(result.identifiers[0].id);
return (await this.find(result.identifiers[0].id))!;
}
update(id, data) {

View file

@ -17,12 +17,12 @@ export class GuildEvents extends BaseGuildRepository {
this.pluginListeners.set(pluginName, new Map());
}
const pluginListeners = this.pluginListeners.get(pluginName);
const pluginListeners = this.pluginListeners.get(pluginName)!;
if (!pluginListeners.has(eventName)) {
pluginListeners.set(eventName, []);
}
const pluginEventListeners = pluginListeners.get(eventName);
const pluginEventListeners = pluginListeners.get(eventName)!;
pluginEventListeners.push(fn);
}

View file

@ -16,7 +16,7 @@ export class GuildLogs extends events.EventEmitter {
constructor(guildId) {
if (guildInstances.has(guildId)) {
// Return existing instance for this guild if one exists
return guildInstances.get(guildId);
return guildInstances.get(guildId)!;
}
super();
@ -27,7 +27,7 @@ export class GuildLogs extends events.EventEmitter {
guildInstances.set(guildId, this);
}
log(type: LogType, data: any, ignoreId = null) {
log(type: LogType, data: any, ignoreId?: string) {
if (ignoreId && this.isLogIgnored(type, ignoreId)) {
this.clearIgnoredLog(type, ignoreId);
return;
@ -36,7 +36,7 @@ export class GuildLogs extends events.EventEmitter {
this.emit("log", { type, data });
}
ignoreLog(type: LogType, ignoreId: any, timeout: number = null) {
ignoreLog(type: LogType, ignoreId: any, timeout?: number) {
this.ignoredLogs.push({ type, ignoreId });
// Clear after expiry (15sec by default)

View file

@ -20,7 +20,7 @@ export class GuildMutes extends BaseGuildRepository {
.getMany();
}
async findExistingMuteForUserId(userId: string): Promise<Mute> {
async findExistingMuteForUserId(userId: string): Promise<Mute | undefined> {
return this.mutes.findOne({
where: {
guild_id: this.guildId,
@ -48,7 +48,7 @@ export class GuildMutes extends BaseGuildRepository {
expires_at: expiresAt,
});
return this.mutes.findOne({ where: result.identifiers[0] });
return (await this.mutes.findOne({ where: result.identifiers[0] }))!;
}
async updateExpiryTime(userId, newExpiryTime) {

View file

@ -39,7 +39,7 @@ export class GuildNicknameHistory extends BaseGuildRepository {
});
}
getLastEntry(userId): Promise<NicknameHistoryEntry> {
getLastEntry(userId): Promise<NicknameHistoryEntry | undefined> {
return this.nicknameHistory.findOne({
where: {
guild_id: this.guildId,

View file

@ -27,7 +27,7 @@ export class GuildPingableRoles extends BaseGuildRepository {
});
}
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole> {
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole | undefined> {
return this.pingableRoles.findOne({
where: {
guild_id: this.guildId,

View file

@ -27,7 +27,7 @@ export class GuildReactionRoles extends BaseGuildRepository {
});
}
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole> {
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole | undefined> {
return this.reactionRoles.findOne({
where: {
guild_id: this.guildId,
@ -37,7 +37,7 @@ export class GuildReactionRoles extends BaseGuildRepository {
});
}
async removeFromMessage(messageId: string, emoji: string = null) {
async removeFromMessage(messageId: string, emoji?: string) {
const criteria: any = {
guild_id: this.guildId,
message_id: messageId,

View file

@ -96,7 +96,7 @@ export class GuildSavedMessages extends BaseGuildRepository {
.getMany();
}
getUserMessagesByChannelAfterId(userId, channelId, afterId, limit = null) {
getUserMessagesByChannelAfterId(userId, channelId, afterId, limit?: number) {
let query = this.messages
.createQueryBuilder()
.where("guild_id = :guild_id", { guild_id: this.guildId })
@ -241,12 +241,12 @@ export class GuildSavedMessages extends BaseGuildRepository {
}
}
async onceMessageAvailable(id: string, handler: (msg: SavedMessage) => any, timeout: number = 60 * 1000) {
async onceMessageAvailable(id: string, handler: (msg?: SavedMessage) => any, timeout: number = 60 * 1000) {
let called = false;
let onceEventListener;
let timeoutFn;
const callHandler = async (msg: SavedMessage) => {
const callHandler = async (msg?: SavedMessage) => {
this.events.off(`create:${id}`, onceEventListener);
clearTimeout(timeoutFn);
@ -259,7 +259,7 @@ export class GuildSavedMessages extends BaseGuildRepository {
onceEventListener = this.events.once(`create:${id}`, callHandler);
timeoutFn = setTimeout(() => {
called = true;
callHandler(null);
callHandler(undefined);
}, timeout);
const messageInDB = await this.find(id);

View file

@ -14,7 +14,7 @@ export class GuildSlowmodes extends BaseGuildRepository {
this.slowmodeUsers = getRepository(SlowmodeUser);
}
async getChannelSlowmode(channelId): Promise<SlowmodeChannel> {
async getChannelSlowmode(channelId): Promise<SlowmodeChannel | undefined> {
return this.slowmodeChannels.findOne({
where: {
guild_id: this.guildId,
@ -51,7 +51,7 @@ export class GuildSlowmodes extends BaseGuildRepository {
});
}
async getChannelSlowmodeUser(channelId, userId): Promise<SlowmodeUser> {
async getChannelSlowmodeUser(channelId, userId): Promise<SlowmodeUser | undefined> {
return this.slowmodeUsers.findOne({
guild_id: this.guildId,
channel_id: channelId,

View file

@ -21,7 +21,7 @@ export class GuildTags extends BaseGuildRepository {
});
}
async find(tag): Promise<Tag> {
async find(tag): Promise<Tag | undefined> {
return this.tags.findOne({
where: {
guild_id: this.guildId,
@ -61,7 +61,7 @@ export class GuildTags extends BaseGuildRepository {
});
}
async findResponseByCommandMessageId(messageId: string): Promise<TagResponse> {
async findResponseByCommandMessageId(messageId: string): Promise<TagResponse | undefined> {
return this.tagResponses.findOne({
where: {
guild_id: this.guildId,
@ -70,7 +70,7 @@ export class GuildTags extends BaseGuildRepository {
});
}
async findResponseByResponseMessageId(messageId: string): Promise<TagResponse> {
async findResponseByResponseMessageId(messageId: string): Promise<TagResponse | undefined> {
return this.tagResponses.findOne({
where: {
guild_id: this.guildId,

View file

@ -39,7 +39,7 @@ export class UsernameHistory extends BaseRepository {
});
}
getLastEntry(userId): Promise<UsernameHistoryEntry> {
getLastEntry(userId): Promise<UsernameHistoryEntry | undefined> {
return this.usernameHistory.findOne({
where: {
user_id: userId,

View file

@ -9,8 +9,8 @@ export class AllowedGuild {
@Column()
name: string;
@Column()
icon: string;
@Column({ nullable: true })
icon: string | null;
@Column()
owner_id: string;

View file

@ -17,5 +17,5 @@ export class ArchiveEntry {
@Column() created_at: string;
@Column() expires_at: string;
@Column({ nullable: true }) expires_at: string | null;
}

View file

@ -13,27 +13,27 @@ export class Case {
@Column() user_name: string;
@Column() mod_id: string;
@Column({ nullable: true }) mod_id: string | null;
@Column() mod_name: string;
@Column({ nullable: true }) mod_name: string | null;
@Column() type: number;
@Column() audit_log_id: string;
@Column({ nullable: true }) audit_log_id: string | null;
@Column() created_at: string;
@Column() is_hidden: boolean;
@Column() pp_id: string;
@Column({ nullable: true }) pp_id: string | null;
@Column() pp_name: string;
@Column({ nullable: true }) pp_name: string | null;
/**
* ID of the channel and message where this case was logged.
* Format: "channelid-messageid"
*/
@Column() log_message_id: string;
@Column({ nullable: true }) log_message_id: string | null;
@OneToMany(
type => CaseNote,

View file

@ -12,7 +12,7 @@ export class Mute {
@Column() created_at: string;
@Column() expires_at: string;
@Column({ nullable: true }) expires_at: string | null;
@Column() case_id: number;
}

View file

@ -1,9 +1,9 @@
import { Column, Entity, PrimaryColumn } from "typeorm";
import { createEncryptedJsonTransformer } from "../encryptedJsonTransformer";
import { Sticker } from "eris";
import { Attachment, Sticker } from "eris";
export interface ISavedMessageData {
attachments?: object[];
attachments?: Attachment[];
author: {
username: string;
discriminator: string;

View file

@ -20,16 +20,16 @@ export class ScheduledPost {
@Column("simple-json") attachments: Attachment[];
@Column() post_at: string;
@Column({ nullable: true }) post_at: string | null;
/**
* How often to post the message, in milliseconds
*/
@Column() repeat_interval: number;
@Column({ nullable: true }) repeat_interval: number | null;
@Column() repeat_until: string;
@Column({ nullable: true }) repeat_until: string | null;
@Column() repeat_times: number;
@Column({ nullable: true }) repeat_times: number | null;
@Column() enable_mentions: boolean;
}