Created
January 11, 2011 01:54
-
-
Save e000/773863 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Core.ZalgoBase.BaseModule import BaseModule | |
from twisted.web.client import getPage | |
from twisted.internet.defer import DeferredLock, inlineCallbacks | |
from Core.ZalgoUtil.CmdWraps import command | |
class Module(BaseModule): | |
parseCommands = True | |
lock = DeferredLock() | |
pool = [] | |
@command('!meme') | |
@inlineCallbacks | |
def meme(self, cmd, user, channel, line, params): | |
""" | |
@description: spews out a meme from automeme.net | |
""" | |
lock = yield self.lock.acquire() | |
spew = lambda: cmd.bot.privmsg(channel, "\x0307,01%s" % self.pool.pop(0).replace('_', "\x02")) | |
try: | |
if self.pool: | |
spew() | |
else: | |
self.pool = (yield getPage('http://api.automeme.net/text?lines=100')).strip().split('\n') | |
if self.pool: | |
spew() | |
finally: | |
lock.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment