Skip to content

Commit d309e05

Browse files
authored
Merge pull request #6 from PyBotDevs/replit-deployment
Get YAToDB ready for replit deployment
2 parents cb3f072 + d1e7ec1 commit d309e05

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

config/startup.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"owner_id": ""
44
},
55
"auth": {
6-
"token": "",
6+
"token": null,
77
"public_key": ""
88
}
99
}

main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import os, os.path
66
import utils.auth
7+
import utils.ping
78
from random import choice
89
from discord import ApplicationContext, option
910
from discord.ext import commands
@@ -24,6 +25,8 @@
2425
async def on_ready():
2526
print(f"[client] Bot client successfully signed into API. ({round(time.time()) - start_time}ms)")
2627
print(f"[client] Logged in as \"{client.user.name}\".")
28+
print("[utils/ping] Starting web pinging server...")
29+
utils.ping.host()
2730

2831
# Functions
2932
@client.slash_command(

utils/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Functions
1616
def get_token() -> str:
1717
"""Returns the bot token, if provided in the `startup.json` file."""
18+
if config["auth"]["token"] == None: return os.environ["TOKEN"]
1819
return config["auth"]["token"]
1920

2021
def get_public_key() -> str:

utils/ping.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask
2+
from threading import Thread
3+
4+
app = Flask('')
5+
6+
@app.route('/')
7+
def main():
8+
return """
9+
YAToDB is online.
10+
""", 200
11+
12+
def run():
13+
app.run(host="0.0.0.0", port="8080")
14+
15+
def host(*, no_thread: bool = False):
16+
if no_thread: run()
17+
else:
18+
server = Thread(target=run)
19+
server.daemon = True
20+
server.start()

0 commit comments

Comments
 (0)