-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabayanSystem3.py
More file actions
608 lines (456 loc) · 33.4 KB
/
TabayanSystem3.py
File metadata and controls
608 lines (456 loc) · 33.4 KB
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
# -*- coding: UTF8 -*-
# Tabayan developers:
# Rawan Mohammed Alowaymir,
# Abdulmalik Sulaiman Alaqel.
import requests
import pickle
import csv
import datetime
import json
class BotHandler:
def __init__(self, token):
self.token = token
self.api_url = "https://api.telegram.org/bot{}/".format(token)
# url = "https://api.telegram.org/bot<token>/"
def get_updates(self, offset=0, timeout=30):
method = 'getUpdates'
params = {'timeout': timeout, 'offset': offset}
resp = requests.get(self.api_url + method, params)
result_json = resp.json()['result']
return result_json
def send_message(self, chat_id, text, reply_markup=None):
params = {'chat_id': chat_id, 'text': text, 'reply_markup': reply_markup}
method = 'sendMessage'
resp = requests.post(self.api_url + method, params)
return resp
def send_multipleChoiceMessage(self, chat_id, text, choiceslist):
# ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
reply_markup = {'keyboard': [choiceslist], 'one_time_keyboard': True, 'resize_keyboard': True}
params = {'chat_id': chat_id, 'text': text, 'reply_markup': json.dumps(reply_markup), 'parse_mode': 'HTML'}
method = 'sendMessage'
resp = requests.post(self.api_url + method, params)
return resp
def send_reply(self, chat_id, text, reply_to_message_id):
params = {'chat_id': chat_id, 'text': text, 'reply_to_message_id': reply_to_message_id, 'parse_mode': 'HTML'}
method = 'sendMessage'
resp = requests.post(self.api_url + method, params)
return resp
def get_first_update(self):
get_result = self.get_updates()
if len(get_result) > 0:
last_update = get_result[0]
else:
last_update = None
return last_update
# Token of bot
token='xxxxxxxxxxxxxxxxxx' # For @TabayanBot
token1='xxxxxxxxxxxxxxxxxxxx' # For @Tabayantest2bot
My_bot = BotHandler(token1) # Bot's name
def addScore(scoreName):
with open('QayemniStats.txt', 'r') as file:
lines=file.read().split('\n')
QayemniHeader=lines[0].split(',')
scores=lines[1].split(',')
if (scoreName == 4):
scores[0]='{}'.format(int(scores[0]) + 1)
elif scoreName == 3:
scores[1]='{}'.format( int(scores[1]) + 1 )
elif scoreName == 2:
scores[2]='{}'.format( int(scores[2]) + 1 )
elif scoreName == 1:
scores[3]='{}'.format( int(scores[3]) + 1 )
scores[4]='{}'.format( int(scores[4]) + 1 )
with open('QayemniStats.txt', 'w') as file:
file.write(QayemniHeader[0]+','+QayemniHeader[1]+','+QayemniHeader[2]+','+QayemniHeader[3]+','+QayemniHeader[4]+'\n')
file.write(scores[0]+','+scores[1]+','+scores[2]+','+scores[3]+','+scores[4]+'\n')
def getStat():
with open('QayemniStats.txt', 'r') as file:
lines=file.read().split('\n')
QayemniHeader=lines[0].split(',')
scores=lines[1].split(',')
all = int(scores[4])
if all == 0:
all = 1
print('\n-------------In getStat()-------------:')
print(QayemniHeader[0], (int(scores[0]) / all) * 100, '%')
print(QayemniHeader[1], (int(scores[1]) / all) * 100, '%')
print(QayemniHeader[2], (int(scores[2]) / all) * 100, '%')
print(QayemniHeader[3], (int(scores[3]) / all) * 100, '%')
print('Where total scores:', all)
print('---------------------------------------\n\n')
def test(sample, model):
return model.predict(
[sample.replace(',', ' ').replace('"""', ' ').replace('""', ' ').replace(' ', ' ').replace(' ', ' ')])
def initialize():
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import LinearSVC
from imblearn.pipeline import Pipeline
data = pd.read_csv('all without duplicates.csv', sep=',', )
Targets_list = data['Target'].values.astype('U')
features = (data['tweet_w_EOL'] + " " + data['created_at']).values.astype('U')
pipeline = Pipeline([('vect', TfidfVectorizer(ngram_range=(1, 1), sublinear_tf=True)),
# ('chi', SelectKBest(chi2, k=5)),
('clf', LinearSVC(C=1.0, penalty='l1', max_iter=1000, dual=False))])
model = pipeline.fit(features, Targets_list)
# save the classifier
with open('my_dumped_classifier.pkl', 'wb') as fid:
pickle.dump(model, fid)
def TabayanModel():
# load the model again
with open('my_dumped_classifier.pkl', 'rb') as fid:
model_loaded = pickle.load(fid)
return model_loaded
def main():
new_offset = 0
print('Now launching...')
# initialize() # No need to run this function more than one time ; through this function, we have been trained the model and save it to the disk
trainedmodel = TabayanModel()
verify = False
getdate = False
qayemni = False
suggestion = False
isSuggested = False
analyze=False
newsdatelist = ['لا أعلم', 'حدد تاريخ النشر']
suggestionlist = ['لا شكراً', 'أود تقديم مقترح']
Qayemnilist = ['غير راض جداً', 'غير راض', 'راض', 'راض جداً']
def_msgs = ["عرف بنفسك", "عرفنا بنفسك", "عرف عن نفسك", "عرفنا عن نفسك", "كلمنا عن نفسك", "حدثنا عن نفسك",
"تحدث عن نفسك", "تكلم عن نفسك", "من أنت", "من انت", "مين أنت","من تكون" ,"مين انت"]
while True:
all_updates = My_bot.get_updates(new_offset)
if len(all_updates) > 0:
for current_update in all_updates:
print("current_update = ", current_update)
first_update_id = current_update['update_id']
try:
current_update['message']
add = ''
except:
add = 'edited_'
if 'text' not in current_update[add + 'message']:
first_chat_text = 'New member'
else:
first_chat_text = current_update[add + 'message']['text']
first_chat_id = current_update[add + 'message']['chat']['id']
if 'first_name' in current_update[add + 'message']:
first_chat_name = current_update[add + 'message']['chat']['first_name']
# elif 'new_chat_member' in current_update[add + 'message']:
# try:
# first_chat_name = current_update[add + 'message']['new_chat_member']['username']
# except:
# pass
elif 'from' in current_update[add + 'message']:
first_chat_name = current_update[add + 'message']['from']['first_name']
else:
first_chat_name = "unknown"
message_type = current_update[add + 'message']['chat']['type']
print('message_type = ', message_type)
print('first_chat_name:',first_chat_name)
if (message_type == 'group'):
try:
mention = current_update[add + 'message']['entities'][0]['type'] # this is mean the text has a mention to the bot.
print("mention=", mention)
if mention == 'mention' and '@TabayanBot' in first_chat_text:
is_it_mention = True
first_chat_text = first_chat_text.replace('@TabayanBot','').replace(' ', ' ')
else:
is_it_mention = False
except:
print(" it's not mention :) (don't reply)")
is_it_mention = False
try:
orignal_text = current_update[add + 'message']['reply_to_message']['text'] # This is mean it's a reply to a message.
reply = True
except:
print("it's not reply")
orignal_text = ''
reply = False
if (is_it_mention or reply): # maybe I will make the bot reply directly when this True.
print("first_chat_text = ", first_chat_text, 'and its length:', len(first_chat_text))
if ('الرجاء التحقق من التالي' in first_chat_text):
first_chat_text = first_chat_text.replace('الرجاء التحقق من التالي','').replace(' ', ' ')
if (len(first_chat_text) > 10):
detectionResult = test(first_chat_text, trainedmodel)
print('Prediction:', detectionResult[0], ',News text:', first_chat_text)
if (detectionResult[0] == 'Non-rumor'):
message = 'ليست إشاعة ✅'
else:
message = 'إشاعة ❌'
My_bot.send_reply(first_chat_id, "الخبر : {} \n"
""
"نتيجة التحقق : {}".format(first_chat_text, message),
current_update[add + 'message']['message_id'])
# Saving classifier results on disk (For improvement purpose)
with open('Classifiers_results.csv', 'a') as file:
wr = csv.writer(file)
if knwondate:
date = first_chat_text
else:
date = datetime.datetime.today().strftime("%d-%B-%Y %H:%M:%S")
wr.writerow(["{}".format(detectionResult[0]), "{}".format(newstext), "{}".format(date)])
###########################################################
elif (reply and len(orignal_text) > 10 and current_update[add + 'message']['reply_to_message']['from']['username'] != 'TabayanBot'):
detectionResult = test(orignal_text, trainedmodel)
print('Prediction:', detectionResult[0], ',News text:', orignal_text)
if (detectionResult[0] == 'Non-rumor'):
message = 'ليست إشاعة ✅'
else:
message = 'إشاعة ❌'
My_bot.send_reply(first_chat_id, "الخبر : {} \n"
""
"نتيجة التحقق : {}".format(orignal_text, message),
current_update[add + 'message']['message_id'])
# Saving classifier results on disk (For improvement purpose)
with open('Classifiers_results.csv', 'a') as file:
wr = csv.writer(file)
if knwondate:
date = first_chat_text
else:
date = datetime.datetime.today().strftime("%d-%B-%Y %H:%M:%S")
wr.writerow(["{}".format(detectionResult[0]), "{}".format(newstext), "{}".format(date)])
###########################################################
else:
My_bot.send_reply(first_chat_id, "يهدف تبيّن إلى مساعدة مرتادي منصة التلقرام عن طريق توفير خدمة تمكنهم من التحقق من صحة الأخبار، ولتحقيق هذا الغرض، يرجى استخدام أوامر التحقق للإشارة إلى الأخبار فقط !",current_update[add + 'message']['message_id'])
elif ('تحقق' in first_chat_text):
if(not reply):#mention only
My_bot.send_reply(first_chat_id, "مع الإشارة إليّ، يرجى الرد على الخبر 'Reply' مع تضمين 'تحقق'، أو، ابدأ الخبر المراد التحقق منه بـ'الرجاء التحقق من التالي:'..\n",current_update[add + 'message']['message_id'])
elif len(orignal_text)<10 or current_update[add + 'message']['reply_to_message']['from']['username'] == 'TabayanBot' :
My_bot.send_reply(first_chat_id, "يهدف تبيّن إلى مساعدة مرتادي منصة التلقرام عن طريق توفير خدمة تمكنهم من التحقق من صحة الأخبار، ولتحقيق هذا الغرض، يرجى استخدام أوامر التحقق عند الإشارة إلى الأخبار فقط !",current_update[add + 'message']['message_id'])
else:
detectionResult = test(orignal_text, trainedmodel)
print('Prediction:', detectionResult[0], ',News text:', orignal_text)
if (detectionResult[0] == 'Non-rumor'):
message = 'ليست إشاعة ✅'
else:
message = 'إشاعة ❌'
My_bot.send_reply(first_chat_id, "الخبر : {} \n"
""
"نتيجة التحقق : {}".format(orignal_text, message),
current_update[add + 'message']['message_id'])
# Saving classifier results on disk (For improvement purpose)
with open('Classifiers_results.csv', 'a') as file:
wr = csv.writer(file)
if knwondate:
date = first_chat_text
else:
date = datetime.datetime.today().strftime("%d-%B-%Y %H:%M:%S")
wr.writerow(["{}".format(detectionResult[0]), "{}".format(newstext), "{}".format(date)])
###########################################################
elif len(first_chat_text)<3:
if (not reply): #Mention only
My_bot.send_reply(first_chat_id,
"السلام عليكم ورحمة الله وبركاته , أنا تبيّن، مكتشف الشائعات !\n للتحقق من خبر ما إن كان إشاعة أم لا، أشر إلى الحساب الخاص بي 'Reply' مع كلمة 'تحقق' للرسالة التي تتضمن الخبر الذي تود التحقق منه أو،\n أشر إلى الحساب مع تضمين 'الرجاء التحقق من التالي' في بداية الرسالة لتفعيل خدمة التحقق. "
"\n"
"ملاحظة: يفضّل تضمين تاريخ نشر الخبر مع الخبر للحصول على أفضل النتائج.."
"\n\n"
"هذا كل شيء، شكراً لاستخدامكم تبيّن. 😊"
, current_update[add + 'message']['message_id'])
else:
My_bot.send_reply(first_chat_id," الرجاء تضمين كلمة 'تحقق' إن كنت تود التحقق من الخبر المشار إليه ..",current_update[add + 'message']['message_id'])
elif (("سلام" in first_chat_text and len(first_chat_text) < 13) or "السلام عليكم" in first_chat_text) and (len(first_chat_text) < 50):
My_bot.send_reply(first_chat_id, 'وعليكم السلام ورحمة الله وبركاته',current_update[add + 'message']['message_id'])
elif ("مشكور" in first_chat_text or "شكرا" in first_chat_text) and len(first_chat_text) < 40:
My_bot.send_reply(first_chat_id, 'أهلاً وسهلاً 🤍، '
'\n'
'نأمل أن يكون حاز على رضاك واستحسانك 😊.',current_update[add + 'message']['message_id'])
elif ("اهلا" in first_chat_text or "أهلا" in first_chat_text) and len(first_chat_text) < 35:
My_bot.send_reply(first_chat_id, 'أهلاً وسهلاً بك 🤍',current_update[add + 'message']['message_id'])
elif ("هلا" == first_chat_text or "مرحبا" in first_chat_text) and (len(first_chat_text) < 30):
My_bot.send_reply(first_chat_id, 'أهلاً وسهلا ً',current_update[add + 'message']['message_id'])
elif ("حياك" in first_chat_text) and (len(first_chat_text) < 20):
My_bot.send_reply(first_chat_id, 'الله يحييك',current_update[add + 'message']['message_id'])
elif ("اخبارك" in first_chat_text or "أخبارك" in first_chat_text) and (len(first_chat_text) < 30):
My_bot.send_reply(first_chat_id, 'فرحان فيكم🤍',current_update[add + 'message']['message_id'])
elif ("كيف حالك" in first_chat_text or "كيف الحال" in first_chat_text) and (len(first_chat_text) < 30):
My_bot.send_reply(first_chat_id, 'عال العال', current_update[add + 'message']['message_id']) # To mention: ('\n@'+current_update[add+'message']['from']['username']+'\n')
elif ("صباح ال" in first_chat_text) and len(first_chat_text) < 40:
My_bot.send_message(first_chat_id, 'صباح النور والسرور ياهلا !')
elif ("مساء ال" in first_chat_text) and len(first_chat_text) < 40:
My_bot.send_message(first_chat_id, 'مساء النور أهلاً وسهلاً !')
elif ((any(i in first_chat_text for i in def_msgs) and (len(first_chat_text) < 40)) or len(first_chat_text) < 2):
My_bot.send_reply(first_chat_id,
"السلام عليكم ورحمة الله وبركاته , أنا تبيّن، مكتشف الشائعات !\n للتحقق من خبر ما إن كان إشاعة أم لا، أشر إلى الحساب الخاص بي 'Reply' مع كلمة 'تحقق' للرسالة التي تتضمن الخبر الذي تود التحقق منه أو،\n أشر إلى الحساب مع تضمين 'الرجاء التحقق من التالي' في بداية الرسالة لتفعيل خدمة التحقق. "
"\n"
"ملاحظة: يفضّل تضمين تاريخ نشر الخبر مع الخبر للحصول على أفضل النتائج.."
"\n\n"
"هذا كل شيء، شكراً لاستخدامكم تبيّن. 😊"
, current_update[add + 'message']['message_id'])
else:
if len(first_chat_text) > 5 and first_chat_text != '/start' and first_chat_text not in Qayemnilist and first_chat_text not in suggestionlist and first_chat_text not in newsdatelist:
with open('UnexpectedMessages.txt', 'a') as file:
file.write(first_chat_text + ",\r\n")
print("Unexpected message has been added to UnexpectedMessages.txt")
print('in line 373')
print('is_it_mention:',is_it_mention)
print('reply:', reply)
new_offset = first_update_id + 1
else:# Not 'mention' nor 'Reply'
new_offset = first_update_id + 1
else: # It means that this message is in a private chat.
if first_chat_text == '/start':
My_bot.send_message(first_chat_id, first_chat_name + ' !\n'
"مرحباً بك في تبيّن ، مكتشف الشائعات !\nللتحقق من خبر ما إن كان إشاعة أم لا، أرسل كلمة 'تحقق' أما إن وددت الخروج، فأرسل 'إنهاء'.. "
"\n"
"ملاحظة: يفضّل تضمين تاريخ نشر الخبر مع الخبر للحصول على أفضل النتائج."
"\n\n"
"\n"
"هذا كل شيء، شكراً لاستخدامك تبيّن. 😊")
elif verify:
newstext = first_chat_text
if (len(newstext) < 10):
My_bot.send_message(first_chat_id,
"يهدف تبيّن إلى مساعدة مرتادي منصة التلقرام عن طريق توفير خدمة تمكنهم من التحقق من صحة الأخبار، ولتحقيق هذا الغرض، يرجى استخدام أوامر التحقق عند الإشارة إلى الأخبار فقط !")
else:
My_bot.send_multipleChoiceMessage(first_chat_id, "في أي تاريخ تم نشر الخبر؟ ", newsdatelist)
getdate = True
verify = False
elif getdate:
getdate = False
analyze = True
if first_chat_text == 'حدد تاريخ النشر':
My_bot.send_message(first_chat_id, "إذاً، من فضلك أدخل تاريخ النشر باستخدام الصيغة التالية: "
"yyyy-mm-dd"
"\n\n"
"مثال: 16-07-2020")
knwondate = True
else:
knwondate = False
continue
elif analyze:
if knwondate:
newstext += " " + first_chat_text
print('date:',first_chat_text)
detectionResult = test(newstext, trainedmodel)
print('Prediction:',detectionResult[0],',News text:',newstext)
if (detectionResult[0] == 'Non-rumor'):
message = 'ليست إشاعة ✅'
else:
message = 'إشاعة ❌'
newstext= newstext[:len(newstext) - len(first_chat_text)]
My_bot.send_message(first_chat_id, "الخبر : {} \n"
"\n"
"نتيجة التحقق : {}".format(newstext, message))
# Saving classifier results on disk (For improvement purpose)
with open('Classifiers_results.csv', 'a', newline='') as file:
wr = csv.writer(file)
if knwondate:
date=first_chat_text
else:
date=datetime.datetime.today().strftime("%d-%B-%Y %H:%M:%S")
wr.writerow(["{}".format(detectionResult[0]), "{}".format(newstext),"{}".format(date)])
###########################################################
analyze = False
elif qayemni:
isParticipated = True
# ['غير راض جداً', 'غير راض', 'راض', 'راض جداً']
if first_chat_text == 'غير راض جداً':
addScore(1)
elif first_chat_text == 'راض جداً':
addScore(4)
elif first_chat_text == 'راض':
addScore(3)
elif first_chat_text == 'غير راض':
addScore(2)
else:
print('Unexpected score:', first_chat_text)
isParticipated = False
My_bot.send_message(first_chat_id, "شاكرين لك استخدامك تبيّن،"
"\n"
"إلى اللقاء 😊💛."
"\n")
getStat()
if isParticipated:
My_bot.send_multipleChoiceMessage(first_chat_id, 'شكراً لك، نقدر لك هذا..'
'\n'
'كما نسعد بأي اقتراحات إن وددت، ستكون محل اهتمامنا بكل تأكيد.',suggestionlist)
suggestion = True
qayemni = False
print("the message text = ", first_chat_text)
elif suggestion:
if first_chat_text == 'أود تقديم مقترح':
My_bot.send_message(first_chat_id, "تفضل !")
isSuggested = True
else:
My_bot.send_message(first_chat_id, "حسناً !"
"\n"
"شكراً لاستخدامك تبيّن، إلى اللقاء 😊💛."
"\n")
suggestion = False
elif isSuggested:
if first_chat_text != '/start' and len(first_chat_text) > 5:
with open('Suggestions.txt', 'a') as file:
file.write(first_chat_text + ",\r\n")
My_bot.send_message(first_chat_id, "شاكرين ومقدرين لك إسهامك في تحسين تبيّن، شكراً لك !"
"\n\n")
isSuggested = False
elif first_chat_text == 'أود تقديم مقترح':
suggestion = True
continue
elif ('أهلا' in first_chat_text or 'اهلا' in first_chat_text or 'اهلا وسهلا' in first_chat_text or 'هلا' == first_chat_text or "مرحبا" in first_chat_text) and (len(first_chat_text) < 40):
My_bot.send_message(first_chat_id,("أهلاً وسهلاً بك "+first_chat_name+" 🤍، إن لم تكن على معرفة بيّ، فيمكنك سؤالي عن من أكون.. \nمثل، من تكون؟، من أنت؟، عرفني عن نفسك! \n\n\n"))
elif 'تحقق' in first_chat_text and (len(first_chat_text) < 10):
My_bot.send_message(first_chat_id, "الرجاء إرسال الخبر الذي تود التحقق منه")
verify = True
elif (first_chat_text == 'مساعدة' or (any(i in first_chat_text for i in def_msgs) and (len(first_chat_text) < 25))):
My_bot.send_message(first_chat_id,
"السلام عليكم ورحمة الله وبركاته، أنا تبيّن، مكتشف الشائعات !\nللتحقق من خبر ما إن كان إشاعة أم لا، أرسل كلمة 'تحقق' أما إن وددت الخروج، فأرسل 'إنهاء'.. "
"\n"
"ملاحظة: يفضّل تضمين تاريخ نشر الخبر مع الخبر للحصول على أفضل النتائج."
"\n\n"
"\n"
"هذا كل شيء، شكراً لاستخدامك تبيّن 😊🤍.")
elif (("السلام عليكم" in first_chat_text or "سلام" == first_chat_text) and (len(first_chat_text) < 25)) or len(first_chat_text) < 2:
My_bot.send_message(first_chat_id,('وعليكم السلام ورحمة الله وبركاته،أهلاً وسهلاً بك '+first_chat_name+'🤍، إن لم تكن على معرفة بيّ، فيمكنك سؤالي عن من أكون.. \nمثل، من تكون؟، من أنت؟، عرفني عن نفسك! \n\n\n'))
elif ("صباح ال" in first_chat_text) and len(first_chat_text) < 20:
My_bot.send_message(first_chat_id, 'صباح النور والسرور ياهلا !')
print("the message text = ", first_chat_text)
elif ("مساء ال" in first_chat_text) and len(first_chat_text) < 20:
My_bot.send_message(first_chat_id, 'مساء النور أهلاً وسهلاً !')
print("the message text = ", first_chat_text)
elif ("كيف حالك" in first_chat_text or "كيف الحال" in first_chat_text) and (len(first_chat_text) < 20):
My_bot.send_message(first_chat_id, 'عال العال')
print("the message text = ", first_chat_text)
elif ("اخبارك" in first_chat_text or "أخبارك" in first_chat_text) and (len(first_chat_text) < 20):
My_bot.send_message(first_chat_id, 'فرحان فيك 🤍')
print("the message text = ", first_chat_text)
elif ("حياك" in first_chat_text) and (len(first_chat_text) < 20):
My_bot.send_message(first_chat_id, 'الله يحييك')
print("the message text = ", first_chat_text)
elif 'إنهاء' in first_chat_text or 'انهاء' in first_chat_text and (len(first_chat_text) < 13):
My_bot.send_message(first_chat_id, 'شكراً لاستخدامك تبيّن، نأمل أن يكون حاز على رضاك واستحسانك.')
My_bot.send_multipleChoiceMessage(first_chat_id, 'قيمني:'
'\n'
'نسعى دائماً لتقديم الأفضل لكم، لذا نرجو منك تقييم الخدمة المقدمة لك إذا تفضلت 😊',
Qayemnilist)
qayemni = True
print("the message text = ", first_chat_text)
elif ("مشكور" in first_chat_text or "شكرا" in first_chat_text) and 'لا شكراً' != first_chat_text and len(first_chat_text) < 20:
My_bot.send_message(first_chat_id, 'اهلاً وسهلاً 😊🤍.'
'\n'
'شكراً لاستخدامك تبيّن، نأمل أن يكون حاز على رضاك واستحسانك.')
My_bot.send_multipleChoiceMessage(first_chat_id, 'قيمني:'
'\n'
'نسعى دائماً لتقديم الأفضل لكم، لذا نرجو منك تقييم الخدمة المقدمة لك إذا تفضلت 😊',
Qayemnilist)
qayemni = True
print("the message text = ", first_chat_text)
else:
My_bot.send_message(first_chat_id, "الرجاء إرسال كلمة 'تحقق' لتفعيل خدمة التحقق من الأخبار، 'إنهاء' لإنهاء المحادثة أو 'مساعدة' إن أردت إعادة تعريف النظام. "
'\n')
print("Unexpected message:", first_chat_text)
if (len(first_chat_text) > 5 and first_chat_text != '/start' and first_chat_text not in Qayemnilist and first_chat_text not in suggestionlist and first_chat_text not in newsdatelist):
with open('UnexpectedMessages.txt', 'a') as file:
file.write(first_chat_text + ",\r")
print("Unexpected message has been added to UnexpectedMessages.txt")
new_offset = first_update_id + 1
if __name__ == '__main__':
try:
main()
print('Done !')
except KeyboardInterrupt:
exit()
# This code has been written by Rawan Mohammed Alowaymir and Abdulmalik Sulaiman Alaqel
# Developers Information:
# Rawan Mohammed Alowaymir, Email:rawan864md@gmail.com
# Abdulmalik Sulaiman Alaqel, Email: Mloooki.3@gmail.com