skybot icon indicating copy to clipboard operation
skybot copied to clipboard

Any way to send a message to a channel unprompted?

Open avehlies opened this issue 10 years ago • 11 comments

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?

avehlies avatar Apr 30 '14 02:04 avehlies

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

rmmh avatar Apr 30 '14 02:04 rmmh

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 avatar Apr 30 '14 03:04 avehlies

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.

avehlies avatar May 01 '14 00:05 avehlies

cloudbot renamed 'say' to 'message'

rmmh avatar May 01 '14 03:05 rmmh

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.

craisins avatar May 10 '14 00:05 craisins

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?

elitan avatar Jan 11 '15 21:01 elitan

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!

dmptrluke avatar Jan 11 '15 22:01 dmptrluke

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.

gtwy avatar Nov 25 '17 00:11 gtwy

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

Red-M avatar Nov 25 '17 03:11 Red-M

Does my PR provide the features requested?

Red-M avatar Dec 18 '17 07:12 Red-M

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

gtwy avatar Dec 18 '17 15:12 gtwy