This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fbridge_check.py
72 lines (55 loc) · 2.15 KB
/
fbridge_check.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
from re import search
import logging
from fbridge_handle_extra import get_attachments
async def find_ignore_path(regex_format, text):
try:
# Find the configured pattern to ignore
regex = search(r'' + regex_format, text)
except TypeError:
pass # Just go on error, so that the script doesn't stop
else:
if regex:
return True
return False
async def check_if_same_authors(event, session, regex_format, text):
if event == session:
return await find_ignore_path(regex_format, text)
return False
async def check_event_match(event, client, threads, users):
gateway = ''
if event.thread.id in threads:
gateway = threads[event.thread.id]
username = ''
if event.author.id in users:
username = users[event.author.id]
send_text = event.message.text
if event.message.attachments:
send_text = await get_attachments(event.message.attachments, send_text,
client)
return [gateway, username, send_text]
async def find_file_type(search_text, search_link=True, url_protocol="https"):
types = {"image": ["jpg", "png", "jpeg", "gif", "webp"], "video": ["webm"]}
found_type = None
found_url = None
found_cat = None
for tp in types:
for find_tp in types[tp]:
try:
if search_link is True:
find_img_url = search(url_protocol + r".+\.(" + find_tp + ")", search_text)
else:
find_img_url = search(r".+\.(" + find_tp + ')$', search_text)
except TypeError as e:
logging.info(f"searching for file returned: {e}")
break
if find_img_url:
found_url = find_img_url.group(0)
found_type = find_img_url.group(1)
found_cat = tp
logging.info(f"found_url: {found_url} ; found_type: {found_type} ; found_cat: {found_cat}")
break
if found_type == "jpg":
found_type = "jpeg"
if found_type == "webp":
found_type = "png"
return found_type, found_url, found_cat