This commit is contained in:
phidias authored and GitHub committed 2026-10-09 18:22:56 +09:00
1 parent ef5d18a171
commit b56904e8ae
13 files changed
+296 -222

No files matched your search

+47
View File
@@ -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) => {
});
}