-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnMute.js
53 lines (47 loc) · 1.91 KB
/
UnMute.js
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
46
47
48
49
50
51
52
53
import {pluginResolve} from "../services/BotService.js";
const TEST_SIMULATION_HANDLE = "martijnrijk.bsky.social";
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, doSimulate} = config;
const result = await plugin.unMuteMutedActors({context, doSimulate});
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(config) {
const {logger, blueskyService} = this;
const {context, doSimulate} = config;
try {
let mutes = await blueskyService.getMutes();
logger.debug(`MUTES ARE: ${JSON.stringify(mutes)}`, context);
let unMuted = [];
if (doSimulate === true) {
mutes = mutes.filter(m => TEST_SIMULATION_HANDLE === m?.handle);// for tests unmute is limited to one entry
}
const result = await Promise.all(mutes.map(
m => blueskyService.safeUnMuteMuted(m, context)
.then(() => unMuted.push(m.handle))
));
if (unMuted?.length > 0) {
logger.debug(`${doSimulate === true ? "SIMULATE" : ""} unMuteMutedActors result: ${result}`, context);
return unMuted;
}
} catch (err) {
logger.warn(`unMuteMutedActors err: ${err.message}`, context);
}
return null;
}
}