hangoutsbot / hangoutsbot

Google Hangouts bot
GNU Affero General Public License v3.0
570 stars 269 forks source link

Bot as an import. #901

Open ryanpeach opened 6 years ago

ryanpeach commented 6 years ago

So, I have a quick feature request that I've just spent basically all day trying to implement with no success, because I really can't for the life of me figure out how to tap into your plugins.load function for my own maniacal purposes. Basically, heres the deal, I want to change up this bot platform so it can be imported and ran from python. Basically you import the bot, build it half way, inject your plugin code, build it the rest of the way and run it. Mostly because I'm using the bot more as a service or as an app than as a long term companion, I just want to be able to import the bot and say "send me progress reports as this code runs" and maybe be able to stop it from my phone, change a parameter, and restart or something. Any ideas on how to get it to do that?

ryanpeach commented 6 years ago
import hangups
from hangupsbot.hangupsbot import get_bot
from hangupsbot.handlers import handler
from hangupsbot.commands import command

bot = get_bot()

@bot.handler.register(priority=5, event=hangups.ChatMessageEvent)
def receive_message(bot, event, *args):
    print("hello world!")

bot.run()

Would be the ideal final code.