refactor(*): remove unused exception variables (#193)

This commit is contained in:
Almeida 2021-05-06 19:23:47 +01:00 committed by GitHub
parent 38ab38645b
commit a4a7eb41b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 35 additions and 35 deletions

View file

@ -4,11 +4,11 @@ const path = require('path');
try { try {
fs.accessSync(path.resolve(__dirname, 'bot.env')); fs.accessSync(path.resolve(__dirname, 'bot.env'));
require('dotenv').config({ path: path.resolve(__dirname, 'bot.env') }); require('dotenv').config({ path: path.resolve(__dirname, 'bot.env') });
} catch (e) { } catch {
try { try {
fs.accessSync(path.resolve(__dirname, 'api.env')); fs.accessSync(path.resolve(__dirname, 'api.env'));
require('dotenv').config({ path: path.resolve(__dirname, 'api.env') }); require('dotenv').config({ path: path.resolve(__dirname, 'api.env') });
} catch (e) { } catch {
throw new Error("bot.env or api.env required"); throw new Error("bot.env or api.env required");
} }
} }

View file

@ -4,7 +4,7 @@ export class AddTypeAndPermissionsToApiPermissions1573158035867 implements Migra
public async up(queryRunner: QueryRunner): Promise<any> { public async up(queryRunner: QueryRunner): Promise<any> {
try { try {
await queryRunner.dropPrimaryKey("api_permissions"); await queryRunner.dropPrimaryKey("api_permissions");
} catch (e) {} // tslint:disable-line } catch {} // tslint:disable-line
const table = (await queryRunner.getTable("api_permissions"))!; const table = (await queryRunner.getTable("api_permissions"))!;
if (table.indices.length) { if (table.indices.length) {

View file

@ -52,7 +52,7 @@ export async function postCaseToCaseLogChannel(
try { try {
await pluginData.client.editMessage(channelId, messageId, caseEmbed); await pluginData.client.editMessage(channelId, messageId, caseEmbed);
return null; return null;
} catch (e) {} // tslint:disable-line:no-empty } catch {} // tslint:disable-line:no-empty
} }
try { try {
@ -63,7 +63,7 @@ export async function postCaseToCaseLogChannel(
}); });
} }
return postedMessage; return postedMessage;
} catch (e) { } catch {
pluginData.state.logs.log(LogType.BOT_ALERT, { pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Failed to post case #${theCase.case_number} to the case log channel`, body: `Failed to post case #${theCase.case_number} to the case log channel`,
}); });

View file

@ -14,7 +14,7 @@ export async function censorMessage(
try { try {
await pluginData.client.deleteMessage(savedMessage.channel_id, savedMessage.id, "Censored"); await pluginData.client.deleteMessage(savedMessage.channel_id, savedMessage.id, "Censored");
} catch (e) { } catch {
return; return;
} }

View file

@ -13,7 +13,7 @@ export async function rehostAttachment(attachment: Attachment, targetChannel: Te
let downloaded; let downloaded;
try { try {
downloaded = await downloadFile(attachment.url, 3); downloaded = await downloadFile(attachment.url, 3);
} catch (e) { } catch {
return "Failed to download attachment after 3 tries"; return "Failed to download attachment after 3 tries";
} }
@ -23,7 +23,7 @@ export async function rehostAttachment(attachment: Attachment, targetChannel: Te
file: await fsp.readFile(downloaded.path), file: await fsp.readFile(downloaded.path),
}); });
return rehostMessage.attachments[0].url; return rehostMessage.attachments[0].url;
} catch (e) { } catch {
return "Failed to rehost attachment"; return "Failed to rehost attachment";
} }
} }

View file

@ -15,7 +15,7 @@ export async function moveMember(
await modMember.edit({ await modMember.edit({
channelID: target.voiceState.channelID, channelID: target.voiceState.channelID,
}); });
} catch (e) { } catch {
sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?"); sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?");
return; return;
} }

View file

@ -21,7 +21,7 @@ export async function sendWhere(
let invite: Invite; let invite: Invite;
try { try {
invite = await createOrReuseInvite(voice); invite = await createOrReuseInvite(voice);
} catch (e) { } catch {
sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!"); sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!");
return; return;
} }

View file

@ -23,7 +23,7 @@ export async function saveMessagesToDB(
} }
await pluginData.state.savedMessages.createFromMsg(thisMsg, { is_permanent: true }); await pluginData.state.savedMessages.createFromMsg(thisMsg, { is_permanent: true });
} catch (e) { } catch {
failed.push(id); failed.push(id);
} }
} }

View file

