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

View File

@ -13,7 +13,7 @@ class Intercom {
} }
send(type, message = {}) { 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 if (!process.send) return; // Nowhere to send, the client was not spawned as a shard
return process.send({ return process.send({
[`_${type}`]: true, [`_${type}`]: true,

View File

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