diff --git a/config/config.sample.yaml b/config/config.sample.yaml index 2b8350597ca9ef0ddf984570efa16e2d3eda00cd..925df2bbadf7195dd2049b2c01c901c61620e0fa 100644 --- a/config/config.sample.yaml +++ b/config/config.sample.yaml @@ -87,5 +87,9 @@ channel: # Make all the discord users leave the room. ghostsLeave: true limits: - # Delay between discord users joining a room. + # Delay in milliseconds between discord users joining a room. roomGhostJoinDelay: 6000 + # Delay in milliseconds before sending messages to discord to avoid echos. + # (Copies of a sent message may arrive from discord before we've + # fininished handling it, causing us to echo it back to the room) + discordSendDelay: 750 diff --git a/config/config.schema.yaml b/config/config.schema.yaml index 56de3a8585438f47d06b7636f0849b9163a72c6a..4f832fa6ce069b1a2560c318a806e09c9127b00a 100644 --- a/config/config.schema.yaml +++ b/config/config.schema.yaml @@ -89,6 +89,8 @@ properties: properties: roomGhostJoinDelay: type: "number" + discordSendDelay: + type: "number" channel: type: "object" properties: diff --git a/src/bot.ts b/src/bot.ts index 523073ef213e45daac04592eda7ffad0d3eed3cd..96b8fa9fcb3d6f57f1fa3ceea7a559d2e23f32c5 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -119,11 +119,11 @@ export class DiscordBot { Bluebird.delay(this.config.limits.discordSendDelay), ]).then(() => this.OnMessageUpdate(oldMessage, newMessage)); }); - client.on("message", (msg: Discord.Message) => { + client.on("message", async (msg: Discord.Message) => { + // 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()); - // tslint:disable-next-line:await-promise - await Bluebird.delay(this.config.limits.discordSendDelay); await this.OnMessage(msg); })(); });