Skip to content
Extraits de code Groupes Projets
Valider 7aadcf01 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Update the other functions too

parent 669b1680
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -19,9 +19,6 @@ import * as mime from "mime"; ...@@ -19,9 +19,6 @@ import * as mime from "mime";
const log = new Log("DiscordBot"); const log = new Log("DiscordBot");
// Due to messages often arriving before we get a response from the send call,
// messages get delayed from discord.
const MSG_PROCESS_DELAY = 750;
const MIN_PRESENCE_UPDATE_DELAY = 250; const MIN_PRESENCE_UPDATE_DELAY = 250;
// TODO: This is bad. We should be serving the icon from the own homeserver. // TODO: This is bad. We should be serving the icon from the own homeserver.
...@@ -107,17 +104,24 @@ export class DiscordBot { ...@@ -107,17 +104,24 @@ export class DiscordBot {
client.on("guildUpdate", (_, newGuild) => { this.channelSync.OnGuildUpdate(newGuild); }); client.on("guildUpdate", (_, newGuild) => { this.channelSync.OnGuildUpdate(newGuild); });
client.on("guildDelete", (guild) => { this.channelSync.OnGuildDelete(guild); }); client.on("guildDelete", (guild) => { this.channelSync.OnGuildDelete(guild); });
client.on("messageDelete", (msg: Discord.Message) => { // Due to messages often arriving before we get a response from the send call,
this.discordMessageQueue[msg.channel.id] = Promise.all([ // messages get delayed from discord. We use Bluebird.delay to handle this.
this.discordMessageQueue[msg.channel.id] || Promise.resolve(),
Bluebird.delay(this.config.limits.discordSendDelay), client.on("messageDelete", async (msg: Discord.Message) => {
]).then(() => this.DeleteDiscordMessage(msg)); // tslint:disable-next-line:await-promise
await Bluebird.delay(this.config.limits.discordSendDelay);
this.discordMessageQueue[msg.channel.id] = (async () => {
await (this.discordMessageQueue[msg.channel.id] || Promise.resolve());
await this.OnMessage(msg);
})();
}); });
client.on("messageUpdate", (oldMessage: Discord.Message, newMessage: Discord.Message) => { client.on("messageUpdate", async (oldMessage: Discord.Message, newMessage: Discord.Message) => {
this.discordMessageQueue[newMessage.channel.id] = Promise.all([ // tslint:disable-next-line:await-promise
this.discordMessageQueue[newMessage.channel.id] || Promise.resolve(), await Bluebird.delay(this.config.limits.discordSendDelay);
Bluebird.delay(this.config.limits.discordSendDelay), this.discordMessageQueue[newMessage.channel.id] = (async () => {
]).then(() => this.OnMessageUpdate(oldMessage, newMessage)); await (this.discordMessageQueue[newMessage.channel.id] || Promise.resolve());
await this.OnMessageUpdate(oldMessage, newMessage);
})();
}); });
client.on("message", async (msg: Discord.Message) => { client.on("message", async (msg: Discord.Message) => {
// tslint:disable-next-line:await-promise // tslint:disable-next-line:await-promise
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter