Skip to content

Commit

Permalink
Merge branch 'release/v8.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Sep 12, 2019
2 parents 3a9d818 + c514b6b commit e5c9756
Show file tree
Hide file tree
Showing 64 changed files with 472 additions and 337 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "start"],
"port": 9229,
"timeout": 15000
}
]
}
5 changes: 4 additions & 1 deletion locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,10 @@
"premiumOnly": "This command is only available for premium subscribers!",
"rateLimit": "Slow down! Please wait {{ cooldown }} seconds and try again.",
"role": "You do not have permission to use this command.\nYou need one of the following roles: {{{ roles }}}",
"viewAuditLogs": "View Audit Logs"
"viewAuditLogs": "View Audit Logs",
"manageMessages": "permissions.manageMessages",
"readMessageHistory": "permissions.readMessageHistory",
"missing": "permissions.missing"
},
"prompt": {
"canceled": "Canceled"
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-invite-manager",
"version": "8.2.1",
"version": "8.3.0",
"description": "",
"main": "./bin/bot.js",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion scripts/dev-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ child.on('error', error => console.log(error));
child.on('close', () => {
child = spawn(
'node',
['--inspect', './bin/bot.js', '--no-rabbitmq', config.devToken, '1', '1'],
[
'--inspect-brk=9229',
'./bin/bot.js',
'--no-rabbitmq',
config.devToken,
'1',
'1'
],
{
stdio: 'inherit'
}
Expand Down
33 changes: 14 additions & 19 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ export class IMClient extends Client {
this.music = new MusicService(this);

// Services
this.rabbitmq.init();
this.cmds.init();
this.rabbitmq.init();
this.scheduler.init();

this.disabledGuilds = new Set();

Expand Down Expand Up @@ -323,7 +324,7 @@ export class IMClient extends Client {
this.dbl = new DBL(this.config.bot.dblToken, this);
}

this.setActivity();
await this.setActivity();
this.activityInterval = setInterval(
() => this.setActivity(),
1 * 60 * 1000
Expand Down Expand Up @@ -506,7 +507,7 @@ export class IMClient extends Client {
if (modLogChannelId) {
const logChannel = guild.channels.get(modLogChannelId) as TextChannel;
if (logChannel) {
this.msg.sendEmbed(logChannel, embed);
await this.msg.sendEmbed(logChannel, embed);
}
}
}
Expand Down Expand Up @@ -554,7 +555,7 @@ export class IMClient extends Client {
}
]
});
this.msg.sendEmbed(logChannel, embed);
await this.msg.sendEmbed(logChannel, embed);
}
}

Expand All @@ -569,18 +570,8 @@ export class IMClient extends Client {
createdAt: new Date(),
updatedAt: new Date()
},
{
id: guild.id,
name: guild.name,
icon: guild.iconURL,
memberCount: guild.memberCount,
banReason: null
},
{
id: message.author.id,
discriminator: message.author.discriminator,
name: message.author.username
}
guild,
message.author
);
}

