-
Notifications
You must be signed in to change notification settings - Fork 0
/
todobot.py
5256 lines (4519 loc) Β· 332 KB
/
todobot.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from telegram.ext import (Updater, CommandHandler, MessageHandler, InlineQueryHandler, Filters,
PicklePersistence, CallbackQueryHandler, ConversationHandler)
from telegram import (InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton,
InlineKeyboardMarkup, ForceReply)
import telegram.ext
import logging
import datetime
#import schedule
import time
from uuid import uuid4
from _datetime import timedelta
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
#NEW
import os
api_id = 1665385
api_hash = 'cdf2fc6fe9c4ee703e6d1940da92eeb6'
PORT = int(os.environ.get('PORT', 5000))
TOKEN = '1347940499:AAHRH7u0KI4zD3SPqx-GVuRD1Jiz4uL9WSs'
#################################### STATES ####################################
(FRONT_MENU,
WORK_MENU,
GROUP_WORK_MENU,
GROUP_WORK_TO_DO_LIST_MENU,
GROUP_WORK_VIEW_TO_DO_LIST_MENU,
GROUP_WORK_VIEW_INDIVIDUAL_TASK_MENU,
GROUP_WORK_TO_DO_ADD_TASK_MENU,
GROUP_WORK_TO_DO_ADD_HEADER_WAITING_INPUT,
GROUP_WORK_TO_DO_EDIT_INFO_MENU,
GROUP_WORK_TO_DO_EDIT_TASK_DETAILS_WAITING_INPUT,
GROUP_WORK_TO_DO_EDIT_DEADLINE_WAITING_INPUT,
GROUP_WORK_TO_DO_EDIT_TASK_STATUS_MENU,
GROUP_WORK_REMOVE_TASK_MENU,
GROUP_WORK_REMINDERS_MENU,
GROUP_WORK_SET_REMINDER_MENU,
GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED,
GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_EDIT_TIME_WAITING_INPUT,
GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_EDIT_INTERVAL_WAITING_INPUT,
GROUP_WORK_REMINDER_ADD_EVENT_MENU,
GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_HEADER_WAITING_INPUT,
GROUP_WORK_SET_REMINDER_FOR_EVENT_DETAILS_MENU,
GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_DATE_WAITING_INPUT,
GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_TIME_WAITING_INPUT,
GROUP_WORK_EDIT_TASK,
GROUP_WORK_REMOVE_REMINDER_MENU,
MODULE_MENU,
MODULE_VIEW_MODULES_MENU,
MODULE_TO_DO_LIST_MENU,
MODULE_TO_DO_VIEW_TO_DO_LIST_MENU,
MODULE_TO_DO_VIEW_INDIVIDUAL_TASK_MENU,
MODULE_TO_DO_ADD_TASK_MENU,
MODULE_TO_DO_ADD_HEADER_WAITING_INPUT,
MODULE_TO_DO_EDIT_INFO_MENU,
MODULE_TO_DO_EDIT_TASK_DETAILS_WAITING_INPUT,
MODULE_TO_DO_EDIT_DEADLINE_WAITING_INPUT,
MODULE_TO_DO_EDIT_TASK_STATUS_MENU,
MODULE_REMOVE_TASK_MENU,
MODULE_ADD_MODULE_WAITING_INPUT,
MODULE_REMOVE_MODULE_MENU,
MODULE_REMINDERS_MENU,
MODULE_SET_REMINDER_MENU,
MODULE_SET_REMINDER_FOR_TO_DO_LIST_CHOOSE_MODULE,
MODULE_SET_REMINDER_FOR_TO_DO_LIST_CLICKED,
MODULE_SET_REMINDER_FOR_TO_DO_LIST_EDIT_TIME_WAITING_INPUT,
MODULE_SET_REMINDER_FOR_TO_DO_LIST_EDIT_INTERVAL_WAITING_INPUT,
MODULE_REMINDER_ADD_EVENT_MENU,
MODULE_SET_REMINDER_FOR_EVENT_ADD_HEADER_WAITING_INPUT,
MODULE_SET_REMINDER_FOR_EVENT_DETAILS_MENU,
MODULE_SET_REMINDER_FOR_EVENT_ADD_DATE_WAITING_INPUT,
MODULE_SET_REMINDER_FOR_EVENT_ADD_TIME_WAITING_INPUT,
MODULE_EDIT_TASK,
MODULE_REMOVE_REMINDER_MENU,
CCA_MENU,
CCA_ADD_SESSION_MENU,
CCA_ADD_SESSION_TITLE_WAITING_INPUT,
CCA_ADD_SESSION_DETAILS_WAITING_INPUT,
CCA_ADD_SESSION_DATE_WAITING_INPUT,
CCA_ADD_SESSION_TIME_WAITING_INPUT,
CCA_ADD_SESSION_LOCATION_WAITING_INPUT,
CCA_ADD_SESSION_DEADLINE_WAITING_INPUT,
CCA_ADD_SESSION_DONE_MENU,
CCA_USER_SET_REMINDER_WAITING_INPUT,
CCA_USER_SET_REMINDER_DONE_MENU,
CCA_VIEW_SESSIONS,
CCA_REMOVE_SESSION_MENU,
LEISURE_MENU,
LEISURE_ADD_SESSION_MENU,
LEISURE_ADD_SESSION_TITLE_WAITING_INPUT,
LEISURE_ADD_SESSION_DETAILS_WAITING_INPUT,
LEISURE_ADD_SESSION_DATE_WAITING_INPUT,
LEISURE_ADD_SESSION_TIME_WAITING_INPUT,
LEISURE_ADD_SESSION_LOCATION_WAITING_INPUT,
LEISURE_ADD_SESSION_DEADLINE_WAITING_INPUT,
LEISURE_ADD_SESSION_DONE_MENU,
LEISURE_USER_SET_REMINDER_WAITING_INPUT,
LEISURE_USER_SET_REMINDER_DONE_MENU,
LEISURE_VIEW_SESSION,
LEISURE_REMOVE_SESSION_MENU,
HELP_MENU,
HELP_GROUP_WORK_MENU,
HELP_MODULE_MENU) = range(81)
###################################### BOT ######################################
# takes in a string and adds \ in front of characters that cannot be parsed otherwise
# parameter: string
# returns: string with escapes
def add_escape_to_string(str):
return str.replace('_', '\_') \
.replace('[', '\[') \
.replace(']', '\]') \
.replace('(', '\(') \
.replace(')', '\)') \
.replace('~', '\~') \
.replace('>', '\>') \
.replace('#', '\#') \
.replace('+', '\+') \
.replace('-', '\-') \
.replace('=', '\=') \
.replace('|', '\|') \
.replace('{', '\{') \
.replace('}', '\}') \
.replace('.', '\.') \
.replace('!', '\!')
#.replace('*', '\*') \s
def remove_escape_from_string(str):
return str.replace('\_', '_') \
.replace('\*', '*') \
.replace('\[', '[') \
.replace('\]', ']') \
.replace('\(', '(') \
.replace('\)', ')') \
.replace('\~', '~') \
.replace('\>', '>') \
.replace('\#', '#') \
.replace('\+', '+') \
.replace('\-', '-') \
.replace('\=', '=') \
.replace('\|', '|') \
.replace('\{', '{') \
.replace('\}', '}') \
.replace('\.', '.') \
.replace('\!', '!')
# print to-do list
# parameter: context
# returns: string with the specified format
def print_to_do_list(context):
all_tasks_str = ""
for header,info_dict in context.chat_data['to-do list'].items():
task_details = ": \n" + info_dict['task details'] if info_dict['task details'] != "_\(empty\)_" else ""
deadline = "\n\[Deadline: " + info_dict['deadline'] + "\]" if info_dict['deadline'] != "_\(empty\)_" else ""
status = "\n\[Status: " + info_dict['status'] + "\]" if info_dict['status'] != "_\(empty\)_" else ""
all_tasks_str = (all_tasks_str + "\n\nπ " + "*" + header + "*" + task_details + deadline + status)
#all_tasks_str = (all_tasks_str + "\n\n \-\- " + "*" + header + "*" + task_details + deadline + status)
return all_tasks_str
def print_individual_task(context, header):
task_str = ""
info_dict = context.chat_data['to-do list'][header]
task_details = ": \n" + info_dict['task details'] if info_dict['task details'] != "_\(empty\)_" else ""
deadline = "\n\[Deadline: " + info_dict['deadline'] + "\]" if info_dict['deadline'] != "_\(empty\)_" else ""
status = "\n\[Status: " + info_dict['status'] + "\]" if info_dict['status'] != "_\(empty\)_" else ""
task_str = (task_str + "\n\nπ " + "*" + header + "*" + task_details + deadline + status)
return task_str
#print reminders
#parameter: context
# returns: string with the specified format
def print_reminders(context, category):
all_reminders=""
for header in context.chat_data['reminders'][category].keys():
#if header == 'Reminder for To\-Do List':
if ('Reminder for ' in header) & ('s To\-Do List' in header):
date = "\n\[Interval: " + context.chat_data['reminders'][category][header]['date'] + "\]"
time = "\n\[Time: " + context.chat_data['reminders'][category][header]['time'] + "\]"
else:
# if date is empty, leave as empty else assign format for date
date = "\n\[Date: " + context.chat_data['reminders'][category][header]['date'] + "\]" if context.chat_data['reminders'][category][header]['date'] != "_\(empty\)_" else ""
time = "\n\[Time: " + context.chat_data['reminders'][category][header]['time'] + "\]" if context.chat_data['reminders'][category][header]['time'] != "_\(empty\)_" else ""
all_reminders = all_reminders + "\n\nπ " + "*" + header + "*" + ": " + date + time
return all_reminders
# print module's to-do list
# parameter: context
# returns: string with the specified format
def print_module_to_do_list(context, current_module):
all_tasks_str = ""
for header,info_dict in context.chat_data['modules'][current_module]['to-do list'].items():
task_details = ": \n" + info_dict['task details'] if info_dict['task details'] != "_\(empty\)_" else ""
deadline = "\n\[Deadline: " + info_dict['deadline'] + "\]" if info_dict['deadline'] != "_\(empty\)_" else ""
status = "\n\[Status: " + info_dict['status'] + "\]" if info_dict['status'] != "_\(empty\)_" else ""
all_tasks_str = (all_tasks_str + "\n\nπ " + "*" + header + "*" + task_details + deadline + status)
return all_tasks_str
def print_module_individual_task(context, current_module, header):
task_str = ""
info_dict = context.chat_data['modules'][current_module]['to-do list'][header]
task_details = ": \n" + info_dict['task details'] if info_dict['task details'] != "_\(empty\)_" else ""
deadline = "\n\[Deadline: " + info_dict['deadline'] + "\]" if info_dict['deadline'] != "_\(empty\)_" else ""
status = "\n\[Status: " + info_dict['status'] + "\]" if info_dict['status'] != "_\(empty\)_" else ""
task_str = (task_str + "\n\nπ " + "*" + header + "*" + task_details + deadline + status)
return task_str
################################### CALLBACKS ###################################
# start callback (CommandHandler)
def start(update, context):
if len(context.chat_data) == 0:
context.chat_data['current task'] = {}
context.chat_data['current reminder'] = {}
context.chat_data['current module'] = ""
context.chat_data['current cca'] = {}
context.chat_data['current leisure'] = {}
context.chat_data['to-do list'] = {}
context.chat_data['reminders'] = {}
context.chat_data['reminders']['work'] = {}
context.chat_data['reminders']['module'] = {}
context.chat_data['reminders']['cca'] = {}
context.chat_data['reminders']['leisure'] = {}
context.chat_data['modules'] = {}
context.chat_data['cca'] = {}
context.chat_data['leisure'] = {}
chat_type = update.message.chat.type
if chat_type == 'private':
context.chat_data['chat_type'] = 'private'
else:
context.chat_data['chat_type'] = 'group'
update.message.reply_text(text="Eh hello\! I'm the doYourWorkLah bot\!\n\n" +
"If you a bit blur blur hor π¦,\nsend /help to see what I can do\.\n"
"If you want me to shut up π€,\nsend /cancel to stop talking to me\.\n\n" +
"*You better start doing your work ah\! Hurry choose one π΅:*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=front_keyboard(context))
return FRONT_MENU
# front callback (CallbackQueryHandler)
def front(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="Eh hello\! I'm the doYourWorkLah bot\!\n\n" +
"If you a bit blur blur hor π¦,\nsend /help to see what I can do\.\n"
"If you want me to shut up π€,\nsend /cancel to stop talking to me\.\n\n" +
"*You better start doing your work ah\! Hurry choose one π΅:*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=front_keyboard(context))
return FRONT_MENU
# work callback (CallbackQueryHandler)
def work(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Faster choose choose: π₯±*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=work_keyboard(context))
return WORK_MENU
# ---------------------------------WORK > GROUP WORK--------------------------------- #
# group_work callback (CallbackQueryHandler)
def group_work(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Just choose lah: π₯±*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_keyboard())
return GROUP_WORK_MENU
# ----------------------------WORK > GROUP WORK (TO-DO LIST)---------------------------- #
# group_work_to_do_list callback (CallbackQueryHandler)
def group_work_to_do_list(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Quick quick choose one: π΄*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_list_keyboard())
return GROUP_WORK_TO_DO_LIST_MENU
def view_to_do_list(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Aiyo just choose something: πͺ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_view_to_do_list_keyboard())
return GROUP_WORK_VIEW_TO_DO_LIST_MENU
# view_entire_to_do_list callback (CallbackQueryHandler)
def view_entire_to_do_list(update, context):
query = update.callback_query
if len(context.chat_data['to-do list']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*π __To\-Do List__ π*" + print_to_do_list(context),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
def view_individual_task(update, context):
query = update.callback_query
if len(context.chat_data['to-do list']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Which task do you want to see? π€*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_view_individual_task_keyboard(context))
return GROUP_WORK_VIEW_INDIVIDUAL_TASK_MENU
def group_work_view_individual_task_user_choice(update, context):
query = update.callback_query
callback_data = query.data
header_without_esc = callback_data.partition('user_')[2]
header_with_esc = add_escape_to_string(header_without_esc)
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*π __Task__ π*" + print_individual_task(context, header_with_esc),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
return ConversationHandler.END
# group_work_add_task callback (CallbackQueryHandler)
def group_work_add_task(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Aiyo just choose something: πͺ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_add_task_keyboard())
return GROUP_WORK_TO_DO_ADD_TASK_MENU
# group_work_to_do_add_header callback (CallbackQueryHandler)
def group_work_to_do_add_header(update, context):
#context.bot.send_message(chat_id=update.effective_chat.id,
# text="entered group_work_to_do_add_header block")
query = update.callback_query
if query is not None:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Create a header for your task\!* π \(You cannot use back the same header and it cannot be more than 45 characters ok\!\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Create a header for your task\!* π \(You cannot use back the same header and it cannot be more than 45 characters ok\!\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return GROUP_WORK_TO_DO_ADD_HEADER_WAITING_INPUT
#NEW
# group_work_to_do_add_header_waiting_input callback (MessageHandler)
def group_work_to_do_add_header_waiting_input(update, context):
# clear context.chat_data['current task'] dictionary
context.chat_data['current task'].clear()
header_without_esc = update.message.text
header_with_esc = add_escape_to_string(header_without_esc)
# limit header_without_esc to 45 characters
if len(header_without_esc) <= 45:
if header_with_esc not in context.chat_data['to-do list']:
context.chat_data['current task'][header_with_esc] = {'task details':"_\(empty\)_", 'deadline':"_\(empty\)_", 'status':"_\(empty\)_"}
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Still got some more information to fill in below:* π€‘ \(Actually you don't want to fill in also can\)\n\n" +
"π*Header:* " + header_with_esc + "\n" +
"π*Task Details:* " + context.chat_data['current task'][header_with_esc]['task details'] + "\n" +
"β³*Deadline:* " + context.chat_data['current task'][header_with_esc]['deadline'] + "\n" +
"π*Status:* " + context.chat_data['current task'][header_with_esc]['status']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_info_keyboard())
return GROUP_WORK_TO_DO_EDIT_INFO_MENU
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Aiyo this header is already taken\! π± Choose another one\!*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_to_do_add_header(update, context)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Aiyo this header exceeds the maximum number of characters leh\!* π±" + "\n\(Current number of characters: "
+ "*"+ str(len(header_without_esc)) + "*" + "\)" + "\n*Choose another one\!*"),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_to_do_add_header(update, context)
# group_work_to_do_edit_task_details callback (CallbackQueryHandler)
def group_work_to_do_edit_task_details(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Quick quick tell me all the details: πͺ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
return GROUP_WORK_TO_DO_EDIT_TASK_DETAILS_WAITING_INPUT
# group_work_to_do_edit_task_details_waiting_input callback (MessageHandler)
def group_work_to_do_edit_task_details_waiting_input(update, context):
#context.bot.send_message(chat_id=update.effective_chat.id,
# text="entered group_work_to_do_edit_task_details_waiting_input block")
task_details = update.message.text
task_details_with_esc = add_escape_to_string(task_details)
current_header = list(context.chat_data['current task'].keys())[0]
context.chat_data['current task'][current_header]['task details'] = task_details_with_esc
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Still got some more information to fill in below:* π€‘ \(Actually you don't want to fill in also can\)\n\n" +
"π*Header:* " + current_header + "\n" +
"π*Task Details:* " + context.chat_data['current task'][current_header]['task details'] + "\n" +
"β³*Deadline:* " + context.chat_data['current task'][current_header]['deadline'] + "\n" +
"π*Status:* " + context.chat_data['current task'][current_header]['status']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_info_keyboard())
return GROUP_WORK_TO_DO_EDIT_INFO_MENU
# group_work_to_do_edit_deadline callback (CallbackQueryHandler)
def group_work_to_do_edit_deadline(update, context):
query = update.callback_query
if query is not None:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Faster edit your deadline\!* π \n\(Die die must follow this format: \nDD/MM/YYYY HH:MM\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Faster edit your deadline\!* π \n\(Die die must follow this format: \nDD/MM/YYYY HH:MM\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return GROUP_WORK_TO_DO_EDIT_DEADLINE_WAITING_INPUT
#NEW
# group_work_to_do_edit_deadline_waiting_input callback (MessageHandler)
def group_work_to_do_edit_deadline_waiting_input(update, context):
deadline = update.message.text
deadline_date = deadline.partition(' ')[0]
deadline_time = deadline.partition(' ')[2]
try:
# check formatting
deadline_date_checked = datetime.datetime.strptime(deadline_date, '%d/%m/%Y').strftime('%d/%m/%Y')
deadline_time_checked = datetime.datetime.strptime(deadline_time, '%H:%M').strftime('%H:%M')
deadline_checked_without_esc = deadline_date_checked + " " + deadline_time_checked
datetime_object_local = datetime.datetime.strptime(deadline_checked_without_esc, '%d/%m/%Y %H:%M')
datetime_object_uct = datetime_object_local - datetime.timedelta(hours = 8)
current_datetime_local = datetime.datetime.now()
if datetime_object_uct < current_datetime_local:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Wah jialat your deadline is already over\!* π€§",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
group_work_to_do_edit_deadline(update, context)
else:
deadline_checked_with_esc = add_escape_to_string(deadline_checked_without_esc)
current_header = list(context.chat_data['current task'].keys())[0]
context.chat_data['current task'][current_header]['deadline'] = deadline_checked_with_esc
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Still got some more information to fill in below:* π€‘ \(Actually you don't want to fill in also can\)\n\n" +
"π*Header:* " + current_header + "\n" +
"π*Task Details:* " + context.chat_data['current task'][current_header]['task details'] + "\n" +
"β³*Deadline:* " + context.chat_data['current task'][current_header]['deadline'] + "\n" +
"π*Status:* " + context.chat_data['current task'][current_header]['status']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_info_keyboard())
return GROUP_WORK_TO_DO_EDIT_INFO_MENU
except ValueError:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Wah jialat your deadline is in the wrong format leh\!* π€§",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_to_do_edit_deadline(update, context)
#NEW
def group_work_to_do_edit_task_status(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Faster choose a task status\!:* π©",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_task_status_keyboard())
return GROUP_WORK_TO_DO_EDIT_TASK_STATUS_MENU
#NEW
def group_work_to_do_edit_task_status_user_choice(update, context):
query = update.callback_query
callback_data = query.data
current_header = list(context.chat_data['current task'].keys())[0]
if callback_data == "haven't do!":
context.chat_data['current task'][current_header]['status'] = "Paiseh paiseh haven't do yet π
"
elif callback_data == "doing!":
context.chat_data['current task'][current_header]['status'] = "Doing already πͺ"
else:
context.chat_data['current task'][current_header]['status'] = "Finish liao π"
context.bot.edit_message_text(chat_id=update.effective_chat.id,
message_id=query.message.message_id,
text=("*Still got some more information to fill in below:* π€‘ \(Actually you don't want to fill in also can\)\n\n" +
"π*Header:* " + current_header + "\n" +
"π*Task Details:* " + context.chat_data['current task'][current_header]['task details'] + "\n" +
"β³*Deadline:* " + context.chat_data['current task'][current_header]['deadline'] + "\n" +
"π*Status:* " + context.chat_data['current task'][current_header]['status']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_info_keyboard())
return GROUP_WORK_TO_DO_EDIT_INFO_MENU
#NEW
# group_work_to_do_done callback (CallbackQueryHandler)
def group_work_to_do_done(update, context):
query = update.callback_query
current_datetime = datetime.datetime.now()
current_header = list(context.chat_data['current task'].keys())[0]
#if context.chat_data['current task'][current_header]['deadline'] != "_\(empty\)_":
# deadline = remove_escape_from_string(context.chat_data['current task'][current_header]['deadline'])
# datetime_object_uct = datetime.datetime.strptime(deadline, '%d/%m/%Y %H:%M')
# datetime_object_local = datetime_object_uct - datetime.timedelta(hours = 8)
# if datetime_object_local < current_datetime:
# to_edit = False
# context.bot.edit_message_text(chat_id=query.message.chat_id,
# message_id=query.message.message_id,
# text="*Aiyo your date and time is already over\!*π",
# parse_mode=telegram.ParseMode.MARKDOWN_V2,
# reply_markup=group_work_to_do_edit_info_keyboard())
# return GROUP_WORK_TO_DO_EDIT_INFO_MENU
# save stuff in 'current task' to 'to-do list'
context.chat_data['to-do list'][current_header] = context.chat_data['current task'][current_header]
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*π __To\-Do List__ π*" + print_to_do_list(context),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
#group_work_edit_task callback (CallbackQueryHandler)
def group_work_edit_task(update,context):
query = update.callback_query
if len(context.chat_data['to-do list']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text= "*Which one you want to edit?:* π",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_edit_task_keyboard(context))
return GROUP_WORK_EDIT_TASK
#NEW
#group_work_edit_task_user_choice callback (CallbackQueryHandler)
def group_work_edit_task_user_choice(update, context):
query = update.callback_query
callback_data = query.data
current_header = callback_data.partition('groupwork_edit_task_')[2]
context.chat_data['current task'].clear()
context.chat_data['current task'][current_header] = context.chat_data['to-do list'][current_header]
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text=("π*Header:* " + current_header + "\n" +
"π*Task Details:* " + context.chat_data['to-do list'][current_header]['task details'] + "\n" +
"β³*Deadline:* " + context.chat_data['to-do list'][current_header]['deadline'] + "\n" +
"π*Status:* " + context.chat_data['current task'][current_header]['status']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_to_do_edit_info_keyboard())
return GROUP_WORK_TO_DO_EDIT_INFO_MENU
# group_work_remove_task callback (CallbackQueryHandler)
def group_work_remove_task(update, context):
query = update.callback_query
if len(context.chat_data['to-do list']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*π __To\-Do List__ π*" + print_to_do_list(context),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
context.bot.send_message(chat_id=query.message.chat_id,
text="*Which one you want to remove?:* πͺ",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_remove_task_keyboard(context))
return GROUP_WORK_REMOVE_TASK_MENU
# group_work_remove_task_user_choice callback (CallbackQueryHandler)
def group_work_remove_task_user_choice(update, context):
query = update.callback_query
callback_data = query.data
header_without_esc = callback_data.partition('user_')[2]
header_with_esc = add_escape_to_string(header_without_esc)
context.chat_data['to-do list'].pop(header_with_esc, None)
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="Okok I removed *" + header_with_esc + "* from the to\-do list liao\. π₯΄",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
if len(context.chat_data['to-do list']) == 0:
context.bot.send_message(chat_id=query.message.chat_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.send_message(chat_id=query.message.chat_id,
text="*π __To\-Do List__ π*" + print_to_do_list(context),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
return ConversationHandler.END
# ----------------------------WORK > GROUP WORK (REMINDERS)---------------------------- #
#group_work_reminders callback (CallbackQueryHandler)
def group_work_reminders(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="Choose faster can: π
",
reply_markup=group_work_reminders_keyboard())
return GROUP_WORK_REMINDERS_MENU
#group_work_view_reminders callback (CallbackQueryHandler)
def group_work_view_reminders(update, context):
query = update.callback_query
if len(context.chat_data['reminders']['work']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh you don't have work reminders what\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*π __Reminders__ π*" + print_reminders(context, "work"),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
#group_work_set_reminder callback
def group_work_set_reminder(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="You don't know what 'choose faster' means is it: π",
reply_markup=group_work_set_reminder_keyboard())
return GROUP_WORK_SET_REMINDER_MENU
#group_work_set_reminder_for_to_do_list callback
def group_work_set_reminder_for_to_do_list(update, context):
query = update.callback_query
if len(context.chat_data['to-do list']) == 0:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh your to\-do list is empty leh\! π€¦ββοΈ*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
else:
context.chat_data['current reminder for tdl'] = {'time':"_\(empty\)_", 'interval':"_\(empty\)_"}
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Still got some more information to fill in below:* π \(Eh this one cannot leave blank ah\)\n\n" +
"β°*Time:* " + context.chat_data['current reminder for tdl']['time'] + "\n" +
"π*Interval:* " + context.chat_data['current reminder for tdl']['interval'],
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED #this is the edit menu
def group_work_set_reminder_for_to_do_list_edit_time(update, context):
query = update.callback_query
if query is not None:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*What time do want me to remind you?* π₯³ \n\(Must be this format ok, don't try to be funny: HH:MM\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*What time do want me to remind you?* π₯³ \n\(Must be this format ok, don't try to be funny: HH:MM\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_EDIT_TIME_WAITING_INPUT
def group_work_set_reminder_for_to_do_list_edit_time_waiting_input(update, context):
time = update.message.text
try:
# check formatting
time_checked = datetime.datetime.strptime(time, '%H:%M').strftime('%H:%M')
time_checked_with_esc = add_escape_to_string(time_checked)
context.chat_data['current reminder for tdl']['time'] = time_checked_with_esc
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Still got some more information to fill in below:* π \(Eh this one cannot leave blank ah\)\n\n" +
"β°*Time:* " + context.chat_data['current reminder for tdl']['time'] + "\n" +
"π*Interval:* " + context.chat_data['current reminder for tdl']['interval'],
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED
except ValueError:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*You trying to be funny is it, your time is not in the correct format leh\!* π€",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_to_do_list_edit_time(update, context)
def group_work_set_reminder_for_to_do_list_edit_interval(update, context):
query = update.callback_query
if query is not None:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Hurry choose the interval between each reminder \(in days\)\.* βοΈ" + "\n"
"\(e\.g\. if you want me to kachiao you with your to\-do list every 2 days, then reply with the number 2\.\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Hurry choose the interval between each reminder \(in days\)\.* βοΈ" + "\n"
"\(e\.g\. if you want me to kachiao you with your to\-do list every 2 days, then reply with the number 2\.\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_EDIT_INTERVAL_WAITING_INPUT
def group_work_set_reminder_for_to_do_list_edit_interval_waiting_input(update, context):
interval = update.message.text
try:
num_of_day = int(interval)
if num_of_day >= 1:
if interval == '1':
context.chat_data['current reminder for tdl']['interval'] = "Every day"
else:
context.chat_data['current reminder for tdl']['interval'] = "Every {} days".format(interval)
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Still got some more information to fill in below:* π \(Eh this one cannot leave blank ah\)\n\n" +
"β°*Time:* " + context.chat_data['current reminder for tdl']['time'] + "\n" +
"π*Interval:* " + context.chat_data['current reminder for tdl']['interval'],
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED
else:
context.bot.send_message(chat_id=update.message.chat_id,
text="*Wah your maths need tuition ah, enter an integer greater than or equal to 1 leh\!* π§βπ«",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_to_do_list_edit_interval(update, context)
except ValueError:
context.bot.send_message(chat_id=update.message.chat_id,
text="*Aiyo enter an integer\!* π₯±",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_to_do_list_edit_interval(update, context)
#callback function for group work > set reminder for to-do list to be sent every X days
def callback_day(context):
chat_id = context.job.context['chat_id']
chat_data = context.job.context['chat_data']
all_tasks_str = ""
for header,info_dict in chat_data['to-do list'].items():
# if date is empty, leave as empty else assign format for date
if (info_dict['task details'] == "_\(empty\)_") and (info_dict['deadline'] == "_\(empty\)_"):
all_tasks_str = all_tasks_str + "\n\nπ " + "*" + header + "*"
elif (info_dict['task details'] == "_\(empty\)_"):
all_tasks_str = all_tasks_str + "\n\nπ " + "*" + header + "*" + "\n\[β³Deadline: " + info_dict['deadline'] + "\]"
elif (info_dict['deadline'] == "_\(empty\)_"):
all_tasks_str = all_tasks_str + "\n\nπ " + "*" + header + "*" + ": \n" + info_dict['task details']
else:
all_tasks_str = all_tasks_str + "\n\nπ " + "*" + header + "*" + ": \n" + info_dict['task details'] + "\n\[β³Deadline: " + info_dict['deadline'] + "\]"
context.bot.send_message(chat_id=chat_id,
text="*π __To\-Do List__ π*" + all_tasks_str,
parse_mode=telegram.ParseMode.MARKDOWN_V2)
def group_work_set_reminder_for_to_do_list_done(update, context):
query = update.callback_query
if (context.chat_data['current reminder for tdl']['time'] == "_\(empty\)_") and (context.chat_data['current reminder for tdl']['interval'] == "_\(empty\)_"):
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Why you never fill in the time and the interval\!* π‘",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED
elif context.chat_data['current reminder for tdl']['time'] == "_\(empty\)_":
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Why you never fill in the time\!* π‘",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED
elif context.chat_data['current reminder for tdl']['interval'] == "_\(empty\)_":
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Why you never fill in the interval\!* π‘",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_to_do_list_edit_info_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_TO_DO_LIST_CLICKED
else:
if 'Reminder for To\-Do List' in context.chat_data['reminders']['work']:
old_job = context.chat_data['reminders']['work']['Reminder for To\-Do List']['job']
old_job.schedule_removal()
else:
context.chat_data['reminders']['work']['Reminder for To\-Do List'] ={}
context.chat_data['reminders']['work']['Reminder for To\-Do List']['time'] = context.chat_data['current reminder for tdl']['time']
context.chat_data['reminders']['work']['Reminder for To\-Do List']['date'] = context.chat_data['current reminder for tdl']['interval']
time_with_esc = context.chat_data['reminders']['work']['Reminder for To\-Do List']['time']
time = remove_escape_from_string(time_with_esc)
context.chat_data['reminders']['work']['Reminder for To\-Do List']['interval'] = context.chat_data['current reminder for tdl']['interval']
interval = context.chat_data['reminders']['work']['Reminder for To\-Do List']['interval']
num_of_day = 0
if interval == "Every day":
num_of_day = 1
else:
num_of_day = int(interval[6])
datetime_object_local = datetime.datetime.strptime(time, '%H:%M')
datetime_object_uct = datetime_object_local - timedelta(hours = 8)
time_object_uct = datetime_object_uct.time()
# need to change from minutes to days
new_job = context.job_queue.run_repeating(callback_day, timedelta(days=int(num_of_day)), first=time_object_uct, context={'chat_data': context.chat_data, 'chat_id': str(query.message.chat_id)})
context.chat_data['reminders']['work']['Reminder for To\-Do List']['job'] = new_job
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="Ok nice nice π A new reminder for your to\-do list has been created\! π I will remind you at *{} {}*\.".format(time, interval.lower()),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return ConversationHandler.END
#callback group_work_set_reminder_for_event
def group_work_set_reminder_for_event(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="Lailai choose choose: π€ͺ",
reply_markup=group_work_add_event_keyboard())
return GROUP_WORK_REMINDER_ADD_EVENT_MENU
#group_work_set_reminder_for_event_add_header callback (CallbackQueryHandler)
def group_work_set_reminder_for_event_add_header(update, context):
query = update.callback_query
if query is not None:
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh create a header for your event\!* πͺ \(You cannot use back the same header and it cannot be more than 45 characters ah\!\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
else:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Eh create a header for your event\!* πͺ \(You cannot use back the same header and it cannot be more than 45 characters ah\!\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
return GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_HEADER_WAITING_INPUT
# group_work_set_reminder_for_event_add_header_waiting_input (MessageHandler)
#state called by group work set reminder for event
def group_work_set_reminder_for_event_add_header_waiting_input(update, context):
#checks if current reminder dictionary is empty
# limit header_without_esc to 45 characters
header_without_esc = update.message.text
header_with_esc = add_escape_to_string(header_without_esc)
if len(header_without_esc) > 45:
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Aiyo this header exceeds the maximum number of characters leh\!* π±" + "\n\(Current number of characters: "
+ "*"+ str(len(header_without_esc)) + "*" + "\)" + "\n*Choose another one\!*"),
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_event_add_header(update, context)
elif header_with_esc in context.chat_data['reminders']['work']:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Aiyo this header is already taken\! π± Choose another one\!*",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_event_add_header(update, context)
else:
context.chat_data['current reminder'][header_with_esc] = {'date':"_\(empty\)_", 'time':"_\(empty\)_"}
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Still got some more information to fill in below:* π» \(Eh this one cannot leave blank ah\)\n\n" +
"π*Header:* " + header_with_esc + "\n" +
"π*Date:* " + context.chat_data['current reminder'][header_with_esc]['date'] + "\n" +
"β°*Time:* " + context.chat_data['current reminder'][header_with_esc]['time']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_event_details_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_EVENT_DETAILS_MENU
#callback group_work_set_reminder_for_event_date
def group_work_set_reminder_for_event_date(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Eh choose your event date\!* π€ \n\(Must be this format ok, don't try to be funny: DD/MM/YYYY\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
return GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_DATE_WAITING_INPUT
def group_work_set_reminder_for_event_add_date_waiting_input(update, context):
date = update.message.text
try:
# check formatting
date_checked = datetime.datetime.strptime(date, '%d/%m/%Y').strftime('%d/%m/%Y')
date_with_esc = add_escape_to_string(date_checked)
current_header = list(context.chat_data['current reminder'].keys())[0]
context.chat_data['current reminder'][current_header]['date'] = date_with_esc
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Still got some more information to fill in below:* π» \(Eh this one cannot leave blank ah\)\n\n" +
"π*Header:* " + current_header + "\n" +
"π*Date:* " + context.chat_data['current reminder'][current_header]['date'] + "\n" +
"β°*Time:* " + context.chat_data['current reminder'][current_header]['time']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_event_details_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_EVENT_DETAILS_MENU
except ValueError:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*Aiyo your date is not in the correct format leh\!* π",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_event_date(update, context)
# group_work_set_reminder_for_event_time callback (CallbackQuery Handler)
def group_work_set_reminder_for_event_time(update, context):
query = update.callback_query
context.bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text="*Faster edit your event time\!*π\n\(Die die must be this format ah: HH:MM\)",
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=None)
return GROUP_WORK_SET_REMINDER_FOR_EVENT_ADD_TIME_WAITING_INPUT
#group_work_set_reminder_for_event_add_time_waiting_input callback (MessageHandler)
def group_work_set_reminder_for_event_add_time_waiting_input(update, context):
time = update.message.text
try:
# check formatting
time_checked = datetime.datetime.strptime(time, '%H:%M').strftime('%H:%M')
time_with_esc = add_escape_to_string(time_checked)
current_header = list(context.chat_data['current reminder'].keys())[0]
context.chat_data['current reminder'][current_header]['time'] = time_with_esc
context.bot.send_message(chat_id=update.effective_chat.id,
text=("*Eh fill in the rest of the information below:*π \(You CANNOT leave the following fields blank\)\n\n" +
"π*Header:* " + current_header + "\n" +
"π*Date:* " + context.chat_data['current reminder'][current_header]['date'] + "\n" +
"β°*Time:* " + context.chat_data['current reminder'][current_header]['time']),
parse_mode=telegram.ParseMode.MARKDOWN_V2,
reply_markup=group_work_set_reminder_for_event_details_keyboard())
return GROUP_WORK_SET_REMINDER_FOR_EVENT_DETAILS_MENU
except ValueError:
context.bot.send_message(chat_id=update.effective_chat.id,
text="*You never read properly is it, your time is not in the correct format\!* π²",
parse_mode=telegram.ParseMode.MARKDOWN_V2)
group_work_set_reminder_for_event_time(update, context)
def reminder_callback(context):
chat_id = context.job.context['chat_id']
chat_data = context.job.context['chat_data']
current_header = context.job.context['header']
date_with_esc = chat_data['reminders']['work'][current_header]['date']
time_with_esc = chat_data['reminders']['work'][current_header]['time']
job_queue = context.job.context['job_queue']