Exemplo n.º 1
0
def mention_answer(client: Client, message: Message, aid: int, uid: int,
                   action_type: str) -> str:
    # Mention abuse
    try:
        # Basic data
        gid = message.chat.id
        mid = message.message_id

        # Abuse
        if action_type == "abuse":
            message.reply_to_message = message
            message.reply_to_message.from_user.id = uid
            message.reply_to_message.from_user.is_self = lang("abuse_mention")
            text, markup = warn_user(client, message, uid, aid)
            text += f"{lang('reason')}{lang('colon')}{code(lang('reason_abuse'))}\n"

            # Edit the report message
            thread(edit_message_text, (client, gid, mid, text, markup))
            delay(180, delete_message, [client, gid, mid])

        # Delete
        elif action_type == "delete":
            glovar.message_ids[gid] = (0, 0)
            save("message_ids")
            delete_message(client, gid, mid)
    except Exception as e:
        logger.warning(f"Mention answer error: {e}", exc_info=True)

    return ""
Exemplo n.º 2
0
def send_report_message(secs: int, client: Client, cid: int, text: str, mid: int = None,
                        markup: InlineKeyboardMarkup = None) -> Optional[bool]:
    # Send a message that will be auto deleted to a chat
    result = None

    try:
        result = send_message(
            client=client,
            cid=cid,
            text=text,
            mid=mid,
            markup=markup
        )

        if not result:
            return None

        mid = result.message_id
        mids = [mid]
        result = delay(secs, delete_messages, [client, cid, mids])
    except Exception as e:
        logger.warning(f"Send report message to {cid} error: {e}", exc_info=True)

    return result
Exemplo n.º 3
0
from pyrogram import Client, idle

from plugins import glovar
from plugins.functions.etc import delay
from plugins.functions.timers import backup_files, interval_hour_01, interval_min_10, reset_data, update_admins
from plugins.functions.timers import update_status

# Enable logging
logger = logging.getLogger(__name__)

# Config session
app = Client(session_name="account")
app.start()

# Send online status
delay(3, update_status, [app, "online"])

# Timer
scheduler = BackgroundScheduler(job_defaults={"misfire_grace_time": 60})
scheduler.add_job(interval_min_10, "interval", [app], minutes=10)
scheduler.add_job(interval_hour_01, "interval", [app], hours=1)
scheduler.add_job(update_status,
                  "cron", [app, "awake"],
                  minute=randint(30, 34),
                  second=randint(0, 59))
scheduler.add_job(backup_files, "cron", [app], hour=20)
scheduler.add_job(reset_data, "cron", [app], day=glovar.date_reset, hour=22)
scheduler.add_job(update_admins, "cron", [app], hour=22, minute=30)
scheduler.start()

# Hold
Exemplo n.º 4
0
def config(client: Client, message: Message) -> bool:
    # Request CONFIG session

    if not message or not message.chat:
        return True

    # Basic data
    gid = message.chat.id
    mid = message.message_id

    try:
        # Check permission
        if not is_class_c(None, None, message):
            return True

        # Check command format
        command_type = get_command_type(message)
        if not command_type or not re.search(f"^{glovar.sender}$",
                                             command_type, re.I):
            return True

        now = get_now()

        # Check the config lock
        if now - glovar.configs[gid]["lock"] < 310:
            return True

        # Set lock
        glovar.configs[gid]["lock"] = now
        save("configs")

        # Ask CONFIG generate a config session
        group_name, group_link = get_group_info(client, message.chat)
        share_data(client=client,
                   receivers=["CONFIG"],
                   action="config",
                   action_type="ask",
                   data={
                       "project_name": glovar.project_name,
                       "project_link": glovar.project_link,
                       "group_id": gid,
                       "group_name": group_name,
                       "group_link": group_link,
                       "user_id": message.from_user.id,
                       "config": glovar.configs[gid],
                       "default": glovar.default_config
                   })

        # Send debug message
        text = get_debug_text(client, message.chat)
        text += (
            f"{lang('admin_group')}{lang('colon')}{code(message.from_user.id)}\n"
            f"{lang('action')}{lang('colon')}{code(lang('config_create'))}\n")
        thread(send_message, (client, glovar.debug_channel_id, text))

        return True
    except Exception as e:
        logger.warning(f"Config error: {e}", exc_info=True)
    finally:
        if is_class_c(None, None, message):
            delay(3, delete_message, [client, gid, mid])
        else:
            delete_message(client, gid, mid)

    return False
