From e6141c5bf8ff34c2c7502b8a8d9ed339b3db60cc Mon Sep 17 00:00:00 2001 From: a2569875 Date: Mon, 9 Oct 2023 17:07:48 +0800 Subject: [PATCH 1/2] let transport of Discord work properly --- .gitignore | 3 +++ config.example.js | 5 +++-- lib/handlers/DiscordMessageHandler.js | 9 ++++++--- main.js | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 684cf28..aff4c88 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ jspm_packages # config config.js badwords.js + +# other +package-lock.json diff --git a/config.example.js b/config.example.js index 42588fe..a99d737 100644 --- a/config.example.js +++ b/config.example.js @@ -6,7 +6,7 @@ module.exports = { "IRC": { - "disabled": false, // 設為 true 之後會禁止 IRC 機器人 + "disabled": true, // 設為 true 之後會禁止 IRC 機器人 "bot": { "server": "irc.freenode.net", "nick": "", // IRC 暱稱 @@ -49,7 +49,7 @@ module.exports = { 注意:QQ 機器人需要與酷 Q 和 https://github.com/mrhso/cqsocketapi 配合使用! */ "QQ": { - "disabled": false, // 設定為 true 後會禁止 QQ 機器人 + "disabled": true, // 設定為 true 後會禁止 QQ 機器人 "qq": "10000", // Bot 的 QQ 號碼 "options": { "selfCensorship": true, // 敏感詞列表,位於 badwords.js @@ -91,6 +91,7 @@ module.exports = { [ 'irc/#test', 'telegram/-12345678', // Telegram 群組號碼:可以先把 bot 拉到群組中,然後透過 /thisgroupid 來取得 id + 'Discord/1234567898765432123', 'qq/12345678' // 'QQ/87654321' // 如果有這種需求,亦可以連接 ] diff --git a/lib/handlers/DiscordMessageHandler.js b/lib/handlers/DiscordMessageHandler.js index 451f4b6..07127a9 100644 --- a/lib/handlers/DiscordMessageHandler.js +++ b/lib/handlers/DiscordMessageHandler.js @@ -46,10 +46,10 @@ class DiscordMessageHandler extends MessageHandler { client: 'Discord', type: 'photo', id: p.id, - size: p.filesize, + size: p.size, url: this._useProxyURL ? p.proxyURL : p.url, }]; - text += ` `; + text += ` `; } } @@ -100,7 +100,10 @@ class DiscordMessageHandler extends MessageHandler { } else if (this._keepSilence.indexOf(target) !== -1) { return Promise.resolve(); } else { - this._client.channels.get(target).send(message); + this._client.channels.fetch(target) + .then(target_channel => { + (async () => await target_channel.send(message))() + }); return Promise.resolve(); } } diff --git a/main.js b/main.js index fe93554..b540431 100644 --- a/main.js +++ b/main.js @@ -265,7 +265,7 @@ if (config.Discord && !config.Discord.disabled) { useProxyURL: options.useProxyURL, }; - const discordHandler = new DiscordMessageHandler(discordClient); + const discordHandler = new DiscordMessageHandler(discordClient, options2); pluginManager.handlers.set('Discord', discordHandler); pluginManager.handlerClasses.set('Discord', { object: DiscordMessageHandler, From 0426132b601f2d8637153d2f405f68203e2eb865 Mon Sep 17 00:00:00 2001 From: a2569875 Date: Mon, 9 Oct 2023 17:26:40 +0800 Subject: [PATCH 2/2] remove testing code --- config.example.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.example.js b/config.example.js index a99d737..78b8e33 100644 --- a/config.example.js +++ b/config.example.js @@ -6,7 +6,7 @@ module.exports = { "IRC": { - "disabled": true, // 設為 true 之後會禁止 IRC 機器人 + "disabled": false, // 設為 true 之後會禁止 IRC 機器人 "bot": { "server": "irc.freenode.net", "nick": "", // IRC 暱稱 @@ -49,7 +49,7 @@ module.exports = { 注意:QQ 機器人需要與酷 Q 和 https://github.com/mrhso/cqsocketapi 配合使用! */ "QQ": { - "disabled": true, // 設定為 true 後會禁止 QQ 機器人 + "disabled": false, // 設定為 true 後會禁止 QQ 機器人 "qq": "10000", // Bot 的 QQ 號碼 "options": { "selfCensorship": true, // 敏感詞列表,位於 badwords.js