diff --git a/README.md b/README.md index a491336..20d2251 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -Cluster Chat Sync +Chat Relay ======================== -One way chat forward to Discord. +One way chat relay to Discord. +Plugin of Clusterio https://github.com/clusterio/clusterio diff --git a/controller.ts b/controller.ts index b26f3a8..b8e76ee 100644 --- a/controller.ts +++ b/controller.ts @@ -24,10 +24,10 @@ export default async function(context: ControllerPluginContext) { const connect = async () => { await clientDestroy(); - const token = controller.config.get('ClusterChatSync.discord_bot_token') as string | undefined; + const token = controller.config.get('chat_relay.discord_bot_token') as string | undefined; if (!token) { - logger.error('[Chat Sync] Discord bot token not configured.'); + logger.error('[Chat Relay] Discord bot token not configured.'); return; } @@ -37,23 +37,23 @@ export default async function(context: ControllerPluginContext) { Discord.GatewayIntentBits.MessageContent, ]}); - logger.info('[Chat Sync] Logging into Discord.'); + logger.info('[Chat Relay] Logging into Discord.'); try { await client.login(token); } catch (err) { - logger.error(`[Chat Sync] Discord login error:\n${(err as Error).stack}`); + logger.error(`[Chat Relay] Discord login error:\n${(err as Error).stack}`); await clientDestroy(); return; } - logger.info('[Chat Sync] Logged in Discord successfully.'); + logger.info('[Chat Relay] Logged in Discord successfully.'); }; const sendMessage = async (instanceName: string, message: string) => { if (!client) return; - const mapping = controller.config.get('ClusterChatSync.discord_channel_mapping') as Record; + const mapping = controller.config.get('chat_relay.discord_channel_mapping') as Record; const channelId = mapping?.[instanceName]; if (!channelId) return; @@ -63,19 +63,19 @@ export default async function(context: ControllerPluginContext) { channel = await client.channels.fetch(channelId); } catch (err) { if ((err as {code?: number}).code !== 10003) { - logger.error(`[Chat Sync] Discord channel fetch error:\n${(err as Error).stack}`); + logger.error(`[Chat Relay] Discord channel fetch error:\n${(err as Error).stack}`); } return; } if (channel === null || !channel.isSendable()) { - logger.error(`[Chat Sync] Discord Channel ID ${channelId} is not a usable channel.`); + logger.error(`[Chat Relay] Discord Channel ID ${channelId} is not a usable channel.`); return; } let nrcMsg = message; - if (controller.config.get('ClusterChatSync.datetime_on_message')) { + if (controller.config.get('chat_relay.datetime_on_message')) { const now = new Date(); const p = (n: number) => String(n).padStart(2, '0'); const stamp = `${now.getFullYear()}${p(now.getMonth() + 1)}${p(now.getDate())} ${p(now.getHours())}${p(now.getMinutes())}${p(now.getSeconds())}`; @@ -126,9 +126,9 @@ export default async function(context: ControllerPluginContext) { }); controller.config.on('fieldChanged', (field) => { - if (field === 'ClusterChatSync.discord_bot_token') { + if (field === 'chat_relay.discord_bot_token') { connect().catch(err => { - logger.error(`[Chat Sync] Discord bot token:\n${(err as Error).stack}`); + logger.error(`[Chat Relay] Discord bot token:\n${(err as Error).stack}`); }); } }); diff --git a/index.ts b/index.ts index 9d7d104..1968abf 100644 --- a/index.ts +++ b/index.ts @@ -6,7 +6,7 @@ export class ChatEvent { static type = 'event' as const; static src = 'instance' as const; static dst = 'controller' as const; - static plugin = 'ClusterChatSync' as const; + static plugin = 'chat_relay' as const; static permission = null; constructor( @@ -29,32 +29,32 @@ export class ChatEvent { declare module '@clusterio/lib' { interface ControllerConfigFields { - 'ClusterChatSync.discord_bot_token': string; - 'ClusterChatSync.datetime_on_message': boolean; - 'ClusterChatSync.discord_channel_mapping': Record; + 'chat_relay.discord_bot_token': string; + 'chat_relay.datetime_on_message': boolean; + 'chat_relay.discord_channel_mapping': Record; } } export const plugin: lib.PluginDeclaration = { - name: 'ClusterChatSync', - title: 'Cluster Chat Sync', - description: 'One way chat forward to Discord.', + name: 'chat_relay', + title: 'Chat Relay', + description: 'One way chat relay to Discord.', webEntrypoint: './web', instanceEntrypoint: 'dist/node/instance.js', controllerEntrypoint: 'dist/node/controller.js', controllerConfigFields: { - 'ClusterChatSync.discord_bot_token': { + 'chat_relay.discord_bot_token': { title: 'Discord Bot Token', description: 'API Token', type: 'string' }, - 'ClusterChatSync.datetime_on_message': { + 'chat_relay.datetime_on_message': { title: 'Message Datetime', description: 'Append datetime in front', type: 'boolean', initialValue: true }, - 'ClusterChatSync.discord_channel_mapping': { + 'chat_relay.discord_channel_mapping': { title: 'Discord Channels', description: 'Instance and Discord channel ID relations', type: 'object', diff --git a/package.json b/package.json index 7e0689a..27d10f6 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { - "name": "@phidias0303/clusterio_chat_sync", + "name": "@phidias0303/chat_relay", "version": "1.0.3", - "description": "One way chat forward to Discord", + "description": "One way chat relay to Discord", "author": "PHIDIAS ", "license": "MIT", - "homepage": "https://github.com/PHIDIAS0303/ClusterChatSync#readme", + "homepage": "https://github.com/PHIDIAS0303/chat_relay#readme", "repository": { "type": "git", - "url": "git+https://github.com/PHIDIAS0303/ClusterChatSync" + "url": "git+https://github.com/PHIDIAS0303/chat_relay" }, "bugs": { - "url": "https://github.com/PHIDIAS0303/ClusterChatSync/issues" + "url": "https://github.com/PHIDIAS0303/chat_relay/issues" }, "type": "module", "keywords": [