Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: python -m bot
worker: python -m bot
17 changes: 5 additions & 12 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@
"description": "Obtain a Telegram bot token by contacting @BotFather"
},
"TG_USER_SESSION": {
"description": "Create a PyroGram User Session, using https://generatestringsession.spechide.repl.run/"
"description": "Create a PyroGram User Session, using https://t.me/useTGxBot"
}
},
"buildpacks": [
{
"url": "heroku/python"
}
],
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
}
"buildpacks": [{
"url": "heroku/python"
}],
"stack": "heroku-20"
}
15 changes: 14 additions & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@
# given the amount of sql data accesses,
# and the way python asynchronous calls work.
TG_BOT_WORKERS = int(get_config("TG_BOT_WORKERS", "4"))
# add an auto sleep time,
# in the Pyrogram Client
TG_SLEEP_THRESHOLD = int(get_config("TG_SLEEP_THRESHOLD", 10))
# path to store LOG files
LOG_FILE_ZZGEVC = get_config("LOG_FILE_ZZGEVC", "MessageDeletErBot.log")
# number of messages that can be deleted in One Request, in Telegram
TG_MAX_SEL_MESG = int(get_config("TG_MAX_SEL_MESG", 99))
TG_MIN_SEL_MESG = int(get_config("TG_MIN_SEL_MESG", 0))
# a dictionary to store the currently running processes
AKTIFPERINTAH = {}
# should the user / bot leave the chat after finishing tasks
SHTL_USR_HCAT_QO = bool(get_config("SHTL_USR_HCAT_QO", False))
SHTL_BOT_HCAT_QO = bool(get_config("SHTL_BOT_HCAT_QO", False))


