forked from Galactic/galactic-bot
api shard restarting
This commit is contained in:
parent
675762f738
commit
eec63d5542
@ -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;
|
@ -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,
|
||||
|
@ -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'],
|
||||
|
Loading…
Reference in New Issue
Block a user