mirror of
https://github.com/PHIDIAS0303/ClusterChatSync.git
synced 2025-12-27 11:05:22 +09:00
.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { Client, GatewayIntentBits } from 'discord.js';
|
import { Client, GatewayIntentBits } from 'discord.js';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { BaseControllerPlugin } from '@clusterio/controller';
|
import { BaseControllerPlugin } from '@clusterio/controller';
|
||||||
import { InstanceActionEvent } from './info';
|
import { InstanceActionEvent } from './info.ts';
|
||||||
import { ChatEvent } from './message';
|
import { ChatEvent } from './message.ts';
|
||||||
|
|
||||||
const MAX_DISCORD_MESSAGE_LENGTH = 1950;
|
const MAX_DISCORD_MESSAGE_LENGTH = 1950;
|
||||||
const MIN_CONFIDENCE_SCORE = 10.0;
|
const MIN_CONFIDENCE_SCORE = 10.0;
|
||||||
|
|||||||
81
info.js
81
info.js
@@ -1,81 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
const lib = require('@clusterio/lib');
|
|
||||||
|
|
||||||
class InstanceActionEvent {
|
|
||||||
static type = 'event';
|
|
||||||
static src = 'instance';
|
|
||||||
static dst = 'controller';
|
|
||||||
static plugin = 'ClusterChatSync';
|
|
||||||
|
|
||||||
constructor(instanceName, action, content) {
|
|
||||||
this.instanceName = instanceName;
|
|
||||||
this.action = action;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const plugin = {
|
|
||||||
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.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',
|
|
||||||
initialValue: {
|
|
||||||
'S1': '123'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'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_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-Hant en'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
messages: [InstanceActionEvent],
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {plugin, InstanceActionEvent};
|
|
||||||
88
info.ts
Normal file
88
info.ts
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import type { PluginConfigFields, SerializedEvent } from '@clusterio/lib';
|
||||||
|
|
||||||
|
export class InstanceActionEvent {
|
||||||
|
static type = 'event';
|
||||||
|
static src = 'instance';
|
||||||
|
static dst = 'controller';
|
||||||
|
static plugin = 'ClusterChatSync';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public instanceName: string,
|
||||||
|
public action: string,
|
||||||
|
public content: string
|
||||||
|
) {}
|
||||||
|
|
||||||
|
static jsonSchema = {
|
||||||
|
type: 'object',
|
||||||
|
required: ['instanceName', 'action', 'content'] as const,
|
||||||
|
properties: {
|
||||||
|
instanceName: { type: 'string' },
|
||||||
|
action: { type: 'string' },
|
||||||
|
content: { type: 'string' }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static fromJSON(json: SerializedEvent<InstanceActionEvent>): InstanceActionEvent {
|
||||||
|
return new this(json.instanceName, json.action, json.content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChannelMapping {
|
||||||
|
[instanceName: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pluginConfigFields: PluginConfigFields = {
|
||||||
|
'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',
|
||||||
|
initialValue: true,
|
||||||
|
},
|
||||||
|
'ClusterChatSync.discord_channel_mapping': {
|
||||||
|
title: 'Channels',
|
||||||
|
description: 'Putting the discord channel id and instance relations here',
|
||||||
|
type: 'object',
|
||||||
|
initialValue: {
|
||||||
|
'S1': '123'
|
||||||
|
} as ChannelMapping,
|
||||||
|
},
|
||||||
|
'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_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-Hant en',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const plugin = {
|
||||||
|
name: 'ClusterChatSync',
|
||||||
|
title: 'Cluster Chat Sync',
|
||||||
|
description: 'One way chat sync.',
|
||||||
|
instanceEntrypoint: 'instance',
|
||||||
|
controllerEntrypoint: 'controller',
|
||||||
|
controllerConfigFields: pluginConfigFields,
|
||||||
|
messages: [InstanceActionEvent],
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user