-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelegram_bot.py
1159 lines (1119 loc) · 66.8 KB
/
telegram_bot.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
import logging # Import the logging module for handling logs
import time
import os
import mutagen
from botDatabase import (
start_db,
updateIDUser,
updateAge,
update_age_automatically,
get_user_age,
set_language,
get_language
)
from difflib import SequenceMatcher # Import SequenceMatcher for string similarity comparison
from googletrans import Translator # Import Translator from googletrans for text translation
from apiget.animeapi import AnimeApp # Import AnimeApp from apiget.animeapi for anime-related data
from songGet.songs import songsAnime
from apiget.mangapi import MangaApp
from telegram import Update, BotCommand, InlineKeyboardButton, InlineKeyboardMarkup # Import Telegram-related classes
from telegram.ext import (
Application, # Import Application for handling different types of interactions
CommandHandler, # Import CommandHandler for handling commands
ContextTypes, # Import ContextTypes for context management
MessageHandler,
CallbackQueryHandler, # Import CallbackQueryHandler for handling callback queries
CallbackContext, # Import CallbackContext for context in callback queries
filters
)
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
) # Set up logging configuration
logging.getLogger("httpx").setLevel(logging.WARNING) # Set log level for httpx module
# Create a logger for this module
logger = logging.getLogger(__name__) # Initialize logger for this script/module
class telegramBot:
def __init__(self) -> None:
# Initialize a dictionary to map language names to their corresponding codes
self.dict_languages = {
"Español":"es",
"English":"en",
"Français":"fr",
"Deutsch":"de",
"Português":"pt",
"Italiano":"it",
"Русский":"ru",
"عرب":"ar",
"हिंदू":"hi",
"Română":"ro",
"日本語":"ja",
"简体中文":"zh-tw",
"한국인":"ko"
}
# Define a dictionary of bot commands and their descriptions
self.commands_dictionary = {
"start":"The bot starts ₍^ >ヮ<^₎ .ᐟ.ᐟ",
"language":f"Change language of the Bot 🇪🇸➡️🇬🇧",
"request": f"+'name'. Request information about an anime from MyAnimeList 🗄🔎📺 (japanese or english)",
"mangarequest": f"+'name'. Request information about a manga from MyAnimeList 🗄🔎📖 (japanese or english)",
"random": f"Random information about an anime 🎲",
"mangarand":f"Random information about a manga 🎲📖",
"hoshiimanga":f"+ 'gender'. Manga suggestion by gender 🍱📖",
"hoshii": f"+'gender'. Anime suggestion by gender 🌍🍱",
"showgen":f"Show all available genders 🍘🎎",
"help":f"Give you information about my functions 🆘❔"
}
#
# List of anime genres
self.__genders = ['Action', 'Comedy', 'Horror', 'Sports', 'Adventure', 'Drama',
'Mystery', 'Supernatural', 'Avant Garde', 'Fantasy', 'Romance',
'Suspense', 'Award Winning', 'Girls Love', 'Sci-Fi', 'Boys Love',
'Gourmet', 'Slice of Life', 'Ecchi', 'Erotica', 'Hentai']
# Initialize language-related attributes
self.language = str
self.translator = Translator()
self.sourceLanguage = "en"
# Placeholder for data
self.data = str
# Initialize an empty dictionary to store information about manga message
self.info_manga = {
f"🎥 {'Title'}": "",
f"🎌 {'Japanese Title'}": "",
f"✍️ {'Author(s)'}": "",
f"🟥 {'Themes'}":"",
f"📚 {'Volumes'}": "",
f"📔 {'Serialization'}":"",
f"#️⃣ {'Chapters'}": "",
f"📝 {'Gender'}": "",
f"📜 {'Status'}": "",
f"⭐ {'Score'}": "",
f"📝 {'Synopsis'}": ""
}
# Initialize an empty dictionary to store information messages
self.info_message = {
f"🎥 {'Title'}": "",
f"🎌 {'Japanese Title'}": "",
f"📺 {'Type'}": "",
f"🏷️ {'Genre'}":"",
f"🗓️ {'Aired'}": "",
f"🖥️ {'Episodes'}": "",
f"⭐ {'Score'}": "",
f"🔞 {'Rating'}": "",
f"📜 {'Status'}": "",
f"📝 {'Synopsis'}": ""
}
# Initialize an empty dictionary to store information about genders
self.gender_info = {
f"🔫":"",
f"😂":"",
f"🏚":"",
f"🤾♀️":"",
f"🗺":"",
f"🎭":"",
f"🔮":"",
f"👾":"",
f"⚔️":"",
f"🧙♂️":"",
f"💝":"",
f"🧩":"",
f"🏆":"",
f"👭":"",
f"🧪":"",
f"👬":"",
f"🍽":"",
f"🌅":"",
f"🫣":"",
f"❤️👯":"",
f"🔞💋":""
}
def getAbbreviation(self,lang):
"""
Returns the abbreviation for the specified language
Args:
lang (str): Language code (e.g., 'en' for English)
Returns:
str: Language abbreviation
"""
self.language = lang
return self.language
def showHelp(self):
"""
Displays a help message with available commands
Returns:
dict: Dictionary of commands and their descriptions
"""
if self.language == str:
return self.commands_dictionary
else:
# Translate command descriptions if language is not English
self.commands_dictionary = {x: self.translatedData(y) for x,y in self.commands_dictionary}
return self.commands_dictionary
def showGender(self):
help_gender = '\n'.join(f'{k}: {v}'for k,v in zip(self.gender_info.keys(),self.__genders))
return help_gender
def translatedData(self,data) -> str:
"""
Translates data from the source language to the specified language
Args:
data (str): Text to be translated
Returns:
str: Translated text
"""
self.data = self.translator.translate(data,src=self.sourceLanguage,dest=self.language).text
self.data = self.data.replace('\u200b', '').replace('\n\n', '')
return self.data
def getSimilarity(self,gender):
"""
Finds a gender match based on similarity
Args:
gender (str): Gender to compare
Returns:
str: Matching gender (if found)
"""
gender_get = next((i for i in self.__genders if SequenceMatcher(None, i.lower(), gender).ratio() > 0.5), '')
return gender_get
# Instances
telebot = telegramBot() # Create an instance of the TelegramBot class
animeApp = AnimeApp() # Create an instance of the AnimeApp class
songAnime = songsAnime()
mangaApp = MangaApp()
start_db()
update_age_automatically()
#Functons for Anime commands
"""Start Command"""
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""
Handles the start command for the bot
Args:
update (Update): Telegram update object
context (ContextTypes.DEFAULT_TYPE): Telegram context object
"""
user = update.message.chat
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
updateIDUser(user_id,language=lang,age=age)
if lang != None:
telebot.getAbbreviation(str(lang))
# Send a translated welcome message if the language is not English
await update.message.reply_text(telebot.translatedData(f"Hi, {user.first_name}!!♡⸜(˃ ᵕ ˂ )⸝ I’m Hoshimya ✨, but you can call me ‘mya-chan’ if you prefer (ᵕ—ᴗ—). I’m at your service! 🌟\nWhat does this bot do? ❓ Well, when boredom strikes, I’ll whisk you away to the world of anime with a recommendation. Share your preferred genre, and I’ll conjure up a suggestion! I understand around 10 languages. 🌐\nWhile there are some things I can’t do, I’ll give my best shot.\nIf you’re a programmer itching to improve something new, go ahead! 👨💻👩💻 Check out the repository on GitHub. 🐈⬛ https://github.com/Hoshimya-Animation/hoshiTelegramBot \nAnd lastly, like the stars and constellations, I’ll be here for you until eternity. ( > 〰 < )♡✨🌃🌍"))
if age==None:
await update.message.reply_text(telebot.translatedData(f"How old are you?"))
context.user_data['awaiting_age'] = True
else:pass
else:
# Send the default welcome message in English
await update.message.reply_text(f"Hi, {user.first_name}!!♡⸜(˃ ᵕ ˂ )⸝ I’m Hoshimya ✨, but you can call me ‘mya-chan’ if you prefer (ᵕ—ᴗ—). I’m at your service! 🌟\nWhat does this bot do? ❓ Well, when boredom strikes, I’ll whisk you away to the world of anime with a recommendation. Share your preferred genre, and I’ll conjure up a suggestion! I understand around 10 languages. 🌐\nWhile there are some things I can’t do, I’ll give my best shot.\nIf you’re a programmer itching to improve something new, go ahead! 👨💻👩💻 Check out the repository on GitHub. 🐈⬛ https://github.com/Hoshimya-Animation/hoshiTelegramBot \nAnd lastly, like the stars and constellations, I’ll be here for you until eternity. ( > 〰 < )♡✨🌃🌍")
if age==None:
await update.message.reply_text(f"How old are you?")
context.user_data['awaiting_age'] = True
else:pass
"""Change commands"""
async def changeCommands(application:Application) -> None:
"""
Updates the bot's commands and chat menu button
Args:
application (Application): The application instance
"""
command = [BotCommand((key),(value)) for key,value in telebot.commands_dictionary.items()]
await application.bot.set_my_commands(command)
await application.bot.set_chat_menu_button()
"""Start command menu"""
async def language(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Sends a message with three inline buttons attached for language selection.
Args:
update (Update): Telegram update object
context (ContextTypes.DEFAULT_TYPE): Telegram context object
"""
keyboard = [
[
InlineKeyboardButton(f"Español 🇲🇽", callback_data="lang_Español"),
InlineKeyboardButton(f"English 🇬🇧🇺🇸", callback_data="lang_English"),
InlineKeyboardButton(f"Français 🇫🇷", callback_data="lang_Français"),
],
[ InlineKeyboardButton(f"Deutsch 🇩🇪", callback_data="lang_Deutsch"),
InlineKeyboardButton(f"Português 🇵🇹🇧🇷", callback_data="lang_Português"),
InlineKeyboardButton(f"Italiano 🇮🇹", callback_data="lang_Italiano"),
],
[
InlineKeyboardButton(f"Русский 🇷🇺", callback_data="lang_Русский"),
InlineKeyboardButton(f"عرب 🇸🇦", callback_data="lang_عرب"),
InlineKeyboardButton(f"हिंदू 🇮🇳", callback_data="lang_हिंदू"),
],
[
InlineKeyboardButton(f"Română 🇷🇴", callback_data="lang_Română"),
InlineKeyboardButton(f"日本語 🇯🇵", callback_data="lang_日本語"),
InlineKeyboardButton(f"简体中文 🇨🇳", callback_data="lang_简体中文"),
InlineKeyboardButton(f"한국인 🇰🇷", callback_data="lang_한국인"),
]
]
reply_markup = InlineKeyboardMarkup(keyboard)
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
if lang == None:
await update.message.reply_text("Please choose:", reply_markup=reply_markup)
else:
telebot.getAbbreviation(str(lang))
await update.message.reply_text(telebot.translatedData("Please choose:"), reply_markup=reply_markup)
async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Parses the CallbackQuery and updates the message text.
Args:
update (Update): The update received from Telegram.
context (ContextTypes.DEFAULT_TYPE): The context object.
"""
query = update.callback_query
user_id = query.from_user.id
await query.answer()
lang = get_language(user_id=user_id)
if lang==None:
if query.data.split('_')[1] in telebot.dict_languages and query.data.startswith('lang_'):
# Get the language from the query data
language = telebot.dict_languages[query.data.split('_')[1]]
set_language(user_id=user_id,language=language)
language = get_language(user_id=user_id)
telebot.getAbbreviation(lang=language)
# Get the abbreviation for the language
animeApp.changeLanguage(language=language)
# Change the language in the animeApp
await query.edit_message_text(text=f"{telebot.translatedData('Selected option')}: {query.data.split('_')[1]}")
elif lang!=None:
if query.data.split('_')[1] in telebot.dict_languages and query.data.startswith('lang_'):
# Get the language from the query data
language = telebot.dict_languages[query.data.split('_')[1]]
set_language(user_id=user_id,language=language)
language = get_language(user_id=user_id)
telebot.getAbbreviation(lang=language)
# Get the abbreviation for the language
animeApp.changeLanguage(language=language)
# Change the language in the animeApp
await query.edit_message_text(text=f"{telebot.translatedData('Selected option')}: {query.data.split('_')[1]}")
async def handle_songs_download(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Handle the download and sending of anime songs.
This function fetches songs associated with anime, updates the audio metadata,
and sends the audio files via the Telegram bot. It also cleans up the directory
after sending the files.
Parameters:
update (Update): The update object containing the callback query.
context (ContextTypes.DEFAULT_TYPE): The context object for the callback.
Example:
await handle_songs_download(update, context)
Raises:
Exception: If an error occurs during the processing or sending of audio files.
"""
query = update.callback_query
user_id = query.from_user.id
lang = get_language(user_id=user_id)
try:
telebot.getAbbreviation(str(lang))
# Fetch and download songs using the songAnime object
songAnime.getSongs()
# Get the current working directory and the new directory path for songs
current_path = os.getcwd()
new_dir_path = os.path.join(current_path, songAnime.songsDirectory)
# Walk through the new directory to find audio files
for root, dirs, files in os.walk(new_dir_path):
for file in files:
audio_path = os.path.join(root, file)
try:
# Split the file name and extension
file_root, file_ext = os.path.splitext(file)
# Update the audio metadata (title and artist)
titleName, artistName = songAnime.updateString(audio_path)
# Open the audio file and send it via Telegram bot
with open(audio_path, 'rb') as audio_file:
await update.callback_query.message.reply_audio(
audio=audio_file,
filename=file_root,
title=f'{titleName}',
performer=f'{artistName}'
)
except Exception as e:
# Send a failure message if an exception occurs
failure_message = telebot.translatedData("Failed! (╥﹏╥)") if lang is not None else"Failed! (╥﹏╥)"
await update.callback_query.message.reply_text(failure_message)
# Pause for 3 seconds before cleaning up the directory
time.sleep(3)
# Destroy the directory containing the downloaded songs
songAnime.destroyDirectory(os.path.join(os.getcwd(), "animeSongs"))
except Exception as e:
# Send a failure message if an exception occurs in the main try block
failure_message = telebot.translatedData("Failed! (╥﹏╥)") if lang is not None else "Failed! (╥﹏╥)"
await update.callback_query.message.reply_text(failure_message)
async def buttonDownload(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Handle button press events for downloading or canceling song downloads.
This function processes user input from a callback query button press. If the user
selects the 'yes_option', it triggers the song download and upload process. If the
user selects the 'no_option', it cancels the operation. The user data is cleared
after processing.
Parameters:
update (Update): The update object containing the callback query.
context (ContextTypes.DEFAULT_TYPE): The context object for the callback.
Example:
await buttonDownload(update, context)
Raises:
None
"""
query = update.callback_query
user_id = query.from_user.id
lang = get_language(user_id=user_id)
await query.answer()
if query.data == 'yes_option':
if lang == None:
text = "Downloading and uploading"
await query.edit_message_text(text=text)
await handle_songs_download(update,context)
context.user_data.clear()
else:
telebot.getAbbreviation(str(lang))
text = telebot.translatedData("Downloading and uploading")
await query.edit_message_text(text=text)
await handle_songs_download(update, context)
context.user_data.clear()
elif query.data == 'no_option':
text = "Cancelled"
await query.edit_message_text(text=text)
context.user_data.clear()
context.user_data.clear()
"""
Request Random Anime Function
This function handles a user's request for a random anime recommendation.
It interacts with an external anime application to retrieve data and sends
the information back to the user via a Telegram bot.
"""
async def requestRandom(update: Update, context: CallbackContext) -> None:
"""
Stores the info about the user and ends the conversation.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (CallbackContext): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
# Check if the language setting in the telebot is set to a string (indicating English)
if lang == None:
try:
# Change the language of the anime application to English
animeApp.changeLanguage('en')
# Request a random anime from the anime application
animeApp.getOption('randanime')
# Get the anime data from the anime application
animedata = animeApp.getAnimeData()
# Create a help_info string with the anime data formatted as "key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_message.keys(),animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text("Sorry, we cannot show you this content (◞‸◟;)")
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=False)
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(f"You have openings and endings inthis anime. Do you wanna to dowloaded?",reply_markup=reply_markup)
else:pass
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
except:
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
elif lang!= None:
try:
telebot.getAbbreviation(str(lang))
# If the language setting in the telebot is not a string, use the set language
animeApp.changeLanguage(lang)
# Request a random anime from the anime application
animeApp.getOption('randanime')
# Get the anime data from the anime application
animedata = animeApp.getAnimeData()
# Create a help_info string with the anime data formatted as "translated key: value"
help_info = '\n'.join(f'{telebot.translatedData(k)}: {v}'for k,v in zip(telebot.info_message.keys(),animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text(telebot.translatedData("Sorry, we cannot show you this content (◞‸◟;)"))
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=False)
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(telebot.translatedData(f"You have openings and endings in this anime. Do you wanna to dowloaded?"),reply_markup=reply_markup)
else:pass
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
except:
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
"""
Request Anime by User Function
This function handles a user's request for a specific anime recommendation.
It interacts with an external anime application to retrieve data based on the user's input and sends
the information back to the user via a Telegram bot.
"""
async def requestAnime(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Handles the user's request for an anime by name.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (ContextTypes.DEFAULT_TYPE): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
# Get the user's input text and split it into command and anime name
user_input = update.message.text.split(maxsplit=1)
# Check if the user provided an anime name
if len(user_input) > 1:
name = user_input[1]
# Check if the language setting in the telebot is set to a string (indicating English)
if lang == None:
try:
# Change the language of the anime application to English
animeApp.changeLanguage('en')
# Change the anime source in the anime application to the user's input
animeApp.changeAnimeSource(str(name))
# Request the user-specified anime from the anime application
animeApp.getOption('useranime')
# Get the anime data from the anime application
animedata = animeApp.getAnimeData()
# Create a help_info string with the anime data formatted as "key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_message.keys(),animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text("Sorry, we cannot show you this content (◞‸◟;)")
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=False)
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(f"You have openings and endings in this anime. Do you wanna to dowloaded?",reply_markup=reply_markup)
else:
pass
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
elif lang != None:
try:
telebot.getAbbreviation(str(lang))
# If the language setting in the telebot is not a string, use the set language
animeApp.changeLanguage(lang)
# Change the anime source in the anime application to the user's input
animeApp.getOption('useranime')
# Request the user-specified anime from the anime application
animeApp.changeAnimeSource(name)
# Get the anime data from the anime application
animedata = animeApp.getAnimeData()
# Create a help_info string with the anime data formatted as "translated key: value"
help_info = '\n'.join(f'{telebot.translatedData(k)}: {v}'for k,v in zip(telebot.info_message.keys(),animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text(telebot.translatedData("Sorry, we cannot show you this content (◞‸◟;)"))
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10], caption=help_info,has_spoiler=False)
animeID = animeApp.getAnimeID()
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(telebot.translatedData(f"You have openings and endings in this anime. Do you wanna to dowloaded?"),reply_markup=reply_markup)
else:
pass
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
else:
# If the user did not provide an anime name, prompt them to type an anime name
if lang == None:
response = "Type your anime (ෆ˙ᵕ˙ෆ)♡"
await update.message.reply_text(response)
else:
telebot.getAbbreviation(str(lang))
response = telebot.translatedData("Type your anime (ෆ˙ᵕ˙ෆ)♡")
await update.message.reply_text(response)
"""
Request Anime by Gender Function
This function handles a user's request for an anime recommendation by genre.
It interacts with an external anime application to retrieve data based on the user's input and sends
the information back to the user via a Telegram bot.
"""
async def requestgender(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Handles the user's request for an anime by genre.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (ContextTypes.DEFAULT_TYPE): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
# Get the user's input text and split it into command and genre name
user_input = update.message.text.split(maxsplit=1)
# Check if the user provided a genre name
if len(user_input) > 1:
name = user_input[1]
# Check if the language setting in the telebot is set to a string (indicating English)
if lang == None:
try:
# Change the language of the anime application to English
animeApp.changeLanguage('en')
# Get the genre that closely matches the user's input
gender_ = telebot.getSimilarity(name)
# If a matching genre is found
if gender_!='':
try:
# Request anime suggestions by genre from the anime application
animedata = animeApp.getSuggestbyGenre(str(gender_))
# Create a help_info string with the anime data formatted as "key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_message.keys(), animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text("Sorry, we cannot show you this content (◞‸◟;)")
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=False)
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(f"You have openings and endings in this anime. Do you wanna to dowloaded?",reply_markup=reply_markup)
else:pass
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
except:pass
else:
# If no matching genre is found, notify the user
await update.message.reply_text("Error! Maybe your gender is not into the list. ( ˶°ㅁ°) !!\nPlease use the command /showgen to show the genders are available. (˶ᵔ ᵕ ᵔ˶)")
except:
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
elif lang != None:
try:
telebot.getAbbreviation(str(lang))
# If the language setting in the telebot is not a string, use the set language
animeApp.changeLanguage(lang)
# Get the genre that closely matches the user's input
gender_ = telebot.getSimilarity(name)
# If a matching genre is found
if gender_!='':
try:
# Request anime suggestions by genre from the anime application
animedata = animeApp.getSuggestbyGenre(str(gender_))
# Create a help_info string with the anime data formatted as "translated key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_message.keys(), animedata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in animedata[3] or '#hentai' in animedata[3] or '#Erotica' in animedata[3] or '#erotica' in animedata[3])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text(telebot.translatedData("Sorry, we cannot show you this content (◞‸◟;)"))
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=animedata[10],caption=help_info,has_spoiler=False)
songAnime.changeID(animeApp.getAnimeID())
songAnime.call_request()
songAnime.hasOpenings()
if songAnime.songsBool:
keyboard = [
[InlineKeyboardButton(f"✅",callback_data='yes_option')],
[InlineKeyboardButton(f"❌",callback_data='no_option')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(telebot.translatedData(f"You have openings and endings in this anime. Do you wanna to dowloaded?"),reply_markup=reply_markup)
else:pass
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
else:
# If no matching genre is found, notify the user
await update.message.reply_text(telebot.translatedData("Error! Maybe your gender is not into the list. ( ˶°ㅁ°) !!\nPlease use the command /showgen to show the genders are available. (˶ᵔ ᵕ ᵔ˶)"))
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
else:
# If the user did not provide a genre name, prompt them to type a genre name
if lang == None:
response = "Type your anime (ෆ˙ᵕ˙ෆ)♡"
await update.message.reply_text(response)
else:
telebot.getAbbreviation(str(lang))
response = telebot.translatedData("Type the gender please (ෆ˙ᵕ˙ෆ)♡")
await update.message.reply_text(response)
"""
Show Help Function
This function provides help information to the user, displaying the available commands and their descriptions.
"""
async def help(update: Update, context:CallbackContext)->None:
"""
Provides help information to the user.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (CallbackContext): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
# Check if the language setting in the telebot is not a string (indicating a specific language setting)
if lang!=None:
telebot.getAbbreviation(str(lang))
# Create a help_info string with the translated commands and their descriptions
help_info = '\n'.join(f'/{x}: {telebot.translatedData(y)}'for x,y in telebot.commands_dictionary.items())
await update.message.reply_text(help_info)
else:
# Create a help_info string with the commands and their descriptions in English
help_info = '\n'.join(f'/{x}: {y}'for x,y in telebot.commands_dictionary.items())
await update.message.reply_text(help_info)
async def showGen(update:Update, context:CallbackContext) -> None:
"""
Provides information about the genders
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (CallbackContext): The context object that contains the bot's data and helper functions.
"""
# Check if the language setting in the telebot is not a string (indicating a specific language setting)
await update.message.reply_text(telebot.showGender())
"""
"""
async def handle_non_command_message(update:Update, context: CallbackContext) -> None:
text = update.message.text
user_data = update.message.from_user
lang = get_language(user_id=user_data['id'])
if 'awaiting_age' in context.user_data:
try:
updateAge(user_data['id'],text)
await update.message.reply_text("Ok!")
del context.user_data['awaiting_age']
except:
if lang == None:await update.message.reply_text("Error! ( • ᴖ • 。")
else:
telebot.getAbbreviation(str(lang))
await update.message.reply_text(telebot.translatedData("Error! ( • ᴖ • 。"))
else:
if lang == None and (not text.startswith("/")):
await update.message.reply_text("Hey! I didn't receive a command ( • ᴖ • 。)")
elif lang != None and (not text.startswith("/")):
telebot.getAbbreviation(str(lang))
await update.message.reply_text(telebot.translatedData("Hey! I didn't receive a command ( • ᴖ • 。)"))
#Fucntions for Manga commands
async def requestRandomManga(update: Update, context: CallbackContext) -> None:
"""
Stores the info about the user and ends the conversation.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (CallbackContext): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
# Check if the language setting in the telebot is set to a string (indicating English)
if lang == None:
try:
# Change the language of the anime application to English
mangaApp.changeLanguage('en')
# Request a random anime from the anime application
mangaApp.getOption('randmanga')
# Get the anime data from the anime application
mangadata = mangaApp.getMangaData()
# Create a help_info string with the anime data formatted as "key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_manga.keys(),mangadata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
is_adult_content = ('#Hentai' in mangadata[7] or '#hentai' in mangadata[7] or '#Erotica' in mangadata[7] or '#erotica' in mangadata[7])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text("Sorry, we cannot show you this content (◞‸◟;)")
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=False)
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
except:await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
elif lang != None:
try:
telebot.getAbbreviation(str(lang))
# If the language setting in the telebot is not a string, use the set language
mangaApp.changeLanguage(lang)
# Request a random anime from the anime application
mangaApp.getOption('randmanga')
# Get the anime data from the anime application
mangadata = mangaApp.getMangaData()
# Create a help_info string with the anime data formatted as "translated key: value"
help_info = '\n'.join(f'{telebot.translatedData(k)}: {v}'for k,v in zip(telebot.info_manga.keys(),mangadata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in mangadata[7] or '#hentai' in mangadata[7] or '#Erotica' in mangadata[7] or '#erotica' in mangadata[7])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text(telebot.translatedData("Sorry, we cannot show you this content (◞‸◟;)"))
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=False)
except:
# If an error occurs, notify the user
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
except:
await update.message.reply_text(telebot.translatedData("Error! Try it again, please. (╥﹏╥)"))
async def requestManga(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""
Handles the user's request for an anime by name.
Parameters:
update (Update): The update object that contains all the information about the incoming update.
context (ContextTypes.DEFAULT_TYPE): The context object that contains the bot's data and helper functions.
"""
user_id = update.message.from_user['id']
lang = get_language(user_id=user_id)
age = get_user_age(user_id=user_id)
# Get the user's input text and split it into command and anime name
user_input = update.message.text.split(maxsplit=1)
# Check if the user provided an anime name
if len(user_input) > 1:
name = user_input[1]
# Check if the language setting in the telebot is set to a string (indicating English)
if lang == None:
try:
# Change the language of the anime application to English
mangaApp.changeLanguage('en')
# Change the anime source in the anime application to the user's input
mangaApp.changemangaSource(str(name))
# Request the user-specified anime from the anime application
mangaApp.getOption('usermanga')
# Get the anime data from the anime application
mangadata = mangaApp.getMangaData()
# Create a help_info string with the anime data formatted as "key: value"
help_info = '\n'.join(f'{k}: {v}'for k,v in zip(telebot.info_manga.keys(),mangadata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in mangadata[7] or '#hentai' in mangadata[7] or '#Erotica'in mangadata[7] or '#erotica' in mangadata[7])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text("Sorry, we cannot show you this content (◞‸◟;)")
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=True)
else:
if not is_adult_content:
try:
# Notify the user that an anime suggestion is being sent
await update.message.reply_text("Ok!⸜(。˃ ᵕ ˂ )⸝♡")
# Send the anime image and information as a photo without a spoiler warning
await context.bot.send_photo(chat_id=update.message.chat_id,photo=mangadata[11],caption=help_info,has_spoiler=False)
except:
# If an error occurs, notify the user
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
except:
await update.message.reply_text("Error! Try it again, please. (╥﹏╥)")
elif lang != None:
telebot.getAbbreviation(str(lang))
# If the language setting in the telebot is not a string, use the set language
mangaApp.changeLanguage(lang)
# Change the anime source in the anime application to the user's input
mangaApp.getOption('usermanga')
# Request the user-specified anime from the anime application
mangaApp.changemangaSource(name)
# Get the anime data from the anime application
mangadata = mangaApp.getMangaData()
# Create a help_info string with the anime data formatted as "translated key: value"
help_info = '\n'.join(f'{telebot.translatedData(k)}: {v}'for k,v in zip(telebot.info_manga.keys(),mangadata))
# If the help_info string is longer than 1000 characters, truncate it and add ellipses
if len(help_info)>=1000:
help_info = help_info[0:997]+"..."
# Check if the anime is categorized as hentai or erotica
is_adult_content = ('#Hentai' in mangadata[7] or '#hentai' in mangadata[7] or '#Erotica'in mangadata[7] or '#erotica' in mangadata[7])
# Check if the anime is categorized as hentai or erotica
if is_adult_content and (age is None or age <18):
await update.message.reply_text(telebot.translatedData("Sorry, we cannot show you this content (◞‸◟;)"))
elif is_adult_content and (age>=18):
# Notify the user that an anime suggestion is being sent