@ -69,7 +69,7 @@ export const ForcebanCmd = modActionsCmd({
try { try {
// FIXME: Use banUserId()? // FIXME: Use banUserId()?
await pluginData.guild.banMember(user.id, 1, reason != null ? encodeURIComponent(reason) : undefined); await pluginData.guild.banMember(user.id, 1, reason != null ? encodeURIComponent(reason) : undefined);
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member"); sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
return; return;
} }

View file

@ -77,7 +77,7 @@ export const MassbanCmd = modActionsCmd({
}); });
pluginData.state.events.emit("ban", userId, banReason); pluginData.state.events.emit("ban", userId, banReason);
} catch (e) { } catch {
failedBans.push(userId); failedBans.push(userId);
} }
} }

View file

@ -69,7 +69,7 @@ export const MassunbanCmd = modActionsCmd({
reason: `Mass unban: ${unbanReason}`, reason: `Mass unban: ${unbanReason}`,
postInCaseLogOverride: false, postInCaseLogOverride: false,
}); });
} catch (e) { } catch {
failedUnbans.push({ userId, reason: UnbanFailReasons.UNBAN_FAILED }); failedUnbans.push({ userId, reason: UnbanFailReasons.UNBAN_FAILED });
} }
} }

View file

@ -50,7 +50,7 @@ export const UnbanCmd = modActionsCmd({
try { try {
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id); ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
await pluginData.guild.unbanMember(user.id, reason != null ? encodeURIComponent(reason) : undefined); await pluginData.guild.unbanMember(user.id, reason != null ? encodeURIComponent(reason) : undefined);
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?"); sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?");
return; return;
} }

View file

@ -83,7 +83,7 @@ export async function actualKickMemberCmd(
try { try {
await memberToKick.ban(1, encodeURIComponent("kick -clean")); await memberToKick.ban(1, encodeURIComponent("kick -clean"));
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)"); sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)");
} }
@ -92,7 +92,7 @@ export async function actualKickMemberCmd(
try { try {
await pluginData.guild.unbanMember(memberToKick.id, encodeURIComponent("kick -clean")); await pluginData.guild.unbanMember(memberToKick.id, encodeURIComponent("kick -clean"));
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)"); sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)");
} }
} }

View file

@ -30,7 +30,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
} }
lock.unlock(); lock.unlock();
} catch (e) { } catch {
pluginData.state.serverLogs.log(LogType.BOT_ALERT, { pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
body: `Failed to remove mute role from {userMention(member)}`, body: `Failed to remove mute role from {userMention(member)}`,
member: stripObjectToScalars(member), member: stripObjectToScalars(member),

View file

@ -126,7 +126,7 @@ export async function muteUser(
// TODO: Add back the voiceState check once we figure out how to get voice state for guild members that are loaded on-demand // TODO: Add back the voiceState check once we figure out how to get voice state for guild members that are loaded on-demand
try { try {
await member.edit({ channelID: moveToVoiceChannel }); await member.edit({ channelID: moveToVoiceChannel });
} catch (e) {} // tslint:disable-line } catch {} // tslint:disable-line
} }
} }

View file

@ -34,7 +34,7 @@ export async function scheduledPostLoop(pluginData: GuildPluginData<PostPluginTy
channel: stripObjectToScalars(channel), channel: stripObjectToScalars(channel),
messageId: postedMessage.id, messageId: postedMessage.id,
}); });
} catch (e) { } catch {
pluginData.state.logs.log(LogType.BOT_ALERT, { pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`, body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`,
channel: stripObjectToScalars(channel), channel: stripObjectToScalars(channel),

View file

@ -36,7 +36,7 @@ export async function postDueRemindersLoop(pluginData: GuildPluginData<Reminders
}, },
}); });
} }
} catch (e) { } catch {
// Probably random Discord internal server error or missing permissions or somesuch // Probably random Discord internal server error or missing permissions or somesuch
// Try again next round unless we've already tried to post this a bunch of times // Try again next round unless we've already tried to post this a bunch of times
const tries = pluginData.state.tries.get(reminder.id) || 0; const tries = pluginData.state.tries.get(reminder.id) || 0;

View file

@ -82,7 +82,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
await msg.member.edit({ await msg.member.edit({
roles: Array.from(newRoleIds), roles: Array.from(newRoleIds),
}); });
} catch (e) { } catch {
sendErrorMessage( sendErrorMessage(
pluginData, pluginData,
msg.channel, msg.channel,

View file

@ -56,7 +56,7 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
`<@!${msg.author.id}> Removed ${removedRolesStr.join(", ")} ${removedRolesWord}`, `<@!${msg.author.id}> Removed ${removedRolesStr.join(", ")} ${removedRolesWord}`,
); );
} }
} catch (e) { } catch {
sendSuccessMessage( sendSuccessMessage(
pluginData, pluginData,
msg.channel, msg.channel,

View file

@ -17,7 +17,7 @@ export async function disableBotSlowmodeForChannel(
for (const slowmodeUser of users) { for (const slowmodeUser of users) {
try { try {
await clearBotSlowmodeFromUserId(pluginData, channel, slowmodeUser.user_id); await clearBotSlowmodeFromUserId(pluginData, channel, slowmodeUser.user_id);
} catch (e) { } catch {
// Removing the slowmode failed. Record this so the permissions can be changed manually, and remove the database entry. // Removing the slowmode failed. Record this so the permissions can be changed manually, and remove the database entry.
failedUsers.push(slowmodeUser.user_id); failedUsers.push(slowmodeUser.user_id);
await pluginData.state.slowmodes.clearSlowmodeUser(channel.id, slowmodeUser.user_id); await pluginData.state.slowmodes.clearSlowmodeUser(channel.id, slowmodeUser.user_id);

View file

@ -19,7 +19,7 @@ export const StarboardReactionAddEvt = starboardEvt({
// Message is not cached, fetch it // Message is not cached, fetch it
try { try {
msg = await msg.channel.getMessage(msg.id); msg = await msg.channel.getMessage(msg.id);
} catch (e) { } catch {
// Sometimes we get this event for messages we can't fetch with getMessage; ignore silently // Sometimes we get this event for messages we can't fetch with getMessage; ignore silently
return; return;
} }

View file

@ -25,7 +25,7 @@ export const AboutCmd = utilityCmd({
try { try {
const lcl = new LCL(rootDir); const lcl = new LCL(rootDir);
lastCommit = await lcl.getLastCommit(); lastCommit = await lcl.getLastCommit();
} catch (e) {} // tslint:disable-line:no-empty } catch {} // tslint:disable-line:no-empty
let lastUpdate; let lastUpdate;
let version; let version;

View file

@ -32,7 +32,7 @@ export const NicknameCmd = utilityCmd({
await args.member.edit({ await args.member.edit({
nick: args.nickname, nick: args.nickname,
}); });
} catch (e) { } catch {
msg.channel.createMessage(errorMessage("Failed to change nickname")); msg.channel.createMessage(errorMessage("Failed to change nickname"));
return; return;
} }

View file

@ -23,7 +23,7 @@ export const NicknameResetCmd = utilityCmd({
await args.member.edit({ await args.member.edit({
nick: "", nick: "",
}); });
} catch (e) { } catch {
msg.channel.createMessage(errorMessage("Failed to reset nickname")); msg.channel.createMessage(errorMessage("Failed to reset nickname"));
return; return;
} }

View file

@ -38,7 +38,7 @@ export const VcdisconnectCmd = utilityCmd({
await args.member.edit({ await args.member.edit({
channelID: null, channelID: null,
}); });
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member"); sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member");
return; return;
} }

View file

@ -75,7 +75,7 @@ export const VcmoveCmd = utilityCmd({
await args.member.edit({ await args.member.edit({
channelID: channel.id, channelID: channel.id,
}); });
} catch (e) { } catch {
sendErrorMessage(pluginData, msg.channel, "Failed to move member"); sendErrorMessage(pluginData, msg.channel, "Failed to move member");
return; return;
} }
@ -174,7 +174,7 @@ export const VcmoveAllCmd = utilityCmd({
currMember.edit({ currMember.edit({
channelID: channel.id, channelID: channel.id,
}); });
} catch (e) { } catch {
if (msg.member.id === currMember.id) { if (msg.member.id === currMember.id) {
sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members"); sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members");
return; return;

View file

@ -46,7 +46,7 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({
if (config.send_dm) { if (config.send_dm) {
try { try {
await sendDM(member.user, formatted, "welcome message"); await sendDM(member.user, formatted, "welcome message");
} catch (e) { } catch {
pluginData.state.logs.log(LogType.DM_FAILED, { pluginData.state.logs.log(LogType.DM_FAILED, {
source: "welcome message", source: "welcome message",
user: stripObjectToScalars(member.user), user: stripObjectToScalars(member.user),
@ -60,7 +60,7 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({
try { try {
await createChunkedMessage(channel, formatted); await createChunkedMessage(channel, formatted);
} catch (e) { } catch {
pluginData.state.logs.log(LogType.BOT_ALERT, { pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`, body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`,
member: stripObjectToScalars(member), member: stripObjectToScalars(member),

View file

@ -526,7 +526,7 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] {
try { try {
matchUrl = new URL(withProtocol) as MatchedURL; matchUrl = new URL(withProtocol) as MatchedURL;
matchUrl.input = match; matchUrl.input = match;
} catch (e) { } catch {
return urls; return urls;
} }

View file

@ -22,7 +22,7 @@ export const AuthStore: Module<AuthState, RootState> = {
await dispatch("setApiKey", storedKey); await dispatch("setApiKey", storedKey);
return; return;
} }
} catch (e) {} // tslint:disable-line } catch {} // tslint:disable-line
console.log("Unable to validate key, removing from localStorage"); // tslint:disable-line console.log("Unable to validate key, removing from localStorage"); // tslint:disable-line
localStorage.removeItem("apiKey"); localStorage.removeItem("apiKey");