-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
53 lines (37 loc) · 1.26 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
import dotenv
import psycopg2
from telegram.ext import Updater, PicklePersistence
from cache import userdata
from bot.conversation import handler
from travellermap import api
from traveller import equipment
if __name__ == '__main__':
config = dotenv.dotenv_values()
# Load global data
equipment.load_equipment(config['EQUIP_PATH'])
api.load_map(config['MAP_PATH'])
userdata.load_data(config['CACHE_PATH'])
print(f'{len(equipment.equipments)} items loaded!')
print(f'{len(api.data)} sectors loaded!')
print(f'Loaded cached user data for {len(userdata.user_data)} players!')
conn = psycopg2.connect(
user=config['DB_USER'],
password=config['DB_PASS'],
database=config['DB_NAME'],
host='localhost',
port=5432
)
print('Successfully connected to Database!')
# with open('schema.sql') as f:
# conn.cursor().execute(f.read())
updater = Updater(
token=config['TELEGRAM_TOKEN'],
persistence=PicklePersistence(filename=config['CONV_PATH']),
use_context=True,
)
conversation = handler(conn)
updater.dispatcher.add_handler(conversation)
updater.start_polling()
print('Bot started!')
updater.idle()
userdata.write_data(config['CACHE_PATH'])