-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ellie.py
executable file
·1395 lines (1149 loc) · 45.7 KB
/
Ellie.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
# This Ai is made by Rafi Ahmed Saad (RAS) aka MrChocolat3-
# Started since January 2019
#----------------- Main Files ------------------ #
import datetime
import os
import random
import sys
import pyttsx3
import speech_recognition as sr
import json
import smtplib
import textwrap
import pygame
import urllib.request
import urllib.parse
import re
import wikipedia
import platform
import multiprocessing
import threading
#----------------- Custom Libraries ------------------ #
import E3P.Ellie_Visual_effect as VE
from E3P.WordAnalizer import WordMeaning
from E3P.YouTube import YouTube_Downloader
#----------------- Custom Files ------------------ #
# import music_player
import face
import Videoplayer
import GLOBALS
#----------------- Specific Files From Custom Files ------------------#
from connector import Connector, XML, JSON
from notifier import send_notification
#----------------- Specific Files From Libreries ------------------ #
from kivy.clock import Clock
from itertools import islice
from pathlib import Path
from time import sleep
from pygame.locals import *
from moviepy.editor import *
#----------------- Custom Class Section ------------------ #
from Interrogative import Interrogative as inter
from WriteHistory import add_on_history
from misc import stats, files, network, log
from Tokenizer import Tokenizer
# ------------------------------ INITIALIZE GLOBAL VARIABLS -------------------------------
#----------------- Class Section ------------------ #
class Mail:
''' Sends email to a person '''
def __init__(self):
pass
def save_mail(self, mail):
text = "Okay...... What is the subject?"
data = f'''<info> <mail> "{mail}" </mail>\n <subject> "SOME TEXT" </subject>\n<content> "some text" </content>\n</info> '''
try:
with open(files().open_file("Settings", "mail.xml"), "w") as file:
file.writelines(data)
except Exception as e:
print(log().error("Error saving mail_address", "Save_mail", "Mail", "Ellie"))
Connector().get_input_for_function(self.save_subject, isMiddleInput=False)
type_print(text, text)
def save_subject(self, subject):
text = "what is the content?"
mail = XML().read(files().open_file("Settings", "mail.xml"), "mail")
data = f'''<info> <mail> "{mail}" </mail>\n <subject> "{subject}" </subject>\n<content> some text </content>\n</info> '''
try:
with open(files().open_file("Settings", "mail.xml"), "w") as file:
file.writelines(data)
except Exception as e:
print(log().error("Error saving mail_subject", "Save_subject", "Mail", "Ellie"))
type_print(text, text)
Connector().get_input_for_function(self.save_content, isMiddleInput=False)
def save_content(self, content):
mail = XML().read(files().open_file("Settings", "mail.xml"), "mail")
subject = XML().read(files().open_file("Settings", "mail.xml"), "subject")
data = f'''<info> <mail> "{mail}" </mail>\n <subject> "{subject}" </subject>\n<content> "{content}" </content>\n</info> '''
try:
with open(files().open_file("Settings", "mail.xml"), "w") as file:
file.writelines(data)
except Exception as e:
print(log().error("Error saving mail_content", "Save_content", "Mail", "Ellie"))
text = "okay sending the mail...........\nPlease wait................................."
type_print(text, text)
self.send_mail()
def send_mail(self):
print(log().info("Sending email", "Send_mail", "Mail", "Ellie"))
file = files().open_file("Settings", "mail.xml")
receiver = XML().read(file, "mail")
body = XML().read(file, "content")
# filename = "document.pdf"
subject = XML().read(file, "subject")
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = "mcismrchocolat3@gmail.com"
receiver_email = receiver
password = "Hopeisasadthing!123"
message = f"""\
Subject: {subject}
{body}"""
try:
type_print("Trying to send the mail", "Trying to send the mail")
context = ssl.create_default_context()
# with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(sender_email, "Hopeisasadthing!")
server.sendmail(sender_email, receiver_email, message)
server.quit()
print(log().message("Email sent successfully", "send_mail", "mail", "ellie"))
type_print("Okay mail is sent :)", "Okay mail is sent :)")
except Exception as e:
print(log().error(e, "send_mail", "mail", "ellie"))
type_print(
f"SORRY! COUDN'T SEND THE EMAIL")
# FROMADDR = "mcismrchocolat3@gmail.com"
# LOGIN = FROMADDR
# PASSWORD = "Hopeisasadthing!"
# TOADDRS = ["pttrafiahmed@gmail.com"]
# SUBJECT = "Test"
# msg = (f"From:{FROMADDR}\nTo: {TOADDRS}\nSubject: {SUBJECT}")
# msg += "some text\r\n"
# server = smtplib.SMTP('smtp.gmail.com', 587)
# server.set_debuglevel(1)
# server.ehlo()
# server.starttls()
# server.login(LOGIN, PASSWORD)
# server.sendmail(FROMADDR, TOADDRS, msg)
# server.quit()
class Log:
"""
Custom loger for ellie
"""
def EllieTxt(self, text):
files().write_on_file('Log', 'log.txt', text.strip()+'\n', 'a+')
def UserTxt(self, text):
files().write_on_file('Log', 'log.txt', n+": "+text+'\n', 'a+')
def EllieSaveHistory(self, EllieTxt):
if EllieTxt.startswith('Ellie:'):
text = f'{EllieTxt.strip()}'
else:
text = f'Ellie: {EllieTxt.strip()}'
add_on_history('Log', 'ChatHistory.txt', text)
def userSaveHistory(self, userTxt):
text = f'{n}: {userTxt}'
add_on_history('Log', 'ChatHistory.txt', text)
def clearHistoty(self):
with open(files().open_file('Log', 'log.txt'), 'w') as file:
file.write(' ')
class reaction:
''' Contains different types of reaction and their expressions '''
def __init__(self):
self.affermative = ['ok', 'okay', 'sure', 'yes', 'yeah',
'yup', 'ok fine', 'okay fine', 'alright', 'k']
self.negative = ['no', 'nah', 'nope', 'dont']
def confution(self, text):
unknow_words = ['i dont know', 'idk', 'dont know']
confuse_reply = [
'If you don\'t know, then how will I know? :)',
'Come one why dont know it? :!',
'Oh! Okay :(',
'Really? Wired :/ ',
'If you dont know then I dont know xD'
]
confuse_replyT = [
'If you dont know, then how would I know?',
'Come one why dont know it?',
'Oh! Okay',
'Really? Wired',
'If you dont know then I dont know!'
]
for words in unknow_words:
if text == words:
confused = True
break
else:
confused = False
if confused:
word = random.choice(confuse_reply)
tword = random.choice(confuse_replyT)
type_print(N+word, tword)
def curious(self, text):
common_quotes = [
'why', 'how', 'tell me', 'hahaha why'
]
reply = [
'I am not in the mood to tell.. go watch movies XD',
'I am will tell you soon when we will become good friends :)',
'No I wont tell you go do something else heheehe'
]
for words in common_quotes:
if text == words:
curious = True
break
else:
curious = False
if curious:
word = random.choice(reply)
tword = random.choice(reply)
type_print(N+word, tword)
def funny(self, text):
common_quotes = [
'hahahaha', 'lol', 'lmao', 'rofl', 'haha', 'hahaha'
]
reply_text = [
'hahaha why are you laughing?', 'hahaha hey stop laughing xDD', 'Hahaha I know right?'
]
for words in common_quotes:
if text in words:
funny = True
break
else:
funny = False
if funny:
word = random.choice(reply_text)
tword = random.choice(reply_text)
type_print(N+word, tword)
def Thanks(self, *text, **text2):
common_quotes = [
'haha thanks', 'thanks you', 'thx', 'thnx', 'thanks', 'great'
]
reply_text = [
'you are welcome', 'its okay, you are welcome!', 'Its okay.Hey, wanna hear a joke?'
]
def middle_input(text2):
for words in self.affermative:
if text2 in words:
self.Joke()
break
else:
type_print("Okay......")
if "MIDDLE_INPUT" in text2:
middle_input(text2["MIDDLE_INPUT"])
else:
for words in common_quotes:
if text[0] in common_quotes:
Thanks = True
break
else:
Thanks = False
if Thanks:
t = random.choice(reply_text)
type_print(t, t)
if t.endswith("a joke?"):
Connector().get_input_for_function(self.Thanks, isMiddleInput=True)
# self.Joke(i)
def annoying(self, text):
isAngry = False
angry = [
'fuck you', 'fuck u', 'bitch', 'mother fucker', 'pussy', 'motherscooter', 'useless piece of shit'
]
unexpected_moment = [
'tf', 'wtf', 'what the fuck?', 'what the fuck', 'fuck', 'god damn it'
]
for words in angry:
if text in words:
reply = f'OI WHOM YOU CALLING A {text} HUH? \n\nYOU MOTHER SCOOTER! \n\nPUCK YOU! .i.'
type_print(reply, reply)
isAngry = True
break
for words in unexpected_moment:
if text in words and isAngry == False:
reply = "What happend?\n\nIS there anything wrong?\n\nanything I did wrong?"
type_print(reply, reply)
break
def Joke(self):
jokes = [
'Did you hear about the Italian chef that died recently?\n\nHE PASTA AWAYA :(',
'Why are frogs are so happy?\n\nThey eat whatever bugs them. B)',
'Why do chicken coups always have two doors?\n\nWith four, they’d be chicken sedans.',
'What do you do if someone thinks an onion is the only food that can make them cry?\n\nThrow a coconut at their face.',
'What do you call a guy with a rubber toe?\n\nROBERTOE',
'What do you do with a sick boat?\n\nTake is to the doc already!',
'What did the rubber band factory worker say when he was fired?\n\nOH, CRAP... NOT AGAIN YOU STUPID BOSS... YOU LITTLE BASTARD! YOU CRAZY A*S CREAPY MOTHERSCOOTER! F**K YOU'
]
t = random.choice(jokes)
if SETTINGS["discord"]:
reply = f"```{t}```"
else:
reply = t
type_print(reply)
Connector().get_input_for_function(self.funny, isMiddleInput=False)
class feelings:
def __init__(self):
self.affermative = ['ok', 'okay', 'sure', 'yes', 'yeah',
'yup', 'ok fine', 'okay fine', 'alright', 'k']
self.negative = ['no', 'nah', 'nope', 'dont']
self.Sad = ['I am sad', ':(']
self.Sreply = ['Anything Wrong?', 'What happened?',
'Hey if your mood is off then I can play you a song, Should I?']
self.Happy = [
'I am fine', 'fine', 'good', 'great', 'amazing'
]
self.Hreaply = [
'Glad to know that you are fine', 'Ah Great!', 'Amazing wanna hear some song?'
]
def analize_feelings(self, *text):
text = text[0]
for words in self.Sad:
if text in words:
self.Sad = True
break
else:
self.Sad = False
for words in self.Happy:
if text in words:
self.Happy = True
break
else:
self.Happy = False
if self.Happy and not self.Sad:
r = random.choice(self.Hreaply)
type_print(r, r)
if r.endswith("are fine"):
Connector().get_input_for_function(reaction().Thanks, isMiddleInput=False)
# send_text_to_function(self.Thanks, 'hi')
# self.Thanks(i)
if r.endswith("song?"):
Connector().get_input_for_function(feelings.middle_input, isMiddleInput=False)
elif not self.Happy and self.Sad:
r = random.choice(self.Sreply)
type_print(r, r)
if r.endswith("I?"):
Connector().get_input_for_function(feelings.middle_input, isMiddleInput=False)
def middle_input(self, i):
for words in self.affermative:
if words in i or words == i:
type_print('Wait a moment Please.............',
'Wait a moment please.............')
# playMusic('Minar - Shada')
break
else:
type_print("Okay okay...........", "Okay okay")
reaction().Joke()
class Event:
def __init__(self):
self.P = [
'okay', 'sure', 'ok', 'yes', 'go', 'do it'
]
self.N = [
'no', 'nope', 'just go', 'nah'
]
self._EVENTLIST_ = [
'playSong-Fun', 'playSong-Sad'
]
def affermative(self, text, eventName):
do_event = False
for words in self.P:
if text in self.P:
affermative = True
break
else:
affermative = False
if affermative:
do_event = True
else:
do_event = False
class AnalizeQuestion:
""" Analizes questions from Interrogative Sentence \n
and gets different questions type according to the sentence type"""
def __init__(self, txt):
self.text = txt
self.a, self.b, self.c, self.d = self.get_data()
self.question_type = self.get_question_type(self.a)
self.QT, self.Qa, self.Qb, self.Qc = self.get_question_style(
self.question_type)
if self.QT == "WH":
if self.Qa == "who":
_MEANING_.clear()
_MEANING_.append(self.WHOQuestion())
elif self.Qa == "what":
_MEANING_.clear()
_MEANING_.append(self.WHATQuestion())
elif self.Qa == "how":
_MEANING_.clear()
_MEANING_.append(self.HOWQuestion())
files().write_on_file(
"Log", "EL-QS-WH-HOW.ellie", f"{self.text}\n", "a+")
else:
_MEANING_.clear()
_MEANING_.append("NOTHING")
elif self.QT == "TOBE":
_MEANING_.clear()
_MEANING_.append(self.TOBEQuestion())
elif self.QT == "TOHAVE":
_MEANING_.clear()
_MEANING_.append(self.TOHAVEQuestion())
else:
_MEANING_.clear()
_MEANING_.append("NOTHING")
def get_data(self):
a, b, c, d = isInterrogativeSentence(self.text)
return a, b, c, d
def get_question_type(self, a):
if a == "WH":
return "WH"
elif a == "TOBE":
return "TOBE"
elif a == "TOHAVE":
return "TOHAVE"
elif a == "NOHELPV":
return "NOHELPV"
def get_question_style(self, question_type):
if question_type == "WH":
question_Word = self.b
verb = self.c
extention = self.d
return question_type, question_Word, verb, extention
elif question_type == "TOBE":
verb = self.b
sub = self.c
extention = self.d
files().write_on_file(
"Log", "EL-QS-TBV.ellie", f"{self.text}\n", "a+")
return question_type, sub, verb, extention
elif question_type == "TOHAVE":
helpingVerb = self.b,
sub = self.c
extention = self.d
text = f"\n|{extention} |\n{self.text}\n"
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-THV.ellie'))]
for lines in question_token:
if lines == f"|{extention} |":
break
else:
files().write_on_file("Log", "EL-QS-THV.ellie", text, "a+")
return question_type, helpingVerb, sub, extention
elif question_type == "NOHELPV":
helpingVerb = self.b,
sub = self.c
extention = self.d
files().write_on_file("Log", "EL-QS-NHV", f"{self.text}\n", "a+")
return question_type, helpingVerb, sub, extention
#-------------------// WHS QUESTIONS //-------------------#
def WHATQuestion(self):
if self.Qb == "is":
if "your" in self.Qc:
meaning = self.Qc.replace("your", "")
text = f"\n|{meaning}|\n{self.text}\n"
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-WH-WHAT.ellie'))]
for lines in question_token:
if lines == f"|{meaning}|":
break
else:
files().write_on_file("Log", "EL-QS-WH-WHAT.ellie", text, "a+")
return meaning, "WHAT"
elif "my" in self.Qc and "your" not in self.Qc:
meaning = self.Qc.replace("my", 'users')
text = f"\n|{meaning}|\n{self.text}\n"
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-WH-WHAT.ellie'))]
for lines in question_token:
if lines == f"|{meaning}|":
break
else:
files().write_on_file("Log", "EL-QS-WH-WHAT.ellie", text, "a+")
return meaning, "WHAT"
elif "mine" in self.Qc and "your" not in self.Qc:
meaning = self.Qc.replace("mine", 'users')
text = f"\n|{meaning}|\n{self.text}\n"
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-WH-WHAT.ellie'))]
for lines in question_token:
if lines == f"|{meaning}|":
break
else:
files().write_on_file("Log", "EL-QS-WH-WHAT.ellie", text, "a+")
return meaning, "WHAT"
elif "a" in self.Qc and ("your" not in self.Qc) and ("my" or "mine" not in self.Qc):
meaning = self.Qc.replace("a", "")
text = f"\n|{meaning}|\n{self.text}\n"
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-WH-WHAT.ellie'))]
for lines in question_token:
if lines == f"|{meaning}|":
break
else:
files().write_on_file("Log", "EL-QS-WH-WHAT.ellie", text, "a+")
return meaning, "WHAT"
def WHOQuestion(self):
if self.Qb == "are" and ("you" in self.Qc):
meaning = "WhoIsShe"
return meaning, "WHO"
elif self.Qb == "is" and ("your creator" in self.Qc):
meaning = "aboutCreator"
return meaning, "WHO"
elif self.Qb == "is" and ("your friend" in self.Qc):
meaning = "aboutFreinds"
return meaning, "WHO"
def HOWQuestion(self):
if self.Qb == "are" and "you" in self.Qc:
meaning = "health"
return meaning, "HOW"
elif self.Qb == "old" and "you" in self.Qc:
meaning = "age"
return meaning, "HOW"
else:
meaning = "Nothing"
return meaning, "HOW"
#-------------------// TOBES QUESTIONS //-------------------#
def TOBEQuestion(self):
verb = self.Qb
sub = self.Qa
ext = self.Qc
if verb == "are" and sub == "you":
meaning = f"Fealing_OF: {ext} :Ness"
return meaning, "TOBE"
#-------------------// TOHAVES QUESTIONS //-------------------#
def TOHAVEQuestion(self):
HV = self.Qa
sub = self.Qb
ext = self.Qc
if HV[0] == "do":
if "you" in sub:
meaning = f"Have {ext}"
return meaning, "TOHAVE"
elif HV[0] == "does":
if "he" in sub:
meaning = f"Have {ext} [DH]"
return meaning, "TOHAVE"
else:
return "Nothing"
elif HV[0] == "did":
if "you" in sub:
meaning = "Nothing"
return meaning, "TOHAVE"
else:
return "Nothing", "TOHAVE"
class AnalizedAnswers:
''' Gives different answers according to the question type '''
def __init__(self, text):
AnalizeQuestion(text)
self.text = text
self.N = ['no', 'no way', 'why would I be?',
'No why?', 'Any problem? I dont think so']
self.P = ['yes', 'yes I am', 'Yeah Any problem?',
'I dont care, do you have any problem?', 'What do you think I AM?']
self.P_Clam_mood = [
'yes', 'yeah I am good', 'Yes.. what about you?', 'I\'m fine, what about you?'
]
self.N_Clam_mood = [
'no', 'no I am not', 'no.. I dont feel so good', 'I\'m sad, what about you?'
]
self.NClamNoQuestion = [
'no', 'no I dont', 'nah', 'no way'
]
self.PClamNoQuestion = [
'yes', 'yes i do', 'To be honest I am feeling so shy to tell the answer ^_^'
]
self.PHealth_Nquestion = [
'I\'m fine', 'Feeling Geart', 'Amazing', 'Just chilling with you xD'
]
self.Nheath_Nquestion = [
'Not bad', 'Feeling a little wired', 'Feeling a little awkward'
]
self.PHealth_Question = [
'I\'m Feeling great! what about you?', 'Nothing just moving with the flow.And you?',
'Just chilling with you and feeling amazing. How do you feel?'
]
self.NHealth_Question = [
'I\'m not feeling good, what about you?', 'Kinda bored, And you?',
'Feeling wired...Ah, How do you feel?'
]
for Codes in _MEANING_:
self.meaning = Codes[0]
self.question_type = Codes[1]
if self.question_type == "TOBE":
self.TOBEAnswers()
files().write_on_file("Log", "EL-ANS-TOBE.ellie",
f"{reply_text[0]}\n", "a+")
if self.question_type == "TOHAVE":
self.TOHAVEAnswers()
if self.question_type == "HOW":
self.HOWAnswers()
if self.question_type == "WHAT":
self.WHATAnswers()
def TOBEAnswers(self):
meaning = self.meaning
N_P_list = list()
if meaning != "Fealing_OF: okay :Ness":
Nwords = random.choice(self.N)
Pwords = random.choice(self.P)
N_P_list.clear()
N_P_list.append(Nwords)
N_P_list.append(Pwords)
reply_word = random.choice(N_P_list)
type_print(f"{reply_word}\n", f"{reply_word}\n")
reply_text.clear()
reply_text.append(reply_word)
if reply_word.endswith("?"):
Connector().get_input_for_function(reaction().confution, isMiddleInput=False)
# i = input("\nSay Something:")
# reaction().confution(i)
else:
Nwords = random.choice(self.N_Clam_mood)
Pwords = random.choice(self.P_Clam_mood)
N_P_list.clear()
N_P_list.append(Nwords)
N_P_list.append(Pwords)
reply_word = random.choice(N_P_list)
type_print(f"{reply_word}\n", f"{reply_word}\n")
reply_text.clear()
reply_text.append(reply_word)
if reply_word.endswith("?"):
Connector().get_input_for_function(reaction().confution, isMiddleInput=False)
# i = input("\nSay Something:")
# reaction().confution(i)
def TOHAVEAnswers(self):
meainng = f"{self.meaning} "
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-THV.ellie'))]
answer_token = [line.strip() for line in open(
files().open_file('Log', 'EL-ANS-THV.ellie'))]
token = ""
Atoken = ""
for lines in question_token:
if lines.startswith("|") and lines.endswith("|"):
t = lines.replace("|", "")
if t in meainng:
token = t
break
for num, lines in enumerate(answer_token, 1):
if lines.startswith("|") and lines.endswith("|"):
t = lines.replace("|", "")
if t in token:
d = os.getcwd()
data_folder = Path(d+'/Log')
file_to_Open = data_folder / 'EL-ANS-THV.ellie'
file = open(file_to_Open, 'r')
for line in islice(file, num, (num+1)):
type_print(line, line)
break
break
else:
Ntext = random.choice(self.NClamNoQuestion)
Ptext = random.choice(self.PClamNoQuestion)
j = list()
j.append(Ntext)
j.append(Ptext)
text = random.choice(j)
type_print(text, text)
textInput = f"\n|{t}|\n{text}\n"
files().write_on_file("Log", "EL-ANS-THV.ellie", textInput, "a+")
def HOWAnswers(self):
meaning = self.meaning
if meaning == "health":
PhN = random.choice(self.PHealth_Nquestion)
NhN = random.choice(self.Nheath_Nquestion)
PhQ = random.choice(self.PHealth_Question)
NhQ = random.choice(self.NHealth_Question)
PH = [PhN, PhQ]
NH = [NhN, NhQ]
P = random.choice(PH)
N = random.choice(NH)
Reply = [P, N]
text = random.choice(Reply)
type_print(text, text)
for lines in self.PHealth_Question:
if text in lines:
Connector().get_input_for_function(
feelings().analize_feelings, isMiddleInput=False)
# i = input("\nSay Something:")
# feelings().analize_feelings(i)
break
else:
for lines in self.NHealth_Question:
if text in lines:
Connector().get_input_for_function(
feelings().analize_feelings, isMiddleInput=False)
# i = input("\nSay Something:")
# feelings().analize_feelings(i)
break
else:
for lines in self.Nheath_Nquestion:
if text in lines:
Connector().get_input_for_function(
feelings().analize_feelings, isMiddleInput=False)
# i = input("\nSay Something:")
# reaction().curious(i)
break
if meaning == "Nothing":
P = ['Hmm I dont think I know', 'Nothing comeing on my mind right now',
'Ah comeon please stop asking these questions, I am bored :('
]
N = ['.......', 'really? stop asking these question',
'Meh I am bored can\'t talk -_-']
Pr = random.choice(P)
Nr = random.choice(N)
R = [Pr, Nr]
text = random.choice(R)
type_print(text, text)
Connector().get_input_for_function(reaction().curious, isMiddleInput=False)
# i = input("\nSay Something:")
# reaction().curious(i)
def WHATAnswers(self):
meaning = self.meaning
question_token = [line.strip() for line in open(
files().open_file('Log', 'EL-QS-WH-WHAT.ellie'))]
answer_token = [line.strip() for line in open(
files().open_file('Log', 'EL-ANS-WH-WHAT.ellie'))]
AnswerToken = ""
for lines in question_token:
if lines.startswith("|") and lines.endswith("|"):
t = lines.replace("|", "")
if t in meaning:
token = t
break
for num, lines in enumerate(answer_token, 1):
if lines.startswith("|") and lines.endswith("|"):
t = lines.replace("|", "")
if t in token:
d = os.getcwd()
data_folder = Path(d+'/Log')
file_to_Open = data_folder / 'EL-ANS-WH-WHAT.ellie'
file = open(file_to_Open, 'r')
for line in islice(file, num, (num+1)):
print(line)
break
break
else:
#-----------------------------Alternate Online way------------------------------#
self.answer = searchWeb(token)
self.textInput = f"\n|{token}|\n{self.answer}\n"
files().write_on_file("Log", "EL-ANS-WH-WHAT.ellie", self.textInput, "a+")
type_print(self.answer, self.answer)
# text = [
# 'Sorry I dont know the answer yet :( Do you know it? I will remember it :) (yes/no)',
# 'Ah I can\'t remember it... DO you know it? Please tell me (yes/no)',
# ]
# t = random.choice(text)
# while True:
# type_print(t, t)
# ans = input("Say something: ")
# if "yes" in ans:
# t = "Thanks.... tell me! I want to know :)"
# type_print(t, t)
# i = input("\nSay Something: ")
# textInput = f"\n|{token}|\n{i}\n"
# files().write_on_file("Log", "EL-ANS-WH-WHAT.ellie", textInput, "a+")
# break
# elif "no" in ans:
# t = "hmm next time then.... :( I will just keep the question in mind :("
# type_print(t, t)
# break
# else:
# t = "Come on! Yes or No only..... I so excited to know the answer please dont make fun :("
# type_print(t, t)
# continue
class AnalizedReaction(reaction):
''' Gets reactions based on user texts and returns expression according to the user reaction '''
def __init__(self, text):
self.text = text
self.Sad = ['I am sad', ':(']
self.Happy = ['lol', 'hahaha', 'lmao']
self.Thanks = ['thanks', 'thank you', 'great']
self.confuse = ['idk', 'what', 'what are you saying']
# self.sed_reaction(text)
# self.happy_reaction(text)
# self.thanks_react(text)
# self.confusion(text)
super().confution(text)
super().curious(text)
super().funny(text)
super().annoying(text)
# super().feelings(text)
super().Thanks(text)
# super().Joke(text)
''' some useless functions
def sed_reaction(self, text):
for words in self.Sad:
if text in words:
feelings().analize_feelings(text)
break
def happy_reaction(self, text):
for words in self.Happy:
if text in words:
reaction().funny(text)
break
def thanks_react(self, text):
for words in self.Thanks:
if text in words:
reaction().Thanks(text)
break
def confusion(self, text):
for words in self.confuse:
if text in words:
reaction().confution(text)
break
'''
#----------------- Test Functions ------------------ #
def isInterrogativeSentence(sentence):
''' CHECKS IF A SENTENCE IS IN INTERROGATIVE FORM '''
s = inter()
s.is_tobe_sentance(sentence)
s.is_tohave_sentance(sentence)
s.is_no_helping_verb_sentance(sentence)
s.is_wh_sentance(sentence)
toBeS = bool()
toHaveS = bool()
noHelpVS = bool()
whS = bool()
if s.isTobeS:
toBeS = True
sub, verb, ext = s.is_tobe_sentance(sentence)
return "TOBE", sub, verb, ext
else:
toBeS = False
if s.isToHaveS:
toHaveS = True
doDidDoes, sub, ext = s.is_tohave_sentance(sentence)
return "TOHAVE", doDidDoes, sub, ext
else:
toHaveS = False
if s.isNoHelpVerbS:
noHelpVS = True
doDidDoes, sub, ext = s.is_no_helping_verb_sentance(sentence)
return "NOHELPV", doDidDoes, sub, ext
else:
noHelpVS = False
if s.isWhS:
whS = True
whQ, verb, ext = s.is_wh_sentance(sentence)
return "WH", whQ, verb, ext
else:
whS = False
#----------------- Ellie Functions ------------------ #
def Info():
'''Gives a little introduction to the user about Ellie and it runs only on the first run'''
word = """\nHello there, welcome! This is Ellie and I will chat with you all day. You can tell me whatever you
want and after you close the program I will forget everything :D or If you want I can remember all
"""
type_print(word, word)
files().write_on_file('Settings', 'userSetting.json', 'first_time = False', 'w+')
def greet():
'''