rmmh / skybot

Python IRC bot
https://github.com/rmmh/skybot/wiki
The Unlicense
250 stars 171 forks source link

Any way to send a message to a channel unprompted? #105

Open avehlies opened 10 years ago

avehlies commented 10 years ago

I'd like to make a plugin that scrapes an RSS feed every 15-30 minutes and stores any new news items in a database. I'd like any new news items to be sent to the channel, but I can't seem to find any way to send a message without being prompted (by a command). I tried poking around with the say() and message() methods in the Input class, but couldn't get anywhere with those. Does anyone have any ideas?

rmmh commented 10 years ago

A simple way to do this could be something like @hook.timer(delay), which calls your plugin approximately every delay seconds.

avehlies commented 10 years ago

Regrettably, I'm not sure how to implement a new hook. I'm still pretty new to Python. So far what I've been doing to implement a new "crond" is making a new function like so:

@hook.singlethread
@hook.command('JOIN')
def crond(db=None):
    while(True):
         #code goes here
         time.sleep(60)

Not sure how this would play into returning an actual string to a channel though. Especially because I might want to return a few strings at a time.

avehlies commented 10 years ago

So my code looks like this:

def crond(inp, nick='', db=None, notice=None, message=None):
    while True:
        message("message here")
        sleep(60)

And the intention is to get the bot to say "message here" every 60 seconds, but I keep getting

TypeError: 'NoneType' object is not callable

I thought that "message" was automatically passed to the hook functions. I also tried without the named argument, and it simply told me that global "message" was not defined. I feel like there's something I'm missing here, as I have this functionality working in another bot (which is actually forked off of skybot: http://github.com/cloudev/cloudbot) and I don't know if there's a difference internally that changes how it works.

rmmh commented 10 years ago

cloudbot renamed 'say' to 'message'

craisins commented 10 years ago

You're right, I wasn't passing the say object in the function.

Feel free to close this issue.

It would be nice to have a @hook.timer(##) hook though.

elitan commented 9 years ago

I am working on a fork of skybot, a bot that will be able to be called from a client (your rss script) and output any given message to any given channel in any given network. All done asynchronously.

Have a look: https://github.com/elitan/skybot


I dont know, should I trie to make a pull request of my code to this repo?

dmptrluke commented 9 years ago

Yeah, it was renamed at some point in my bot. Not entirely sure why, but theres no really any direct backwards compatibility between skybot and modern cloudbot due to the differing python versions anyway!

gtwy commented 7 years ago

Elitan, did you ever implement the timer? I was trying to look through your code to see how it was done. I am in need of this feature.

Red-M commented 7 years ago

I've made #171 to provide the requested hook.

Red-M commented 6 years ago

Does my PR provide the features requested?

gtwy commented 6 years ago

@Red-M Your request hook did work. Thank you!