Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
More fixes and switch from telethon to pyrogram
Browse files Browse the repository at this point in the history
Signed-off-by: devops117 <[email protected]>
  • Loading branch information
devops117 committed Mar 16, 2022
1 parent b62f7fc commit 425c2da
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 1,052 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kangsticker.png
updates.txt

# Session files
*.session
*.session*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ FROM docker.io/python:3.10-alpine AS base

RUN apk update
RUN apk upgrade
RUN apk add libjpeg-turbo-dev
RUN apk add libjpeg-turbo-dev libwebp-dev

WORKDIR /opt/Clara

FROM base AS builder

RUN apk add gcc git libffi-dev libwebp-dev python3-dev musl-dev libxml2-dev libxslt-dev
RUN apk add gcc git python3-dev musl-dev libxml2-dev libxslt-dev libffi-dev

ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1

RUN python3 -m venv /venv
RUN /venv/bin/pip3 install wheel

COPY requirements.txt .

RUN /venv/bin/pip3 install wheel setuptools
RUN /venv/bin/pip3 install -U -r requirements.txt

FROM base AS deployment

RUN apk add postgresql neofetch

COPY --from=builder /venv /venv
COPY . .

CMD [ "sh", "-c", "source /venv/bin/activate; python -m SaitamaRobot" ]
23 changes: 11 additions & 12 deletions SaitamaRobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ruamel.yaml import YAML

import telegram.ext
from telethon import TelegramClient
from pyrogram import Client

StartTime = time.time()

Expand All @@ -27,10 +27,11 @@

OWNER_USERID = int(config_data.get("OWNER_USERID"))
OWNER_USERNAME = config_data.get("OWNER_USERNAME")
PREFIX = config_data.get("PREFIX")
JOIN_LOGGER = config_data.get("JOIN_LOGGER")
ALLOW_CHATS = config_data.get("ALLOW_CHATS")
DEV_USERS = set(config_data.get("DEV_USERS") or [])
DRAGONS = set(config_data.get("DRAGONS") or [])
DEV_USERS = frozenset(config_data.get("DEV_USERS") or [] + [OWNER_USERID])
DRAGONS = set(config_data.get("DRAGONS"))
EVENT_LOGS = config_data.get("EVENT_LOGS")
WEBHOOK = config_data.get("WEBHOOK")
URL = config_data.get("URL")
Expand All @@ -44,23 +45,21 @@
LOAD = config_data.get("LOAD")
NO_LOAD = config_data.get("NO_LOAD")
DEL_CMDS = config_data.get("DEL_CMDS")
ALLOW_EXCL = config_data.get("ALLOW_EXCL")
CASH_API_KEY = config_data.get("CASH_API_KEY")
TIME_API_KEY = config_data.get("TIME_API_KEY")
WALL_API = config_data.get("WALL_API")
SUPPORT_CHAT = config_data.get("SUPPORT_CHAT")
INFOPIC = config_data.get("INFOPIC")

BL_CHATS = set(config_data.get("BL_CHATS") or [])
DEV_USERS.add(OWNER_USERID)
BL_CHATS = frozenset(config_data.get("BL_CHATS") or [])

updater = telegram.ext.Updater(TELEGRAM_BOT_TOKEN)
dispatcher = updater.dispatcher

# telethn = TelegramClient(
# "saitama",
# env.get("TELEGRAM_API_ID"), env.get("TELEGRAM_API_HASH"),
# )
pyrogram_app = Client(
"clara",
env.get("TELEGRAM_API_ID"),
env.get("TELEGRAM_API_HASH"),
bot_token=env.get("TELEGRAM_BOT_TOKEN"),
)

