Ejemplo n.º 1
0
            username=("@" + (await escape_markdown(escape(user.username)))
                      if user.username else
                      (await
                       (mention_html(escape(user.first_name), user.id)))),
            mention=await (mention_html(escape(user.first_name), user.id)),
            chatname=escape(m.chat.title)
            if m.chat.type != "private" else escape(user.first_name),
            id=user.id,
        )
    else:
        teks = ""

    return teks


@Alita.on_message(command("cleanwelcome") & admin_filter)
async def cleanwlcm(_, m: Message):
    db = Greetings(m.chat.id)
    status = db.get_current_cleanwelcome_settings()
    args = m.text.split(" ", 1)

    if len(args) >= 2:
        if args[1].lower() == "on":
            db.set_current_cleanwelcome_settings(True)
            await m.reply_text("Turned on!")
            return
        if args[1].lower() == "off":
            db.set_current_cleanwelcome_settings(False)
            await m.reply_text("Turned off!")
            return
        await m.reply_text("what are you trying to do ??")
Ejemplo n.º 2
0
# initialise
bldb = Blacklist()
gbandb = GBan()
notesdb = Notes()
rulesdb = Rules()
userdb = Users()
appdb = Approve()
chatdb = Chats()
fldb = Filters()
pinsdb = Pins()
notesettings_db = NotesSettings()
warns_db = Warns()
warns_settings_db = WarnSettings()


@Alita.on_message(command("stats", DEV_PREFIX_HANDLER) & dev_filter)
async def get_stats(_, m: Message):
    replymsg = await m.reply_text("<b><i>Fetching Stats...</i></b>", quote=True)
    rply = (
        f"<b>Users:</b> <code>{(userdb.count_users())}</code> in <code>{(chatdb.count_chats())}</code> chats\n"
        f"<b>Anti Channel Pin:</b> <code>{(pinsdb.count_chats('antichannelpin'))}</code> enabled chats\n"
        f"<b>Clean Linked:</b> <code>{(pinsdb.count_chats('cleanlinked'))}</code> enabled chats\n"
        f"<b>Filters:</b> <code>{(fldb.count_filters_all())}</code> in <code>{(fldb.count_filters_chats())}</code> chats\n"
        f"    <b>Aliases:</b> <code>{(fldb.count_filter_aliases())}</code>\n"
        f"<b>Blacklists:</b> <code>{(bldb.count_blacklists_all())}</code> in <code>{(bldb.count_blackists_chats())}</code> chats\n"
        f"    <b>Action Specific:</b>\n"
        f"        <b>None:</b> <code>{(bldb.count_action_bl_all('none'))}</code> chats\n"
        f"        <b>Kick</b> <code>{(bldb.count_action_bl_all('kick'))}</code> chats\n"
        f"        <b>Warn:</b> <code>{(bldb.count_action_bl_all('warn'))}</code> chats\n"
        f"        <b>Ban</b> <code>{(bldb.count_action_bl_all('ban'))}</code> chats\n"
        f"<b>Rules:</b> Set in <code>{(rulesdb.count_chats())}</code> chats\n"
Ejemplo n.º 3
0
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from asyncio import sleep

from pyrogram.errors import MessageDeleteForbidden, RPCError
from pyrogram.types import Message

from alita import SUPPORT_GROUP
from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils.custom_filters import admin_filter, command


@Alita.on_message(command("purge") & admin_filter)
async def purge(c: Alita, m: Message):

    if m.chat.type != "supergroup":
        await m.reply_text(tlang(m, "purge.err_basic"))
        return

    if m.reply_to_message:
        message_ids = list(range(m.reply_to_message.message_id, m.message_id))

        def divide_chunks(l, n):
            for i in range(0, len(l), n):
                yield l[i:i + n]

        # Dielete messages in chunks of 100 messages
        m_list = list(divide_chunks(message_ids, 100))
Ejemplo n.º 4
0
    InlineKeyboardButton,
    InlineKeyboardMarkup,
    Message,
)

from alita import BOT_ID, BOT_USERNAME, LOGGER, OWNER_ID, SUPPORT_GROUP, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, admin_cache_reload
from alita.utils.custom_filters import command, restrict_filter
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html
from alita.utils.string import extract_time


