Skip to content

Commit

Permalink
Improve logging of gallery channels message handler (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia authored Oct 26, 2022
1 parent 3904e15 commit 77ed118
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Replacing `CLIENT_ID` with the application's public ID, access the following lin
https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot+applications.commands&permissions=8
```

The bot needs the **Server Members Intent** and the **Message Content Intent** enabled
on [Discord's Application](https://discord.com/developers/applications) -> Bot page.
If this is not enabled, an error will be thrown on startup.

### Development

If you're looking at the source code, you should probably run
Expand Down
23 changes: 18 additions & 5 deletions src/modules/galleryChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,29 @@ export async function handleMessage(
!message.attachments.size &&
!message.content.startsWith("https://")
) {
logger.info(
{ message },
"Deleting non-image message on gallery channel"
);
const sermon = await message.reply({
content: `This is a gallery channel, ${message.author}, so only images may be sent here.`,
allowedMentions: { users: [message.author.id] },
failIfNotExists: false,
});
await message.delete().catch(() => undefined);
setTimeout(
async () => await sermon.delete().catch(() => undefined),
5000
);
await message.delete().catch((err) => {
logger.error(
{ err },
"Failed to delete message on gallery channel"
);
});
setTimeout(async () => {
await sermon.delete().catch((err) => {
logger.error(
{ err },
"Failed to delete sermon on gallery channel"
);
});
}, 5000);
return true;
}
}
Expand Down

0 comments on commit 77ed118

Please sign in to comment.