-
Notifications
You must be signed in to change notification settings - Fork 122
/
bot.py
204 lines (177 loc) · 6.55 KB
/
bot.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# This file is part of the AutoAnime distribution.
# Copyright (c) 2024 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)
from traceback import format_exc
from telethon import Button, events
from core.bot import Bot
from core.executors import Executors
from database import DataBase
from functions.info import AnimeInfo
from functions.schedule import ScheduleTasks, Var
from functions.tools import Tools, asyncio
from functions.utils import AdminUtils
from libs.ariawarp import Torrent
from libs.logger import LOGS, Reporter
from libs.subsplease import SubsPlease
tools = Tools()
tools.init_dir()
bot = Bot()
dB = DataBase()
subsplease = SubsPlease(dB)
torrent = Torrent()
schedule = ScheduleTasks(bot)
admin = AdminUtils(dB, bot)
@bot.on(
events.NewMessage(
incoming=True, pattern="^/start ?(.*)", func=lambda e: e.is_private
)
)
async def _start(event):
xnx = await event.reply("`Please Wait...`")
msg_id = event.pattern_match.group(1)
await dB.add_broadcast_user(event.sender_id)
if Var.FORCESUB_CHANNEL and Var.FORCESUB_CHANNEL_LINK:
is_user_joined = await bot.is_joined(Var.FORCESUB_CHANNEL, event.sender_id)
if is_user_joined:
pass
else:
return await xnx.edit(
f"**Please Join The Following Channel To Use This Bot 🫡**",
buttons=[
[Button.url("🚀 JOIN CHANNEL", url=Var.FORCESUB_CHANNEL_LINK)],
[
Button.url(
"♻️ REFRESH",
url=f"https://t.me/{((await bot.get_me()).username)}?start={msg_id}",
)
],
],
)
if msg_id:
if msg_id.isdigit():
msg = await bot.get_messages(Var.BACKUP_CHANNEL, ids=int(msg_id))
await event.reply(msg)
else:
items = await dB.get_store_items(msg_id)
if items:
for id in items:
msg = await bot.get_messages(Var.CLOUD_CHANNEL, ids=id)
await event.reply(file=[i for i in msg])
else:
if event.sender_id == Var.OWNER:
return await xnx.edit(
"** < ADMIN PANEL > **",
buttons=admin.admin_panel(),
)
await event.reply(
f"**Enjoy Ongoing Anime's Best Encode 24/7 🫡**",
buttons=[
[
Button.url("👨💻 DEV", url="t.me/kaif_00z"),
Button.url(
"💖 OPEN SOURCE",
url="https://github.com/kaif-00z/AutoAnimeBot/",
),
]
],
)
await xnx.delete()
@bot.on(
events.NewMessage(incoming=True, pattern="^/about", func=lambda e: e.is_private)
)
async def _(e):
await admin._about(e)
@bot.on(events.callbackquery.CallbackQuery(data="slog"))
async def _(e):
await admin._logs(e)
@bot.on(events.callbackquery.CallbackQuery(data="sret"))
async def _(e):
await admin._restart(e, schedule)
@bot.on(events.callbackquery.CallbackQuery(data="entg"))
async def _(e):
await admin._encode_t(e)
@bot.on(events.callbackquery.CallbackQuery(data="butg"))
async def _(e):
await admin._btn_t(e)
@bot.on(events.callbackquery.CallbackQuery(data="scul"))
async def _(e):
await admin._sep_c_t(e)
@bot.on(events.callbackquery.CallbackQuery(data="cast"))
async def _(e):
await admin.broadcast_bt(e)
@bot.on(events.callbackquery.CallbackQuery(data="bek"))
async def _(e):
await e.edit(buttons=admin.admin_panel())
async def anime(data):
try:
torr = [data.get("480p"), data.get("720p"), data.get("1080p")]
anime_info = AnimeInfo(torr[0].title)
poster = await tools._poster(bot, anime_info)
if await dB.is_separate_channel_upload():
chat_info = await tools.get_chat_info(bot, anime_info, dB)
await poster.edit(
buttons=[
[
Button.url(
f"EPISODE {anime_info.data.get('episode_number', '')}".strip(),
url=chat_info["invite_link"],
)
]
]
)
poster = await tools._poster(bot, anime_info, chat_info["chat_id"])
btn = [[]]
original_upload = await dB.is_original_upload()
button_upload = await dB.is_button_upload()
for i in torr:
try:
filename = f"downloads/{i.title}"
reporter = Reporter(bot, i.title)
await reporter.alert_new_file_founded()
await torrent.download_magnet(i.link, "./downloads/")
exe = Executors(
bot,
dB,
{
"original_upload": original_upload,
"button_upload": button_upload,
},
filename,
AnimeInfo(i.title),
reporter,
)
result, _btn = await exe.execute()
if result:
if _btn:
if len(btn[0]) == 2:
btn.append([_btn])
else:
btn[0].append(_btn)
await poster.edit(buttons=btn)
asyncio.ensure_future(exe.further_work())
continue
await reporter.report_error(_btn, log=True)
await reporter.msg.delete()
except BaseException:
await reporter.report_error(str(format_exc()), log=True)
await reporter.msg.delete()
except BaseException:
LOGS.error(str(format_exc()))
try:
bot.loop.run_until_complete(subsplease.on_new_anime(anime))
bot.run()
except KeyboardInterrupt:
subsplease._exit()