Various improvements #3
22
src/main.ts
22
src/main.ts
|
@ -61,25 +61,29 @@ async function register({
|
|||
}
|
||||
|
||||
async function addListeners(listenerInput: string) {
|
||||
let objs: ListenerData[];
|
||||
let listeners: ListenerData[];
|
||||
try {
|
||||
objs = JSON.parse(listenerInput);
|
||||
listeners = JSON.parse(listenerInput);
|
||||
} catch {
|
||||
logger.warn('Erreur: malformé');
|
||||
return;
|
||||
}
|
||||
let newListeners = listeners.filter(item => !listenersDataBinding.has(item.address));
|
||||
let removedUrls = Array.from(listenersDataBinding.keys()).filter(url => !listeners.some(listener => listener.url === url));
|
||||
|
||||
for (const item of objs) {
|
||||
if (listenersDataBinding.has(item.address)) break;
|
||||
listenersDataBinding.set(item.address, {
|
||||
ChannelId: item.ChannelId,
|
||||
firstUpdate: item.firstUpdate,
|
||||
address: item.address,
|
||||
for (const newItem of newListeners) {
|
||||
listenersDataBinding.set(newItem.address, {
|
||||
ChannelId: newItem.ChannelId,
|
||||
firstUpdate: newItem.firstUpdate,
|
||||
address: newItem.address,
|
||||
});
|
||||
}
|
||||
for (const removedUrl of removedUrls) {
|
||||
listenersDataBinding.delete(removedUrl);
|
||||
}
|
||||
|
||||
myManager.stopAll();
|
||||
await myManager.saveOverride(objs);
|
||||
await myManager.saveOverride(listeners);
|
||||
firstUpdate = true;
|
||||
|
||||
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
||||
|
|
Loading…
Reference in New Issue
Block a user