discordbot / server.py
joytou's picture
Fixed server.py that application spell error
cb843fb
# server.py
# where your python app starts
# init project
from flask import Flask, jsonify, render_template, request
#from typing_extensions import Literal
#from quart import Quart, jsonify, render_template, request
from discord_bot import discord_bot, sendMessageToChannel
# from pingpong import pingpong
from threading import Thread
import json
application = Flask(__name__)
#application.config['TIMEOUT'] = 1000
# I've started you off with Flask,
# but feel free to use whatever libs or frameworks you'd like through `.requirements.txt`.
# unlike express, static files are automatic: http://flask.pocoo.org/docs/0.12/quickstart/#static-files
# http://flask.pocoo.org/docs/0.12/quickstart/#routing
# http://flask.pocoo.org/docs/0.12/quickstart/#rendering-templates
@application.route('/')
def hello():
return render_template('index.html')
# Simple in-memory store
dreams = [
'Find and count some sheep',
'Climb a really tall mountain',
'Wash the dishes',
]
@application.route('/status')
def status():
return "Hello. I am alive!"
@application.route('/webhook', methods=['POST'])
def webhook():
data = request.json
message = data.get('message', 'No message provided')
if 'id' in data or 'log_message' in data:
sendMessageToChannel(data)
return data
return jsonify({'status': 'Message sent to Discord'})
@application.route('/dreams', methods=['GET'])
def get_dreams():
return jsonify(dreams)
# could also use the POST body instead of query string: http://flask.pocoo.org/docs/0.12/quickstart/#the-request-object
@application.route('/dreams', methods=['POST'])
def add_dream():
dreams.append(request.args.get('dream'))
return ''
@application.route('/disclaimer')
def disclaimer():
return render_template("disclaimer.html")
@application.route('/eula')
def eula():
return render_template("eula.html")
@application.route('/privacy_policy')
def privacyPolicy():
return render_template("privacy_policy.html")
@application.route('/terms_of_service')
def termsOfService():
return render_template("terms_of_service.html")
with open("metadata.json", "r") as f:
json_data = json.load(f)
@application.route('/metadata')
def metadata():
return jsonify(json_data)
# listen for requests
def run():
if __name__ == "__main__":
from os import environ
application.run(host='0.0.0.0', port=7860)
t = Thread(target=run)
t.start()
# pingpong()
discord_bot()