Skip to content

Commit

Permalink
Merge pull request #6 from PyBotDevs/replit-deployment
Browse files Browse the repository at this point in the history
Get YAToDB ready for replit deployment
  • Loading branch information
notsniped authored Jun 7, 2023
2 parents cb3f072 + d1e7ec1 commit d309e05
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/startup.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"owner_id": ""
},
"auth": {
"token": "",
"token": null,
"public_key": ""
}
}
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import os, os.path
import utils.auth
import utils.ping
from random import choice
from discord import ApplicationContext, option
from discord.ext import commands
Expand All @@ -24,6 +25,8 @@
async def on_ready():
print(f"[client] Bot client successfully signed into API. ({round(time.time()) - start_time}ms)")
print(f"[client] Logged in as \"{client.user.name}\".")
print("[utils/ping] Starting web pinging server...")
utils.ping.host()

# Functions
@client.slash_command(
Expand Down
1 change: 1 addition & 0 deletions utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Functions
def get_token() -> str:
"""Returns the bot token, if provided in the `startup.json` file."""
if config["auth"]["token"] == None: return os.environ["TOKEN"]
return config["auth"]["token"]

def get_public_key() -> str:
Expand Down
20 changes: 20 additions & 0 deletions utils/ping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def main():
return """
YAToDB is online.
""", 200

def run():
app.run(host="0.0.0.0", port="8080")

def host(*, no_thread: bool = False):
if no_thread: run()
else:
server = Thread(target=run)
server.daemon = True
server.start()

0 comments on commit d309e05

Please sign in to comment.