This repository has been archived by the owner on Mar 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun.py
61 lines (53 loc) · 2.04 KB
/
run.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
# -*- coding: utf-8 -*-
#
# Copyright 2019, JohnnyCarcinogen ( https://github.com/JohnRipper/ ), All rights reserved.
#
# Created by dev at 2/8/20
# This file is part of QuantumJump.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import asyncio
import sys
import traceback
from concurrent import futures
from blumpkin import QuantumJumpBot, BotState
from lib.config import Configuration
async def start(executor, bot, loop, count=0):
loop.run_in_executor(executor, bot.process_input, loop)
try:
await bot.run()
except Exception as e:
# print the caught exception so it doesnt get lost in narnia
print(e)
traceback.print_exc(file=sys.stdout)
bot.state = BotState.EXCEPTION
await asyncio.sleep(5)
if bot.botconfig.restart_on_error and count <= bot.botconfig.restart_attempts:
count += 1
await start(executor, bot, loop, count)
def load_config():
try:
return Configuration("config.toml")
except FileNotFoundError:
from lib.config import generate_config, write_config
generated = generate_config()
towrite = write_config(generated, "config.toml")
if towrite:
return Configuration("config.toml")
else:
sys.exit("Couldn't load the configuration")
executor = futures.ThreadPoolExecutor(max_workers=2, )
bot = QuantumJumpBot(load_config())
loop = asyncio.get_event_loop()
loop.run_until_complete(start(executor, bot, loop))