@Alita.on_message(command("tban") & restrict_filter)
async def tban_usr(c: Alita, m: Message):
    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text(tlang(m, "admin.ban.no_target"))
        await m.stop_propagation()

    try:
        user_id, user_first_name, _ = await extract_user(c, m)
    except Exception:
        return

    if not user_id:
        await m.reply_text("Cannot find user to ban")
        return
    if user_id == BOT_ID:
        await m.reply_text("Huh, why would I ban myself?")
Ejemplo n.º 5
0
from alita import HELP_COMMANDS, LOGGER
from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils.custom_filters import command
from alita.utils.kbhelpers import ikb
from alita.utils.start_utils import (
    gen_cmds_kb,
    gen_start_kb,
    get_help_msg,
    get_private_note,
    get_private_rules,
)


@Alita.on_message(
    command("donate") & (filters.group | filters.private),
)
async def donate(_, m: Message):
    LOGGER.info(f"{m.from_user.id} fetched donation text in {m.chat.id}")
    await m.reply_text(tlang(m, "general.donate_owner"))
    return


@Alita.on_callback_query(filters.regex("^close_admin$"))
async def close_admin_callback(_, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {"creator", "administrator"}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
Ejemplo n.º 6
0
from alita.utils.cmd_senders import send_cmd
from alita.utils.custom_filters import admin_filter, command, owner_filter
from alita.utils.msg_types import Types, get_note_type
from alita.utils.parser import mention_html
from alita.utils.string import (
    build_keyboard,
    escape_mentions_using_curly_brackets,
    parse_button,
)

# Initialise
db = Notes()
db_settings = NotesSettings()


@Alita.on_message(command("save") & admin_filter)
async def save_note(_, m: Message):

    existing_notes = [i[0] for i in db.get_all_notes(m.chat.id)]

    note_name, text, data_type, content = await get_note_type(m)
    note_name = note_name.lower()

    if note_name in existing_notes:
        await m.reply_text(f"This note ({note_name}) already exists!")
        return

    if not note_name:
        await m.reply_text(
            f"<code>{m.text}</code>\n\nError: You must give a name for this note!",
        )
Ejemplo n.º 7
0
    CallbackQuery,
    InlineKeyboardButton,
    InlineKeyboardMarkup,
    Message,
)

from alita import LOGGER
from alita.bot_class import Alita
from alita.database.rules_db import Rules
from alita.tr_engine import tlang
from alita.utils.custom_filters import admin_filter, command

db = Rules()


@Alita.on_message(command("rules") & filters.group)
async def get_rules(_, m: Message):

    chat_id = m.chat.id
    rules = db.get_rules(chat_id)
    LOGGER.info(f"{m.from_user.id} fetched rules in {m.chat.id}")

    if not rules:
        await m.reply_text(
            (tlang(m, "rules.no_rules")),
            quote=True,
        )
        return

    priv_rules_status = db.get_privrules(m.chat.id)
Ejemplo n.º 8
0
)
from alita.bot_class import Alita
from alita.database.antispam_db import GBan
from alita.database.users_db import Users
from alita.tr_engine import tlang
from alita.utils.clean_file import remove_markdown_and_html
from alita.utils.custom_filters import command, sudo_filter
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html

# Initialize
db = GBan()
user_db = Users()


@Alita.on_message(command(["gban", "globalban"]) & sudo_filter)
async def gban(c: Alita, m: Message):

    if len(m.text.split()) == 1:
        await m.reply_text(tlang(m, "antispam.gban.how_to"))
        return

    if len(m.text.split()) == 2 and not m.reply_to_message:
        await m.reply_text(tlang(m, "antispam.gban.enter_reason"))
        return

    user_id, user_first_name, _ = await extract_user(c, m)

    if m.reply_to_message:
        gban_reason = m.text.split(None, 1)[1]
    else:
Ejemplo n.º 9
0
from alita.database.approve_db import Approve
from alita.database.reporting_db import Reporting
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK, admin_cache_reload
from alita.utils.custom_filters import (
    DEV_LEVEL,
    admin_filter,
    command,
    owner_filter,
    promote_filter,
)
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html


