Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit e8c4243

Browse files
committed
AutoAnimeBot v2.0
1 parent 3ac0344 commit e8c4243

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1352
-1355
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ __pycache__/config.cpython-39.pyc
22
*.pyc
33
*.session
44
*.session-journal
5-
main/modules/text.py
5+
main/modules/text.py
6+
logs.txt
7+
.vscode/launch.json
8+
logs.txt
9+
delete all.py

AutoAnimeBot/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from AutoAnimeBot.core.bot import AutoAnimeBot
2+
3+
app = AutoAnimeBot()

AutoAnimeBot/__main__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import asyncio
2+
from pyrogram import filters
3+
from pyrogram.types import Message
4+
5+
from uvloop import install
6+
from contextlib import closing, suppress
7+
from pyrogram import idle
8+
import AutoAnimeBot.modules.vote
9+
from AutoAnimeBot import app
10+
11+
loop = asyncio.get_event_loop()
12+
13+
14+
@app.on_message(filters.command(["start", "help", "ping"]))
15+
async def start(bot, message: Message):
16+
await message.reply_photo(
17+
"assets/thumb.jpg",
18+
caption="⭐️ **Bot Is Online...**\n\n**Updates :** @TechZBots **| Support :** @TechZBots_Support",
19+
)
20+
21+
22+
@app.on_message(filters.command("logs"))
23+
async def logs(bot, message: Message):
24+
await message.reply_document(
25+
"logs.txt",
26+
caption="AutoAnimeBot Logs, Send this to @TechZBots_Support if you need help",
27+
)
28+
29+
30+
async def main():
31+
await app.start()
32+
33+
await idle()
34+
app.logger.info("BOT STOPPED")
35+
await app.stop()
36+
for task in asyncio.all_tasks():
37+
task.cancel()
38+
39+
40+
if __name__ == "__main__":
41+
install()
42+
with closing(loop):
43+
with suppress(asyncio.exceptions.CancelledError):
44+
loop.run_until_complete(main())
45+
loop.run_until_complete(asyncio.sleep(3.0))

AutoAnimeBot/core/bot.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from pyrogram import Client
2+
from config import *
3+
import asyncio
4+
from AutoAnimeBot.modules.parser import auto_parser
5+
from pyrogram.errors import MessageNotModified
6+
from AutoAnimeBot.modules.tg_handler import tg_handler
7+
from AutoAnimeBot.inline import button1
8+
from pyrogram.types import Message
9+
from AutoAnimeBot.core.log import LOGGER
10+
11+
12+
class AutoAnimeBot(Client):
13+
def __init__(self):
14+
self.logger = LOGGER("AutoAnimeBot")
15+
self.logger.info("Starting AutoAnimeBot")
16+
super().__init__(
17+
"AutoAnimeBot", api_id=int(API_ID), api_hash=API_HASH, bot_token=BOT_TOKEN
18+
)
19+
20+
async def start(self):
21+
await super().start()
22+
23+
self.logger.info("Getting Channel IDs")
24+
self.INDEX_CHANNEL_ID = (await self.get_chat(INDEX_CHANNEL_USERNAME)).id
25+
self.UPLOADS_CHANNEL_ID = (await self.get_chat(UPLOADS_CHANNEL_USERNAME)).id
26+
27+
self.logger.info("Getting Status Messages")
28+
self.queue = []
29+
self.status: Message = await self.get_messages(
30+
self.UPLOADS_CHANNEL_ID, int(STATUS_MSG_ID)
31+
)
32+
self.schedule: Message = await self.get_messages(
33+
self.UPLOADS_CHANNEL_ID, int(SCHEDULE_MSG_ID)
34+
)
35+
36+
self.logger.info("==================================")
37+
self.logger.info("AutoAnimeBot Started Bot Successfully")
38+
self.logger.info("==========JOIN @TECHZBOTS=========")
39+
40+
self.logger.info("Adding Parsing Task")
41+
asyncio.create_task(auto_parser(TECHZ_API_KEY, self))
42+
asyncio.create_task(tg_handler(self, TECHZ_API_KEY))
43+
44+
async def update_status(self, text):
45+
try:
46+
logger = LOGGER("Status")
47+
logger.info(text)
48+
text = self.status_text(text)
49+
await self.status.edit_text(text, reply_markup=button1)
50+
except MessageNotModified:
51+
pass
52+
except Exception as e:
53+
logger.warning(str(e))
54+
55+
def status_text(self, text):
56+
stat = """
57+
⭐️ **Status :** {}
58+
59+
⏳ **Queue :**
60+
61+
{}
62+
"""
63+
64+
queue_text = ""
65+
for i in self.queue[:10]:
66+
queue_text += "📌 " + i.replace("-", " ").title().strip() + "\n"
67+
68+
if queue_text == "":
69+
queue_text = "❌ Empty"
70+
71+
return stat.format(text, queue_text)

