Skip to content

Commit

Permalink
Update channel.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MRK-YT authored May 1, 2022
1 parent 25ba377 commit 058607f
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions bot/plugins/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from pyrogram import Client, filters
from pyrogram.errors import UserAlreadyParticipant, FloodWait

from bot import VERIFY # pylint: disable=import-error
from bot import VERIFY, LOGGER # pylint: disable=import-error
from bot.bot import Bot # pylint: disable=import-error
from bot.database import Database # pylint: disable=import-error
from bot.plugins.auto_filter import recacher # pylint: disable=import-error

db = Database()
logger = LOGGER(__name__)

@Client.on_message(filters.command(["add"]) & filters.group, group=1)
async def connect(bot: Bot, update):
Expand Down Expand Up @@ -50,25 +51,26 @@ async def connect(bot: Bot, update):
await update.reply_text("Invalid Input...\nYou Should Specify Valid <code>chat_id(-100xxxxxxxxxx)</code> or <code>@username</code>")
return

# Exports invite link from target channel for user to join
try:
join_link = await bot.export_chat_invite_link(target)
join_link = join_link.replace('+', 'joinchat/')
except Exception as e:
print(e)
await update.reply_text(f"Make Sure Im Admin At <code>{target}</code> And Have Permission For '<i>Inviting Users via Link</i>' And Try Again.....!!!")
logger.exception(e, exc_info=True)
await update.reply_text(f"Make Sure Im Admin At <code>{target}</code> And Have Permission For <i>Inviting Users via Link</i> And Try Again.....!!!\n\n<i><b>Error Logged:</b></i> <code>{e}</code>", parse_mode='html')
return

userbot_info = await bot.USER.get_me()
userbot_id = userbot_info.id
userbot_name = userbot_info.first_name

# Joins to targeted chat using above exported invite link
# If aldready joined, code just pass on to next code
try:
await bot.USER.join_chat(join_link)

except UserAlreadyParticipant:
pass

except Exception:
await update.reply_text(f"My UserBot [{userbot_name}](tg://user?id={userbot_id}) Couldnt Join The Channel `{target}` Make Sure Userbot Is Not Banned There Or Add It Manually And Try Again....!!")
except Exception as e:
logger.exception(e, exc_info=True)
await update.reply_text(f"{userbot_info.mention} Couldnt Join The Channel <code>{target}</code> Make Sure Userbot Is Not Banned There Or Add It Manually And Try Again....!!\n\n<i><b>Error Logged:</b></i> <code>{e}</code>", parse_mode='html')
return

try:
Expand Down Expand Up @@ -101,51 +103,39 @@ async def connect(bot: Bot, update):
# Using 'if elif' instead of 'or' to determine 'file_type'
# Better Way? Make A PR
try:
try:
file_id = await bot.get_messages(channel_id, message_ids=msgs.id)
except FloodWait as e:
await asyncio.sleep(e.value)
file_id = await bot.get_messages(channel_id, message_ids=msgs.id)
except Exception as e:
print(e)
continue

if msgs.video:
try:
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except FloodWait as e:
asyncio.sleep(e.x)
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except Exception as e:
print(e)
continue
file_id = file_id.video.file_id
file_name = msgs.video.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.video.file_size
file_type = "video"

elif msgs.audio:
try:
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except FloodWait as e:
asyncio.sleep(e.x)
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except Exception as e:
print(e)
continue
file_id = file_id.audio.file_id
file_name = msgs.audio.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.audio.file_size
file_type = "audio"

elif msgs.document:
try:
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except FloodWait as e:
asyncio.sleep(e.x)
file_id = await bot.get_messages(channel_id, message_ids=msgs.message_id)
except Exception as e:
print(str(e))
continue
file_id = file_id.document.file_id
file_name = msgs.document.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.document.file_size
file_type = "document"

else:
return

for i in ["_", "|", "-", "."]: # Work Around
try:
file_name = file_name.replace(i, " ")
Expand Down Expand Up @@ -284,7 +274,7 @@ async def delall(bot: Bot, update):
await update.reply_text("Sucessfully Deleted All Connected Chats From This Group....")


@Client.on_message(filters.channel & (filters.video | filters.audio | filters.document) & ~filters.edited, group=0)
@Client.on_message(filters.channel & (filters.video | filters.audio | filters.document), group=0)
async def new_files(bot: Bot, update):
"""
A Funtion To Handle Incoming New Files In A Channel ANd Add Them To Respective Channels..
Expand Down Expand Up @@ -355,3 +345,4 @@ async def new_files(bot: Bot, update):
data.append(data_packets)
await db.add_filters(data)
return

0 comments on commit 058607f

Please sign in to comment.