russss / polybot

A framework for making social media bots for multiple networks
BSD 3-Clause "New" or "Revised" License
44 stars 9 forks source link

Handle mentions to bots #10

Open OddBloke opened 5 years ago

OddBloke commented 5 years ago

I would like to be able to extend my bots to be able to handle the mentions they receive, including an easy interface to reply to them.

(Specifically, I'd like people to be able to give the start of a wrestling promo and have @PromoBot reply back with one generated using Markov chains.)

OddBloke commented 5 years ago

This is a feature that I've already starting playing around with implementing locally. I have the beginnings of something that works for Mastodon.

(I'm currently not running any Twitter bots, so I won't be able to build out the Twitter-specific part of the change.)

OddBloke commented 5 years ago

OK, I'm putting this down for now, so I'm going to checkpoint my thinking (a) so I can pick it up more easily when I come back to it, and (b) so that anyone else who cares can comment on it.

My initial (very WIP) implementation adds a handle_mentions method to Bot. This iterates over each service calling service.get_mentions(), which generates a set of parameters for each mention. Those parameters are passed to self.handle_mention by handle_mentions. The expectation is that a bot implementer will (a) implement handle_mention, and (b) call self.handle_mentions() in their main implementation to trigger the handling.

handle_mention takes three parameters:

(I currently haven't done anything to handle only fetching mentions since the last time the bot ran.)

russss commented 5 years ago

Thanks, this looks good!

I don't have time to think about this in detail at the moment, but I think it might be useful to have a class which encapsulates a status update and handles the HTML issue, as well as stuff like message length and attachments when posting tweets/toots.