api shard restarting

This commit is contained in:
Erik 2022-07-24 11:46:51 +03:00
parent 675762f738
commit eec63d5542
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 18 additions and 7 deletions

View File

@ -1,16 +1,21 @@
class ApiClientUtil {
constructor(client) {
this.client = client;
this.client = client;
this.cache = {};
}
get apiManager() {
return this.client.api;
}
async handleMessage(shard, message) {
const { type, id } = message;
let response = null;
try {
switch (type) {
case 'guild-live':
@ -25,6 +30,9 @@ class ApiClientUtil {
case 'settings':
response = await this.settings(message);
break;
case 'restart':
response = await this.restartAPIShards(message);
break;
default:
return shard.send({ id, failure: true, error: '[IPC] No such type' });
}
@ -41,10 +49,7 @@ class ApiClientUtil {
async settings({ guildId }) {
const evalFunc = async (client, { guildId }) => {
const guild = client.guilds.resolve(guildId);
if (!guild) return null;
const wrapper = new client.wrapperClasses.GuildWrapper(client, guild);
const wrapper = client.getGuildWrapper(guildId);
const settings = await wrapper.settings();
return settings;
};
@ -102,6 +107,11 @@ class ApiClientUtil {
}
async restartAPIShards(message) {
const { shards } = message;
await this.apiManager.restartShards(shards);
}
}
module.exports = ApiClientUtil;

View File

@ -13,7 +13,7 @@ class Intercom {
}
send(type, message = {}) {
if (typeof message !== 'object') return false;
if (typeof message !== 'object') throw new Error('Invalid message object');
if (!process.send) return; // Nowhere to send, the client was not spawned as a shard
return process.send({
[`_${type}`]: true,

View File

@ -11,7 +11,8 @@ class NicknameCommand extends ModerationCommand {
options: [{
name: 'name',
description: 'The new nickname to give',
type: 'STRING'
type: 'STRING',
required: true
}],
memberPermissions: ['ManageNicknames'],
clientPermissions: ['ManageNicknames'],