Skip to content

Instantly share code, notes, and snippets.

@agrif
Created September 24, 2012 01:33
Show Gist options
  • Save agrif/3773742 to your computer and use it in GitHub Desktop.
Save agrif/3773742 to your computer and use it in GitHub Desktop.
import phosphorus
from phosphorus.irc import IRC
import sys
_, host, port, nick = sys.argv
def main():
irc = IRC(host, port, nick)
yield phosphorus.fork(irc.run())
yield phosphorus.until_elapsed(2)
yield from irc.send_command("join", "#overviewer")
while 1:
cmd = (yield from irc.get_next_command('privmsg'))
if not cmd:
break
source, message = cmd[1]
if source == "#overviewer":
if "fnord" in message.lower():
yield from irc.send_command("privmsg", "#overviewer", message.lower().replace("fnord", ""))
phosphorus.run(main())
@agrif
Copy link
Author

agrif commented Sep 24, 2012

class TimeCondition(Condition):
    def __init__(self, end_time):
        super(TimeCondition, self).__init__()
        self.end_time = end_time
    def is_fulfilled(self, rlist, wlist, xlist):
        return time.time() >= self.end_time
    def get_max_timeout(self):
        return self.end_time - time.time()

def until_elapsed(seconds):
    return TimeCondition(time.time() + seconds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment