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
75
76
77
78
79
80
81
82
83
|
#!/usr/bin/env python
import logging
from telegram.ext import (
Application,
CallbackQueryHandler,
CommandHandler,
MessageHandler,
filters,
ConversationHandler
)
from callback import (
callback_skip_media,
callback_location_sharing,
callback_manual_location,
callback_location_confirmation,
callback_location_keyword_search,
callback_skip_location_keyword,
callback_add_comment,
callback_skip_comment,
callback_add_media
)
from command import (
start_command,
cancel_command,
help_command
)
from config import (
WAIT_LOCATION,
LOCATION_SEARCH_KEYWORD,
LOCATION_CONFIRMATION,
ADD_MEDIA,
ADD_COMMENT,
BOT_TOKEN
)
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)
def main() -> None:
application = Application.builder().token(BOT_TOKEN).build()
checkin_handler = ConversationHandler(
entry_points=[
CommandHandler("start", start_command),
MessageHandler(filters.LOCATION, callback_location_sharing),
],
states={
WAIT_LOCATION: [
MessageHandler(filters.LOCATION, callback_location_sharing),
],
LOCATION_SEARCH_KEYWORD: [
MessageHandler(filters.TEXT, callback_location_keyword_search),
CallbackQueryHandler(callback_skip_location_keyword),
],
LOCATION_CONFIRMATION: [
CallbackQueryHandler(callback_location_confirmation),
MessageHandler(filters.TEXT, callback_manual_location)
],
ADD_COMMENT: [
MessageHandler(filters.TEXT, callback_add_comment),
CallbackQueryHandler(callback_skip_comment),
],
ADD_MEDIA: [MessageHandler(filters.PHOTO, callback_add_media),
CallbackQueryHandler(callback_skip_media)],
},
fallbacks=[CommandHandler("cancel", cancel_command)],
per_message=False,
allow_reentry=True,
)
application.add_handler(CommandHandler("help", help_command))
application.add_handler(checkin_handler)
application.run_polling()
if __name__ == "__main__":
main()
|