Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
Haha New Update Go Brrr (#57)
Browse files Browse the repository at this point in the history
- Fixed .ars
- New Fake Report Image When a user is Blocked in Pm Permit
- New Plugin spoiler.py
  • Loading branch information
code-rgb authored Nov 9, 2020
1 parent 2d69ec3 commit a3d1d3d
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ pictest.py
resources/ProductSans-BoldItalic.ttf
resources/ProductSans-Light.ttf
resources/Roboto-Regular.ttf
resources/font.ttf
resources/font.ttf
resources/Roboto-Medium
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiofiles
aiohttp
aiohttp==3.6.3
bs4
cowpy
dnspython
Expand Down
Binary file added resources/Roboto-Medium.ttf
Binary file not shown.
Binary file modified resources/Roboto-Regular.ttf
Binary file not shown.
4 changes: 3 additions & 1 deletion userge/plugins/bot/bot_forwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ async def forward_bot(_, message: Message):
& filters.user(Config.OWNER_ID)
& filters.private
& filters.reply
& ~filters.regex(pattern=r"^\/.+")
& ~filters.regex(
pattern="^(/.*|\{}spoiler(?:$|.*))".format(Config.SUDO_TRIGGER)
)
)
async def forward_reply(_, message: Message):
replied = message.reply_to_message
Expand Down
4 changes: 4 additions & 0 deletions userge/plugins/bot/inline_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"help_txt": "**Download Youtube Videos with Buttons**\n\nTo Download video from youtube with desired quality.\n>>> `ytdl [link]`",
"i_q": "ytdl https://www.youtube.com/watch?v=dQw4w9WgXcQ",
},
"spoiler": {
"help_txt": "**Send Saved Spoiler Via Inline**\n For more info see `.help spoiler`\n\n>>> `spoiler [ID]`",
"i_q": "spoiler",
},
}


Expand Down
160 changes: 160 additions & 0 deletions userge/plugins/bot/spoiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Copyright (C) 2020 BY - GitHub.com/code-rgb [TG - @deleteduser420]
# All rights reserved.


import datetime
import json
import os
from uuid import uuid1

from pyrogram import filters
from pyrogram.errors import MessageNotModified
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup

from userge import Config, Message, userge
from userge.utils import mention_html

CHANNEL = userge.getCLogger(__name__)
PATH = "./userge/xcache/spoiler_db.json"


class Spoiler_DB:
def __init__(self):
if not os.path.exists(PATH):
d = {}
json.dump(d, open(PATH, "w"))
self.db = json.load(open(PATH))

def save_msg(self, rnd_id: str, msg_id: int):
savetime = (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
self.db[rnd_id] = {"msg_id": msg_id, "savetime": str(savetime)}
self.save()

def save(self):
with open(PATH, "w") as outfile:
json.dump(self.db, outfile, indent=4)


SPOILER_DB = Spoiler_DB()


@userge.on_cmd(
"spoiler",
about={
"header": "Share a spoiler",
"usage": "{tr}spoiler [reply to media] or Text",
},
)
async def spoiler_alert_(message: Message):
content = message.input_str
reply = message.reply_to_message
if reply and reply.text:
content = reply.text.html
content = "{}".format(content or "")
if not (content or (reply and reply.media)):
await message.err("No Content Found!")
return
rnd_hex = uuid1().hex
rnd_id = f"spoiler_{rnd_hex}"
SPOILER_DB.save_msg(rnd_hex, (await CHANNEL.store(reply, content)))
bot_name = (await userge.bot.get_me()).username
link = f"https://t.me/{bot_name}?start={rnd_id}"
buttons = None
text_ = "**{} Shared A Spoiler** !\n[> **Click To View** <]({})".format(
mention_html(message.from_user.id, message.from_user.first_name), link
)
if message.client.is_bot:
buttons = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Button", callback_data="getl{}".format(rnd_id)
),
InlineKeyboardButton(
"Text Link", callback_data="nobtnspoiler{}".format(rnd_id)
),
],
[
InlineKeyboardButton(
"Via Inline", switch_inline_query=rnd_id.replace("_", " ")
)
],
]
)
text_ = "<b><u>Choose How You Want to Share the Spoiler.</b></u>"
await message.edit(text_, reply_markup=buttons, disable_web_page_preview=True)


@userge.bot.on_message(
filters.private
& (
filters.regex(pattern=r"^/start spoiler_([\S]+)")
| filters.regex(pattern=r"^/spoiler_([\S]+)")
)
)
async def spoiler_get(_, message: Message):
spoiler_key = message.matches[0].group(1)
if not os.path.exists(PATH):
await message.err("Not Found", del_in=5)
view_data = SPOILER_DB.db
mid = view_data.get(spoiler_key, None)
if mid:
return await CHANNEL.forward_stored(
client=userge.bot,
message_id=mid["msg_id"],
user_id=message.from_user.id,
chat_id=message.chat.id,
reply_to_message_id=message.message_id,
)
await message.reply("Not Found / Expired")


if userge.has_bot:

@userge.bot.on_callback_query(filters.regex(pattern=r"^getl([\S]+)$"))
async def get_spoiler_link(_, c_q: CallbackQuery):
u_id = c_q.from_user.id
if u_id != Config.OWNER_ID and u_id not in Config.SUDO_USERS:
return await c_q.answer(
"Given That It's A Stupid-Ass Decision, I've Elected To Ignore It.",
show_alert=True,
)
await c_q.answer("With Buttons", show_alert=False)
bot_name = (await userge.bot.get_me()).username
buttons = [
[
InlineKeyboardButton(
"View Spoiler",
url=f"https://t.me/{bot_name}?start={c_q.matches[0].group(1)}",
)
]
]
try:
await c_q.edit_message_text(
"<b>Click To View The Spoiler !</b>",
reply_markup=InlineKeyboardMarkup(buttons),
)
except MessageNotModified:
pass

