Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices
commit
338f880bd4
|
@ -38,6 +38,7 @@
|
||||||
"object-curly-newline": "off",
|
"object-curly-newline": "off",
|
||||||
"import/prefer-default-export": "off",
|
"import/prefer-default-export": "off",
|
||||||
"no-useless-constructor": "off",
|
"no-useless-constructor": "off",
|
||||||
"@typescript-eslint/no-useless-constructor": 2
|
"@typescript-eslint/no-useless-constructor": 2,
|
||||||
|
"import/extensions": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
|
||||||
|
typescript_build:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- cp ../config.json ./src/config.json
|
||||||
|
- yarn install --ignore-engines
|
||||||
|
- tsc -p ./tsconfig.json
|
||||||
|
|
||||||
|
lint:
|
||||||
|
stage: test
|
||||||
|
before_script:
|
||||||
|
- cp ../config.json ./src/config.json
|
||||||
|
- yarn install --ignore-engines
|
||||||
|
script:
|
||||||
|
- yarn run lint-find
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"main": "dist/Client.js",
|
"main": "dist/Client.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint ./ --ext ts --fix",
|
"lint": "eslint ./ --ext ts --fix",
|
||||||
"build": "tsc -p ./tsconfig.json"
|
"build": "tsc -p ./tsconfig.json",
|
||||||
|
"lint-find": "eslint ./ --ext ts"
|
||||||
},
|
},
|
||||||
"author": "Library of Code sp-us Engineering Team",
|
"author": "Library of Code sp-us Engineering Team",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
|
|
|
@ -119,7 +119,11 @@ export default class Client extends Eris.Client {
|
||||||
});
|
});
|
||||||
this.server = new Server(this, { port: this.config.port });
|
this.server = new Server(this, { port: this.config.port });
|
||||||
|
|
||||||
require.cache = Object.create(null);
|
const corepath = '/var/CloudServices/dist';
|
||||||
|
const cmdFiles = await fs.readdir('/var/CloudServices/dist/commands');
|
||||||
|
cmdFiles.forEach((f) => delete require.cache[`${corepath}/${f}`]);
|
||||||
|
delete require.cache[`${corepath}/config.json`];
|
||||||
|
delete require.cache[`${corepath}/class/Util`];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,15 +44,16 @@ export default class Help extends Command {
|
||||||
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
|
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
|
||||||
return createPaginationEmbed(message, this.client, cmdPages);
|
return createPaginationEmbed(message, this.client, cmdPages);
|
||||||
}
|
}
|
||||||
const { cmd } = await this.client.util.resolveCommand(args, message);
|
const resolved = await this.client.util.resolveCommand(args, message);
|
||||||
if (!cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`);
|
if (!resolved) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`);
|
||||||
|
const { cmd } = resolved;
|
||||||
const perms: string[] = [];
|
const perms: string[] = [];
|
||||||
let allowedRoles = cmd.permissions && cmd.permissions.roles && cmd.permissions.roles.map((r) => `<@&${r}>`).join(', ');
|
let allowedRoles = cmd.permissions && cmd.permissions.roles && cmd.permissions.roles.map((r) => `<@&${r}>`).join(', ');
|
||||||
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
|
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
|
||||||
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', ');
|
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', ');
|
||||||
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
|
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
|
||||||
const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : '';
|
const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : '';
|
||||||
const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName}${alias}`).join(', ')}` : '';
|
const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName} ` : ''}${alias}`).join(', ')}` : '';
|
||||||
const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : '';
|
const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : '';
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
||||||
|
|
|
@ -9,21 +9,24 @@ export default class Load extends Command {
|
||||||
this.description = '(Re)loads command, config or util';
|
this.description = '(Re)loads command, config or util';
|
||||||
this.aliases = ['reload'];
|
this.aliases = ['reload'];
|
||||||
this.permissions = { users: ['253600545972027394', '278620217221971968'] };
|
this.permissions = { users: ['253600545972027394', '278620217221971968'] };
|
||||||
this.enabled = false;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
||||||
const allowed = ['config', 'util', 'command', 'function'];
|
const allowed = ['config', 'util', 'command'];
|
||||||
const type = args[0].toLowerCase();
|
const type = args[0].toLowerCase();
|
||||||
if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`);
|
if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`);
|
||||||
|
|
||||||
const corepath = '/var/CloudServices/dist';
|
const corepath = '/var/CloudServices/dist';
|
||||||
if (type === 'config') this.client.config = require(`${corepath}/config.json`);
|
if (type === 'config') {
|
||||||
else if (type === 'util') {
|
this.client.config = require(`${corepath}/config.json`);
|
||||||
const Util = require(`${corepath}/class/Util`);
|
delete require.cache[`${corepath}/config.json`];
|
||||||
|
} else if (type === 'util') {
|
||||||
|
const Util = require(`${corepath}/class/Util`).default;
|
||||||
this.client.util = new Util(this.client);
|
this.client.util = new Util(this.client);
|
||||||
|
delete require.cache[`${corepath}/class/Util.js`];
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const cmdIndex = require('../commands');
|
const cmdIndex = require('../commands');
|
||||||
|
@ -32,6 +35,8 @@ export default class Load extends Command {
|
||||||
Cmd = require(`${corepath}/commands/${args[1]}`).default;
|
Cmd = require(`${corepath}/commands/${args[1]}`).default;
|
||||||
this.client.commands.remove(args[1]);
|
this.client.commands.remove(args[1]);
|
||||||
this.client.loadCommand(Cmd);
|
this.client.loadCommand(Cmd);
|
||||||
|
delete require.cache[`${corepath}/commands/index.js`];
|
||||||
|
delete require.cache[`${corepath}/commands/${args[1]}.js`];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`);
|
if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default class Pull extends Command {
|
||||||
try {
|
try {
|
||||||
if (this.client.updating) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`);
|
if (this.client.updating) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`);
|
||||||
this.client.updating = true;
|
this.client.updating = true;
|
||||||
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\ngit pull\n\`\`\``);
|
const updateMessage = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching latest commit...***\n\`\`\`sh\n$ git pull\n\`\`\``);
|
||||||
let pull: string;
|
let pull: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -33,14 +33,14 @@ export default class Pull extends Command {
|
||||||
this.client.updating = false;
|
this.client.updating = false;
|
||||||
return updateMessage.edit(updatedMessage);
|
return updateMessage.edit(updatedMessage);
|
||||||
}
|
}
|
||||||
if (!pull.includes('origin/master')) {
|
if (!pull.includes('origin/master') && !pull.includes(' changed, ')) {
|
||||||
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`)
|
const updatedMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.error} ***Unexpected git output***`)
|
||||||
.replace(/```$/, `${pull}\n\`\`\``);
|
.replace(/```$/, `${pull}\n\`\`\``);
|
||||||
this.client.updating = false;
|
this.client.updating = false;
|
||||||
return updateMessage.edit(updatedMessage);
|
return updateMessage.edit(updatedMessage);
|
||||||
}
|
}
|
||||||
const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`)
|
const continueMessage = updateMessage.content.replace(`${this.client.stores.emojis.loading} ***Fetching latest commit...***`, `${this.client.stores.emojis.success} ***Pulled latest commit***\n${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`)
|
||||||
.replace(/```$/, `${pull}\nyarn install\n\`\`\``);
|
.replace(/```$/, `${pull}\n$ yarn install\n\`\`\``);
|
||||||
const passedPull = await updateMessage.edit(continueMessage);
|
const passedPull = await updateMessage.edit(continueMessage);
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,11 +56,11 @@ export default class Pull extends Command {
|
||||||
let updatedPackages: Message;
|
let updatedPackages: Message;
|
||||||
if (install.includes('Already up-to-date')) {
|
if (install.includes('Already up-to-date')) {
|
||||||
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***No dependency updates available***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
||||||
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
|
.replace(/```$/, `${install}\n$ yarn run build\n\`\`\``);
|
||||||
updatedPackages = await updateMessage.edit(updatedMessage);
|
updatedPackages = await updateMessage.edit(updatedMessage);
|
||||||
} else if (install.includes('success Saved lockfile.')) {
|
} else if (install.includes('success Saved lockfile.')) {
|
||||||
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.success} ***Updated dependencies***\n${this.client.stores.emojis.loading} ***Rebuilding files...***`)
|
||||||
.replace(/```$/, `${install}\nyarn run build\n\`\`\``);
|
.replace(/```$/, `${install}\n$ yarn run build\n\`\`\``);
|
||||||
updatedPackages = await updateMessage.edit(updatedMessage);
|
updatedPackages = await updateMessage.edit(updatedMessage);
|
||||||
} else {
|
} else {
|
||||||
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`)
|
const updatedMessage = passedPull.content.replace(`${this.client.stores.emojis.loading} ***Reinstalling dependencies...***`, `${this.client.stores.emojis.error} ***Unexpected yarn install output***`)
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default class Restart extends Command {
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
if (this.client.updating && args[0] !== '-f') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`);
|
if (this.client.updating && args[0] !== '-f') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Update in progress***`);
|
||||||
if (this.client.buildError) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Build error, resolve before restarting***`);
|
if (this.client.buildError) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Build error, resolve before restarting. See CI job on Gitlab***`);
|
||||||
await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Restarting...***`);
|
await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Restarting...***`);
|
||||||
return process.exit(1);
|
return process.exit(1);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in New Issue