-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #5 add bot activity summary on last 7 days
- add summary service and rely on cache - clear cache on new bot post - add summary plugin to notify via discord - ui: add summary tab - GHActions add 3 per week trigger
- Loading branch information
Showing
16 changed files
with
216 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# create bot summary trigger | ||
name: BES_trigger_summary_action | ||
on: | ||
schedule: | ||
- cron: "0 6 * * 1" # Lundi matin 6h00 UTC | ||
- cron: "0 10 * * 3" # Mercredi midi 10h00 UTC | ||
- cron: "0 16 * * 5" # Vendredi soir 16h00 UTC | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
environment: github_actions_bes | ||
steps: | ||
- name: trigger botEnSky Summary | ||
env: | ||
BES_SIMULATION_TOKEN: ${{ secrets.BES_SIMULATION_TOKEN }} | ||
BES_SIMULATION_URL: ${{ secrets.BES_SIMULATION_URL }} | ||
run: | | ||
curl -q -H "API-TOKEN: ${BES_SIMULATION_TOKEN}" -H "PLUGIN-NAME: Summary" "${BES_SIMULATION_URL}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {cacheEvictKey, cacheGetTtlObject} from "../lib/MemoryCache.js"; | ||
import {htmlOfPosts, txtOfPosts} from "../domain/post.js"; | ||
|
||
export const SUMMARY_CACHE_KEY = "cache:summary"; | ||
export const ONE_DAY_SECOND = 60 * 60 * 24; | ||
|
||
export default class SummaryService { | ||
constructor(config, loggerService, blueskyService) { | ||
this.config = config; | ||
this.logger = loggerService.getLogger().child({label: 'SummaryService'}); | ||
this.blueskyService = blueskyService; | ||
} | ||
|
||
cacheGetWeekSummary(config) { | ||
return cacheGetTtlObject(SUMMARY_CACHE_KEY, ONE_DAY_SECOND, this.getWeekSummary.bind(this, config)); | ||
} | ||
|
||
async getWeekSummary(options) { | ||
const {blueskyService, logger} = this; | ||
const {context = {}} = options; | ||
const botPosts = await blueskyService.searchPosts({ | ||
searchQuery: "from:botensky.bsky.social", | ||
"hasImages": true, | ||
"maxHoursOld": 7 * 24,// now-7d ... now | ||
"limit": 100 | ||
}) | ||
logger.info(`Summary - ${botPosts.length} post(s)`, context); | ||
const analytics = { | ||
posts: 0, likes: 0, replies: 0, reposts: 0, | ||
bestScore: 0, bestScorePosts: [], | ||
bestLikes: 0, bestLikesPosts: [] | ||
}; | ||
botPosts.forEach(p => { | ||
// DEBUG // logger.info(` - ${p.record.createdAt} - likes:${p.likeCount} replies:${p.replyCount}, reposts:${p.repostCount}`, context); | ||
analytics.posts++; | ||
analytics.likes += p.likeCount; | ||
analytics.replies += p.replyCount; | ||
analytics.reposts += p.repostCount; | ||
const postScore = p.likeCount * 2 + p.replyCount * 3 + p.repostCount * 4; | ||
if (postScore === analytics.bestScore) { | ||
analytics.bestScorePosts.push(p); | ||
} else if (postScore > analytics.bestScore) { | ||
analytics.bestScorePosts = [p]; | ||
analytics.bestScore = postScore; | ||
} | ||
if (p.likeCount === analytics.bestLikes) { | ||
analytics.bestLikesPosts.push(p); | ||
} else if (p.likeCount > analytics.bestLikes) { | ||
analytics.bestLikesPosts = [p]; | ||
analytics.bestLikes = p.likeCount; | ||
} | ||
}); | ||
analytics.bestScorePostsHtml = htmlOfPosts(analytics.bestScorePosts, 2); | ||
analytics.bestLikesPostsHtml = htmlOfPosts(analytics.bestLikesPosts, 2); | ||
analytics.bestScorePostsTxt = txtOfPosts(analytics.bestScorePosts, 2); | ||
analytics.bestLikesPostsTxt = txtOfPosts(analytics.bestLikesPosts, 2); | ||
return analytics; | ||
} | ||
} | ||
|
||
export const clearSummaryCache = () => cacheEvictKey(SUMMARY_CACHE_KEY); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/services/LogtailService.js → src/servicesExternal/LogtailService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/services/PlantnetApiService.js → src/servicesExternal/PlantnetApiService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.