Expand Down Expand Up @@ -619,7 +610,11 @@ export class IMClient extends Client {

public async setActivity() {
if (this.dbl) {
this.dbl.postStats(this.guilds.size, this.shardId - 1, this.shardCount);
await this.dbl.postStats(
this.guilds.size,
this.shardId - 1,
this.shardCount
);
}

await this.updateGatewayInfo();
Expand Down Expand Up @@ -660,13 +655,13 @@ export class IMClient extends Client {
private async onConnect() {
console.error('DISCORD CONNECT');
this.gatewayConnected = true;
this.rabbitmq.sendStatusToManager();
await this.rabbitmq.sendStatusToManager();
}

private async onDisconnect(err: Error) {
console.error('DISCORD DISCONNECT');
this.gatewayConnected = false;
this.rabbitmq.sendStatusToManager(err);
await this.rabbitmq.sendStatusToManager(err);

if (err) {
console.error(err);
Expand Down
88 changes: 50 additions & 38 deletions src/framework/services/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CommandsService {
this.commandCalls = new Map();
}

public async init() {
public init() {
console.log(`Loading commands...`);

// Load all commands
Expand Down Expand Up @@ -151,7 +151,7 @@ export class CommandsService {
if (content === '') {
// If the content is an empty string then the user just mentioned the
// bot, so we'll print the prefix to help them out.
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t('bot.mentionHelp', {
prefix: sets.prefix
Expand Down Expand Up @@ -225,7 +225,7 @@ export class CommandsService {
if (!lastCall.warned) {
lastCall.warned = true;
lastCall.last = now + cooldown * 1000;
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t('permissions.rateLimit', {
cooldown: cooldown.toString()
Expand All @@ -247,7 +247,7 @@ export class CommandsService {
: false;

if (!isPremium && cmd.premiumOnly) {
this.client.msg.sendReply(message, t('permissions.premiumOnly'));
await this.client.msg.sendReply(message, t('permissions.premiumOnly'));
return;
}

Expand All @@ -267,7 +267,7 @@ export class CommandsService {
console.error(
`Could not get member ${message.author.id} for ${guild.id}`
);
this.client.msg.sendReply(message, t('permissions.memberError'));
await this.client.msg.sendReply(message, t('permissions.memberError'));
return;
}

Expand All @@ -283,7 +283,7 @@ export class CommandsService {
if (perms && perms.length > 0) {
// Check that we have at least one of the required roles
if (!perms.some(p => member.roles.indexOf(p) >= 0)) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t('permissions.role', {
roles: perms.map(p => `<@&${p}>`).join(', ')
Expand All @@ -293,7 +293,7 @@ export class CommandsService {
}
} else if (cmd.strict) {
// Allow commands that require no roles, if strict is not true
this.client.msg.sendReply(message, t('permissions.adminOnly'));
await this.client.msg.sendReply(message, t('permissions.adminOnly'));
return;
}
}
Expand All @@ -310,7 +310,7 @@ export class CommandsService {
!(channel as GuildChannel).permissionsOf(this.client.user.id).has(p)
);
if (missingPerms.length > 0) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t(`permissions.missing`, {
channel: `<#${channel.id}>`,
Expand Down Expand Up @@ -395,7 +395,7 @@ export class CommandsService {
let val: any = true;
if (!skipVal) {
if (!hasVal) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
`Missing required value for flag \`${flag.name}\`.\n` +
`\`${cmd.usage.replace('{prefix}', sets.prefix)}\`\n` +
Expand All @@ -406,7 +406,7 @@ export class CommandsService {
try {
val = await resolver.resolve(rawVal, context, []);
} catch (e) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
`Invalid value for \`${flag.name}\`: ${e.message}\n` +
`\`${cmd.usage.replace('{prefix}', sets.prefix)}\`\n` +
Expand Down Expand Up @@ -443,7 +443,7 @@ export class CommandsService {
const val = await resolver.resolve(rawVal, context, args);

if (typeof val === typeof undefined && arg.required) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t('resolvers.missingRequired', {
name: arg.name,
Expand All @@ -456,7 +456,7 @@ export class CommandsService {

args.push(val);
} catch (e) {
this.client.msg.sendReply(
await this.client.msg.sendReply(
message,
t('resolvers.invalid', {
name: arg.name,
Expand All @@ -473,56 +473,68 @@ export class CommandsService {
}

// Run command
let error: any = null;
try {
await cmd.action(message, args, flags, context);
} catch (e) {
console.error(e);
// Save the error for later so error handling doesn't count to command process time
error = e;
}

const execTime = Date.now() - start;

if (error) {
console.error(error);

withScope(scope => {
scope.setTag('command', cmd.name);
scope.setExtra('message', message.content);
if (guild) {
scope.setUser({ id: guild.id });
}
captureException(e);
scope.setTag('command', cmd.name);
scope.setExtra('message', message.content);
captureException(error);
});
this.client.msg.sendReply(

if (guild) {
this.client.dbQueue.addIncident(
{
id: null,
guildId: guild.id,
error: error.message,
details: {
command: cmd.name,
author: message.author.id,
message: message.content
}
},
guild
);
}

await this.client.msg.sendReply(
message,
t('cmd.error', {
error: e.message
error: error.message
})
);
return;
}

const execTime: number = Date.now() - start;

// Ignore messages that are not in guild chat or from disabled guilds
if (guild && !this.client.disabledGuilds.has(guild.id)) {
// We have to add the guild and members too, in case our DB does not have them yet
/*this.client.dbQueue.addCommandUsage(
this.client.dbQueue.addCommandUsage(
{
id: null,
guildId: guild.id,
memberId: message.author.id,
command: cmd.name,
args: args.join(' '),
time: execTime,
createdAt: new Date(),
updatedAt: new Date()
errored: error !== null,
time: execTime
},
{
id: guild.id,
name: guild.name,
icon: guild.iconURL,
memberCount: guild.memberCount,
banReason: null
},
{
id: message.author.id,
name: message.author.username,
discriminator: message.author.discriminator
}
);*/
guild,
message.author
);
}
}
}
Loading

0 comments on commit e5c9756

Please sign in to comment.