Skip to content

Commit

Permalink
finish resetbot command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Nov 21, 2019
1 parent 13d268f commit 68b0db0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var result,shards,firstShardID,lastShardID;
// How many clusters we will have
var clusters = Math.ceil(shards/5);
if(debug){
shards = 2;
shards = 4;
firstShardID = 0;
lastShardID = shards-1;
clusters = 2
Expand Down
28 changes: 2 additions & 26 deletions src/commands/commandList/admin/resetbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,8 @@ module.exports = new CommandInterface({
dm:true,

execute: function(p){
p.msg.channel.send("Restarting all shards...").then(function(){
for(var i=0;i<p.client.shard.count;i++){
if(i!=p.client.shard.ids[0]){
var func = resetShard(p,i);
setTimeout(func,(i+1)*delay);
}
}
setTimeout(function(){
p.msg.channel.send("["+p.client.shard.ids[0]+"] Restarting last shard...").then(function(){
console.log("["+p.client.shard.ids[0]+"] Shard is restarting!");
process.exit(0);
});
},(p.client.shard.count+1)*delay);
});
p.send("Restarting all shards");
p.pubsub.publish("endProcess");
}

})

function resetShard(p,id){
let num = id;
return function(){
p.client.shard.broadcastEval(`
if(this.shard.ids[0]==${num}){
console.log("["+this.shard.ids[0]+"] Shard is restarting!");
process.exit(0);
}
`);
}
}
21 changes: 21 additions & 0 deletions src/utils/pubsubHandlers/endProcess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* OwO Bot for Discord
* Copyright (C) 2019 Christopher Thai
* This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
* For more information, see README.md and LICENSE
*/

var timer;

exports.handle = async function(main, message){
if(timer){
clearTimeout(timer);
delete timer;
}
let time = main.clusterID*5000;
console.log("ending "+main.clusterID+" in "+time+"ms");
timer = setTimeout(function(){
process.exit(0);
},time);
}

0 comments on commit 68b0db0

Please sign in to comment.