8000 Add timer hooks by Red-M · Pull Request #171 · rmmh/skybot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add timer hooks #171

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add timer hooks #171

wants to merge 4 commits into from

Conversation

Red-M
Copy link
@Red-M Red-M commented Nov 25, 2017

#105 😃

Timers are called when someone speaks anywhere for the first time and only once. Use @hook.event('004') to start timers on bot connect.

An example:

from util import hook

@hook.timer(10)
def test_timer(inp, bot=None):
    print(dir(bot))

An example for messaging a channel using default config values and at bot start up:

from util import hook

@hook.event('004')
@hook.timer(10)
def test_timer(inp, bot=None):
    bot.conns['local irc'].msg("#channel','text')

@Red-M Red-M closed this Nov 25, 2017
Timers are called when someone speaks anywhere for the first time. Use @hook.event('004') to start timers on bot connect.
@Red-M Red-M reopened this Nov 25, 2017
@gtwy
Copy link
gtwy commented Nov 25, 2017

Thank you

@gtwy
Copy link
gtwy commented Nov 25, 2017

There seem to be two bugs with this. 1). The timer does not start until someone interacts with the bot. 2). "return" and "print" don't print to IRC. (they do, however, print to the console window.)

I made a fresh clone of your fork to make sure the issue wasn't from something else and it's still happening. Using your exact example plugin code, too. I'm sure I'm missing something obvious here, but "say", "message", "return" and "print" don't send text to IRC. I tried to look at the command function to see how it passes information to IRC, and all I can tell is that it just "returns" it.

It looks like dispatch doesn't have a way to handle input from a timer. See here: https://github.com/Red-M/skybot/blob/f051014fca683b3f309ef9655fd513f22c9fef35/core/main.py#L132-L153

@Red-M
Copy link
Author
Red-M commented Nov 26, 2017

You just need to find the IRC server object in bot then you can use a .msg

I did put that timers won't start until someone says something in the commits.
Timers are called when someone speaks anywhere for the first time. Use @hook.event('004') to start timers on bot connect.

An example for messaging a channel using default config values:

bot.conns['local irc'].msg("#channel','text')

I've included this in the PR comment for future use.

@Red-M
Copy link
Author
Red-M commented Dec 11, 2017

Did this work for you?

@vesatoivonen
Copy link

Prevention of duplicate timers should also be implemented in my opinion. Event 004 can trigger multiple times if the network connection is flaky, which would lead to multiple running timers for the same hook.

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

Successfully merging this pull request may close these issues.

3 participants
0