You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 15, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 15, 2018. It is now read-only.
Which, works fine and all, but it's really only capable of being used via events, and nowhere else. For instance, the newly added Steam system. We have $rsg which fetches a random Steam game, and gets the info. Then we also have a generic title fetcher for when someone puts a link to a Steam game. In the end, they both do the same thing.
The solution I came up with for that involved a new "TitleFetcherContract" class that you can inject into functions and fetch the title with that (see 8afe10b). While it works, and at the time seemed like a good idea.. It's not the best solution. It would require a bot reboot when you add new ones or even updating the existing code. And I'd prefer to not reboot the bot for that.
The New Idea™
I might of thought of a better way to handle these. It would require significant re-writes to the current system, in the end it should be better than what we got now.
Introducing, crawler()
crawler would be a new helper function for defining title url patters.
crawler('youtube')
->pattern(['*youtube.*', 'youtu.be'])
->priority(5)
->handler(function ($link) {
// Do the magic
return []; // array of segments
});
pattern() - A list of fnmatch patterns to check for
priority() - Execution priority, highest ones go first
handler() - The handler
$link - The link it found
$matches - The regex matches
This would return an array of title segments (see SteamTitleFetcher.php) which then the bot will take and compile them to a string.
Usage outside normal events
My idea here is to have a fetchTitle() function to fetch the title of a given link. As an example, the $rsg command could use:
$title = fetchTitle($link, 'steam');
$link being the link
"steam", optionally being the type of title crawler to use. If you don't define one it'll search for the best bet from the list of defined crawlers.
So, ideas? comments? questions? does this suck? I'm looking for any constructive feedback here.
Activity
matthijs186 commentedon Jun 29, 2016
Very interesting, useful addition! I don't have any further comments.