-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
90 lines (72 loc) · 2.44 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
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 ..core.logger import logging
from ..core.managers import edit_delete, edit_or_reply
from ..core.session import zedub
from ..helpers import *
from ..helpers.utils import _zedtools, _zedutils, _format, install_pip, reply_id
from ..sql_helper.globals import gvarstatus
# =================== CONSTANT ===================
bot = zedub
LOGS = logging.getLogger(__name__)
USERID = zedub.uid if Config.OWNER_ID == 0 else Config.OWNER_ID
ALIVE_NAME = Config.ALIVE_NAME
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")
# 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
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 _zedutils.run_sync(
lottie.exporters.gif.export_gif, animation, result, quality, fps
)
return result_p