@Alita.on_message(command("adminlist"))
async def adminlist_show(_, m: Message):
    global ADMIN_CACHE
    if m.chat.type != "supergroup":
        return await m.reply_text(
            "This command is made to be used in groups only!", )
    try:
        try:
            admin_list = ADMIN_CACHE[m.chat.id]
            note = tlang(m, "admin.adminlist.note_cached")
        except KeyError:
            admin_list = await admin_cache_reload(m, "adminlist")
            note = tlang(m, "admin.adminlist.note_updated")

        adminstr = (tlang(m, "admin.adminlist.adminstr")).format(
            chat_title=m.chat.title, ) + "\n\n"
Ejemplo n.º 10
0
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from asyncio import sleep

from pyrogram.errors import ChatAdminRequired, RPCError
from pyrogram.types import ChatPermissions, Message

from alita import LOGGER
from alita.bot_class import Alita
from alita.database.approve_db import Approve
from alita.tr_engine import tlang
from alita.utils.custom_filters import admin_filter, command, restrict_filter


@Alita.on_message(command("locktypes") & admin_filter)
async def lock_types(_, m: Message):
    await m.reply_text(("**Lock Types:**\n"
                        " - `all` = Everything\n"
                        " - `msg` = Messages\n"
                        " - `media` = Media, such as Photo and Video.\n"
                        " - `polls` = Polls\n"
                        " - `invite` = Add users to Group\n"
                        " - `pin` = Pin Messages\n"
                        " - `info` = Change Group Info\n"
                        " - `webprev` = Web Page Previews\n"
                        " - `inlinebots`, `inline` = Inline bots\n"
                        " - `animations` = Animations\n"
                        " - `games` = Game Bots\n"
                        " - `stickers` = Stickers"), )
    return
Ejemplo n.º 11
0
    InlineKeyboardMarkup,
    Message,
)

from alita import HELP_COMMANDS, LOGGER
from alita.bot_class import Alita
from alita.database.disable_db import Disabling
from alita.utils.custom_filters import (
    admin_filter,
    can_change_filter,
    command,
    owner_filter,
)


@Alita.on_message(command("disable") & can_change_filter)
async def disableit(_, m: Message):
    if len(m.text.split()) < 2:
        return await m.reply_text("What to disable?")
    disable_cmd_keys = sorted(
        k
        for j in [HELP_COMMANDS[i]["disablable"] for i in list(HELP_COMMANDS.keys())]
        for k in j
    )

    db = Disabling(m.chat.id)
    disable_list = db.get_disabled()
    LOGGER.info(f"{m.from_user.id} used disabled cmd in {m.chat.id}")

    if str(m.text.split(None, 1)[1]) in disable_list:
        return await m.reply_text("It's already disabled!")
Ejemplo n.º 12
0
from alita.database.antispam_db import GBan
from alita.database.approve_db import Approve
from alita.database.blacklist_db import Blacklist
from alita.database.chats_db import Chats
from alita.database.filters_db import Filters
from alita.database.greetings_db import Greetings
from alita.database.notes_db import Notes, NotesSettings
from alita.database.pins_db import Pins
from alita.database.rules_db import Rules
from alita.database.disable_db import Disabling
from alita.database.users_db import Users
from alita.database.warns_db import Warns, WarnSettings
from alita.utils.custom_filters import command


@Alita.on_message(command("stats", dev_cmd=True))
async def get_stats(_, m: Message):
    # initialise
    bldb = Blacklist
    gbandb = GBan()
    notesdb = Notes()
    rulesdb = Rules
    grtdb = Greetings
    userdb = Users
    dsbl = Disabling
    appdb = Approve
    chatdb = Chats
    fldb = Filters()
    pinsdb = Pins
    notesettings_db = NotesSettings()
    warns_db = Warns
Ejemplo n.º 13
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from pyrogram import filters
from pyrogram.errors import PeerIdInvalid, RPCError, UserNotParticipant
from pyrogram.types import CallbackQuery, ChatPermissions, Message

from alita import LOGGER, SUPPORT_GROUP
from alita.bot_class import Alita
from alita.database.approve_db import Approve
from alita.utils.custom_filters import admin_filter, command, owner_filter
from alita.utils.extract_user import extract_user
from alita.utils.kbhelpers import ikb
from alita.utils.parser import mention_html


