Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let transport of Discord work properly #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ jspm_packages
# config
config.js
badwords.js

# other
package-lock.json
1 change: 1 addition & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = {
[
'irc/#test',
'telegram/-12345678', // Telegram 群組號碼:可以先把 bot 拉到群組中,然後透過 /thisgroupid 來取得 id
'Discord/1234567898765432123',
'qq/12345678'
// 'QQ/87654321' // 如果有這種需求,亦可以連接
]
Expand Down
9 changes: 6 additions & 3 deletions lib/handlers/DiscordMessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ` <photo: ${p.width}x${p.height}, ${getFriendlySize(p.filesize)}>`;
text += ` <photo: ${p.width}x${p.height}, ${getFriendlySize(p.size)}>`;
}
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down