Guest User

Untitled

a guest
Jan 31st, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. from flask import Flask, render_template, flash, redirect, url_for, request, session
  2. import discord
  3. from discord.ext import commands
  4. import os
  5. import threading
  6.  
  7.  
  8. app = Flask(__name__)
  9. app.config.update(dict(SECRET_KEY=os.urandom(12)))
  10.  
  11. description = '''An example bot to showcase the discord.ext.commands extension
  12. module.
  13. There are a number of utility commands being showcased here.'''
  14. bot = commands.Bot(command_prefix='?', description=description)
  15.  
  16.  
  17. @app.route('/')
  18. def welcome_screen():
  19.     return render_template('instruction.html')
  20.  
  21.  
  22. @app.route('/login', methods=['GET', 'POST'])
  23. def login():
  24.     error = None
  25.     if request.method == 'POST':
  26.         emaild = str(request.form['email'])
  27.         passwordd = str(request.form['password'])
  28.         key = str(request.form['osu_key'])
  29.         hchid = str(request.form['help_id'])
  30.         print(emaild + passwordd)
  31.  
  32.         app_thread = threading.Thread(target=bot_run, args=(emaild, passwordd))
  33.         print('hello')
  34.         app_thread.setDaemon(True)
  35.         app_thread.start()
  36.         print('bye')
  37.  
  38.         session['logged_in'] = True
  39.         flash('You are logged in')
  40.         return redirect(url_for('welcome_screen'))
  41.  
  42.     return render_template('login.html', error=error)
  43.  
  44.  
  45. def bot_run(email, password):
  46.     command = None
  47.     while command != 'terminate':
  48.         bot.run(email, password)
  49.         print('thread died :<')
  50.  
  51.  
  52. @app.route('/logout')
  53. def logout():
  54.     session.pop('logged_in', None)
  55.     flash('You were logged out')
  56.     return redirect(url_for('welcome_screen'))
  57.  
  58.  
  59. @bot.event
  60. async def on_ready():
  61.     print('\nLogged in as')
  62.     print(bot.user.name)
  63.     print(bot.user.id)
  64.     print('------')
  65.  
  66.     # Game Status updating
  67.     now_playing = discord.Game(name='type ' + bot.command_prefix + 'help for help')
  68.     await bot.change_status(game=now_playing, idle=False)
  69.  
  70.  
  71. @bot.command()
  72. async def add(left : int, right : int):
  73.     """Adds two numbers together."""
  74.     await bot.say(left + right)
  75.  
  76.  
  77. if __name__ == '__main__':
  78.     app.run(debug=True)
Add Comment
Please, Sign In to add comment