{"size": 1063, "ext": "js", "max_stars_repo_path": "src/features/guildMemberAdd/restoreMuted.js", "max_stars_repo_name": "Itz-Ravi03/modbot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/features/guildMemberAdd/restoreMuted.js", "max_issues_repo_name": "Itz-Ravi03/modbot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/features/guildMemberAdd/restoreMuted.js", "max_forks_repo_name": "Itz-Ravi03/modbot", "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": 34.2903225806, "max_line_length": 176, "alphanum_fraction": 0.5776105362}
const Log = require('../../Log');
const GuildConfig = require('../../config/GuildConfig');
const util = require('../../util');
const {APIErrors} = require('discord.js').Constants;

exports.event = async (options, member) => {
    if (member.communicationDisabledUntilTimestamp) {
        return;
    }
    let result = await options.database.query('SELECT * FROM moderations WHERE action = \'mute\' AND active = TRUE AND userid = ? AND guildid = ?',[member.id,member.guild.id]);
    if (result) {
        let guildConfig = await GuildConfig.get(member.guild.id);

        try {
            await member.roles.add(guildConfig.mutedRole);
        }
        catch (e) {
            if ([APIErrors.UNKNOWN_MEMBER, APIErrors.UNKNOWN_ROLE].includes(e.code)) {
                return;
            }
            throw e;
        }

        await Log.logEmbed(member.guild,{
            title: `Restored mute | ${util.escapeFormatting(member.user.tag)}`,
            description: `Mute ID: ${result.id}`,
            footer: {text:`ID: ${member.id}`}
        });
    }
};
