forked from HullSeals/HalpyBOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (46 loc) · 1.77 KB
/
main.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
"""
HalpyBOT v1.4.2
> For the Hull Seals, with a boot to the head
Rixxan
Copyright (c) 2021 The Hull Seals,
All rights reserved.
Licensed under the GNU General Public License
See license.md
"""
import logging
import threading
import asyncio
from aiohttp import web
from src.server import APIConnector, MainAnnouncer, HalpyClient
from src.packages.ircclient import HalpyBOT, pool
from src.packages.configmanager import config
logging.basicConfig(format='%(levelname)s\t%(name)s\t%(message)s',
level=logging._nameToLevel.get(config.get('Logging', 'level', fallback='DEBUG'), logging.DEBUG))
def _start_bot():
"""Starts HalpyBOT with the specified config values."""
from src import commands # pylint disable=unused-import
bot_loop = asyncio.new_event_loop()
asyncio.set_event_loop(bot_loop)
loop = asyncio.get_event_loop()
client = HalpyBOT(
nickname=config['IRC']['nickname'],
sasl_identity=config['SASL']['identity'],
sasl_password=config['SASL']['password'],
sasl_username=config['SASL']['username'],
eventloop=loop
)
MainAnnouncer.client = client
HalpyClient.client = client
pool.connect(client, config['IRC']['server'], config['IRC']['port'],
tls=config.getboolean('IRC', 'useSsl'), tls_verify=False)
pool.handle_forever()
def _start_server():
server_loop = asyncio.new_event_loop()
asyncio.set_event_loop(server_loop)
loop = asyncio.get_event_loop()
web.run_app(app=APIConnector, port=int(config['API Connector']['port']))
if __name__ == "__main__":
bthread = threading.Thread(target=_start_bot, name="BotThread", daemon=True)
bthread.start()
sthread = threading.Thread(target=_start_server(), name="ServerThread", daemon=True)
sthread.start()