logging.basicConfig(
Expand Down Expand Up @@ -77,7 +83,8 @@ def LOGGER(name: str) -> logging.Logger:
GIT_REPO_LINK = "https://github.com/SpEcHiDe/DeleteMessagesRoBot"
""" strings to be used in the bot """
START_MESSAGE = get_config("START_MESSAGE", (
"I'm a bot that can delete <s>all</s> your channel or supergroup messages. "
"I'm a bot that can delete <s>all</s> "
"your channel or supergroup messages. "
"\n\n"
f"To use me: read 👉 {REQD_PERMISSIONS} 👈"
"\n\n"
Expand Down Expand Up @@ -107,6 +114,12 @@ def LOGGER(name: str) -> logging.Logger:
f"before using /{SEL_DEL_COMMAND}"
)
)
THANK_YOU_MESSAGE = get_config(
"THANK_YOU_MESSAGE", (
"Thank You for using me, "
f"Join {REQD_PERMISSIONS} to support this Telegram Bot"
)
)
TL_FILE_TYPES = (
"photo",
"animation",
Expand Down
25 changes: 18 additions & 7 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,56 @@
Client,
__version__
)
from pyrogram.enums import ParseMode
from . import (
API_HASH,
APP_ID,
LOGGER,
TG_BOT_SESSION,
TG_BOT_TOKEN,
TG_BOT_WORKERS
TG_BOT_WORKERS,
TG_SLEEP_THRESHOLD
)
from .user import User


class Bot(Client):
""" modded client for MessageDeletERoBot """
BOT_ID: int = None
USER: User = None
USER_ID: int = None

def __init__(self):
super().__init__(
TG_BOT_SESSION,
name=TG_BOT_SESSION,
api_hash=API_HASH,
api_id=APP_ID,
plugins={
"root": "bot/plugins"
"root": "bot.plugins",
"exclude": [
"oatc"
]
},
workers=TG_BOT_WORKERS,
bot_token=TG_BOT_TOKEN
bot_token=TG_BOT_TOKEN,
sleep_threshold=TG_SLEEP_THRESHOLD,
parse_mode=ParseMode.HTML
)
self.LOGGER = LOGGER

async def start(self):
await super().start()
usr_bot_me = await self.get_me()
self.set_parse_mode("html")
usr_bot_me = self.me
self.BOT_ID = usr_bot_me.id
self.LOGGER(__name__).info(
f"@{usr_bot_me.username} based on Pyrogram v{__version__} "
)
self.USER, self.USER_ID = await User().start()
# hack to get the entities in-memory
await self.USER.send_message(usr_bot_me.username, "this is a hack")
await self.USER.send_message(
usr_bot_me.username,
"join https://t.me/SpEcHlDe/857"
)

async def stop(self, *args):
await super().stop()
Expand Down
3 changes: 2 additions & 1 deletion bot/helpers/custom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from pyrogram import filters
from pyrogram.enums import ChatType
from pyrogram.types import Message


async def allowed_chat_filter_fn(_, __, m: Message):
return bool(m.chat and m.chat.type in {"channel", "supergroup"})
return bool(m.chat and m.chat.type in [ChatType.CHANNEL, ChatType.SUPERGROUP])


allowed_chat_filter = filters.create(allowed_chat_filter_fn)
34 changes: 34 additions & 0 deletions bot/helpers/delall_bot_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from typing import Tuple, Union


def extract_c_m_ids(message_link: str) -> Tuple[Union[str, int], int]:
p_m_link = message_link.split("/")
chat_id, message_id = None, None
if len(p_m_link) == 6:
# private link
if p_m_link[3] == "c":
# the Telegram private link
chat_id, message_id = int("-100" + p_m_link[4]), int(p_m_link[5])
elif p_m_link[3] == "DMCATelegramBot":
# bleck magick
chat_id, message_id = int(p_m_link[4]), int(p_m_link[5])
elif len(p_m_link) == 5:
# public link
chat_id, message_id = str("@" + p_m_link[3]), int(p_m_link[4])
return chat_id, message_id
8 changes: 4 additions & 4 deletions bot/helpers/get_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ async def get_messages(
limit=None
):
if (
min_message_id <= msg.message_id and
max_message_id >= msg.message_id
min_message_id <= msg.id and
max_message_id >= msg.id
):
if len(filter_type_s) > 0:
for filter_type in filter_type_s:
obj = getattr(msg, filter_type)
if obj:
messages_to_delete.append(msg.message_id)
messages_to_delete.append(msg.id)
else:
messages_to_delete.append(msg.message_id)
messages_to_delete.append(msg.id)
# append to the list, based on the condition
if len(messages_to_delete) > TG_MAX_SEL_MESG:
await mass_delete_messages(
Expand Down
50 changes: 50 additions & 0 deletions bot/helpers/gulmnek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from pyrogram.types import Message
from pyrogram.enums import MessageEntityType
from .delall_bot_links import extract_c_m_ids


def knemblook(
message: Message
):
_store_r = {}
entities = (
message.entities or
message.caption_entities or
[]
)
text = (
message.text or
message.caption or
""
)
if message and text and len(entities) > 0:
for one_entity in entities:
_url = None
if one_entity.type == MessageEntityType.URL:
_url = text[
one_entity.offset:one_entity.offset + one_entity.length
]
elif one_entity.type == MessageEntityType.TEXT_LINK:
_url = one_entity.url
if _url:
chat_id, message_id = extract_c_m_ids(_url)
if chat_id not in _store_r:
_store_r[chat_id] = []
_store_r[chat_id].append(message_id)
return _store_r
35 changes: 35 additions & 0 deletions bot/helpers/help_for_14121.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from pyrogram.errors import (
UserNotParticipant
)
from bot.bot import Bot


async def check_perm(client: Bot, chat_id: int, user_id: int) -> bool:
try:
_a_ = await client.get_chat_member(
chat_id,
user_id
)
except UserNotParticipant:
return False
else:
if _a_.can_delete_messages:
return True
else:
return False
24 changes: 12 additions & 12 deletions bot/helpers/make_user_join_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.


from asyncio import sleep
from pyrogram.errors import (
InviteHashExpired,
InviteHashInvalid,
UserAlreadyParticipant
)
from pyrogram.types import Message
from pyrogram.enums import ChatMemberStatus
from pyrogram.types import (
Message,
ChatPrivileges
)
from bot.bot import Bot


Expand All @@ -36,19 +40,15 @@ async def make_chat_user_join(
pass
except (InviteHashExpired, InviteHashInvalid) as e:
return False, str(e)
await sleep(7)
_existing_permissions = await message.chat.get_member(user_id)
if _existing_permissions.status == "creator":
return True, None
if _existing_permissions.status == ChatMemberStatus.OWNER:
return True, 140
if not _existing_permissions.can_delete_messages:
await message.chat.promote_member(
user_id,
can_change_info=False,
can_post_messages=False,
can_edit_messages=False,
can_delete_messages=True,
can_restrict_members=False,
can_invite_users=False,
can_pin_messages=False,
can_promote_members=False
ChatPrivileges(
can_delete_messages=True
)
)
return True, None
Loading