1
2
3
|
pip install telethon
pip install telegram
pip install googletrans==3.1.0a0
|
cs |
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
|
# In[0]:asynchronous
import asyncio
import nest_asyncio
nest_asyncio.apply()
# In[1]:googletrans
from googletrans import Translator
translator = Translator()
# In[2]:telegram_bot
import telegram
# ★
TelegramToken = '111111:aaaaaaa' # 텔레그램 봇 토큰(BotPeerID:Hash)
TelegramId = '1111111111' # 아이디(UserPeerID)
# ★
# In[3]:telethon
from telethon import TelegramClient,events
# ★
api_id = 1111111 # 텔레그램 Api id,hash
api_hash = 'aaaaaaaaa111111111'
# ★
client = TelegramClient('session_trans', api_id, api_hash) # session_trans = 오픈 또는 생성할 세션파일명
# 세션파일 오픈 및 세션이 닫히지않게(세션파일이없는경우 콘솔창에 휴대폰번호입력해달라고 인증절차 뜨고 그 이후 생성이됨)
async def Telethon_run():
await client.start()
await client.run_until_disconnected()
# 메세지 상호작용
@client.on(events.NewMessage)
async def handler(event):
msgs=str(event)
# ▼ 초기 실행시 주석풀고 user_id 또는 channel_id 체크
#print(msgs)
# 특정 채널에서 수신한 메세지인 경우
# ★
if 'channel_id=1195956014' in msgs:
# ★
Message=(msgs[msgs.find(', message=')+11:msgs.find(', out=')])
# 메세지 번역후 봇을 통해 유저에게 전송
translation = translator.translate(Message, dest='ko')
telegram.Bot(TelegramToken).sendMessage(TelegramId,translation.text)
# In[4]:run
if __name__ == "__main__":
asyncio.run(Telethon_run())
|
cs |
채널애들 뭐라는건지 궁금해서 짜집기했는데
쓸일없을거같음