Telethon:我想抓取所有链接并加入群组,而不是频道。但是如何区分它们呢?
Telethon: I want to scrape all the links and just join the groups, not channels. but how to distinguish between them?
这是我的代码,我需要一种方法来获取 True/False 布尔值,以确定接收到的 link 是否是一个组 link。
client = TelegramClient('session', api_id, api_hash)
#check whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False, pattern=r'(?i).*joinchat/'))
async def my_event_handler(event):
#extract the hash of that link
hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)', event.raw_text).group(0)
我明白了伙计们:
# checks whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False, pattern=r'(?i).*joinchat/'))
async def my_event_handler(event):
# extracts the hash of that link
hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)', event.raw_text).group(0)
checked = await client(CheckChatInviteRequest(hash=hash))
if checked.megagroup and checked.broadcast == False:
updates = await client(ImportChatInviteRequest(hash))
client.start()
client.run_until_disconnected()
这是我的代码,我需要一种方法来获取 True/False 布尔值,以确定接收到的 link 是否是一个组 link。
client = TelegramClient('session', api_id, api_hash)
#check whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False, pattern=r'(?i).*joinchat/'))
async def my_event_handler(event):
#extract the hash of that link
hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)', event.raw_text).group(0)
我明白了伙计们:
# checks whether there's a 'joinchat' in the msg text?
@client.on(events.NewMessage(outgoing=False, pattern=r'(?i).*joinchat/'))
async def my_event_handler(event):
# extracts the hash of that link
hash = re.search('(?<=joinchat\/)(\w+[-]?\S\w+)', event.raw_text).group(0)
checked = await client(CheckChatInviteRequest(hash=hash))
if checked.megagroup and checked.broadcast == False:
updates = await client(ImportChatInviteRequest(hash))
client.start()
client.run_until_disconnected()