Skip to content

Instantly share code, notes, and snippets.

@e000
Created January 11, 2011 01:54
Show Gist options
  • Save e000/773863 to your computer and use it in GitHub Desktop.
Save e000/773863 to your computer and use it in GitHub Desktop.
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