Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
avehlies opened this issue Apr 30, 2014 · 11 comments
Open

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

avehlies opened this issue Apr 30, 2014 · 11 comments

Comments

@avehlies
Copy link
Contributor

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
Copy link
Owner

rmmh commented Apr 30, 2014

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

@avehlies
Copy link
Contributor Author

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
Copy link
Contributor Author

avehlies commented May 1, 2014

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
Copy link
Owner

rmmh commented May 1, 2014

cloudbot renamed 'say' to 'message'

@craisins
Copy link
Contributor

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
Copy link

elitan commented Jan 11, 2015

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
Copy link

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
Copy link

gtwy commented Nov 25, 2017

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
Copy link

Red-M commented Nov 25, 2017

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

@Red-M
Copy link

Red-M commented Dec 18, 2017

Does my PR provide the features requested?

@gtwy
Copy link

gtwy commented Dec 18, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants