mirror of
				https://github.com/citra-emu/discord-bot.git
				synced 2025-11-04 09:14:59 +00:00 
			
		
		
		
	tree-wide: await all the await-able functions
This commit is contained in:
		
							parent
							
								
									10f80bf1bc
								
							
						
					
					
						commit
						0c3a42e5c7
					
				| 
						 | 
				
			
			@ -26,9 +26,9 @@ console.info('Generating module loader ...');
 | 
			
		|||
let modules = collectModules('commands', '.ts');
 | 
			
		||||
let loader_content = header;
 | 
			
		||||
for (let mod of modules) {
 | 
			
		||||
    loader_content += `import * as ${mod} from "./${mod}";\n`;
 | 
			
		||||
    loader_content += `import * as ${mod} from './${mod}';\n`;
 | 
			
		||||
}
 | 
			
		||||
let loader_map = modules.map((moduleName) => `${moduleName.toLowerCase()}: ${moduleName}`).join(', ');
 | 
			
		||||
let loader_map = modules.map((moduleName) => moduleName.toLowerCase() === moduleName ? moduleName : `${moduleName.toLowerCase()}: ${moduleName}`).join(', ');
 | 
			
		||||
loader_content += `\nexport default { ${loader_map} };\n`;
 | 
			
		||||
fs.writeFileSync("./src/commands/_.ts", loader_content);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,8 @@ import { ban } from '../common';
 | 
			
		|||
import * as discord from 'discord.js';
 | 
			
		||||
 | 
			
		||||
export const roles = ['Admins', 'Moderators', 'CitraBot'];
 | 
			
		||||
