{"size": 2545, "ext": "js", "max_stars_repo_path": "main.js", "max_stars_repo_name": "o0shojo0o/discordBo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.js", "max_issues_repo_name": "o0shojo0o/discordBo", "max_issues_repo_issues_event_min_datetime": "2021-05-05T07:36:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-24T07:32:41.000Z", "max_forks_repo_path": "main.js", "max_forks_repo_name": "o0shojo0o/docker-pixelit-discord-bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 30.2976190476, "max_line_length": 92, "alphanum_fraction": 0.5638506876}
'use strict';

const fs = require('fs');
const axios = require('axios');
require('dotenv').config();
const Discord = require('discord.js');
const sqlRepo = require('./lib/sqlRepo');
//const MessageAttachment = Discord.MessageAttachment;
//const MessageEmbed = Discord.MessageEmbed;
const botToken = process.env.BOT_TOKEN;
// https://discordapp.com/oauth2/authorize?&client_id=EURE-CLIENT-ID&scope=bot&permissions=8
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
bot.events = new Discord.Collection();

sqlRepo.checkDatabase();
// Read all command Handler in commands dir
fs.readdir("./commands/", (err, files) => {
    if (err){
        return console.log(err);
    } 

    for (const key in files){        
        if (!files[key].endsWith(".js")){
            return;
        } 
        const props = require(`./commands/${files[key]}`);        
        const commandName = files[key].split(".")[0];
        bot.commands.set(commandName, props);
        console.log(`Successfully command ${files[key]} loaded.`);
    };
});

//Events "handler"
fs.readdir('./events/', (err, files) => {
    if (err){
        return console.log(err);
    } 

    for (const key in files){        
        if (!files[key].endsWith(".js")){
            return;
        } 
        const eventFunc = require(`./events/${files[key]}`);        
        const eventName = files[key].split(".")[0];
        bot.on(eventName, (...args) => {
                eventFunc.run(bot, ...args)
            }
        );
        console.log(`Successfully event ${files[key]} loaded.`);
    };
});

bot.login(botToken);

bot.on('ready', () => {  
    fs.readdir('./tasks/', (err, files) => {
        if (err){
            return console.log(err);
        } 
    
        for (const key in files){        
            if (!files[key].endsWith(".js")){
                return;
            } 
            console.log(`Successfully task ${files[key]} loaded.`);
            const taskFunc = require(`./tasks/${files[key]}`);
            taskFunc.run(bot);    
        };
    }); 
    
    console.log(`Logged in as ${bot.user.tag}!`);
});
/*
bot.on('guildMemberAdd', member => {
    // Send the message to a designated channel on a server:
    const channel = member.guild.channels.cache.find(x => x.name === 'member-log');
    // Do nothing if the channel wasn't found on this server
    if (!channel) return;
    // Send the message, mentioning the member
    channel.send(`Welcome to the server, ${member}`);
});
*/