Created
October 30, 2017 11:16
-
-
Save Ge0/43f456709d90f4726c794dd1cce41f81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
_HANDLERS = {} | |
def handle(key): | |
def wrapper(func): | |
_HANDLERS[key] = func | |
return wrapper | |
@handle('!say') | |
def on_say(text): | |
print(text) | |
@handle('!ping') | |
def on_ping(text): | |
print('Pong!') | |
if __name__ == "__main__": | |
while True: | |
payload = input('>> ') | |
if payload == '!exit': | |
break | |
if payload.startswith('!'): | |
cmd, *args = payload.split(' ') | |
if cmd in _HANDLERS: | |
_HANDLERS[cmd](' '.join(args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment