mirror of
https://github.com/Rongronggg9/SlashBot.git
synced 2025-02-07 01:23:29 +08:00
[+] Create function to find full name by username
This commit is contained in:
parent
f4f1d89b3f
commit
acfbd58003
@ -1,5 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import List, Dict, Union
|
||||||
|
|
||||||
|
import requests
|
||||||
from telegram.ext import Updater, MessageHandler, filters
|
from telegram.ext import Updater, MessageHandler, filters
|
||||||
|
|
||||||
TELEGRAM = 777000
|
TELEGRAM = 777000
|
||||||
@ -15,6 +18,12 @@ else:
|
|||||||
raise Exception('no token')
|
raise Exception('no token')
|
||||||
|
|
||||||
|
|
||||||
|
# Find someone's full name by their username
|
||||||
|
def find_name_by_username(username: str) -> str:
|
||||||
|
r = requests.get(f'https://t.me/{username}')
|
||||||
|
return re.search('(?<=<meta property="og:title" content=").*(?=")', r.text, re.IGNORECASE).group(0)
|
||||||
|
|
||||||
|
|
||||||
def get_user(msg):
|
def get_user(msg):
|
||||||
if msg['from']['id'] == TELEGRAM:
|
if msg['from']['id'] == TELEGRAM:
|
||||||
return {'first_name': msg['forward_from_chat']['title'], 'id': msg['forward_from_chat']['id']}
|
return {'first_name': msg['forward_from_chat']['title'], 'id': msg['forward_from_chat']['id']}
|
||||||
|
Loading…
Reference in New Issue
Block a user