StarlitGhost / PyMoronBot

All development moved to https://github.com/DesertBot/DesertBot - A modular IRC bot with extensive aliasing capabilities, written in Python.
MIT License
9 stars 0 forks source link

Alias/Chain/Sub support command ideas #15

Open StarlitGhost opened 11 years ago

StarlitGhost commented 11 years ago

Make functions able to call each other, or otherwise pass data between different functions.

Say you have a web-scraper function and a regex matching function. You should be able to chain these together to create a new function that extracts particular pieces of data from a webpage.

something like |scrape http://www.google.com >> regex "<title>(?P<pageTitle>.+?)</title>"[pageTitle]

(actual syntax NOT determined)

This would tie in nicely to aliasing, eg: |alias title scrape $1 >> regex "<title>(?P<pageTitle>.+?)</title>"[pageTitle] |title http://blah.url

StarlitGhost commented 10 years ago

Design thoughts I've been having but not yet noted down. Thanks to @HubbeKing and @Didero for making me crystallize these a bit in order to explain the idea.

Basically you would split the parameters to chain by pipes, then each subsection by spaces, and then look up the first element of each in the function table and execute it if present, with the other params passed in.

Commands could output anything they liked, as you can just add stuff to objects at runtime in python. Probably under a functionOutput dict or something like that though, to keep it organised. The user would need to know what the command outputs in order to use it down the chain, but for single output commands that would be just '%output%' (and anything that could output more would probably have a 'default' bit of data as %output% too). The chain command would be taking care of the replacement before executing each command, using (in this case) functionOutput['output']

None of the exact mechanics or naming or anything are locked down, and likely wouldn't be until I started work on it.

Examples following this train of thought: .repeat 5m chain rss loadingreadyrun.com/rss new | say %rssOutput[title]% (you'd simply take the [title] and check if functionOutput['rssOutput']['title'] exists) .chain mtg cardname | rainbow %output% .chain mtg cardname | tell user check this out: %output%

Aliasing ties into this very strongly, as you could then essentially create new functions on the fly by combining existing functionality. Anything really new would still need new python code, of course.

Lastly, the initial explanation in this issue is basically useless, and would never have worked as written :P

StarlitGhost commented 10 years ago

Some more ideas.

.repeat 15m chain youtubeMonitor AweMeChannel | match "MAN AT ARMS" %ytMon[title]% | tell user New Man at Arms! %ytMon[title]% %ytMon[url]%

youtubeMonitor would only output if the latest video has changed, match would only output if the string matches (regex). If a command doesn't produce any output, the next command in the chain is not executed.

repeat would need to be an admin command to avoid abuse I suspect, and they'd need to be saved when the bot is shut down for people to be able to rely on them.

StarlitGhost commented 10 years ago

Implemented as a proof of concept as of 74a2cc08013ac38b21d469a82379d670abd47867 Needs more 'support' commands like those listed in my previous comments to be of much actual use.