Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Nov 3, 2020
1 parent f64fe72 commit ce107c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class DiscordBot {
});
client.on("message", async (msg: Discord.Message) => {
try {
log.verbose(`Got incoming msg i:${msg.id} c:${msg.channel.id} g:${msg.guild?.id}`);
MetricPeg.get.registerRequest(msg.id);
await this.channelLock.wait(msg.channel.id);
this.clientFactory.bindMetricsToChannel(msg.channel as Discord.TextChannel);
Expand Down Expand Up @@ -382,7 +383,7 @@ export class DiscordBot {
this.ClientFactory.bindMetricsToChannel(channel as Discord.TextChannel);
const lookupResult = new ChannelLookupResult();
lookupResult.channel = channel as Discord.TextChannel;
lookupResult.botUser = this.BotUserId === client.user?.id;
lookupResult.botUser = this.bot.user?.id === client.user?.id;
lookupResult.canSendEmbeds = client.user?.bot || false; // only bots can send embeds
return lookupResult;
}
Expand Down Expand Up @@ -898,7 +899,7 @@ export class DiscordBot {
return; // Skip *our* messages
}
const chan = msg.channel as Discord.TextChannel;
if (msg.author.id === this.BotUserId) {
if (msg.author.id === this.bot.user?.id) {
// We don't support double bridging.
log.verbose("Not reflecting bot's own messages");
MetricPeg.get.requestOutcome(msg.id, true, "dropped");
Expand Down
8 changes: 8 additions & 0 deletions src/clientfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ export class DiscordClientFactory {
messageCacheLifetime: 5,
});

const waitPromise = new Promise((resolve, reject) => {
this.botClient.once("shardReady", resolve);
this.botClient.once("shardError", reject);
});

try {
await this.botClient.login(this.config.botToken, true);
log.info("Waiting for shardReady signal");
await waitPromise;
log.info("Got shardReady signal");
} catch (err) {
log.error("Could not login as the bot user. This is bad!", err);
throw err;
Expand Down
2 changes: 1 addition & 1 deletion src/matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export class MatrixEventProcessor {

public async ProcessStateEvent(event: IMatrixEvent) {
log.verbose(`Got state event from ${event.room_id} ${event.type}`);
const channel = await this.discord.GetChannelFromRoomId(event.room_id) as Discord.TextChannel;

const SUPPORTED_EVENTS = ["m.room.member", "m.room.name", "m.room.topic"];
if (!SUPPORTED_EVENTS.includes(event.type)) {
Expand Down Expand Up @@ -279,6 +278,7 @@ export class MatrixEventProcessor {
}

msg += " on Matrix.";
const channel = await this.discord.GetChannelFromRoomId(event.room_id) as Discord.TextChannel;
await this.discord.sendAsBot(msg, channel, event);
await this.sendReadReceipt(event);
}
Expand Down

0 comments on commit ce107c5

Please sign in to comment.