mirror of
https://github.com/PHIDIAS0303/ClusterChatSync.git
synced 2026-11-19 15:43:12 +09:00
.
This commit is contained in:
1 parent
ef5d18a171
commit
b56904e8ae
13 files changed
+296
-222
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
import type {InstancePluginContext} from '@clusterio/host';
|
||||
import {ChatEvent} from './index.js';
|
||||
|
||||
export default async function(context: InstancePluginContext) {
|
||||
const {instance, host, plugin} = context;
|
||||
let queue: [string, string][] = [];
|
||||
|
||||
instance.hooks.controllerConnectionEvent.attach(plugin.name, async (event) => {
|
||||
if (event !== 'connect' || queue.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pending = queue;
|
||||
queue = [];
|
||||
const failed: [string, string][] = [];
|
||||
|
||||
for (const [action, content] of pending) {
|
||||
try {
|
||||
await instance.sendTo('controller', new ChatEvent(instance.name, action, content));
|
||||
} catch (err) {
|
||||
failed.push([action, content]);
|
||||
}
|
||||
}
|
||||
|
||||
queue = failed;
|
||||
});
|
||||
|
||||
instance.hooks.output.attach(plugin.name, async (output) => {
|
||||
if (output.type !== 'action') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (host.connector.connected) {
|
||||
try {
|
||||
await instance.sendTo('controller', new ChatEvent(instance.name, output.action, output.message));
|
||||
} catch (err) {
|
||||
queue.push([output.action, output.message]);
|
||||
}
|
||||
} else {
|
||||
queue.push([output.action, output.message]);
|
||||
}
|
||||
});
|
||||
|
||||
instance.hooks.controllerConnectionEvent.attach(plugin.name, async (event) => {
|
||||
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user