Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Clinton-Abraham authored Oct 21, 2021
1 parent 3280582 commit c2c0d2a
Show file tree
Hide file tree
Showing 8 changed files with 1,179 additions and 0 deletions.
22 changes: 22 additions & 0 deletions plugins/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# (c) @AbirHasan2005 | Modifieded By : @DC4_WARRIOR

import traceback
import os

from pyrogram import Client as Clinton
from pyrogram import filters

if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from database.access import clinton

@Clinton.on_message(filters.private & filters.command('total'))
async def sts(c, m):
if m.from_user.id != Config.OWNER_ID:
return
total_users = await clinton.total_users_count()
await m.reply_text(text=f"Total user(s) {total_users}", quote=True)

113 changes: 113 additions & 0 deletions plugins/broadcast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# (c) @AbirHasan2005 | X-Noid

import traceback, datetime, asyncio, string, random, time, os, aiofiles, aiofiles.os
from database.access import clinton
from pyrogram import filters
from pyrogram import Client as Clinton
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import FloodWait, InputUserDeactivated, UserIsBlocked, PeerIdInvalid

if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config

broadcast_ids = {}

async def send_msg(user_id, message):
try:
await message.copy(chat_id=user_id)
return 200, None
except FloodWait as e:
await asyncio.sleep(e.x)
return send_msg(user_id, message)
except InputUserDeactivated:
return 400, f"{user_id} : deactivated\n"
except UserIsBlocked:
return 400, f"{user_id} : blocked the bot\n"
except PeerIdInvalid:
return 400, f"{user_id} : user id invalid\n"
except Exception as e:
return 500, f"{user_id} : {traceback.format_exc()}\n"


@Clinton.on_message(filters.private & filters.command('broadcast') & filters.reply)
async def broadcast_(c, m):
if m.from_user.id != Config.OWNER_ID:
return
all_users = await clinton.get_all_users()

broadcast_msg = m.reply_to_message

while True:
broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)])
if not broadcast_ids.get(broadcast_id):
break

out = await m.reply_text(
text = f"Broadcast initiated! You will be notified with log file when all the users are notified."
)
start_time = time.time()
total_users = await clinton.total_users_count()
done = 0
failed = 0
success = 0

broadcast_ids[broadcast_id] = dict(
total = total_users,
current = done,
failed = failed,
success = success
)

async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file:
async for user in all_users:

sts, msg = await send_msg(
user_id = int(user['id']),
message = broadcast_msg
)
if msg is not None:
await broadcast_log_file.write(msg)

if sts == 200:
success += 1
else:
failed += 1

if sts == 400:
await clinton.delete_user(user['id'])

done += 1
if broadcast_ids.get(broadcast_id) is None:
break
else:
broadcast_ids[broadcast_id].update(
dict(
current = done,
failed = failed,
success = success
)
)
if broadcast_ids.get(broadcast_id):
broadcast_ids.pop(broadcast_id)
completed_in = datetime.timedelta(seconds=int(time.time()-start_time))

await asyncio.sleep(3)

await out.delete()

if failed == 0:
await m.reply_text(
text=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
quote=True
)
else:
await m.reply_document(
document='broadcast.txt',
caption=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
quote=True
)

await aiofiles.os.remove('broadcast.txt')
17 changes: 17 additions & 0 deletions plugins/cb_buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K | Modified By > @DC4_WARRIOR


from pyrogram import Client as Clinton
from plugins.youtube_dl_button import youtube_dl_call_back
from plugins.dl_button import ddl_call_back

@Clinton.on_callback_query()
async def button(bot, update):

cb_data = update.data
if "|" in cb_data:
await youtube_dl_call_back(bot, update)
elif "=" in cb_data:
await ddl_call_back(bot, update)
118 changes: 118 additions & 0 deletions plugins/custom_thumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K | Modifieded By : @DC4_WARRIOR

# the logging things
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

import random
import numpy
import os
from PIL import Image
import time
# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
# the Strings used for this "thing"
from translation import Translation
from pyrogram import Client as Clinton
from database.access import clinton
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
logging.getLogger("pyrogram").setLevel(logging.WARNING)
from pyrogram import filters
from database.adduser import AddUser
from helper_funcs.help_Nekmo_ffmpeg import take_screen_shot

@Clinton.on_message(filters.private & filters.photo)
async def save_photo(bot, update):
await AddUser(bot, update)
await clinton.set_thumbnail(update.from_user.id, thumbnail=update.photo.file_id)
await bot.send_message(chat_id=update.chat.id, text=Translation.SAVED_CUSTOM_THUMB_NAIL, reply_to_message_id=update.message_id)

@Clinton.on_message(filters.private & filters.command("delthumbnail"))
async def delthumbnail(bot, update):
await AddUser(bot, update)
await clinton.set_thumbnail(update.from_user.id, thumbnail=None)
await bot.send_message(chat_id=update.chat.id, text=Translation.DEL_ETED_CUSTOM_THUMB_NAIL, reply_to_message_id=update.message_id)

@Clinton.on_message(filters.private & filters.command("viewthumbnail") )
async def viewthumbnail(bot, update):
await AddUser(bot, update)
thumbnail = await clinton.get_thumbnail(update.from_user.id)
if thumbnail is not None:
await bot.send_photo(
chat_id=update.chat.id,
photo=thumbnail,
caption=f"Your current saved thumbnail 🦠",
reply_to_message_id=update.message_id)
else:
await update.reply_text(text=f"No Thumbnail found 🤒")

async def Gthumb01(bot, update):
thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
db_thumbnail = await clinton.get_thumbnail(update.from_user.id)
if db_thumbnail is not None:
thumbnail = await bot.download_media(message=db_thumbnail, file_name=thumb_image_path)
Image.open(thumbnail).convert("RGB").save(thumbnail)
img = Image.open(thumbnail)
img.resize((100, 100))
img.save(thumbnail, "JPEG")
else:
thumbnail = None

return thumbnail

async def Gthumb02(bot, update, duration, download_directory):
thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg"
db_thumbnail = await clinton.get_thumbnail(update.from_user.id)
if db_thumbnail is not None:
thumbnail = await bot.download_media(message=db_thumbnail, file_name=thumb_image_path)
else:
thumbnail = await take_screen_shot(download_directory, os.path.dirname(download_directory), random.randint(0, duration - 1))

return thumbnail

async def Mdata01(download_directory):

width = 0
height = 0
duration = 0
metadata = extractMetadata(createParser(download_directory))
if metadata is not None:
if metadata.has("duration"):
duration = metadata.get('duration').seconds
if metadata.has("width"):
width = metadata.get("width")
if metadata.has("height"):
height = metadata.get("height")

return width, height, duration

async def Mdata02(download_directory):

width = 0
duration = 0
metadata = extractMetadata(createParser(download_directory))
if metadata is not None:
if metadata.has("duration"):
duration = metadata.get('duration').seconds
if metadata.has("width"):
width = metadata.get("width")

return width, duration

async def Mdata03(download_directory):

duration = 0
metadata = extractMetadata(createParser(download_directory))
if metadata is not None:
if metadata.has("duration"):
duration = metadata.get('duration').seconds

return duration
Loading

0 comments on commit c2c0d2a

Please sign in to comment.