mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Fix missing module declarations, broken lings, broken formating and incorrect scopes in the documentation. For modules split over several files it appears the only viable option is to use the memberof directive on each documented member and only declare the index file as a module.
48 lines
1019 B
JavaScript
48 lines
1019 B
JavaScript
/**
|
|
* @module
|
|
*/
|
|
const plugin = require("lib/plugin");
|
|
const luaTools = require("lib/luaTools");
|
|
|
|
|
|
/**
|
|
* Removes gps and train tags from messags
|
|
*/
|
|
function removeTags(content) {
|
|
return content.replace(/(\[gps=-?\d+,-?\d+\]|\[train=\d+\])/g, "");
|
|
}
|
|
|
|
class InstancePlugin extends plugin.BaseInstancePlugin {
|
|
constructor(...args) {
|
|
super(...args);
|
|
}
|
|
|
|
async init() {
|
|
// XXX Nothing?
|
|
}
|
|
|
|
async chatEventHandler(message) {
|
|
// TODO check if cross server chat is enabled
|
|
let content = `[${message.data.instance_name}] ${removeTags(message.data.content)}`;
|
|
await this.instance.server.sendRcon(`/sc game.print('${luaTools.escapeString(content)}')`, true);
|
|
}
|
|
|
|
async onOutput(output) {
|
|
if (output.type === "action" && output.action === "CHAT") {
|
|
this.info.messages.chat.send(this.instance, {
|
|
instance_name: this.instance.name,
|
|
content: output.message,
|
|
});
|
|
}
|
|
}
|
|
|
|
// TODO implement info command in lua?
|
|
}
|
|
|
|
module.exports = {
|
|
InstancePlugin,
|
|
|
|
// For testing only
|
|
_removeTags: removeTags,
|
|
}
|