This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
69 lines (55 loc) · 1.87 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, redirect, render_template, request
import logging
from threading import Thread
import disnake as discord
async def web(bot):
appinfo = await bot.application_info()
app = Flask(
__name__,
template_folder='templates',
static_folder='static'
)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
def help(command):
return f'''[{command.name}{", " if any(command.aliases) else ""}{", ".join(command.aliases)}] {command.signature}
{command.help if command.help else ""}
{command.description if command.description else ""}'''.replace('\n\n', '\n')
@app.route('/')
def home():
return render_template(
'index.html',
name = bot.user.name,
avatar = bot.user.display_avatar.url,
latency = int(bot.latency*1000),
guilds = len(bot.guilds),
cogs = bot.cogs,
emojis = bot.emojis,
description = '\n'.join([line for line in appinfo.description.split('\n') if not line.startswith('Doc: ')]).lstrip('\n'),
url = request.base_url,
help = help
)
@app.route("/invite")
def invite():
return redirect(
discord.utils.oauth_url(bot.user.id, permissions=discord.Permissions(permissions=805579856), scopes=('applications.commands%20bot',)))
@app.route("/server")
def server():
return redirect('https://discord.gg/KubGRbRKWXveeyZdqcjy')
@app.route("/code")
def code():
return redirect(f'https://replit.com/@{appinfo.owner.name}/{bot.user.name}')
@app.route("/code")
def spin():
return redirect(f'https://replit.com/@{appinfo.owner.name}/{bot.user.name}')
def run():
try:
app.run(host='0.0.0.0', port=8080)
except:
return
Thread(target=run).start()
def shutdown():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()