Skip to content

Instantly share code, notes, and snippets.

@Ge0
Created October 30, 2017 11:16
Show Gist options
  • Save Ge0/43f456709d90f4726c794dd1cce41f81 to your computer and use it in GitHub Desktop.
Save Ge0/43f456709d90f4726c794dd1cce41f81 to your computer and use it in GitHub Desktop.
#!/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