lint: automated fix from ESLint

This commit is contained in:
liushuyu 2021-10-28 15:38:02 -06:00
parent 39c8f5979c
commit e2fb430042
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
10 changed files with 51 additions and 54 deletions

View File

@ -6,4 +6,4 @@ export function command (message: discord.Message) {
message.mentions.users.map(async (user) => { message.mentions.users.map(async (user) => {
await ban(user, message.author, message.guild); await ban(user, message.author, message.guild);
}); });
}; }

View File

@ -18,4 +18,4 @@ export function command (message: discord.Message) {
logger.info(`${message.author.username} has cleared all warnings for ${user} ${user.username} [${count?.length}].`); logger.info(`${message.author.username} has cleared all warnings for ${user} ${user.username} [${count?.length}].`);
await state.logChannel?.send(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count?.length}].`); await state.logChannel?.send(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count?.length}].`);
}); });
}; }

View File

@ -29,7 +29,7 @@ async function updateDatabase () {
} }
try { try {
let response = await fetch(targetServer); const response = await fetch(targetServer);
body = await response.json(); body = await response.json();
} catch (e) { } catch (e) {
logger.error('Unable to download latest games list!'); logger.error('Unable to download latest games list!');
@ -104,5 +104,5 @@ export async function command (message: discord.Message) {
.setURL(url) .setURL(url)
.setThumbnail(screenshot); .setThumbnail(screenshot);
await message.channel.send({embeds: [embed]}); await message.channel.send({ embeds: [embed] });
} }

View File

@ -30,9 +30,8 @@ export function command (message: discord.Message) {
logger.error(`Error granting ${user} ${user.username}'s developer speech...`); logger.error(`Error granting ${user} ${user.username}'s developer speech...`);
}); });
} }
}).catch(async () => { }).catch(async () => {
await message.channel.send(`User ${user.toString()} was not found in the channel.`); await message.channel.send(`User ${user.toString()} was not found in the channel.`);
}); });
}); });
} }

View File

@ -24,4 +24,4 @@ export async function command (message: discord.Message) {
await message.channel.send(`\`${user.username} (${totalWarnings}) information:\`${warns.length !== 0 ? warnsString : '\n<No warnings>\n'}${bans.length !== 0 ? bansString : '<Not banned>'}`); await message.channel.send(`\`${user.username} (${totalWarnings}) information:\`${warns.length !== 0 ? warnsString : '\n<No warnings>\n'}${bans.length !== 0 ? bansString : '<Not banned>'}`);
}); });
}; }

View File

