Skip to content
This repository was archived by the owner on Aug 15, 2018. It is now read-only.
This repository was archived by the owner on Aug 15, 2018. It is now read-only.

Title fetcher ideas #90

Open
Open

Description

@UclCommander

Currently, setting up title fetchers is a pain. You have to use on() events with regex matchers to get the URL's out of the messages.

Example:

on('irc.message.public')
    ->name('youtube')
    ->match("/(?:.*)(?:www\.)?youtu(?:be\.com|\.be)\/(?:(?:watch\?v=)?([a-zA-Z0-9\-_]+)(?:[a-zA-Z0-9\&\=\?]+)?)(?:.*)/")
    ->handler(...);

on('irc.message.public')
    ->name('title')
    ->match("#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#")
    ->handler(...);

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

  1. matthijs186 commented on Jun 29, 2016

    @matthijs186
    Collaborator

    Very interesting, useful addition! I don't have any further comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions