Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Alert on new forum topics to Discord

It came to my attention that my AoE2 clan mates and I don't frequent the Age of Empires forums. And it is there that the announcements for voting for the ranked map rotations occur. I decided to remedy our lack of awareness of this situation.

So, I searched on how to get notifications on a Discourse forum, which led me to a discussion on meta.discours.org. Somebody links to a python project that searches a Discourse forum and caches the results, so it can compare over time, and send notifications only on new topics, to a Mac OS notification center. This project works so great that it really only needed the Discord webhook, with no other modifications!

I secured a webhook for my clan's Discord "server" (so-called, because it's really just a namespace for us, not a dedicated VM or instance or anything) and added a few lines of Discord logic to that project, named sniffa.

I set up my sniffa input file, ~/.sniffa/watches-aoe2.ini with this contents:

[sniffa.domain]
url = https://forums.ageofempires.com
webhook = 'https://discord.com/api/webhooks/123498237429749274924/justanexamplewebhook123458987s87'
discord_user = AoE2 forum bot

[VOTE NOW ranked rotation #age-of-empires-ii:aoe2-de in:title]
ids = 666250,280747,280748,666257,651927

And I set up an unprivileged local user and installed pip package discord. And I placed in crontab:

*/30  *  *  *  *  bot   /home/bot/sniffa/sniffa.py aoe2 1>/dev/null 2>&1

How it works

The way sniffa works is it uses the ini section headings [VOTE NOW...] as the search expression, and it uses the modern web abilities to fetch results of mimetype application/json, from the native Discourse search function! It's really clever. And then, it gets better. It caches the results back to the ini file, so that it only alerts on new results.

I crafted my search query by visiting the forum and adjusting my search parameters and options until it was exactly what I want. Additional searches can be added by just adding a new [search query] heading!

Comments