Skip to content

Commit

Permalink
Merge pull request #220 from Half-Shot/soru/redactions
Browse files Browse the repository at this point in the history
have puppet do deletions, if present
  • Loading branch information
Half-Shot committed Sep 10, 2018
2 parents 3e5fd77 + 726a126 commit dd8c4fb
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,20 @@ export class DiscordBot {
}
log.info(`Got redact request for ${event.redacts}`);
log.verbose(`Event:`, event);

const storeEvent = await this.store.Get(DbEvent, {matrix_id: event.redacts + ";" + event.room_id});

if (!storeEvent.Result) {
log.warn(`Could not redact because the event was not in the store.`);
return;
}
log.info(`Redact event matched ${storeEvent.ResultCount} entries`);
while (storeEvent.Next()) {
log.info(`Deleting discord msg ${storeEvent.DiscordId}`);
if (!this.bot.guilds.has(storeEvent.GuildId)) {
log.warn(`Could not redact because the guild could not be found.`);
return;
}
if (!this.bot.guilds.get(storeEvent.GuildId).channels.has(storeEvent.ChannelId)) {
log.warn(`Could not redact because the guild could not be found.`);
return;
}
const channel = <Discord.TextChannel> this.bot.guilds.get(storeEvent.GuildId)
.channels.get(storeEvent.ChannelId);
const msg = await channel.fetchMessage(storeEvent.DiscordId);
const result = await this.LookupRoom(storeEvent.GuildId, storeEvent.ChannelId, event.sender);
const chan = result.channel;

const msg = await chan.fetchMessage(storeEvent.DiscordId);
try {
await msg.delete();
log.info(`Deleted message`);
Expand Down

0 comments on commit dd8c4fb

Please sign in to comment.