-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (49 loc) · 1.71 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
63
64
65
66
67
68
"""
test version of conversation bot for NDP party virtual 2020
to enter venv: source env/bin/activate
to begin: python3 ndpBot_v1.py
send /start to initiate the conversation
to leave venv: deactivate
to terminate: CTRL-C (not command!)
"""
import logging
from uuid import uuid4
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, ConversationHandler)
from handlers import add_disclaimer, add_rules, add_intro, add_name, add_gender, add_age, add_bio, start, cancel, add_catch_random
from config import db
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
#initialize dict keys
DISCLAIMER, RULES, INTRO, NAME, GENDER, BIO, AGE = range(7)
#import token
TOKEN = None
with open("token.txt") as f:
TOKEN = f.read().strip()
def main():
db.setup() #create users table in database
updater = Updater(TOKEN, use_context=True)
dp = updater.dispatcher
#add conversation handler with states defined earlier
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
DISCLAIMER: [add_disclaimer],
RULES: [add_rules],
INTRO: [add_intro],
NAME: [add_name],
GENDER: [add_gender],
AGE: [add_age],
BIO: [add_bio]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
#probably add some handlers for random text a user might send
dp.add_handler(conv_handler)
dp.add_handler(add_catch_random)
logger.info('Up and running')
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()