Skip to content

Commit

Permalink
Starting to convert libraries... This is is going to take awhile 😓
Browse files Browse the repository at this point in the history
basic execution of commands done (ban/cooldown/macro/permission checks)
  • Loading branch information
ChristopherBThai committed Oct 14, 2019
1 parent 5eba9e6 commit 94d3747
Show file tree
Hide file tree
Showing 85 changed files with 2,591 additions and 71 deletions.
109 changes: 46 additions & 63 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,54 @@
* For more information, see README.md and LICENSE
*/

const debug = false;
// Grab tokens and secret files
const debug = true;
if(!debug) var tracer = require('dd-trace').init()

/* Default is 4. Use higher numbers if you have enough cores */
process.env.UV_THREADPOOL_SIZE = 17;

if(debug) var auth = require('../tokens/scuttester-auth.json');
else var auth = require('../tokens/owo-auth.json');

const Discord = require('discord.js');
const Manager = new Discord.ShardingManager('./owo.js',{
token:auth.token
});

var loaded = false;
const global = require('./parent_methods/global.js');
const ramCheck = require('./parent_methods/ramCheck.js');
const vote = require('./parent_methods/vote.js');
const lottery = require('./parent_methods/lottery.js');
const messageHandler = require('./parent_methods/messageHandler.js');
const levelCooldown = require('./parent_methods/levelCooldown.js');


Manager.on('shardCreate', function(shard){
console.log(`Launched shard ${shard.id}`);
if(!loaded && shard.id == Manager.totalShards-1){
loaded = true;
setTimeout(updateActivity,15000);
}
shard.on('message',(message) => {
messageHandler.handle(Manager,shard,message);
});
});

function updateActivity(){
console.log("Done loading all the shards");
if(!debug){
lottery.init();
vote.setManager(Manager);
}
global.setManager(Manager);
Manager.broadcastEval("this.shard.fetchClientValues('guilds.size').then(results => {var result = results.reduce((prev, val) => prev + val, 0);this.user.setActivity('with '+result+' Servers!')}).catch(err => console.error(err))");
// Config file
const config = require('./src/data/config.json');
const request = require('./utils/request.js');
var io;
if (require('cluster').isMaster){
io = require('./utils/socket.js');
}

process.on('exit', function(code) {
console.log("exiting...");
Manager.broadcastEval("process.exit()");
});

try{
console.log("Manager is going to spawn "+Manager.totalShards+" shards...");
Manager.spawn(Manager.totalShards,5500,360000).catch(console.error);
}catch(err){
console.log("Manager Spawner Error");
console.error(err);
}

ramCheck.check(Manager);

process.on('unhandledRejection', (reason, promise) => {
console.error("unhandledRejection at index.js error "+(new Date()).toLocaleString());
console.error(reason);
});

process.on('uncaughtException', (err) => {
console.error("uncaughtException at index.js error "+(new Date()).toLocaleString());
console.error(err);
});
// Eris-Sharder
const Sharder = require('eris-sharder').Master;
var result,shards,firstShardID,lastShardID;

(async () => {
try{
//determine how many shards we will need for this manager
if (require('cluster').isMaster){
result = await request.fetchInit();
shards = result["shards"];
firstShardID = result["firstShardID"];
lastShardID = result["lastShardID"];
}
// How many clusters we will have
var clusters = Math.ceil(shards/5);
if(debug){
shards = 2;
firstShardID = 0;
lastShardID = shards-1;
clusters = 2
}
console.log("Creating shards "+firstShardID+"~"+lastShardID+" out of "+shards+" total shards!");

// Start sharder
const sharder = new Sharder("Bot "+auth.token, config.sharder.path, {
name: config.sharder.name,
clientOptions: config.eris.clientOptions,
debug:true,
shards,clusters,
firstShardID,
lastShardID,
});

}catch(e){
console.error("Failed to start eris sharder");
console.error(e);
}
})();
Empty file added messageReactionAdd.js
Empty file.
14 changes: 8 additions & 6 deletions methods/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ const dir = requireDir('./command',{recurse:true});

const CommandInterface = require('./commandinterface');

const sender = require('../util/sender.js');
const sender = require('../utils/sender.js');
const Error = require("../handler/errorHandler.js");
const mysqlHandler = require("../handler/mysqlHandler.js");
const questHandler = new (require("../handler/questHandler.js"))();

const logger = require('../util/logger.js');
const mysql = require('../util/mysql.js');
const logger = require('../utils/logger.js');
const mysql = require('../utils/mysql.js');
const con = mysql.con;
const global = require('../util/global.js');
const global = require('../utils/global.js');
const config = require('../json/botConfig.json');

const macro = require('../../tokens/macro.js');
const ban = require('../util/ban.js');
const ban = require('../utils/ban.js');

const prefix = config.prefix;
var query;
Expand All @@ -40,7 +40,8 @@ var modCommands = {};
class Command {

//Grabs all commands in ./command/
constructor(Client,dbl){
constructor(main){
/*
this.client = Client;
this.dbl = dbl;
global.client(Client);
Expand All @@ -50,6 +51,7 @@ class Command {
macro.sender(sender);
macro.global(global);
query = new mysqlHandler(con).query;
*/
for(var key in dir){
if(dir[key] instanceof CommandInterface)
addCommand(dir[key]);
Expand Down
4 changes: 2 additions & 2 deletions owo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

//const tracer = require('dd-trace').init()
const debug = false;
const debug = true;
if(!debug) var tracer = require('dd-trace').init()
const whitelist = ['409959187229966337','420104212895105044','552384921914572802']
if(debug) var auth = require('../tokens/scuttester-auth.json');
Expand Down Expand Up @@ -40,7 +40,7 @@ client.on('message',msg => {
if(msg.author.bot) return;

/* Ignore guilds if in debug mode */
//else if(debug&&msg.guild&&!whitelist.includes(msg.guild.id)) return;
else if(debug&&msg.guild&&!whitelist.includes(msg.guild.id)) return;

else if(modChannel.includes(msg.channel.id)) command.executeMod(msg);

Expand Down
Loading

0 comments on commit 94d3747

Please sign in to comment.