-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
74 lines (51 loc) · 2.05 KB
/
app.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
70
71
72
73
74
import asyncio
import os.path
import signal
import threading
import discord
from modules.localization import Localization
from modules.config import Config
from modules.api import inference, queue
from modules.settings import Settings
async def main():
config = Config(str(), str())
local = Localization(str())
print(local.get_localization("console")["start"])
# Discord bot instance and events listeners
bot = discord.Bot(debug_guilds=[1005722426941915187, 1070385362205155408])
@bot.event
async def on_ready():
print(local.get_localization("console")["bot_launched"])
# Loading cogs
from cogs.inference import diffuse
from cogs.utils import ping, settings
from cogs.utils import list as list_cog
bot.add_cog(diffuse.Diffuse(bot))
bot.add_cog(ping.Ping(bot))
bot.add_cog(settings.Settings(bot))
bot.add_cog(list_cog.List(bot))
# Launching bot
print(local.get_localization("console")["bot_launches"])
await bot.start(config.get_environment()["token"] if config.get_environment() else config.get_bot()['token'])
def launch():
print("Press CRTL + C to exit\n")
config = Config("config.yaml", "environment.json")
api = inference.API(config.get_inference()['url'])
config.init_remote(api)
settings = Settings(os.path.join("data", "user"))
local = Localization(config.get_general()['locale'])
# Setting up a queue
api_request_queue = queue.Queue(45, 10)
queue_processor_thread = threading.Thread(target=api_request_queue.process, args=(api,))
queue_requests_updater_thread = threading.Thread(target=api_request_queue.update_requests)
queue_processor_thread.start()
queue_requests_updater_thread.start()
asyncio.run(main())
if __name__ == "__main__":
# code was stolen from a1111's webui
# make the program just exit at ctrl+c without waiting for anything
def sigint_handler(sig, frame):
print("Interrupted with signal {} in {}".format(sig, frame))
os._exit(0)
signal.signal(signal.SIGINT, sigint_handler)
launch()