@Alita.on_message(command("approve") & admin_filter)
async def approve_user(c: Alita, m: Message):
    db = Approve(m.chat.id)

    chat_title = m.chat.title

    try:
        user_id, user_first_name, _ = await extract_user(c, m)
    except Exception:
        return

    if not user_id:
        await m.reply_text(
            "I don't know who you're talking about, you're going to need to specify a user!",
        )
        return
Ejemplo n.º 14
0
from alita.database.approve_db import Approve
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK, admin_cache_reload
from alita.utils.custom_filters import (
    admin_filter,
    command,
    invite_filter,
    promote_filter,
)
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html

app_db = Approve()


@Alita.on_message(command("adminlist") & filters.group)
async def adminlist_show(_, m: Message):
    global ADMIN_CACHE
    try:
        try:
            admin_list = ADMIN_CACHE[m.chat.id]
            note = tlang(m, "admin.adminlist.note_cached")
        except KeyError:
            admin_list = await admin_cache_reload(m, "adminlist")
            note = tlang(m, "admin.adminlist.note_updated")

        adminstr = (tlang(m, "admin.adminlist.adminstr")).format(
            chat_title=m.chat.title,
        ) + "\n\n"

        # format is like: (user_id, username/name,anonyamous or not)
Ejemplo n.º 15
0
from alita.utils.cmd_senders import send_cmd
from alita.utils.custom_filters import admin_filter, command, owner_filter
from alita.utils.kbhelpers import ikb
from alita.utils.msg_types import Types, get_note_type
from alita.utils.string import (
    build_keyboard,
    escape_mentions_using_curly_brackets,
    parse_button,
)

# Initialise
db = Notes()
db_settings = NotesSettings()


@Alita.on_message(command("save") & admin_filter & ~filters.bot)
async def save_note(_, m: Message):
    existing_notes = {i[0] for i in db.get_all_notes(m.chat.id)}
    name, text, data_type, content = await get_note_type(m)
    total_notes = db.get_all_notes(m.chat.id)

    if len(total_notes) >= 1000:
        await m.reply_text(
            "Only 1000 Notes are allowed per chat!\nTo add more Notes, remove the existing ones.",
        )
        return

    if not name:
        await m.reply_text(
            f"<code>{m.text}</code>\n\nError: You must give a name for this note!",
        )
Ejemplo n.º 16
0
    RightForbidden,
    RPCError,
    UserNotParticipant,
)
from pyrogram.types import ChatPermissions, Message

from alita import LOGGER, SUPPORT_GROUP, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, admin_cache_reload
from alita.utils.custom_filters import command, restrict_filter
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html


@Alita.on_message(command("mute") & restrict_filter)
async def mute_usr(c: Alita, m: Message):
    from alita import BOT_ID

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text("I can't mute nothing!")
        return

    if m.reply_to_message and len(m.text.split()) >= 2:
        reason = m.text.split(None, 1)[1]
    elif not m.reply_to_message and len(m.text.split()) >= 3:
        reason = m.text.split(None, 2)[2]
    else:
        reason = None

    user_id, user_first_name, _ = await extract_user(c, m)
Ejemplo n.º 17
0
# 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 <http://www.gnu.org/licenses/>.

from pyrogram.errors import RPCError
from pyrogram.types import Message

from alita import DEV_USERS, LOGGER, OWNER_ID, SUDO_USERS, WHITELIST_USERS
from alita.bot_class import Alita
from alita.utils.custom_filters import command
from alita.utils.parser import mention_html


@Alita.on_message(command("botstaff", dev_cmd=True))
async def botstaff(c: Alita, m: Message):
    try:
        owner = await c.get_users(OWNER_ID)
        reply = f"<b>🌟 Owner:</b> {(await mention_html(owner.first_name, OWNER_ID))} (<code>{OWNER_ID}</code>)\n"
    except RPCError:
        pass
    true_dev = list(set(DEV_USERS) - {OWNER_ID})
    reply += "\n<b>Developers ⚡️:</b>\n"
    if true_dev == []:
        reply += "No Dev Users\n"
    else:
        for each_user in true_dev:
            user_id = int(each_user)
            try:
                user = await c.get_users(user_id)
Ejemplo n.º 18
0
    RPCError,
    UserAdminInvalid,
)
from pyrogram.types import Message

