コード例 #1
0
ファイル: rules.py プロジェクト: timurmoore/timoore
def send_rules(update, chat_id, from_pm=False):
    bot = dispatcher.bot
    chat = update.effective_chat
    user = update.effective_user
    try:
        chat = bot.get_chat(chat_id)
    except BadRequest as excp:
        if excp.message == "Chat not found" and from_pm:
            bot.send_message(user.id,
                             tld(chat.id, "rules_shortcut_not_setup_properly"))
            return
        else:
            raise

    rules = sql.get_rules(chat_id)
    text = tld(chat.id, "rules_display").format(escape_markdown(chat.title),
                                                rules)

    if from_pm and rules:
        bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN)
    elif from_pm:
        bot.send_message(user.id, tld(chat.id, "rules_not_found"))
    elif rules:
        rules_text = tld(chat.id, "rules")
        update.effective_message.reply_text(
            tld(chat.id, "rules_button_click"),
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(text=rules_text,
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat_id))
            ]]))
    else:
        update.effective_message.reply_text(tld(chat.id, "rules_not_found"))
コード例 #2
0
ファイル: rules.py プロジェクト: MhdRezza/Eva
def send_rules(update, chat_id, from_pm=False):
    bot = dispatcher.bot
    user = update.effective_user  # type: Optional[User]
    try:
        chat = bot.get_chat(chat_id)
    except BadRequest as excp:
        if excp.message == "Chat not found" and from_pm:
            bot.send_message(
                user.id,
                "The rules shortcut for this chat hasn't been set properly! Ask admins to "
                "fix this.")
            return
        else:
            raise

    rules, buttons = button_markdown_parser(sql.get_rules(chat_id))
    text = "The rules for *{}* are:\n\n{}".format(escape_markdown(chat.title),
                                                  rules)

    if from_pm and rules:
        bot.send_message(user.id,
                         text,
                         parse_mode=ParseMode.MARKDOWN,
                         reply_markup=InlineKeyboardMarkup(
                             build_keyboard_alternate(buttons)))
    elif from_pm:
        bot.send_message(
            user.id,
            "The group admins haven't set any rules for this chat yet. "
            "This probably doesn't mean it's lawless though...!")
    elif rules:
        update.effective_message.reply_text(
            "Click the button below to get this group's rules.",
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton(text="Rules",
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat_id))
            ]]))
    else:
        update.effective_message.reply_text(
            "The group admins haven't set any rules for this chat yet. "
            "This probably doesn't mean it's lawless though...!")
