Created
May 24, 2013 01:04
-
-
Save wonderb0lt/5640663 to your computer and use it in GitHub Desktop.
Another example for my beloved @Mezgrman
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 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