import slimHTTP import spiderWeb # Requires https://github.com/Torxed/spiderWeb http = slimHTTP.host(slimHTTP.HTTP) websocket = spiderWeb.WebSocket() @websocket.route('/auth/login') def auth_handler(request): print('Auth:', request) @http.on_upgrade def upgrade(request): print('Upgrading to WS_CLIENT_IDENTITY') new_identity = websocket.WS_CLIENT_IDENTITY(request) new_identity.upgrade(request) return new_identity while 1: for event, *event_data in http.poll(): pass
"Here's the link to the official GitHub repo for slimHTTP.", url=github_link) await message.delete() # Delete the !link message await message.author.send(embed=github_link_message) # Create a async friendly functions that can be called # as a task with asyncio.create_task() from a *non*-asyncio function/class. async def send_message(target, message): await target.send(embed=message) # Lets set up the webserver on port 80 # (port needs to be given before @http.configuration hook because it's used at startup) http = slimHTTP.host(slimHTTP.HTTP, port=80, web_root='./web_root', index='index.html') # And add a route to /repo/index.html # We can then set up a GitHub webhook to it, which will update the discord channel each commit. @http.route('/repo/index.html') def repo_change(request): repo_info = json.loads(request.request_payload.decode('UTF-8')) prev_commit_id = repo_info['before'] new_commit_id = repo_info['after'] sender = repo_info['sender']['login'] avatar = repo_info['sender']['avatar_url'] # or 'gravatar_id'
import slimHTTP https = slimHTTP.host(slimHTTP.HTTPS) @https.configuration def config(instance): return { 'web_root': './vhosts/default', 'index': 'index.html', 'ssl': { 'cert': 'cert.pem', 'key': 'key.pem', }, 'vhosts': { 'example.com': { 'module': './example.com/vhost.py' } } } while 1: for event, *event_data in https.poll(): pass