All files / plugins UnMute.js

80% Statements 36/45
75% Branches 6/8
60% Functions 3/5
80% Lines 36/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x  
import {pluginResolve} from "../services/BotService.js";
 
export default class UnMute {
    constructor(config, loggerService, blueskyService) {
        this.logger = loggerService.getLogger().child({label: 'UnMute'});
        this.blueskyService = blueskyService;
        this.isAvailable = true;
    }
 
    getName() {
        return "UnMute";
    }
 
    isReady() {
        return this.isAvailable;
    }
 
    async process(config) {
        const plugin = this;
        let {context} = config;
        const result = await plugin.unMuteMutedActors(context);
        if (result === null) {
            return Promise.resolve(pluginResolve(`Aucun compte masqué`, `Aucun compte masqué`));
        }
        return Promise.resolve(pluginResolve(`Démasqué ${result}`, `Démasqué ${result}`));
    }
 
    async unMuteMutedActors(context) {
        try {
            const mutes = await this.blueskyService.getMutes();
            let unMuted = [];
            const result = await Promise.all(mutes.map(
                m => this.blueskyService.safeUnMuteMuted(m, context)
                    .then(() => unMuted.push(m.handle))
            ));
            if (unMuted?.length > 0) {
                this.logger.debug(`unMuteMutedActors result: ${result}`);
                return unMuted;
            }
        } catch (err) {
            this.logger.warn(`unMuteMutedActors err: ${err.message}`, context);
        }
        return null;
    }
}