from alita import LOGGER, SUPPORT_GROUP, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, admin_cache_reload
from alita.utils.custom_filters import command, restrict_filter
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html


@Alita.on_message(
    command(["kick", "skick", "dkick"]) & restrict_filter, )
async def kick_usr(c: Alita, m: Message):
    from alita import BOT_ID

    if len(m.text.split()) == 1 and not m.reply_to_message:
        await m.reply_text(tlang(m, "admin.kick.no_target"))
        await m.stop_propagation()

    if m.reply_to_message:
        r_id = m.reply_to_message.message_id
        if len(m.text.split()) >= 2:
            reason = m.text.split(None, 1)[1]
    elif not m.reply_to_message:
        r_id = m.message_id
        if len(m.text.split()) >= 3:
            reason = m.text.split(None, 2)[2]
Ejemplo n.º 19
0

from html import escape

from pyrogram import filters
from pyrogram.types import CallbackQuery, Message

from alita import LOGGER
from alita.bot_class import Alita
from alita.database.blacklist_db import Blacklist
from alita.tr_engine import tlang
from alita.utils.custom_filters import command, owner_filter, restrict_filter
from alita.utils.kbhelpers import ikb


@Alita.on_message(command("blacklist") & filters.group)
async def view_blacklist(_, m: Message):
    db = Blacklist(m.chat.id)

    LOGGER.info(f"{m.from_user.id} checking blacklists in {m.chat.id}")

    chat_title = m.chat.title
    blacklists_chat = (tlang(m, "blacklist.curr_blacklist_initial")).format(
        chat_title=chat_title,
    )
    all_blacklisted = db.get_blacklists()

    if not all_blacklisted:
        await m.reply_text(
            (tlang(m, "blacklist.no_blacklist")).format(
                chat_title=chat_title,
Ejemplo n.º 20
0
from alita.utils.custom_filters import admin_filter, command, owner_filter
from alita.utils.kbhelpers import ikb
from alita.utils.msg_types import Types, get_filter_type
from alita.utils.regex_utils import regex_searcher
from alita.utils.string import (
    build_keyboard,
    escape_mentions_using_curly_brackets,
    parse_button,
    split_quotes,
)

# Initialise
db = Filters()


@Alita.on_message(command("filters") & filters.group & ~filters.bot)
async def view_filters(_, m: Message):
    LOGGER.info(f"{m.from_user.id} checking filters in {m.chat.id}")

    filters_chat = f"Список фильтров в чате <b>{m.chat.title}</b>:\n"
    all_filters = db.get_all_filters(m.chat.id)
    actual_filters = [j for i in all_filters for j in i.split("|")]

    if not actual_filters:
        await m.reply_text(f"Нет фильтров в чате {m.chat.title}")
        return

    filters_chat += "\n".join([
        f" • {' | '.join([f'<code>{i}</code>' for i in i.split('|')])}"
        for i in all_filters
    ], )
Ejemplo n.º 21
0
from alita.utils.kbhelpers import ikb


async def gen_formatting_kb(m):
    return ikb([
        [
            ("Markdown Formatting", "formatting.md_formatting"),
            ("Fillings", "formatting.fillings"),
        ],
        [("Random Content", "formatting.random_content")],
        [(("« " + (tlang(m, "general.back_btn"))), "commands")],
    ], )


@Alita.on_message(
    command(["markdownhelp", "formatting"]) & filters.private, )
async def markdownhelp(_, m: Message):
    await m.reply_text(
        tlang(m, f"plugins.{__PLUGIN__}.help"),
        quote=True,
        reply_markup=(await gen_formatting_kb(m)),
    )
    LOGGER.info(f"{m.from_user.id} used cmd '{m.command}' in {m.chat.id}")
    return


@Alita.on_callback_query(filters.regex("^formatting."))
async def get_formatting_info(_, q: CallbackQuery):
    cmd = q.data.split(".")[1]
    kb = ikb([[((tlang(q, "general.back_btn")), "back.formatting")]])
Ejemplo n.º 22
0
from traceback import format_exc

from pyrogram.errors import PeerIdInvalid, RPCError
from pyrogram.types import Message

from alita import LOGGER
from alita.bot_class import Alita
from alita.database.group_blacklist import GroupBlacklist
from alita.utils.custom_filters import command

# initialise database
db = GroupBlacklist()


@Alita.on_message(command("blchat", dev_cmd=True))
async def blacklist_chat(c: Alita, m: Message):
    if len(m.text.split()) >= 2:
        chat_ids = m.text.split()[1:]
        replymsg = await m.reply_text(
            f"Adding {len(chat_ids)} chats to blacklist")
        LOGGER.info(f"{m.from_user.id} blacklisted {chat_ids} groups for bot")
        for chat in chat_ids:
            try:
                get_chat = await c.get_chat(chat)
                chat_id = get_chat.id
                db.add_chat(chat_id)
            except PeerIdInvalid:
                await replymsg.edit_text(
                    "Haven't seen this group in this session, maybe try again later?",
                )
Ejemplo n.º 23
0
from alita import LOGGER, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.database.rules_db import Rules
from alita.database.users_db import Users
from alita.database.warns_db import Warns, WarnSettings
from alita.tr_engine import tlang
from alita.utils.caching import ADMIN_CACHE, admin_cache_reload
from alita.utils.custom_filters import admin_filter, command, restrict_filter
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html
from alita.vars import Config


@Alita.on_message(
    command(["warn", "swarn", "dwarn"]) & restrict_filter,
)
async def warn(c: Alita, m: Message):
    if m.reply_to_message:
        r_id = m.reply_to_message.message_id
        if len(m.text.split()) >= 2:
            reason = m.text.split(None, 1)[1]
        else:
            reason = None
    elif not m.reply_to_message:
        r_id = m.message_id
        if len(m.text.split()) >= 3:
            reason = m.text.split(None, 2)[2]
        else:
            reason = None
    else:
Ejemplo n.º 24
0
from alita import BOT_ID, LOGGER, MESSAGE_DUMP, SUPPORT_GROUP, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.database.antispam_db import GBan
from alita.database.users_db import Users
from alita.tr_engine import tlang
from alita.utils.clean_file import remove_markdown_and_html
from alita.utils.custom_filters import command
from alita.utils.extract_user import extract_user
from alita.utils.parser import mention_html

# Initialize
db = GBan()


@Alita.on_message(command(["gban", "globalban"], sudo_cmd=True))
async def gban(c: Alita, m: Message):
    if len(m.text.split()) == 1:
        await m.reply_text(tlang(m, "antispam.gban.how_to"))
        return

    if len(m.text.split()) == 2 and not m.reply_to_message:
        await m.reply_text(tlang(m, "antispam.gban.enter_reason"))
        return

    user_id, user_first_name, _ = await extract_user(c, m)

    if m.reply_to_message:
        gban_reason = m.text.split(None, 1)[1]
    else:
        gban_reason = m.text.split(None, 2)[2]
Ejemplo n.º 25
0
                    callback_data="start_back",
                ),
            ],
        ], )
    else:
        keyboard = None
    await q.message.edit_text(
        f"🌐 {((tlang(q, 'langs.changed')).format(lang_code=lang_code))}",
        reply_markup=keyboard,
    )
    await q.answer()
    return