@userge.bot.on_callback_query(filters.regex(pattern=r"^nobtnspoiler([\S]+)$"))
async def get_spoiler_link(_, c_q: CallbackQuery):
u_id = c_q.from_user.id
u_name = c_q.from_user.first_name
if u_id != Config.OWNER_ID and u_id not in Config.SUDO_USERS:
return await c_q.answer(
"Given That It's A Stupid-Ass Decision, I've Elected To Ignore It.",
show_alert=True,
)
bot_name = (await userge.bot.get_me()).username
await c_q.answer("Without Buttons", show_alert=False)
url = f"https://t.me/{bot_name}?start={c_q.matches[0].group(1)}"
try:
await c_q.edit_message_text(
"**{} Shared A Spoiler** !\n[> **Click To View** <]({})".format(
mention_html(u_id, u_name), url
),
disable_web_page_preview=True,
)
except MessageNotModified:
pass
59 changes: 59 additions & 0 deletions userge/plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,65 @@ async def inline_answer(_, inline_query: InlineQuery):
if string == "repo":
results.append(REPO_X)

if str_y[0] == "spoiler":
if not os.path.exists("./userge/xcache/spoiler_db.json"):
results.append(
InlineQueryResultArticle(
title="No Spoiler Found",
input_message_content=InputTextMessageContent(
"No Spoiler Found !\nLet's Add Some 😈"
),
description="See .help spoiler for more info",
)
)
else:
bot_name = (await userge.bot.get_me()).username
if len(str_y) == 2:
link = f"https://t.me/{bot_name}?start=spoiler_{str_y[1]}"
buttons = [
[InlineKeyboardButton(text="View Spoiler", url=link)]
]
results.append(
InlineQueryResultArticle(
title="Spoiler",
input_message_content=InputTextMessageContent(
"<b>Click To View The Spoiler !</b>"
),
description="Click To Send",
thumb_url="https://telegra.ph/file/ee3a6439494463acd1a3a.jpg",
reply_markup=InlineKeyboardMarkup(buttons),
)
)
else:
view_db = json.load(open("./userge/xcache/spoiler_db.json"))
if len(view_db) != 0:
numm = 0
for spoilerr in view_db:
numm += 1
buttons = [
[
InlineKeyboardButton(
text="View Spoiler",
url=f"https://t.me/{bot_name}?start=spoiler_{spoilerr}",
)
]
]
saved_at = view_db.get(spoilerr, None)
savetime = (
saved_at.get("savetime", None) if saved_at else None
)
results.append(
InlineQueryResultArticle(
title=f"#{numm} Spoiler",
input_message_content=InputTextMessageContent(
"<b>Click To View The Spoiler !</b>"
),
description=f"Created At: {savetime}",
thumb_url="https://telegra.ph/file/ee3a6439494463acd1a3a.jpg",
reply_markup=InlineKeyboardMarkup(buttons),
)
)

if str_x[0].lower() == "op" and len(str_x) > 1:
txt = i_q[3:]

Expand Down
7 changes: 6 additions & 1 deletion userge/plugins/utils/pmpermit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from userge import Config, Message, filters, get_collection, userge
from userge.utils import SafeDict
from userge.utils.miscellaneous import reported_user_image

CHANNEL = userge.getCLogger(__name__)
SAVED_SETTINGS = get_collection("CONFIGS")
Expand Down Expand Up @@ -271,7 +272,11 @@ async def uninvitedPmHandler(message: Message):
if message.from_user.id in pmCounter:
if pmCounter[message.from_user.id] > 3:
del pmCounter[message.from_user.id]
await message.reply(blocked_message)
# await message.reply(blocked_message)
report_img_ = await reported_user_image(message.from_user.first_name)
await userge.send_photo(
message.chat.id, report_img_, caption=blocked_message
)
await message.from_user.block()
await asyncio.sleep(1)
await CHANNEL.log(
Expand Down
1 change: 1 addition & 0 deletions userge/utils/miscellaneous/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .fake_report import reported_user_image
31 changes: 31 additions & 0 deletions userge/utils/miscellaneous/fake_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2020 BY - GitHub.com/code-rgb [TG - @deleteduser420]
# All rights reserved.


import textwrap
from io import BytesIO

from PIL import Image, ImageDraw, ImageFont
from requests import get



async def reported_user_image(u_name: str):
"""reported user"""
text1 = "Block " + u_name
text2 = f"Do you want to block {u_name} from messaging and calling you on Telegram?"
in_memory = BytesIO(get("https://telegra.ph/file/886e00818c68f53d24f92.jpg").content)
photo = Image.open(in_memory)
drawing = ImageDraw.Draw(photo)
white = (255, 255, 255)
font1 = ImageFont.truetype("resources/Roboto-Regular.ttf", 45)
font2 = ImageFont.truetype("resources/Roboto-Medium.ttf", 55)
drawing.text((132, 201), text1, fill=white, font=font2)
x = 0
for u_text in textwrap.wrap(text2, width=38):
drawing.text(xy=(132, 305 + x), text=u_text, font=font1, fill=white)
x += 53
new_pic = BytesIO()
photo.save(new_pic, format='JPEG')
new_pic.name = "Blocked.jpg"
return new_pic

1 comment on commit a3d1d3d

@vercel
Copy link

@vercel vercel bot commented on a3d1d3d Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.