File size: 6,647 Bytes
de1ee14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#    This file is part of the AutoAnime distribution.
#    Copyright (c) 2025 Kaif_00z
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3.
#
#    This program is distributed in the hope that it will be useful, but
#    WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#    General Public License for more details.
#
# License can be found in <
# https://github.com/kaif-00z/AutoAnimeBot/blob/main/LICENSE > .

# if you are using this following code then don't forgot to give proper
# credit to t.me/kAiF_00z (github.com/kaif-00z)

import platform
from datetime import datetime as dt

from pyrogram import __version__ as _p_v
from telethon import Button
from telethon import __version__ as _t_v
from telethon import events

from core.bot import Bot, Var, asyncio
from database import DataBase
from functions.tools import Tools

ABOUT = """
**⏱ Uptime** : `{}`
**πŸ’‘ Version** : `{}`
**πŸ‘₯ Users** : `{}`
**πŸ—ƒοΈ Documents** : `{}`

β€’ **🐍 Python**: `{}`
β€’ **✈️ Telethon**: `{}`
β€’ **πŸ”οΈ Pyrogram**: `{}`
β€’ **πŸ’» Server**: `{}`
β€’ **πŸ“– Source Code** : {}

~ **Developer**  __@Kaif_00z __
"""


class AdminUtils:
    def __init__(self, dB: DataBase, bot: Bot):
        self.db = dB
        self.bot = bot
        self.tools = Tools()
        self.python_version = platform.python_version()
        self.system = f"{platform.system()}-{platform.release()}"
        self.telethon_version = _t_v
        self.pyrogram_version = _p_v
        self.started_at = dt.now()

    def admin_panel(self):
        btn = [
            [
                Button.inline("πŸ“œ LOGS", data="slog"),
                Button.inline("♻️ Restart", data="sret"),
            ],
            [
                Button.inline("🎞️ Encode [Toogle]", data="entg"),
            ],
            [Button.inline("πŸ”˜ Button Upload [Toogle]", data="butg")],
            [Button.inline("πŸ—ƒοΈ Separate Channel Upload [Toogle]", data="scul")],
            [Button.inline("πŸ”Š Broadcast", data="cast")],
        ]
        return btn

    def back_btn(self):
        return [[Button.inline("πŸ”™", data="bek")]]

    async def _logs(self, e):
        await e.delete()
        await e.reply(
            file="AutoAnimeBot.log", thumb="thumb.jpg", buttons=self.back_btn()
        )

    async def _restart(self, e, schedule):
        await e.reply("`Restarting...`")
        schedule.restart()

    async def _encode_t(self, e):
        if await self.db.is_original_upload():
            await self.db.toggle_original_upload()
            return await e.edit(
                "`Successfully On The Compression`", buttons=self.back_btn()
            )
        await self.db.toggle_original_upload()
        return await e.edit(
            "`Successfully Off The Compression`", buttons=self.back_btn()
        )

    async def _btn_t(self, e):
        if await self.db.is_separate_channel_upload():
            return await e.edit(
                "`You Can't On/Off The Button Upload When Seprate Channel Is Enabled`",
                buttons=self.back_btn(),
            )
        if await self.db.is_button_upload():
            await self.db.toggle_button_upload()
            return await e.edit(
                "`Successfully Off The Button Upload`", buttons=self.back_btn()
            )
        await self.db.toggle_button_upload()
        return await e.edit("`Successfully On The Upload`", buttons=self.back_btn())

    async def _sep_c_t(self, e):
        if Var.SESSION:
            if await self.db.is_button_upload():
                if await self.db.is_separate_channel_upload():
                    await self.db.toggle_separate_channel_upload()
                    return await e.edit(
                        "`Successfully Off The Separate Channel Upload`",
                        buttons=self.back_btn(),
                    )
                await self.db.toggle_separate_channel_upload()
                return await e.edit(
                    "`Successfully On The Separate Channel Upload`",
                    buttons=self.back_btn(),
                )
            else:
                return await e.edit(
                    "`To Use The Separate Channel Upload First You Have To Enable Button Upload`",
                    buttons=self.back_btn(),
                )
        else:
            return await e.edit(
                "`To Use The Separate Channel Upload First You Have To Add SESSION Variable in The Bot",
                buttons=self.back_btn(),
            )

    async def broadcast_bt(self, e):
        users = await self.db.get_broadcast_user()
        await e.edit("**Please Use This Feature Responsibly ⚠️**")
        await e.reply(
            f"**Send a single Message To Broadcast πŸ˜‰**\n\n**There are** `{len(users)}` **Users Currently Using MeπŸ‘‰πŸ»**.\n\nSend /cancel to Cancel Process."
        )
        async with e.client.conversation(e.sender_id) as cv:
            reply = cv.wait_event(events.NewMessage(from_users=e.sender_id))
            repl = await reply
            await e.delete()
            if repl.text and repl.text.startswith("/cancel"):
                return await repl.reply("`Broadcast Cancelled`")
        sent = await repl.reply("`πŸ—£οΈ Broadcasting Your Post...`")
        done, er = 0, 0
        for user in users:
            try:
                if repl.poll:
                    await repl.forward_to(int(user))
                else:
                    await e.client.send_message(int(user), repl.message)
                await asyncio.sleep(0.2)
                done += 1
            except BaseException as ex:
                er += 1
                print(ex)
        await sent.edit(
            f"**Broadcast Completed To** `{done}` **Users.**\n**Error in** `{er}` **Users.**"
        )

    async def _about(self, e):
        total_docs = await self.db.file_store_db.count_documents({})
        total_users = await self.db.broadcast_db.count_documents({})
        text = ABOUT.format(
            self.tools.ts(int((dt.now() - self.started_at).seconds) * 1000),
            Var.__version__,
            total_users,
            total_docs,
            self.python_version,
            self.telethon_version,
            self.pyrogram_version,
            self.system,
            "[OngoingAnimeBot](https://github.com/Kaif-00z/AutoAnimeBot)",
        )
        await e.reply(text, file="assest/about.jpg", link_preview=False)