export function command (message: discord.Message) {
 | 
			
		||||
  message.mentions.users.map(async (user) => {
 | 
			
		||||
export async function command (message: discord.Message) {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    await ban(user, message.author, message.guild);
 | 
			
		||||
  });
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,8 +4,8 @@ import logger from '../logging';
 | 
			
		|||
import * as discord from 'discord.js';
 | 
			
		||||
 | 
			
		||||
export const roles = ['Admins', 'Moderators'];
 | 
			
		||||
export function command (message: discord.Message) {
 | 
			
		||||
  message.mentions.users.map(async (user) => {
 | 
			
		||||
export async function command (message: discord.Message) {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    const count = state.warnings.filter(x => x.id === user.id && !x.cleared);
 | 
			
		||||
    if (count != null && count.length > 0) {
 | 
			
		||||
      count.forEach(warning => { warning.cleared = true; });
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ export function command (message: discord.Message) {
 | 
			
		|||
      await message.channel.send(`${user.toString()}, you have no warnings to clear.`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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.toString()} ${user.username} [${count?.length}].`);
 | 
			
		||||
    await state.logChannel?.send(`${message.author.toString()} has cleared all warnings for ${user.toString()} [${count?.length}].`);
 | 
			
		||||
  });
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ export async function command(message: discord.Message) {
 | 
			
		|||
      throw e;
 | 
			
		||||
    } finally {
 | 
			
		||||
      // We don't need this message anymore
 | 
			
		||||
      waitMessage.then(async waitMessageResult => await waitMessageResult.delete());
 | 
			
		||||
      await waitMessage.then(async waitMessageResult => await waitMessageResult.delete());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,16 +3,16 @@ import logger from '../logging';
 | 
			
		|||
import * as discord from 'discord.js';
 | 
			
		||||
 | 
			
		||||
export const roles = ['Admins', 'Moderators', 'CitraBot'];
 | 
			
		||||
export function command (message: discord.Message) {
 | 
			
		||||
export async function command (message: discord.Message) {
 | 
			
		||||
  const role = process.env.DISCORD_DEVELOPER_ROLE;
 | 
			
		||||
 | 
			
		||||
  if (!role) {
 | 
			
		||||
    logger.error('DISCORD_DEVELOPER_ROLE suddenly became undefined?!');
 | 
			
		||||
    return;
 | 
			
		||||
    return Promise.resolve([]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  message.mentions.users.map((user) => {
 | 
			
		||||
    message.guild?.members.fetch(user).then((member) => {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    return message.guild?.members.fetch(user).then((member) => {
 | 
			
		||||
      const alreadyJoined = member.roles.cache.has(role);
 | 
			
		||||
 | 
			
		||||
      if (alreadyJoined) {
 | 
			
		||||
| 
						 | 
				
			
			@ -20,18 +20,18 @@ export function command (message: discord.Message) {
 | 
			
		|||
          await message.channel.send(`${user.toString()}'s speech has been revoked in the #development channel.`);
 | 
			
		||||
        }).catch(async () => {
 | 
			
		||||
          await state.logChannel?.send(`Error revoking ${user.toString()}'s developer speech...`);
 | 
			
		||||
          logger.error(`Error revoking ${user} ${user.username}'s developer speech...`);
 | 
			
		||||
          logger.error(`Error revoking ${user.toString()} ${user.username}'s developer speech...`);
 | 
			
		||||
        });
 | 
			
		||||
      } else {
 | 
			
		||||
        member.roles.add(role).then(async () => {
 | 
			
		||||
          await message.channel.send(`${user.toString()} has been granted speech in the #development channel.`);
 | 
			
		||||
        }).catch(async () => {
 | 
			
		||||
          await state.logChannel?.send(`Error granting ${user.toString()}'s developer speech...`);
 | 
			
		||||
          logger.error(`Error granting ${user} ${user.username}'s developer speech...`);
 | 
			
		||||
          logger.error(`Error granting ${user.toString()} ${user.username}'s developer speech...`);
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }).catch(async () => {
 | 
			
		||||
      await message.channel.send(`User ${user.toString()} was not found in the channel.`);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,15 +6,15 @@ import * as discord from 'discord.js';
 | 
			
		|||
export const roles = ['Admins', 'Moderators'];
 | 
			
		||||
 | 
			
		||||
function formatWarnings (warnings: UserWarning[]) {
 | 
			
		||||
  return warnings.map(x => `[${x.date}] ${x.warnedByUsername} warned ${x.username} [${x.priorWarnings} + 1]. ${x.silent ? '(silent)' : ''} ${x.cleared ? '(cleared)' : ''}`);
 | 
			
		||||
  return warnings.map(x => `[${x.date.toISOString()}] ${x.warnedByUsername} warned ${x.username} [${x.priorWarnings} + 1]. ${x.silent ? '(silent)' : ''} ${x.cleared ? '(cleared)' : ''}`);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatBans (bans: UserBan[]) {
 | 
			
		||||
  return bans.map(x => `[${x.date}] ${x.warnedByUsername} banned ${x.username} [${x.priorWarnings} + 1].`);
 | 
			
		||||
  return bans.map(x => `[${x.date.toISOString()}] ${x.warnedByUsername} banned ${x.username} [${x.priorWarnings} + 1].`);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function command (message: discord.Message) {
 | 
			
		||||
  message.mentions.users.map(async (user) => {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    const totalWarnings = state.warnings.filter(x => x.id === user.id && x.cleared === false).length;
 | 
			
		||||
    const warns = state.warnings.filter(x => x.id === user.id);
 | 
			
		||||
    const bans = state.bans.filter(x => x.id === user.id);
 | 
			
		||||
| 
						 | 
				
			
			@ -23,5 +23,5 @@ export async function command (message: discord.Message) {
 | 
			
		|||
    const bansString = `Bans: \`\`\`${formatBans(bans).join('\n')}\`\`\``;
 | 
			
		||||
 | 
			
		||||
    await message.channel.send(`\`${user.username} (${totalWarnings}) information:\`${warns.length !== 0 ? warnsString : '\n<No warnings>\n'}${bans.length !== 0 ? bansString : '<Not banned>'}`);
 | 
			
		||||
  });
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ export async function command (message: discord.Message, reply: string | undefin
 | 
			
		|||
  if (reply == null) {
 | 
			
		||||
    replyMessage = message.content.substr(message.content.indexOf(' ') + 1);
 | 
			
		||||
  } else {
 | 
			
		||||
    replyMessage = `${message.mentions.users.map(user => `${user.toString()}`)} ${reply}`;
 | 
			
		||||
    replyMessage = `${message.mentions.users.map(user => `${user.toString()}`).join(' ')} ${reply}`;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  await message.channel.send(replyMessage);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,16 +7,16 @@ const fetchOptions = {
 | 
			
		|||
const repo = process.env.GITHUB_REPOSITORY || 'citra-emu/citra';
 | 
			
		||||
 | 
			
		||||
export const roles = ['Admins', 'Moderators', 'Developer'];
 | 
			
		||||
export function command(message: discord.Message) {
 | 
			
		||||
  const pr_number = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, '');
 | 
			
		||||
  const url = `https://api.github.com/repos/${repo}/pulls/${pr_number}`;
 | 
			
		||||
  fetch(url, fetchOptions).then(response => response.json()).then((pr: any) => {
 | 
			
		||||
export async function command(message: discord.Message) {
 | 
			
		||||
  const prNumber = message.content.substr(message.content.indexOf(' ') + 1).replace(/\n/g, '');
 | 
			
		||||
  const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
 | 
			
		||||
  return fetch(url, fetchOptions).then(response => response.json()).then((pr: any) => {
 | 
			
		||||
    if (!pr || pr.documentation_url || !pr.head) throw new Error('PR not found');
 | 
			
		||||
    const headSHA = pr.head.sha;
 | 
			
		||||
    // 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) => {
 | 
			
		||||
      if (!statuses.check_runs || statuses.total_count < 1) throw new Error('No check runs');
 | 
			
		||||
      const msg = new discord.EmbedBuilder().setTitle(`Status for PR #${pr_number}`).setURL(pr.html_url);
 | 
			
		||||
      const msg = new discord.EmbedBuilder().setTitle(`Status for PR #${prNumber}`).setURL(pr.html_url);
 | 
			
		||||
      let color = 'GREEN' as discord.ColorResolvable;
 | 
			
		||||
      statuses.check_runs.forEach((run: any) => {
 | 
			
		||||
        msg.addFields({ name: run.name, value: `**[${run.status} ${run.conclusion}](${run.html_url})**` });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,13 +5,13 @@ import UserWarning from '../models/UserWarning';
 | 
			
		|||
import * as discord from 'discord.js';
 | 
			
		||||
 | 
			
		||||
export const roles = ['Admins', 'Moderators'];
 | 
			
		||||
export function command(message: discord.Message) {
 | 
			
		||||
export async function command(message: discord.Message) {
 | 
			
		||||
  const silent = message.content.includes('silent');
 | 
			
		||||
 | 
			
		||||
  message.mentions.users.map(async (user) => {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
 | 
			
		||||
 | 
			
		||||
    if (silent === false) {
 | 
			
		||||
    if (!silent) {
 | 
			
		||||
      await message.channel.send(`${user.toString()} You have been warned. Additional infractions may result in a ban.`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -20,5 +20,5 @@ export function command(message: discord.Message) {
 | 
			
		|||
 | 
			
		||||
    state.warnings.push(new UserWarning(user.id, user.username, message.author.id, message.author.username, count, silent));
 | 
			
		||||
    data.flushWarnings();
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
import state from '../state';
 | 
			
		||||
import * as discord from 'discord.js';
 | 
			
		||||
 | 
			
		||||
export function command(message: discord.Message) {
 | 
			
		||||
  message.mentions.users.map(async (user) => {
 | 
			
		||||
export async function command(message: discord.Message) {
 | 
			
		||||
  return Promise.all(message.mentions.users.map(async (user) => {
 | 
			
		||||
    const warnings = state.warnings.filter(x => x.id === user.id && !x.cleared);
 | 
			
		||||
    await message.channel.send(`${user.toString()}, you have ${warnings.length} total warnings.`);
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ export interface IResponses {
 | 
			
		|||
 | 
			
		||||
export interface IModule {
 | 
			
		||||
    readonly roles?: string[],
 | 
			
		||||
    command: (message: Message, args?: string) => void | Promise<void>
 | 
			
		||||
    command: (message: Message, args?: string) => Promise<void> | Promise<void[]>
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ITrigger {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,8 +31,8 @@ if (!rulesRole) {
 | 
			
		|||
  throw new Error('DISCORD_RULES_ROLE somehow became undefined.');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function findArray(haystack: string | any[], arr: any[]) {
 | 
			
		||||
  return arr.some((v: any) => haystack.indexOf(v) >= 0);
 | 
			
		||||
function findArray(haystack: string | string[], arr: string[]) {
 | 
			
		||||
  return arr.some((v: string) => haystack.indexOf(v) >= 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function IsIgnoredCategory(categoryName: string) {
 | 
			
		||||
| 
						 | 
				
			
			@ -158,7 +158,7 @@ client.on('messageCreate', async (message) => {
 | 
			
		|||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!findArray(authorRoles, AllowedMediaRoles)) {
 | 
			
		||||
      const urlRegex = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&\/=]*)/gi);
 | 
			
		||||
      const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/gi;
 | 
			
		||||
      if (message.attachments.size > 0 || message.content.match(urlRegex)) {
 | 
			
		||||
        mediaUsers.set(message.author.id, true);
 | 
			
		||||
      } else if (mediaUsers.get(message.author.id)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -214,16 +214,18 @@ client.on('messageCreate', async (message) => {
 | 
			
		|||
    } catch (err) { logger.error(err); }
 | 
			
		||||
  } else if (message.author.bot === false) {
 | 
			
		||||
    // This is a normal channel message.
 | 
			
		||||
    cachedTriggers.forEach(async function (trigger) {
 | 
			
		||||
      if (!trigger.roles || authorRoles && findArray(authorRoles, trigger.roles)) {
 | 
			
		||||
        if (trigger.trigger(message) === true) {
 | 
			
		||||
          logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
 | 
			
		||||
          try {
 | 
			
		||||
            await trigger.execute(message);
 | 
			
		||||
          } catch (err) { logger.error(err); }
 | 
			
		||||
    await Promise.all(
 | 
			
		||||
      cachedTriggers.map(async function (trigger) {
 | 
			
		||||
        if (!trigger.roles || (authorRoles && findArray(authorRoles, trigger.roles))) {
 | 
			
		||||
          if (trigger.trigger(message)) {
 | 
			
		||||
            logger.debug(`${message.author.username} ${message.author} [Channel: ${message.channel}] triggered: ${message.content}`);
 | 
			
		||||
            try {
 | 
			
		||||
              await trigger.execute(message);
 | 
			
		||||
            } catch (err) { logger.error(err); }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
      })
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,6 @@ export function trigger (message: discord.Message) {
 | 
			
		|||
export async function execute (message: discord.Message) {
 | 
			
		||||
  const count = message.mentions.users.size;
 | 
			
		||||
  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()}`);
 | 
			
		||||
  await state.logChannel?.send(`Ping bomb detected in ${message.channel.toString()} by ${message.author.toString()}`);
 | 
			
		||||
  await ban(message.author, message.author, message.guild);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue