Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Created May 24, 2013 01:04
Show Gist options
  • Save wonderb0lt/5640663 to your computer and use it in GitHub Desktop.
Save wonderb0lt/5640663 to your computer and use it in GitHub Desktop.
Another example for my beloved @Mezgrman
from raxa import config, every, api, on_mention
import re
import random
@config()
def config(c):
print 'Received config object: %s' % str(c)
@api()
def api(api):
print 'Received API - My name appears to be %s...?' % api.user.screen_name
@every(sleep=5)
def every():
pass
# print 'In 5-second-callback'
@on_mention()
def give_number(status):
pattern = r'.*A random number between (\d+) and (\d+).*'
match = re.match(pattern, status.text)
if match:
a, b = int(match.group(1)), int(match.group(2))
n = random.randint(a, b)
response = str(n)
if 'please' not in status.text:
response += ' - and next time, say the magic word'
status.reply(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment