2022-12-11 02:39:19 +02:00
|
|
|
from os import getpid, makedirs
|
2023-01-05 15:33:23 +02:00
|
|
|
from time import time
|
2022-10-17 00:30:07 +03:00
|
|
|
from modules.utils import *
|
2022-10-26 15:54:55 +03:00
|
|
|
from modules.inline import *
|
|
|
|
from app import app
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-12-06 11:26:22 +02:00
|
|
|
from pyrogram import idle
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-10-21 15:00:03 +03:00
|
|
|
pid = getpid()
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-12-11 02:39:19 +02:00
|
|
|
makedirs(f'{configGet("cache", "locations")}{sep}avatars', exist_ok=True)
|
2022-10-21 15:00:03 +03:00
|
|
|
|
2022-12-05 19:49:51 +02:00
|
|
|
# Importing
|
|
|
|
from modules.commands.application import *
|
2022-12-23 02:40:23 +02:00
|
|
|
from modules.commands.cancel import *
|
2023-04-02 19:42:03 +03:00
|
|
|
from modules.commands.export import *
|
2023-01-03 15:30:16 +02:00
|
|
|
from modules.commands.identify import *
|
2023-01-23 15:39:38 +02:00
|
|
|
from modules.commands.issue import *
|
2022-12-10 18:29:06 +02:00
|
|
|
from modules.commands.label import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.commands.message import *
|
2022-12-15 16:12:41 +02:00
|
|
|
from modules.commands.nearby import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.commands.reapply import *
|
|
|
|
from modules.commands.reboot import *
|
2023-01-05 13:41:55 +02:00
|
|
|
from modules.commands.resetcommands import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.commands.rules import *
|
2023-01-04 20:58:54 +02:00
|
|
|
from modules.commands.spoiler import *
|
2022-12-10 11:42:56 +02:00
|
|
|
from modules.commands.sponsorship import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.commands.start import *
|
|
|
|
from modules.commands.warn import *
|
|
|
|
from modules.commands.warnings import *
|
|
|
|
|
2023-04-19 11:28:57 +03:00
|
|
|
# This one is only imported during events
|
|
|
|
# and should be completely rewritten for each one.
|
|
|
|
# from modules.event import *
|
2023-04-14 02:22:41 +03:00
|
|
|
|
2023-01-30 12:28:23 +02:00
|
|
|
from modules.callbacks.ban import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.callbacks.nothing import *
|
|
|
|
from modules.callbacks.reapply import *
|
|
|
|
from modules.callbacks.rules import *
|
2023-01-12 12:04:52 +02:00
|
|
|
from modules.callbacks.spoiler import *
|
2022-12-21 13:51:39 +02:00
|
|
|
from modules.callbacks.sponsorship import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.callbacks.sub import *
|
|
|
|
from modules.callbacks.sus import *
|
2023-04-02 23:17:54 +03:00
|
|
|
from modules.callbacks.warnings import *
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-04-06 17:08:33 +03:00
|
|
|
from modules.handlers.analytics_group import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.handlers.confirmation import *
|
|
|
|
from modules.handlers.contact import *
|
2023-04-04 11:37:46 +03:00
|
|
|
from modules.handlers.group_member_update import *
|
2022-12-18 18:51:21 +02:00
|
|
|
from modules.handlers.voice import *
|
2022-12-05 19:49:51 +02:00
|
|
|
from modules.handlers.welcome import *
|
|
|
|
from modules.handlers.everything import *
|
2022-10-23 17:22:38 +03:00
|
|
|
|
2022-12-10 16:51:37 +02:00
|
|
|
from modules.scheduled import *
|
|
|
|
|
2022-10-17 00:30:07 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
logWrite(f"Starting up with pid {pid}")
|
|
|
|
|
|
|
|
# Yes, it should be in some kind of async main() function but I don't give a shit.
|
2022-10-20 13:24:32 +03:00
|
|
|
# I did compare performance, almost no difference and it's much more useful this way. Change my mind.
|
2022-12-06 11:26:22 +02:00
|
|
|
app.start()
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-12-10 16:51:37 +02:00
|
|
|
try:
|
2023-01-05 14:08:08 +02:00
|
|
|
if path.exists(path.join(configGet("cache", "locations"), "shutdown_time")):
|
2023-03-09 17:25:06 +02:00
|
|
|
downtime = relativedelta(
|
|
|
|
datetime.now(),
|
|
|
|
datetime.fromtimestamp(
|
|
|
|
jsonLoad(
|
|
|
|
path.join(configGet("cache", "locations"), "shutdown_time")
|
|
|
|
)["timestamp"]
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 14:08:08 +02:00
|
|
|
if downtime.days >= 1:
|
2023-03-09 17:25:06 +02:00
|
|
|
app.send_message(
|
|
|
|
configGet("owner"),
|
|
|
|
locale("startup_downtime_days", "message").format(
|
|
|
|
pid, downtime.days
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 14:08:08 +02:00
|
|
|
elif downtime.hours >= 1:
|
2023-03-09 17:25:06 +02:00
|
|
|
app.send_message(
|
|
|
|
configGet("owner"),
|
|
|
|
locale("startup_downtime_hours", "message").format(
|
|
|
|
pid, downtime.hours
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 14:08:08 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
app.send_message(
|
|
|
|
configGet("owner"),
|
|
|
|
locale("startup_downtime_minutes", "message").format(
|
|
|
|
pid, downtime.minutes
|
|
|
|
),
|
|
|
|
)
|
2023-01-05 14:08:08 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
app.send_message(
|
|
|
|
configGet("owner"), locale("startup", "message").format(pid)
|
|
|
|
)
|
2022-12-10 16:51:37 +02:00
|
|
|
except bad_request_400.PeerIdInvalid:
|
2023-03-09 17:25:06 +02:00
|
|
|
logWrite(
|
|
|
|
f"Could not send startup message to bot owner. Perhaps user has not started the bot yet."
|
|
|
|
)
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-12-10 16:51:37 +02:00
|
|
|
scheduler.start()
|
|
|
|
|
2022-10-17 00:30:07 +03:00
|
|
|
idle()
|
|
|
|
|
2022-12-10 16:51:37 +02:00
|
|
|
try:
|
2023-01-05 14:08:08 +02:00
|
|
|
app.send_message(configGet("owner"), locale("shutdown", "message").format(pid))
|
2022-12-10 16:51:37 +02:00
|
|
|
except bad_request_400.PeerIdInvalid:
|
2023-03-09 17:25:06 +02:00
|
|
|
logWrite(
|
|
|
|
f"Could not send shutdown message to bot owner. Perhaps user has not started the bot yet."
|
|
|
|
)
|
2022-10-17 00:30:07 +03:00
|
|
|
|
2022-12-06 11:26:22 +02:00
|
|
|
app.stop()
|
2023-01-05 15:33:23 +02:00
|
|
|
|
|
|
|
makedirs(configGet("cache", "locations"), exist_ok=True)
|
2023-03-09 17:25:06 +02:00
|
|
|
jsonSave(
|
|
|
|
{"timestamp": time()},
|
|
|
|
path.join(configGet("cache", "locations"), "shutdown_time"),
|
|
|
|
)
|
|
|
|
|
|
|
|
killProc(pid)
|