@Alita.on_message(
    command(["lang", "setlang"]) & (admin_filter | filters.private),
    group=7,
)
async def set_lang(_, m: Message):

    args = m.text.split()

    if len(args) > 2:
        await m.reply_text(tlang(m, "langs.correct_usage"))
        return
    if len(args) == 2:
        lang_code = args[1]
        avail_langs = set(lang_dict.keys())
        if lang_code not in avail_langs:
            await m.reply_text(
                f"Please choose a valid language code from: {', '.join(avail_langs)}",
Ejemplo n.º 26
0
# 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 <http://www.gnu.org/licenses/>.


from time import time

from pyrogram.types import Message

from alita import DEV_PREFIX_HANDLER
from alita.bot_class import Alita
from alita.utils.custom_filters import command, sudo_filter


@Alita.on_message(command("test", DEV_PREFIX_HANDLER) & sudo_filter, group=15)
async def test_bot(_, m: Message):
    start = time()
    replymsg = await m.reply_text("Calculating...")
    end = round(time() - start, 2)
    await replymsg.edit_text(f"Test complete\nTime Taken:{end} seconds")
    return
Ejemplo n.º 27
0
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from html import escape
from secrets import choice

from pyrogram.types import Message

from alita.bot_class import Alita
from alita.tr_engine import tlang
from alita.utils import fun_strings
from alita.utils.custom_filters import command
from alita.utils.extract_user import extract_user


@Alita.on_message(command("shout"))
async def fun_shout(_, m: Message):

    if len(m.text.split()) == 1:
        await m.reply_text(
            (tlang(m, "general.check_help")),
            quote=True,
        )
        return
    text = " ".join(m.text.split(None, 1)[1])
    result = []
    result.append(" ".join(list(text)))
    for pos, symbol in enumerate(text[1:]):
        result.append(symbol + " " + "  " * pos + symbol)
    result = list("\n".join(result))
    result[0] = text[0]
Ejemplo n.º 28
0
from traceback import format_exc

from pyrogram import filters
from pyrogram.errors import PeerIdInvalid, RPCError, Unauthorized, UserIsBlocked
from pyrogram.types import CallbackQuery, Message

from alita import LOGGER, SUPPORT_STAFF
from alita.bot_class import Alita
from alita.database.reporting_db import Reporting
from alita.utils.custom_filters import admin_filter, command
from alita.utils.kbhelpers import ikb
from alita.utils.parser import mention_html


@Alita.on_message(
    command("reports") & (filters.private | admin_filter), )
async def report_setting(_, m: Message):
    args = m.text.split()
    db = Reporting(m.chat.id)

    if m.chat.type == "private":
        if len(args) >= 2:
            option = args[1].lower()
            if option in ("yes", "on", "true"):
                db.set_settings(True)
                LOGGER.info(f"{m.from_user.id} enabled reports for them")
                await m.reply_text(
                    "Turned on reporting! You'll be notified whenever anyone reports something in groups you are admin.",
                )

            elif option in ("no", "off", "false"):
Ejemplo n.º 29
0
from pyrogram.types import Message
from speedtest import Speedtest

from alita import LOGFILE, LOGGER, MESSAGE_DUMP, UPTIME
from alita.bot_class import Alita
from alita.database.chats_db import Chats
from alita.tr_engine import tlang
from alita.utils.clean_file import remove_markdown_and_html
from alita.utils.custom_filters import command
from alita.utils.http_helper import HTTPx
from alita.utils.kbhelpers import ikb
from alita.utils.parser import mention_markdown
from alita.vars import Config


@Alita.on_message(command("ping", sudo_cmd=True))
async def ping(_, m: Message):
    LOGGER.info(f"{m.from_user.id} used ping cmd in {m.chat.id}")
    start = time()
    replymsg = await m.reply_text((tlang(m, "utils.ping.pinging")), quote=True)
    delta_ping = time() - start
    await replymsg.edit_text(f"<b>Pong!</b>\n{delta_ping * 1000:.3f} ms")
    return


@Alita.on_message(command("logs", dev_cmd=True))
async def send_log(c: Alita, m: Message):
    replymsg = await m.reply_text("Sending logs...!")
    await c.send_message(
        MESSAGE_DUMP,
        f"#LOGS\n\n**User:** {(await mention_markdown(m.from_user.first_name, m.from_user.id))}",
Ejemplo n.º 30
0
from alita.bot_class import Alita
from alita.database.antispam_db import GBan
from alita.database.users_db import Users
from alita.tr_engine import tlang
from alita.utils.clean_file import remove_markdown_and_html
from alita.utils.custom_filters import command
from alita.utils.extract_user import extract_user
from alita.utils.http_helper import HTTPx, http
from alita.utils.kbhelpers import ikb
from alita.utils.parser import mention_html
from alita.vars import Config

gban_db = GBan()


@Alita.on_message(command("wiki"))
async def wiki(_, m: Message):
    LOGGER.info(f"{m.from_user.id} used wiki cmd in {m.chat.id}")

    if len(m.text.split()) <= 1:
        return await m.reply_text(tlang(m, "general.check_help"))

    search = m.text.split(None, 1)[1]
    try:
        res = summary(search)
    except DisambiguationError as de:
        return await m.reply_text(
            f"Disambiguated pages found! Adjust your query accordingly.\n<i>{de}</i>",
            parse_mode="html",
        )
    except PageError as pe: