[Feature Request] New Event Trigger on: Monitor a txt file for updates/changes
Badhabitz via Discord:
This would allow for triggers to be based around txt file monitoring.
What would be a use case for this? Firing an event when you manually edit a text file?
Correct, so if an external program updated a txt document Firebot would notice the change, fire an event and be able to read from the text document. A good example would be an external program that updates a text document for song information. When the song switches the external program updates the txt file then firebot notices the change and fires the event. The event has an effect that can read a text file and triggers a lower third that pop ups displays the song title from the text document, firebot just read then goes away. I have not seen where firebot can read text documents as well, which would be nice to have the same functions as writing a file.
@Badhabits Thanks for the additional info!
As for reading files, that is done via a $variable instead of an effect. This allows you to read text from files into almost any effect text field. The variable is $readFile[]. If you click the blue $vars button found in the bottom corner of many text fields, you can search the variable to see the various example for how you can use it.
@ebiggz I knew there had to be a way to read from a file with all the features and I was overlooking it somewhere. Thanks I'm still learning this amazing bot and everyone is so very helpful.
Note for devs (and anyone else interested):
I see the need/use for such a feature and watching for file changes is quite straightforward (especially if we use a package that smooths out cross platform quirks).
However the biggest hurdle here is actually a design one. The Events system, as it stands currently, does not provide a way for the user to define how events should be triggered. On the surface level it seems like thats what Filters are for, but they aren't. Filters don't determine how events are triggered under the hood, they simply allow the user to say "I only want these effects to run if an event type that matches these conditions is triggered". To explain with an example, if we were to implement this feature request as it stands now without any fundamental tweaks to the event system, we would have to listen for changes to every txt file on the computer and trigger a File Changed event for each. The user could then add a "file path" filter to filter down to events for a specific file. Obviously such an approach is untenable.
Another solution might be to allow users to define what files should events be triggered for in settings somewhere. That would work well enough from firebots perspective but its a weird experience for the user as they'd still have to set up filters when creating events in the events tab.
I think the most optimal solution would be to allow event types to define settings for themselves and these settings are then rendered for the user after the user selects that event type. In the case of a "File Changed" event for example, a file picker component would appear. We would also need to implement some callbacks so these event types can setup or cleanup internal listeners based on what you user provided whenever the event is saved/deleted.
It's worth mentioning that this isnt the only feature request that would benefit from such an upgrade to the events system. Other requests that we've gotten in the past include an event type that triggers at a given time of day and an event type that triggers when a given channel goes live .