All files / plugins Summary.js

46.15% Statements 18/39
100% Branches 2/2
25% Functions 1/4
46.15% Lines 18/39

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 411x 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 Summary {
    constructor(config, loggerService, summaryService, discordService) {
        this.isAvailable = false;
        this.logger = loggerService.getLogger().child({label: 'Summary'});
        this.summaryService = summaryService;
        this.discordService = discordService;
        this.isAvailable = true;
    }
 
    getName() {
        return "Summary";
    }
 
    isReady() {
        return this.isAvailable;
    }
 
    async process(config) {
        const analytics = await this.summaryService.cacheGetWeekSummary(config);
        // DEBUG // logger.info(`analytics :\n ${JSON.stringify(analytics, null, 2)}`, context);
        let text = `7 jours : posts: ${analytics.posts}, 'j'aime': ${analytics.likes}, réponses: ${analytics.replies}, re-post: ${analytics.reposts}`;
        text += `\n\nmeilleur score: ${analytics.bestScore} (${analytics.bestScorePosts.length} posts) - exemples : \n${analytics.bestScorePostsTxt}`;
        text += `\n\n+ de 'j'aime': ${analytics.bestLikes} (${analytics.bestLikesPosts.length} posts) - exemples : \n${analytics.bestLikesPostsTxt}`;

        let html = `<b>7 jours</b> : posts: ${analytics.posts}, likes: ${analytics.likes}, replies: ${analytics.replies}, reposts: ${analytics.reposts}`;
        html += `<br/><br/><b>Meilleur score</b> : ${analytics.bestScore} (${analytics.bestScorePosts?.length} posts) - exemples : <br/>${analytics.bestScorePostsHtml}`;
        html += `<br/><br/><b>+ de 'j'aime'</b> : ${analytics.bestLikes} (${analytics.bestLikesPosts?.length} posts) - exemples : <br/>${analytics.bestLikesPostsHtml}`;

        let markdown = `**7 jours** : posts: ${analytics.posts}, likes: ${analytics.likes}, replies: ${analytics.replies}, reposts: ${analytics.reposts}`;
        markdown += `\n\n**Meilleur score** : ${analytics.bestScore} (${analytics.bestScorePosts?.length} posts) - exemples : \n${analytics.bestScorePostsTxt}`;
        markdown += `\n\n**+ de 'j'aime'** : ${analytics.bestLikes} (${analytics.bestLikesPosts.length} posts) - exemples : \n${analytics.bestLikesPostsTxt}`;
        await this.discordService.sendMessage(markdown);

        return pluginResolve(text, html);
    }
 
}