# Load at end to ensure all prev variables have been set
from SaitamaRobot.modules.helper_funcs.handlers import (
Expand Down
19 changes: 5 additions & 14 deletions SaitamaRobot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from telegram.utils.helpers import escape_markdown

from SaitamaRobot import (
ALLOW_EXCL,
PREFIX,
CERT_PATH,
dispatcher,
DONATION_LINK,
Expand All @@ -36,7 +36,7 @@
PORT,
StartTime,
SUPPORT_CHAT,
# telethn,
pyrogram_app,
TELEGRAM_BOT_TOKEN,
updater,
URL,
Expand Down Expand Up @@ -95,11 +95,9 @@ def get_readable_time(seconds: int) -> str:
• in a group: will redirect you to pm, with all that chat's settings.
{}
And the following:
""".format(
dispatcher.bot.first_name,
"" if not ALLOW_EXCL else "\nAll commands can either be used with / or !.\n",
dispatcher.bot.first_name
)

SAITAMA_IMG = "https://telegra.ph/file/0576731c890d2cf9cecce.jpg"
Expand Down Expand Up @@ -631,7 +629,6 @@ def migrate_chats(update: Update, context: CallbackContext):

def main():

# test_handler = CommandHandler("test", test, run_async=True)
start_handler = CommandHandler("start", start, run_async=True)

help_handler = CommandHandler("help", get_help, run_async=True)
Expand All @@ -647,7 +644,6 @@ def main():
donate_handler = CommandHandler("donate", donate, run_async=True)
migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats)

# dispatcher.add_handler(test_handler)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(help_handler)
dispatcher.add_handler(settings_handler)
Expand All @@ -669,17 +665,12 @@ def main():

else:
LOGGER.info("Using long polling.")
updater.start_polling(timeout=15, read_latency=4, drop_pending_updates=True)

# if len(sys.argv) not in (1, 3, 4):
# telethn.disconnect()
# else:
# telethn.run_until_disconnected()
updater.start_polling(drop_pending_updates=True)

pyrogram_app.run()
updater.idle()


if __name__ == "__main__":
LOGGER.info("Successfully loaded modules: " + str(ALL_MODULES))
# telethn.start(bot_token=TELEGRAM_BOT_TOKEN)
main()
7 changes: 2 additions & 5 deletions SaitamaRobot/modules/cleaner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import html

from SaitamaRobot import ALLOW_EXCL, CustomCommandHandler, dispatcher
from SaitamaRobot import PREFIX, CustomCommandHandler, dispatcher
from SaitamaRobot.modules.disable import DisableAbleCommandHandler
from SaitamaRobot.modules.helper_funcs.chat_status import (
bot_can_delete,
Expand All @@ -17,7 +17,6 @@
MessageHandler,
)

CMD_STARTERS = ("/", "!") if ALLOW_EXCL else "/"
BLUE_TEXT_CLEAN_GROUP = 13
CommandHandlerList = (CommandHandler, CustomCommandHandler, DisableAbleCommandHandler)
command_list = [
Expand Down Expand Up @@ -48,9 +47,7 @@ def clean_blue_text_must_click(update: Update, context: CallbackContext):
if chat.get_member(bot.id).can_delete_messages and sql.is_enabled(chat.id):
fst_word = message.text.strip().split(None, 1)[0]

if len(fst_word) > 1 and any(
fst_word.startswith(start) for start in CMD_STARTERS
):
if len(fst_word) > 1 and any(fst_word.startswith(start) for start in PREFIX):

command = fst_word[1:].split("@")
chat = update.effective_chat
Expand Down
69 changes: 0 additions & 69 deletions SaitamaRobot/modules/debug.py

This file was deleted.

14 changes: 7 additions & 7 deletions SaitamaRobot/modules/disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Union

from future.utils import string_types
from SaitamaRobot import dispatcher
from SaitamaRobot.modules.helper_funcs.handlers import CMD_STARTERS, SpamChecker
from SaitamaRobot import dispatcher, PREFIX
from SaitamaRobot.modules.helper_funcs.handlers import SpamChecker
from SaitamaRobot.modules.helper_funcs.misc import is_module_loaded
from telegram import ParseMode, Update
from telegram.ext import (
Expand Down Expand Up @@ -51,7 +51,7 @@ def check_update(self, update):
if message.text and len(message.text) > 1:
fst_word = message.text.split(None, 1)[0]
if len(fst_word) > 1 and any(
fst_word.startswith(start) for start in CMD_STARTERS
fst_word.startswith(start) for start in PREFIX
):
args = message.text.split()[1:]
command = fst_word[1:].split("@")
Expand Down Expand Up @@ -136,7 +136,7 @@ def disable(update: Update, context: CallbackContext):
chat = update.effective_chat
if len(args) >= 1:
disable_cmd = args[0]
if disable_cmd.startswith(CMD_STARTERS):
if disable_cmd.startswith(PREFIX):
disable_cmd = disable_cmd[1:]

if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
Expand Down Expand Up @@ -177,7 +177,7 @@ def disable_module(update: Update, context: CallbackContext):
failed_disabled_cmds = []

for disable_cmd in command_list:
if disable_cmd.startswith(CMD_STARTERS):
if disable_cmd.startswith(PREFIX):
disable_cmd = disable_cmd[1:]

if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER):
Expand Down Expand Up @@ -210,7 +210,7 @@ def enable(update: Update, context: CallbackContext):
chat = update.effective_chat
if len(args) >= 1:
enable_cmd = args[0]
if enable_cmd.startswith(CMD_STARTERS):
if enable_cmd.startswith(PREFIX):
enable_cmd = enable_cmd[1:]

if sql.enable_command(chat.id, enable_cmd):
Expand Down Expand Up @@ -251,7 +251,7 @@ def enable_module(update: Update, context: CallbackContext):
failed_enabled_cmds = []

for enable_cmd in command_list:
if enable_cmd.startswith(CMD_STARTERS):
if enable_cmd.startswith(PREFIX):
enable_cmd = enable_cmd[1:]

if sql.enable_command(chat.id, enable_cmd):
Expand Down
Loading

0 comments on commit 425c2da

Please sign in to comment.