AutoAnimeBot/core/log.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import logging
2+
from logging.handlers import RotatingFileHandler
3+
4+
logging.basicConfig(
5+
level=logging.INFO,
6+
format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s",
7+
datefmt="%d-%b-%y %H:%M:%S",
8+
handlers=[
9+
RotatingFileHandler("logs.txt", maxBytes=5000000, backupCount=10),
10+
logging.StreamHandler(),
11+
],
12+
)
13+
14+
logging.getLogger("pyrogram").setLevel(logging.ERROR)
15+
16+
17+
def LOGGER(name: str) -> logging.Logger:
18+
return logging.getLogger(name)

AutoAnimeBot/inline.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from config import (
2+
INDEX_CHANNEL_USERNAME,
3+
SCHEDULE_MSG_ID,
4+
STATUS_MSG_ID,
5+
UPLOADS_CHANNEL_USERNAME,
6+
COMMENTS_GROUP_LINK,
7+
)
8+
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
9+
10+
button1 = InlineKeyboardMarkup(
11+
[
12+
[
13+
InlineKeyboardButton(
14+
text="View Schedule",
15+
url=f"https://t.me/{UPLOADS_CHANNEL_USERNAME}/{SCHEDULE_MSG_ID}",
16+
)
17+
],
18+
[
19+
InlineKeyboardButton(
20+
text="Index Channel", url=f"https://t.me/{INDEX_CHANNEL_USERNAME}"
21+
),
22+
InlineKeyboardButton(text="Discussion Group", url=COMMENTS_GROUP_LINK),
23+
],
24+
]
25+
)
26+
27+
button2 = InlineKeyboardMarkup(
28+
[
29+
[
30+
InlineKeyboardButton(
31+
text="Check Queue",
32+
url=f"https://t.me/{UPLOADS_CHANNEL_USERNAME}/{STATUS_MSG_ID}",
33+
)
34+
]
35+
]
36+
)
Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import asyncio
2-
from main.modules.utils import format_text
1+
from AutoAnimeBot.modules.utils import format_text
32
import requests
4-
import time
5-
import os
6-
from bs4 import BeautifulSoup
7-
from datetime import datetime
8-
from string import digits
93

104
ANIME_QUERY = """
115
query ($id: Int, $idMal:Int, $search: String) {
@@ -62,21 +56,24 @@
6256

6357
ANIME_DB = {}
6458

59+
6560
async def return_json_senpai(query: str, vars_: dict):
6661
url = "https://graphql.anilist.co"
6762
anime = vars_["search"]
6863
db = ANIME_DB.get(anime)
6964

7065
if db:
71-
return db
66+
return db
7267
data = requests.post(url, json={"query": query, "variables": vars_}).json()
7368
ANIME_DB[anime] = data
7469

7570
return data
7671

72+
7773
temp = []
7874

79-
async def get_anime(vars_,less):
75+
76+
async def get_anime(vars_, less):
8077
if 1 == 1:
8178
result = await return_json_senpai(ANIME_QUERY, vars_)
8279

@@ -88,8 +85,8 @@ async def get_anime(vars_,less):
8885
data = temp[0]
8986
temp.pop(0)
9087
else:
91-
data = result["data"]["Media"]
92-
temp.append(data)
88+
data = result["data"]["Media"]
89+
temp.append(data)
9390
idm = data.get("id")
9491
title = data.get("title")
9592
tit = title.get("english")
@@ -98,43 +95,46 @@ async def get_anime(vars_,less):
9895

9996
tit = format_text(tit)
10097
title_img = f"https://img.anili.st/media/{idm}"
101-
98+
10299
if less == True:
103-
return idm, title_img, tit
100+
return idm, title_img, tit
104101

105102
return data
106103

104+
107105
async def get_anime_img(query):
108106
vars_ = {"search": query}
109-
idm, title_img, title = await get_anime(vars_,less=True)
110107

111-
return idm, title_img, title
112-
108+
return await get_anime(vars_, less=True)
109+
110+
113111
def get_anime_name(title):
114112
x = title.split(" - ")[-1]
115-
x = title.replace(x,'').replace('-','').strip()
116-
x = x.split(' ')
113+
x = title.replace(x, "").replace("-", "").strip()
114+
x = x.split(" ")
117115
x = x[:4]
118-
y = ''
116+
y = ""
119117
for i in x:
120-
y += i + ' '
118+
y += i + " "
121119
return y
122120

121+
123122
atext = """
124123
📺 **{}**
125124
({})
126125
127-
🎭 : {}
128-
🧬 : {}
129-
📡 : {}
130-
🗓 : {}
131-
💾 : {}
132-
⭐️ : {}/100
126+
🎭 Genre : `{}`
127+
🧬 Type : `{}`
128+
📡 Status : `{}`
129+
🗓 Episodes : `{}`
130+
💾 Duration : `{}`
131+
⭐️ Rating : `{}/100`
133132
"""
134133

134+
135135
async def get_anilist_data(name):
136136
vars_ = {"search": name}
137-
data = await get_anime(vars_,less=False)
137+
data = await get_anime(vars_, less=False)
138138

139139
id_ = data.get("id")
140140
title = data.get("title")
@@ -152,41 +152,33 @@ async def get_anilist_data(name):
152152
title2 = title.get("romaji")
153153

154154
if title2 == None:
155-
title2 = title.get("native")
155+
title2 = title.get("native")
156156

157157
if title1 == None:
158-
title1 = title2
158+
title1 = title2
159159

160160
# genre
161161

162162
genre = ""
163163

164164
for i in genres:
165-
genre += i + ", "
165+
genre += i + ", "
166166

167167
genre = genre[:-2]
168168

169-
170169
caption = atext.format(
171-
title1,
172-
title2,
173-
genre,
174-
form,
175-
status,
176-
episodes,
177-
duration,
178-
averageScore
170+
title1, title2, genre, form, status, episodes, duration, averageScore
179171
)
180172

181173
if trailer != None:
182-
ytid = trailer.get("id")
183-
site = trailer.get("site")
174+
ytid = trailer.get("id")
175+
site = trailer.get("site")
184176
else:
185-
site = None
177+
site = None
186178

187179
if site == "youtube":
188-
caption += f"\n[Trailer](https://www.youtube.com/watch?v={ytid}) | [More Info](https://anilist.co/anime/{id_})"
180+
caption += f"\n[Trailer](https://www.youtube.com/watch?v={ytid}) | [More Info](https://anilist.co/anime/{id_})"
189181
else:
190-
caption += f"\n[More Info](https://anilist.co/anime/{id_})"
182+
caption += f"\n[More Info](https://anilist.co/anime/{id_})"
191183

192184
return img, caption

0 commit comments

Comments
 (0)