@ -2,12 +2,12 @@ import fetch from 'node-fetch';
import discord = require('discord.js'); import discord = require('discord.js');
const fetchOptions = { const fetchOptions = {
headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)', 'Accept': 'application/vnd.github.antiope-preview+json' } headers: { 'User-Agent': 'Citra-Emu/CitraBot (Node.js)', Accept: 'application/vnd.github.antiope-preview+json' }
}; };
const repo = process.env.GITHUB_REPOSITORY || 'citra-emu/citra'; const repo = process.env.GITHUB_REPOSITORY || 'citra-emu/citra';
export const roles = ['Admins', 'Moderators', 'Developer']; export const roles = ['Admins', 'Moderators', 'Developer'];
export function command(message: discord.Message) { export function command (message: discord.Message) {
const pr_number = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, ''); const pr_number = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, '');
const url = `https://api.github.com/repos/${repo}/pulls/${pr_number}`; const url = `https://api.github.com/repos/${repo}/pulls/${pr_number}`;
fetch(url, fetchOptions).then(response => response.json()).then((pr: any) => { fetch(url, fetchOptions).then(response => response.json()).then((pr: any) => {
@ -16,7 +16,7 @@ export function command(message: discord.Message) {
// use the new GitHub checks API // use the new GitHub checks API
fetch(`https://api.github.com/repos/${repo}/commits/${headSHA}/check-runs`, fetchOptions).then(response => response.json()).then(async (statuses: any) => { fetch(`https://api.github.com/repos/${repo}/commits/${headSHA}/check-runs`, fetchOptions).then(response => response.json()).then(async (statuses: any) => {
if (!statuses.check_runs || statuses.total_count < 1) throw new Error('No check runs'); if (!statuses.check_runs || statuses.total_count < 1) throw new Error('No check runs');
let msg = new discord.MessageEmbed().setTitle(`Status for PR #${pr_number}`).setURL(pr.html_url); const msg = new discord.MessageEmbed().setTitle(`Status for PR #${pr_number}`).setURL(pr.html_url);
let color = 'GREEN' as discord.ColorResolvable; let color = 'GREEN' as discord.ColorResolvable;
statuses.check_runs.forEach((run: any) => { statuses.check_runs.forEach((run: any) => {
msg.addField(`${run.name}`, `**[${run.status} ${run.conclusion}](${run.html_url})**`); msg.addField(`${run.name}`, `**[${run.status} ${run.conclusion}](${run.html_url})**`);
@ -25,7 +25,7 @@ export function command(message: discord.Message) {
msg.setColor(color); msg.setColor(color);
await message.channel.send({ embeds: [msg] }); await message.channel.send({ embeds: [msg] });
}).catch(async () => { }).catch(async () => {
await message.channel.send('I wasn\'t able to get the status of that PR...') await message.channel.send('I wasn\'t able to get the status of that PR...');
}); });
}).catch(async () => { }).catch(async () => {
await message.channel.send('No such PR.'); await message.channel.send('No such PR.');

View File

@ -4,17 +4,17 @@ import logger from './logging';
import UserBan from './models/UserBan'; import UserBan from './models/UserBan';
import discord = require('discord.js'); import discord = require('discord.js');
export async function ban(user: discord.User, moderator: discord.User, guild: discord.Guild | null) { export async function ban (user: discord.User, moderator: discord.User, guild: discord.Guild | null) {
const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0; const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
logger.info(`${moderator.toString()} has banned ${user.toString()} ${user.id} ${user.username}.`); logger.info(`${moderator.toString()} has banned ${user.toString()} ${user.id} ${user.username}.`);
await state.logChannel?.send(`${moderator.toString()} has banned ${user.id} ${user.toString()} [${count}].`); await state.logChannel?.send(`${moderator.toString()} has banned ${user.id} ${user.toString()} [${count}].`);
state.bans.push(new UserBan(user.id, user.username, moderator.id, moderator.username, count)); state.bans.push(new UserBan(user.id, user.username, moderator.id, moderator.username, count));
guild?.members?.ban(user).catch(async function (error) { guild?.members?.ban(user).catch(async function (error) {
await state.logChannel?.send(`Error banning ${user.toString()} ${user.username}`); await state.logChannel?.send(`Error banning ${user.toString()} ${user.username}`);
logger.error(`Error banning ${user.toString()} ${user.id} ${user.username}.`, error); logger.error(`Error banning ${user.toString()} ${user.id} ${user.username}.`, error);
}); });
data.flushBans(); data.flushBans();
} }

View File

@ -13,7 +13,7 @@ const logger = winston.createLogger({
handleExceptions: true handleExceptions: true
}) })
], ],
exitOnError: true, exitOnError: true
}); });
// Setup logging for LogDNA cloud logging. // Setup logging for LogDNA cloud logging.

View File

@ -1,6 +1,4 @@
// Check for environmental variables. // Check for environmental variables.
require('checkenv').check();
import discord = require('discord.js'); import discord = require('discord.js');
import path = require('path'); import path = require('path');
import fs = require('fs'); import fs = require('fs');
@ -10,6 +8,8 @@ import state from './state';
import * as data from './data'; import * as data from './data';
import { IModule, ITrigger } from './models/interfaces'; import { IModule, ITrigger } from './models/interfaces';
require('checkenv').check();
interface IModuleMap { interface IModuleMap {
[name: string]: IModule; [name: string]: IModule;
} }
@ -29,13 +29,13 @@ if (!rluesRole) {
throw new Error('DISCORD_RULES_ROLE somehow became undefined.'); throw new Error('DISCORD_RULES_ROLE somehow became undefined.');
} }
function findArray(haystack: string | any[], arr: any[]) { function findArray (haystack: string | any[], arr: any[]) {
return arr.some(function (v: any) { return arr.some(function (v: any) {
return haystack.indexOf(v) >= 0; return haystack.indexOf(v) >= 0;
}); });
} }
function IsIgnoredCategory(categoryName: string) { function IsIgnoredCategory (categoryName: string) {
const IgnoredCategory = ['internal', 'team', 'development']; const IgnoredCategory = ['internal', 'team', 'development'];
return IgnoredCategory.includes(categoryName); return IgnoredCategory.includes(categoryName);
} }
@ -45,8 +45,8 @@ client.on('ready', async () => {
if (!process.env.DISCORD_LOG_CHANNEL || !process.env.DISCORD_MSGLOG_CHANNEL) { if (!process.env.DISCORD_LOG_CHANNEL || !process.env.DISCORD_MSGLOG_CHANNEL) {
throw new Error('DISCORD_LOG_CHANNEL or DISCORD_MSGLOG_CHANNEL not defined.'); throw new Error('DISCORD_LOG_CHANNEL or DISCORD_MSGLOG_CHANNEL not defined.');
} }
let logChannel = await client.channels.fetch(process.env.DISCORD_LOG_CHANNEL) as discord.TextChannel; const logChannel = await client.channels.fetch(process.env.DISCORD_LOG_CHANNEL) as discord.TextChannel;
let msglogChannel = await client.channels.fetch(process.env.DISCORD_MSGLOG_CHANNEL) as discord.TextChannel; const msglogChannel = await client.channels.fetch(process.env.DISCORD_MSGLOG_CHANNEL) as discord.TextChannel;
if (!logChannel.send) throw new Error('DISCORD_LOG_CHANNEL is not a text channel!'); if (!logChannel.send) throw new Error('DISCORD_LOG_CHANNEL is not a text channel!');
if (!msglogChannel.send) throw new Error('DISCORD_MSGLOG_CHANNEL is not a text channel!'); if (!msglogChannel.send) throw new Error('DISCORD_MSGLOG_CHANNEL is not a text channel!');
state.logChannel = logChannel; state.logChannel = logChannel;
@ -69,22 +69,21 @@ client.on('disconnect', () => {
}); });
client.on('guildMemberAdd', async (member) => { client.on('guildMemberAdd', async (member) => {
if (process.env.DISCORD_RULES_ROLE) if (process.env.DISCORD_RULES_ROLE) { await member.roles.add(process.env.DISCORD_RULES_ROLE); }
await member.roles.add(process.env.DISCORD_RULES_ROLE);
}); });
client.on('messageDelete', async (message) => { client.on('messageDelete', async (message) => {
const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP']; const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP'];
let authorRoles = message.member?.roles?.cache?.map(x => x.name); const authorRoles = message.member?.roles?.cache?.map(x => x.name);
if (!authorRoles) { if (!authorRoles) {
logger.error(`Unable to get the roles for ${message.author}`); logger.error(`Unable to get the roles for ${message.author}`);
return; return;
} }
if (!findArray(authorRoles, AllowedRoles)) { if (!findArray(authorRoles, AllowedRoles)) {
let parent = (message.channel as discord.TextChannel).parent; const parent = (message.channel as discord.TextChannel).parent;
if (parent && IsIgnoredCategory(parent.name) === false) { if (parent && IsIgnoredCategory(parent.name) === false) {
if (((message.content && message.content.startsWith('.') === false) || (message.attachments.size > 0)) && message.author?.bot === false) { if (((message.content && message.content.startsWith('.') === false) || (message.attachments.size > 0)) && message.author?.bot === false) {
let messageAttachment = message.attachments.first()?.proxyURL const messageAttachment = message.attachments.first()?.proxyURL;
const deletionEmbed = new discord.MessageEmbed() const deletionEmbed = new discord.MessageEmbed()
.setAuthor(message.author?.tag, message.author?.displayAvatarURL()) .setAuthor(message.author?.tag, message.author?.displayAvatarURL())
@ -93,9 +92,9 @@ client.on('messageDelete', async (message) => {
.setTimestamp() .setTimestamp()
.setColor('RED'); .setColor('RED');
if (messageAttachment) deletionEmbed.setImage(messageAttachment) if (messageAttachment) deletionEmbed.setImage(messageAttachment);
let userInfo = `${message.author?.toString()} (${message.author?.username}) (${message.author})` const userInfo = `${message.author?.toString()} (${message.author?.username}) (${message.author})`;
await state.msglogChannel?.send({ content: userInfo, embeds: [deletionEmbed] }); await state.msglogChannel?.send({ content: userInfo, embeds: [deletionEmbed] });
logger.info(`${message.author?.username} ${message.author} deleted message: ${message.cleanContent}.`); logger.info(`${message.author?.username} ${message.author} deleted message: ${message.cleanContent}.`);
@ -106,18 +105,18 @@ client.on('messageDelete', async (message) => {
client.on('messageUpdate', async (oldMessage, newMessage) => { client.on('messageUpdate', async (oldMessage, newMessage) => {
const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP']; const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP'];
let authorRoles = oldMessage.member?.roles?.cache?.map(x => x.name); const authorRoles = oldMessage.member?.roles?.cache?.map(x => x.name);
if (!authorRoles) { if (!authorRoles) {
logger.error(`Unable to get the roles for ${oldMessage.author}`); logger.error(`Unable to get the roles for ${oldMessage.author}`);
return; return;
} }
if (!findArray(authorRoles, AllowedRoles)) { if (!findArray(authorRoles, AllowedRoles)) {
let parent = (oldMessage.channel as discord.TextChannel).parent; const parent = (oldMessage.channel as discord.TextChannel).parent;
if (parent && IsIgnoredCategory(parent.name) === false) { if (parent && IsIgnoredCategory(parent.name) === false) {
const oldM = oldMessage.cleanContent || '<no content>'; const oldM = oldMessage.cleanContent || '<no content>';
const newM = newMessage.cleanContent; const newM = newMessage.cleanContent;
if (oldMessage.content !== newMessage.content && oldM && newM) { if (oldMessage.content !== newMessage.content && oldM && newM) {
let messageAttachment = oldMessage.attachments.first()?.proxyURL const messageAttachment = oldMessage.attachments.first()?.proxyURL;
const editedEmbed = new discord.MessageEmbed() const editedEmbed = new discord.MessageEmbed()
.setAuthor(oldMessage.author?.tag || '<unknown>', oldMessage.author?.displayAvatarURL()) .setAuthor(oldMessage.author?.tag || '<unknown>', oldMessage.author?.displayAvatarURL())
@ -127,9 +126,9 @@ client.on('messageUpdate', async (oldMessage, newMessage) => {
.setTimestamp() .setTimestamp()
.setColor('GREEN'); .setColor('GREEN');
if (messageAttachment) editedEmbed.setImage(messageAttachment) if (messageAttachment) editedEmbed.setImage(messageAttachment);
let userInfo = `${oldMessage.author?.toString()} (${oldMessage.author?.username}) (${oldMessage.author})` const userInfo = `${oldMessage.author?.toString()} (${oldMessage.author?.username}) (${oldMessage.author})`;
await state.msglogChannel?.send({ content: userInfo, embeds: [editedEmbed] }); await state.msglogChannel?.send({ content: userInfo, embeds: [editedEmbed] });
logger.info(`${oldMessage.author?.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`); logger.info(`${oldMessage.author?.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`);
@ -151,7 +150,7 @@ client.on('messageCreate', async (message) => {
logger.verbose(`${message.author.username} ${message.author} [Channel: ${(message.channel as discord.TextChannel).name} ${message.channel}]: ${message.content}`); logger.verbose(`${message.author.username} ${message.author} [Channel: ${(message.channel as discord.TextChannel).name} ${message.channel}]: ${message.content}`);
let authorRoles = message.member?.roles?.cache?.map(x => x.name); const authorRoles = message.member?.roles?.cache?.map(x => x.name);
if (message.channel.id === process.env.DISCORD_MEDIA_CHANNEL && !message.author.bot) { if (message.channel.id === process.env.DISCORD_MEDIA_CHANNEL && !message.author.bot) {
const AllowedMediaRoles = ['Administrators', 'Moderators', 'Team', 'VIP']; const AllowedMediaRoles = ['Administrators', 'Moderators', 'Team', 'VIP'];
@ -187,7 +186,7 @@ client.on('messageCreate', async (message) => {
const cmd = message.content.split(' ', 1)[0].slice(1); const cmd = message.content.split(' ', 1)[0].slice(1);
// Check by the name of the command. // Check by the name of the command.
let cachedModule = cachedModules[`${cmd.toLowerCase()}`]; const cachedModule = cachedModules[`${cmd.toLowerCase()}`];
let quoteResponse = null; let quoteResponse = null;
// Check by the quotes in the configuration. // Check by the quotes in the configuration.
if (!cachedModule) quoteResponse = state.responses.quotes[cmd]; if (!cachedModule) quoteResponse = state.responses.quotes[cmd];
@ -208,13 +207,12 @@ client.on('messageCreate', async (message) => {
await message.delete(); await message.delete();
try { try {
if (!!cachedModule) { if (cachedModule) {
await cachedModule.command(message); await cachedModule.command(message);
} else if (cachedModules['quote']) { } else if (cachedModules.quote) {
await cachedModules['quote'].command(message, quoteResponse?.reply); await cachedModules.quote.command(message, quoteResponse?.reply);
} }
} catch (err) { logger.error(err); } } catch (err) { logger.error(err); }
} else if (message.author.bot === false) { } else if (message.author.bot === false) {
// This is a normal channel message. // This is a normal channel message.
cachedTriggers.forEach(async function (trigger) { cachedTriggers.forEach(async function (trigger) {

View File

@ -3,13 +3,13 @@ import state from '../state';
import logger from '../logging'; import logger from '../logging';
import discord = require('discord.js'); import discord = require('discord.js');
export function trigger(message: discord.Message) { export function trigger (message: discord.Message) {
return message.mentions.users.size > 10; return message.mentions.users.size > 10;
} }
export async function execute(message: discord.Message) { export async function execute (message: discord.Message) {
const count = message.mentions.users.size; const count = message.mentions.users.size;
logger.info(`${message.author.toString()} tagged ${count} users in ${message.channel.toString()}`); logger.info(`${message.author.toString()} tagged ${count} users in ${message.channel.toString()}`);
state.logChannel?.send(`Ping bomb detected in ${message.channel.toString()} by ${message.author.toString()}`); state.logChannel?.send(`Ping bomb detected in ${message.channel.toString()} by ${message.author.toString()}`);
await ban(message.author, message.author, message.guild); await ban(message.author, message.author, message.guild);
}; }