From 43a35e81bdda59292e516a7db4de4f92906d452d Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sun, 15 Jun 2025 01:22:31 +0900 Subject: [PATCH] . --- controller.js | 4 +- info.js | 110 +++++++++++++++++++++----------------------------- instance.js | 28 ++++--------- 3 files changed, 55 insertions(+), 87 deletions(-) diff --git a/controller.js b/controller.js index 3d2eaa3..d90de16 100644 --- a/controller.js +++ b/controller.js @@ -154,6 +154,4 @@ class ControllerPlugin extends BaseControllerPlugin { } } -module.exports = { - ControllerPlugin -}; +module.exports = {ControllerPlugin}; diff --git a/info.js b/info.js index 8c58de6..88ee763 100644 --- a/info.js +++ b/info.js @@ -1,11 +1,11 @@ -"use strict"; -const lib = require("@clusterio/lib"); +'use strict'; +const lib = require('@clusterio/lib'); class InstanceActionEvent { - static type = "event"; - static src = "instance"; - static dst = "controller"; - static plugin = "ClusterChatSync"; + static type = 'event'; + static src = 'instance'; + static dst = 'controller'; + static plugin = 'ClusterChatSync'; constructor(instanceName, action, content) { this.instanceName = instanceName; @@ -13,79 +13,63 @@ class InstanceActionEvent { this.content = content; } - static jsonSchema = { - type: "object", - required: ["instanceName", "action", "content"], - properties: { - "instanceName": { type: "string" }, - "action": { type: "string" }, - "content": { type: "string" }, - }, - }; - - static fromJSON(json) { - return new this(json.instanceName, json.action, json.content); - } + static jsonSchema = {type: 'object', required: ['instanceName', 'action', 'content'], properties: {'instanceName': {type: 'string'}, 'action': {type: 'string'}, 'content': {type: 'string'}},}; + static fromJSON(json) {return new this(json.instanceName, json.action, json.content);} } const plugin = { - name: "ClusterChatSync", - title: "Cluster Chat Sync", - description: "One way chat sync.", - instanceEntrypoint: "instance", - controllerEntrypoint: "controller", + name: 'ClusterChatSync', + title: 'Cluster Chat Sync', + description: 'One way chat sync.', + instanceEntrypoint: 'instance', + controllerEntrypoint: 'controller', controllerConfigFields: { - "ClusterChatSync.discord_bot_token": { - title: "Discord Bot Token", - description: "API Token", - type: "string" + 'ClusterChatSync.discord_bot_token': { + title: 'Discord Bot Token', + description: 'API Token', + type: 'string' }, - "ClusterChatSync.datetime_on_message": { - title: "Message Datetime", - description: "Append datetime in front", - type: "boolean", + 'ClusterChatSync.datetime_on_message': { + title: 'Message Datetime', + description: 'Append datetime in front', + type: 'boolean', initialValue: true }, - "ClusterChatSync.discord_channel_mapping": { - title: "Channels", - description: "Putting the discord channel id and instance relations here", - type: "object", + 'ClusterChatSync.discord_channel_mapping': { + title: 'Channels', + description: 'Putting the discord channel id and instance relations here', + type: 'object', initialValue: { - "S1": "123" + 'S1': '123' }, }, - "ClusterChatSync.use_libretranslate": { - title: "Translate Message", - description: "Using self host or paid service of libretranslate", - type: "boolean", + 'ClusterChatSync.use_libretranslate': { + title: 'Translate Message', + description: 'Using self host or paid service of libretranslate', + type: 'boolean', initialValue: false }, - "ClusterChatSync.libretranslate_url": { - title: "Translate Server URL", - description: "Including http protocol, and the port if needed", - type: "string", - initialValue: "http://localhost:5000" + 'ClusterChatSync.libretranslate_url': { + title: 'Translate Server URL', + description: 'Including http protocol, and the port if needed', + type: 'string', + initialValue: 'http://localhost:5000' }, - "ClusterChatSync.libretranslate_key": { - title: "Translate Server API Key", - description: "The API key for the translate server", - type: "string", - initialValue: "123456" + 'ClusterChatSync.libretranslate_key': { + title: 'Translate Server API Key', + description: 'The API key for the translate server', + type: 'string', + initialValue: '123456' }, - "ClusterChatSync.libretranslate_language": { - title: "Translate Server Target Language", - description: "Put a space between each language, using ISO 639-1 codes", - type: "string", - initialValue: "zh-Hants en" + 'ClusterChatSync.libretranslate_language': { + title: 'Translate Server Target Language', + description: 'Put a space between each language, using ISO 639-1 codes', + type: 'string', + initialValue: 'zh-Hants en' }, }, - messages: [ - InstanceActionEvent - ], + messages: [InstanceActionEvent], }; -module.exports = { - plugin, - InstanceActionEvent -}; +module.exports = {plugin, InstanceActionEvent}; diff --git a/instance.js b/instance.js index adca87e..a2d254e 100644 --- a/instance.js +++ b/instance.js @@ -1,33 +1,19 @@ "use strict"; const lib = require("@clusterio/lib"); -const { BaseInstancePlugin } = require("@clusterio/host"); -const { InstanceActionEvent } = require("./info.js"); +const {BaseInstancePlugin} = require("@clusterio/host"); +const {InstanceActionEvent} = require("./info.js"); class InstancePlugin extends BaseInstancePlugin { - async init() { - this.messageQueue = []; - } + async init() {this.messageQueue = [];} onControllerConnectionEvent(event) { - if (event === "connect") { - for (let [action, content] of this.messageQueue) { - this.instance.sendTo("controller", new InstanceActionEvent(this.instance.name, action, content)); - } + if (event === 'connect') { + for (let [action, content] of this.messageQueue) {this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, action, content));} this.messageQueue = []; } } - async onOutput(output) { - if (output.type == "action") { - if (this.host.connector.connected) { - this.instance.sendTo("controller", new InstanceActionEvent(this.instance.name, output.action, output.message)); - } else { - this.messageQueue.push([output.action, output.message]); - } - } - } + async onOutput(output) {if (output.type == 'action') {if (this.host.connector.connected) {this.instance.sendTo('controller', new InstanceActionEvent(this.instance.name, output.action, output.message));} else {this.messageQueue.push([output.action, output.message]);}}} } -module.exports = { - InstancePlugin -}; +module.exports = {InstancePlugin};