-
Notifications
You must be signed in to change notification settings - Fork 102
/
__init__.py
98 lines (78 loc) · 2.7 KB
/
__init__.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
import math
import os
import re
import time
import heroku3
import lottie
import requests
import spamwatch as spam_watch
from validators.url import url
from .. import *
from ..Config import Config
from ..funcs.logger import logging
from ..funcs.managers import edit_delete, edit_or_reply
from ..funcs.session import lionub
from ..helpers import *
from ..helpers.utils import _format, _liontools, _lionutils, install_pip, reply_id
# =================== CONSTANT ===================
bot = lionub
LOGS = logging.getLogger(__name__)
USERID = lionub.uid if Config.OWNER_ID == 0 else Config.OWNER_ID
ALIVE_NAME = Config.ALIVE_NAME
AUTONAME = Config.AUTONAME
DEFAULT_BIO = Config.DEFAULT_BIO
Heroku = heroku3.from_key(Config.HEROKU_API_KEY)
heroku_api = "https://api.heroku.com"
HEROKU_APP_NAME = Config.HEROKU_APP_NAME
HEROKU_API_KEY = Config.HEROKU_API_KEY
thumb_image_path = os.path.join(Config.TMP_DOWNLOAD_DIRECTORY, "thumb_image.jpg")
USERID = lionub.uid if Config.OWNER_ID == 0 else Config.OWNER_ID
# mention user
mention = f"[{Config.ALIVE_NAME}](tg://user?id={USERID})"
hmention = f"<a href = tg://user?id={USERID}>{Config.ALIVE_NAME}</a>"
PM_START = []
PMMESSAGE_CACHE = {}
PMMENU = "pmpermit_menu" not in Config.NO_LOAD
# Gdrive
G_DRIVE_CLIENT_ID = Config.G_DRIVE_CLIENT_ID
G_DRIVE_CLIENT_SECRET = Config.G_DRIVE_CLIENT_SECRET
G_DRIVE_DATA = Config.G_DRIVE_DATA
G_DRIVE_FOLDER_ID = Config.G_DRIVE_FOLDER_ID
TMP_DOWNLOAD_DIRECTORY = Config.TMP_DOWNLOAD_DIRECTORY
# spamwatch support
if Config.SPAMWATCH_API:
token = Config.SPAMWATCH_API
spamwatch = spam_watch.Client(token)
else:
spamwatch = None
# ================================================
if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
# thumb image
if Config.THUMB_IMAGE is not None:
check = url(Config.THUMB_IMAGE)
if check:
try:
with open(thumb_image_path, "wb") as f:
f.write(requests.get(Config.THUMB_IMAGE).content)
except Exception as e:
LOGS.info(str(e))
def set_key(dictionary, key, value):
if key not in dictionary:
dictionary[key] = value
elif isinstance(dictionary[key], list):
if value in dictionary[key]:
return
dictionary[key].append(value)
else:
dictionary[key] = [dictionary[key], value]
async def make_gif(event, reply, quality=None, fps=None):
fps = fps or 1
quality = quality or 256
result_p = os.path.join("temp", "animation.gif")
animation = lottie.parsers.tgs.parse_tgs(reply)
with open(result_p, "wb") as result:
await _lionutils.run_sync(
lottie.exporters.gif.export_gif, animation, result, quality, fps
)
return result_p