-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslator_v2.py
126 lines (106 loc) · 3.1 KB
/
translator_v2.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
import telepot
import time
import urllib3
import random, time
from googletrans import Translator
#change this values by yours
BOT_TOKEN = ""
ADMIN_ID_NUMBER = 000000000
proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}
telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))
bot = telepot.Bot(BOT_TOKEN)
def welcome():
file = open('start.txt', 'r')
word = file.read()
return word
def change(sentense):
f = open("start.txt", "w")
f.write(sentense)
f.close()
LANGUAGES = {
'af': 'afrikaans',
'sq': 'albanian',
'ar': 'arabic',
'hy': 'armenian',
'az': 'azerbaijani',
'bg': 'bulgarian',
'zh-cn': 'chinese (simplified)',
'zh-tw': 'chinese (traditional)',
'cs': 'czech',
'da': 'danish',
'nl': 'dutch',
'en': 'english',
'tl': 'filipino',
'fr': 'french',
'de': 'german',
'el': 'greek',
'haw': 'hawaiian',
'hi': 'hindi',
'is': 'icelandic',
'id': 'indonesian',
'it': 'italian',
'ja': 'japanese',
'kn': 'kannada',
'kk': 'kazakh',
'ko': 'korean',
'ku': 'kurdish (kurmanji)',
'la': 'latin',
'lb': 'luxembourgish',
'mt': 'maltese',
'my': 'myanmar (burmese)',
'ne': 'nepali',
'no': 'norwegian',
'ps': 'pashto',
'fa': 'persian',
'pl': 'polish',
'pt': 'portuguese',
'ro': 'romanian',
'ru': 'russian',
'sr': 'serbian',
'sk': 'slovak',
'so': 'somali',
'es': 'spanish',
'sv': 'swedish',
'tg': 'tajik',
'tr': 'turkish',
'uk': 'ukrainian',
'ur': 'urdu',
'uz': 'uzbek',
'vi': 'vietnamese',
}
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
translator = Translator()
massage = msg["text"]
if chat_id == ADMIN_ID_NUMBER and "/change" in massage :
substring = "/change"
question = massage
question = question.replace(substring, '')
try:
change(question)
bot.sendMessage(chat_id, "CHANGED!")
except:
bot.sendMessage(chat_id, "ERROR!")
else:
answer = ""
if "/start" in massage :
pm = welcome()
bot.sendMessage(chat_id, pm)
else:
if len(massage) < 55:
for language in LANGUAGES.values() :
question = (translator.translate(massage, dest=language)).text
answer = answer + language + " : " + question + "\n"
bot.sendMessage(chat_id, answer)
else :
for language in LANGUAGES.values() :
question = (translator.translate(massage, dest=language)).text
bot.sendMessage(chat_id, (language + " : " + question))
bot.message_loop(handle)
print('BOT IS ONLINE !')
# Keep the program running.
while 1:
time.sleep(10)