Event Loop for a bot

Supposing I had a function in a script for a bot that gives me all the tweets a user has posted on X.com (sharkey, actually, but lets just say x), how would I make some kind of an event listener on a server that listens for mentions of the bot's account? I was thinking about making an infinite loop but that seems wildly inefficient.
5 Replies
Deno AI Helper
Deno AI Helperβ€’6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your description, it sounds like you're looking for a way to listen for events, such as mentions of a bot's account, without resorting to an infinite loop. In general, polling (which is what an infinite loop would effectively be doing) can indeed be inefficient, especially if done without any delay, as it would consume resources unnecessarily. A more efficient approach would be to use webhooks if the service (X.com in your example) supports them. Webhooks allow you to receive real-time notifications when certain events occur, such as mentions of your bot's account. If webhooks are not available and you must poll the service, you should do so with a reasonable delay between each poll to avoid overwhelming the server and your bot. You can use setTimeout or setInterval in JavaScript to handle this kind of timed polling. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you're using a specific library or API for interacting with X.com, it would be best to consult their documentation or support channels for the most efficient way to listen for mentions of your bot's account.
TangJieHao
TangJieHaoβ€’6mo ago
Only thing I could find was this: https://activitypub.software/TransFem-org/Sharkey
GitLab
TransFem.org / Sharkey Β· GitLab
🌎 A Sharkish microblogging platform πŸš€
TangJieHao
TangJieHaoβ€’6mo ago
Which I have looked deep through but it probably has what you want
TangJieHao
TangJieHaoβ€’6mo ago
Sharkey Documentation
Fresh Installation
Before you start, you really need: an always-on machine that can receive connections from the Internet a domain name to dedicate to your Sharkey instance, resolving to the address(es) of that machine a web server running on that machine, with valid TLS certificates for the domain name With Docker Prerequisites:
πŸŽ€π”Έβ„•π”Ύπ”Όπ•ƒ π”»π•†π•ƒπ•ƒπ”½π”Έβ„‚π”ΌπŸŽ€πŸ‡΅πŸ‡Έ
Oh my word, sorry for the late reply!!! I actually ditched that idea, wrote a Sharkey library in Rust.