{"size": 950, "ext": "js", "max_stars_repo_path": "src/listeners/client/guildCreate.js", "max_stars_repo_name": "softhy85/Manga-Universe", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/listeners/client/guildCreate.js", "max_issues_repo_name": "softhy85/Manga-Universe", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/listeners/client/guildCreate.js", "max_forks_repo_name": "softhy85/Manga-Universe", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.6875, "max_line_length": 85, "alphanum_fraction": 0.5621052632}
const { Listener } = require('discord-akairo');
const { Permissions } = require('discord.js');
const { Guild } = require('../../structures/Models')

class GuildCreateListener extends Listener {
    constructor() {
        super('guildCreate', {
            emitter: 'client',
            event: 'guildCreate'
        });
    }

    async exec(guild) {
        const guildRoles = guild.roles.cache;
        var roles = [];

        for (guildRole in guildRoles) {
            const admin = guildRole.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
            roles.push({ id: guildRole.id, admin: admin });
        }

        await Guild.create({ id: guild.id, roles: roles }, err => {
            if (err)
                return console.log("Erreur lors de l'ajout du serveur !", err);
            else
                return console.log(`Nouveau serveur => ${guild.name} (${guild.id})`);
        })

    }
}

module.exports = GuildCreateListener;