Exemplo n.º 5
0
def report_answer(client: Client,
                  message: Message,
                  gid: int,
                  aid: int,
                  mid: int,
                  action_type: str,
                  key: str,
                  reason: str = None) -> str:
    # Answer the user's report
    try:
        report_record = glovar.reports.get(key)

        if not report_record:
            message_text = get_text(message)
            uid = get_int(message_text.split("\n")[0].split(lang("colon"))[1])
            text = (
                f"{lang('description')}{lang('colon')}{code(lang('description_by_admin'))}\n"
                f"{lang('status')}{lang('colon')}{code(lang('status_failed'))}\n"
                f"{lang('reason')}{lang('colon')}{code(lang('expired'))}\n")
            thread(edit_message_text, (client, gid, mid, text))
            delay(15, delete_message, [client, gid, mid])
            glovar.user_ids[uid]["waiting"].discard(gid)
            save("user_ids")
            return ""

        if not report_record["time"]:
            return ""

        rid = report_record["reporter_id"]
        uid = report_record["user_id"]
        r_mid = report_record["message_id"]
        record_reason = report_record["reason"]

        if not reason:
            reason = record_reason

        if not (init_user_id(rid) and init_user_id(uid)):
            return ""

        # Check users' locks
        if gid in glovar.user_ids[uid]["lock"] or gid in glovar.user_ids[rid][
                "lock"]:
            return lang("answer_proceeded")

        # Lock the report status
        glovar.reports[key]["time"] = 0
        try:
            if action_type == "ban":
                text, markup = ban_user(client, message, uid, aid, 0, reason)
                thread(delete_message, (client, gid, r_mid))
            elif action_type == "warn":
                text, markup = warn_user(client, message, uid, aid, reason)
                thread(delete_message, (client, gid, r_mid))
            elif action_type == "abuse":
                if not rid:
                    return ""

                message.reply_to_message.from_user.id = rid
                message.reply_to_message.from_user.is_self = lang(
                    "abuse_report")
                text, markup = warn_user(client, message, rid, aid)
                text += f"{lang('reason')}{lang('colon')}{code(lang('reason_abuse'))}\n"
            else:
                reported_link = general_link(
                    r_mid, f'{get_channel_link(message)}/{r_mid}')

                if rid:
                    reporter_text = code(rid)
                else:
                    reporter_text = code(lang("auto_triggered"))

                text = (
                    f"{lang('reported_user')}{lang('colon')}{mention_id(uid)}\n"
                    f"{lang('reported_message')}{lang('colon')}{reported_link}\n"
                    f"{lang('reporter')}{lang('colon')}{reporter_text}\n"
                    f"{lang('action')}{lang('colon')}{code(lang('action_cancel'))}\n"
                    f"{lang('status')}{lang('colon')}{code(lang('status_succeeded'))}\n"
                    f"{lang('description')}{lang('colon')}{code(lang('description_by_admin'))}\n"
                )
                markup = None

            if markup:
                secs = 180
            else:
                secs = 15

            thread(edit_message_text, (client, gid, mid, text, markup))
            delay(secs, delete_message, [client, gid, mid])
        finally:
            glovar.user_ids[uid]["lock"].discard(gid)
            glovar.user_ids[rid]["lock"].discard(gid)
            glovar.user_ids[uid]["waiting"].discard(gid)
            glovar.user_ids[rid]["waiting"].discard(gid)
            save("user_ids")
    except Exception as e:
        logger.warning(f"Report answer error: {e}", exc_info=True)

    return ""
Exemplo n.º 6
0
# Renew session
renew()

# Config session
app = Client(
    session_name="bot",
    ipv6=glovar.ipv6,
    bot_token=glovar.bot_token,
    workdir=glovar.SESSION_DIR_PATH,
    config_file=glovar.CONFIG_PATH,
    sleep_threshold=0
)
app.start()

# Start the bot
delay(10, restart_program, [app, glovar.creator_id])

# Start update
sleep(glovar.interval)
interval_sec_n(app)

# Timer
scheduler = BackgroundScheduler(job_defaults={"misfire_grace_time": 60})
scheduler.add_job(interval_min_10, "interval", minutes=10)
scheduler.add_job(log_rotation, "cron", hour=23, minute=59)
scheduler.add_job(restart_program, "cron", [app], hour=glovar.restart, minute=get_int(glovar.restart_text))
scheduler.start()

# Hold
idle()