コード例 #3
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:
    bot = dispatcher.bot

    if is_user_admin(chat, user.id):
        message.reply_text(tld(chat.id, 'warns_warn_admin_no_warn'))
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = tld(chat.id, 'warns_warn_admin_autofilter')

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # kick
            chat.unban_member(user.id)
            reply = tld(chat.id, 'warns_max_warn_kick').format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = tld(chat.id, 'warns_max_warn_ban').format(
                limit, mention_html(user.id, user.first_name))

        for warn_reason in reasons:
            reply += "\n - {}".format(html.escape(warn_reason))

        keyboard = []
        log_reason = tld(chat.id, 'warns_warn_ban_log_channel').format(
            html.escape(chat.title), warner_tag,
            mention_html(user.id, user.first_name), user.id, reason, num_warns,
            limit)

    else:
        keyboard = [[
            InlineKeyboardButton(tld(chat.id, 'warns_btn_remove_warn'),
                                 callback_data="rm_warn({})".format(user.id))
        ]]
        rules = rules_sql.get_rules(chat.id)

        if rules:
            keyboard[0].append(
                InlineKeyboardButton(tld(chat.id, 'warns_btn_rules'),
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat.id)))

        reply = tld(chat.id, 'warns_user_warned').format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += tld(chat.id, 'warns_latest_warn_reason').format(
                html.escape(reason))

        log_reason = tld(chat.id, 'warns_warn_log_channel').format(
            html.escape(chat.title), warner_tag,
            mention_html(user.id, user.first_name), user.id, reason, num_warns,
            limit)

    try:
        message.reply_text(reply,
                           reply_markup=InlineKeyboardMarkup(keyboard),
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(reply,
                               reply_markup=InlineKeyboardMarkup(keyboard),
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
コード例 #4
0
ファイル: rules.py プロジェクト: MhdRezza/hitsuki
def send_rules(update, chat_id, from_pm=False):
    bot = dispatcher.bot
    user = update.effective_user
    try:
        chat = bot.get_chat(chat_id)
    except BadRequest as excp:
        if excp.message == "Chat not found" and from_pm:
            bot.send_message(user.id, tl(update.effective_message,
                                         "Pintasan aturan untuk obrolan ini belum diatur dengan benar! Mintalah admin untuk "
                                         "perbaiki ini."))
            return
        else:
            raise

    conn = connected(bot, update, chat, user.id, need_admin=False)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title

    rules, buttons = button_markdown_parser(sql.get_rules(chat_id))
    try:
        text = tl(update.effective_message, "Peraturan untuk *{}* adalah:\n\n{}").format(escape_markdown(chat.title),
                                                                                         rules)
    except TypeError:
        send_message(update.effective_message,
                     tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM"))
        return ""

    is_private = sql.get_private_rules(chat_id)

    if from_pm and rules:
        bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN,
                         reply_markup=InlineKeyboardMarkup(build_keyboard_alternate(buttons)))
    elif from_pm:
        if conn:
            bot.send_message(user.id,
                             tl(update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk *{}*. "
                                                          "Bukan berarti obrolan ini tanpa hukum...!").format(
                                 chat_name), parse_mode="markdown")
        else:
            bot.send_message(user.id, tl(update.effective_message,
                                         "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. "
                                         "Bukan berarti obrolan ini tanpa hukum...!"))
    elif rules:
        if (update.effective_message.chat.type == "private" or not is_private) and rules:
            if not is_private:
                send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN,
                             reply_markup=InlineKeyboardMarkup(build_keyboard_alternate(buttons)))
            else:
                bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN,
                                 reply_markup=InlineKeyboardMarkup(build_keyboard_alternate(buttons)))
        else:
            send_message(update.effective_message,
                         tl(update.effective_message, "Hubungi saya di PM untuk mendapatkan aturan grup ini"),
                         reply_markup=InlineKeyboardMarkup(
                             [[InlineKeyboardButton(text=tl(update.effective_message, "Peraturan"),
                                                    url="t.me/{}?start={}".format(bot.username,
                                                                                  chat_id))]]))
    else:
        if conn:
            send_message(update.effective_message,
                         tl(update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk *{}*. "
                                                      "Bukan berarti obrolan ini tanpa hukum...!").format(chat_name),
                         parse_mode="markdown")
        else:
            send_message(update.effective_message,
                         tl(update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. "
                                                      "Bukan berarti obrolan ini tanpa hukum...!"))
コード例 #5
0
ファイル: rules.py プロジェクト: MhdRezza/hitsuki
def __chat_settings__(chat_id, user_id):
    return tl(user_id, "Obrolan ini memiliki aturan yang ditetapkan: `{}`").format(bool(sql.get_rules(chat_id)))
コード例 #6
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:
    bot = dispatcher.bot

    if is_user_admin(chat, user.id):
        message.reply_text("I'm not going to warn an admin!")
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = "Automated warn filter."

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # kick
            chat.unban_member(user.id)
            reply = "{} warnings, {} has been kicked!".format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = "{} warnings, {} has been banned!".format(
                limit, mention_html(user.id, user.first_name))

        for warn_reason in reasons:
            reply += "\n - {}".format(html.escape(warn_reason))

        message.bot.send_sticker(chat.id,
                                 BAN_STICKER)  # banhammer marie sticker
        keyboard = []
        log_reason = "<b>{}:</b>" \
                     "\n#WARN_BAN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}" \
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)
    else:
        keyboard = [[
            InlineKeyboardButton("тЪая╕П Remove warn",
                                 callback_data="rm_warn({})".format(user.id))
        ]]
        rules = rules_sql.get_rules(chat.id)

        if rules:
            keyboard[0].append(
                InlineKeyboardButton("ЁЯУЭ Rules",
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat.id)))

        reply = "{} <b>has been warned!</b>\nThey have {}/{} warnings.".format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += "\nThe latest warning was because:\n<code>{}</code>".format(
                html.escape(reason))

        log_reason = "<b>{}:</b>" \
                     "\n#WARN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}" \
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    try:
        message.reply_text(reply,
                           reply_markup=InlineKeyboardMarkup(keyboard),
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(reply,
                               reply_markup=InlineKeyboardMarkup(keyboard),
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
コード例 #7
0
ファイル: rules.py プロジェクト: MhdRezza/Eva
def __chat_settings__(bot, update, chat, chatP, user):
    return "This chat has had it's rules set: `{}`".format(
        bool(sql.get_rules(chat.id)))