Esempio n. 1
0
from typing import Dict

from userbot import userbot, Message, Filters, get_collection

FILTERS_COLLECTION = get_collection("filters")

FILTERS_DATA: Dict[int, Dict[str, str]] = {}
FILTERS_CHATS = Filters.create(lambda _, query: query.chat.id in FILTERS_DATA)


def _filter_updater(chat_id: int, name: str, content: str) -> None:
    if chat_id in FILTERS_DATA:
        FILTERS_DATA[chat_id].update({name: content})
    else:
        FILTERS_DATA[chat_id] = {name: content}


def _filter_deleter(chat_id: int, name: str) -> None:
    if chat_id in FILTERS_DATA and name in FILTERS_DATA[chat_id]:
        FILTERS_DATA[chat_id].pop(name)
        if not FILTERS_DATA[chat_id]:
            FILTERS_DATA.pop(chat_id)


async def _init() -> None:
    async for flt in FILTERS_COLLECTION.find():
        _filter_updater(flt['chat_id'], flt['name'], flt['content'])


@userbot.on_cmd("filters", about={'header': "List all saved filters"})
async def filters_active(message: Message) -> None:
Esempio n. 2
0
import json

import requests
import spamwatch

from userbot import userbot, Message, Config, get_collection, Filters

GBAN_USER_BASE = get_collection("GBAN_USER")
WHITELIST = get_collection("WHITELIST_USER")
GBAN_LOG = userbot.getCLogger(__name__)
LOG = userbot.getLogger(__name__)


async def is_admin(message: Message, me_id):
    check_user = await userbot.get_chat_member(message.chat.id, me_id)
    user_type = check_user.status
    if user_type == "member":
        return False
    if user_type == "administrator":
        rm_perm = check_user.can_restrict_members
        if rm_perm:
            return True
        return False
    return True


async def guadmin_check(chat_id, user_id) -> bool:
    check_status = await userbot.get_chat_member(chat_id=chat_id, user_id=user_id)
    admin_strings = ["creator", "administrator"]
    if check_status.status not in admin_strings:
        return False
Esempio n. 3
0
_CREDS: object = None
_AUTH_FLOW: object = None
_PARENT_ID = ""
OAUTH_SCOPE = [
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/drive.metadata"
]
REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder"
G_DRIVE_FILE_LINK = "📄 <a href='https://drive.google.com/open?id={}'>{}</a> __({})__"
G_DRIVE_FOLDER_LINK = "📁 <a href='https://drive.google.com/drive/folders/{}'>{}</a> __(folder)__"

_LOG = userbot.getLogger(__name__)
_GDRIVE_COLLECTION = get_collection("gdrive")


class _DBase:
    """Database Class for GDrive"""
    def __init__(self, id_: str) -> None:
        self._id = id_
        asyncio.get_event_loop().run_until_complete(self._init())

    async def _init(self) -> None:
        global _CREDS
        _LOG.debug("Setting GDrive DBase...")
        if not _CREDS:
            result = await _GDRIVE_COLLECTION.find_one({'_id': self._id},
                                                       {'creds': 1})
            _CREDS = pickle.loads(result['creds']) if result else None
Esempio n. 4
0
import asyncio

from pyrogram.errors.exceptions.bad_request_400 import PeerIdInvalid

from userbot import userbot, Message, Config, get_collection

CHANNEL = userbot.getCLogger(__name__)

SUDO_USERS_COLLECTION = get_collection("sudo_users")
SUDO_CMDS_COLLECTION = get_collection("sudo_cmds")


async def _init() -> None:
    async for i in SUDO_USERS_COLLECTION.find():
        Config.SUDO_USERS.add(i['_id'])
    async for i in SUDO_CMDS_COLLECTION.find():
        Config.ALLOWED_COMMANDS.add(i['_id'])


@userbot.on_cmd("addsudo",
                about={
                    'header': "add sudo user",
                    'usage': "{tr}addsudo [username | reply to msg]"
                })
async def add_sudo(message: Message):
    user_id = message.input_str
    if message.reply_to_message:
        user_id = message.reply_to_message.from_user.id
    if not user_id:
        await message.err(f'user: `{user_id}` not found!')
        return
Esempio n. 5
0
from userbot import userbot, Message, Config, get_collection

SAVED_SETTINGS = get_collection("CONFIGS")


async def _init() -> None:
    msg_t = await SAVED_SETTINGS.find_one({'_id': 'MSG_DELETE_TIMEOUT'})
    if msg_t:
        Config.MSG_DELETE_TIMEOUT = msg_t['data']
    wel_t = await SAVED_SETTINGS.find_one({'_id': 'WELCOME_DELETE_TIMEOUT'})
    if wel_t:
        Config.WELCOME_DELETE_TIMEOUT = wel_t['data']
    pp_t = await SAVED_SETTINGS.find_one({'_id': 'AUTOPIC_TIMEOUT'})
    if pp_t:
        Config.AUTOPIC_TIMEOUT = pp_t['data']


@userbot.on_cmd("sdelto (\\d+)",
                about={
                    'header':
                    "Set auto message delete timeout",
                    'usage':
                    "{tr}sdelto [timeout in seconds]",
                    'examples':
                    "{tr}sdelto 15\n{tr}sdelto 0 : for disable deletion"
                })
async def set_delete_timeout(message: Message):
    """set delete timeout"""
    await message.edit("`Setting auto message delete timeout...`")
    t_o = int(message.matches[0].group(1))
    Config.MSG_DELETE_TIMEOUT = t_o
Esempio n. 6
0
from userbot import userbot, Message, get_collection

NOTES_COLLECTION = get_collection("notes")


@userbot.on_cmd("notes", about={'header': "List all saved notes"})
async def notes_active(message: Message) -> None:
    out = ''
    async for note in NOTES_COLLECTION.find({'chat_id': message.chat.id},
                                            {'name': 1}):
        out += " 📌 `{}`\n".format(note['name'])
    if out:
        await message.edit("**--Notes saved in this chat:--**\n\n" + out,
                           del_in=0)
    else:
        await message.err("There are no saved notes in this chat")


@userbot.on_cmd("delnote",
                about={
                    'header': "Deletes a note by name",
                    'usage': "{tr}delnote [note name]"
                })
async def remove_notes(message: Message) -> None:
    notename = message.input_str
    if not notename:
        out = "`Wrong syntax`\nNo arguements"
    elif await NOTES_COLLECTION.find_one_and_delete({
            'chat_id': message.chat.id,
            'name': notename
    }):
Esempio n. 7
0
import asyncio
from typing import Dict

from userbot import userbot, Filters, Message, Config, get_collection
from userbot.utils import SafeDict

CHANNEL = userbot.getCLogger(__name__)
SAVED_SETTINGS = get_collection("CONFIGS")
ALLOWED_COLLECTION = get_collection("PM_PERMIT")

allowAllPms = True
pmCounter: Dict[int, int] = {}
allowAllFilter = Filters.create(lambda _, query: bool(allowAllPms))
noPmMessage = ("Hello {fname} this is an automated message\n"
               "Please wait untill you get approved to direct message "
               "And please dont spam untill then ")


async def _init() -> None:
    global allowAllPms, noPmMessage
    async for chat in ALLOWED_COLLECTION.find({"status": 'allowed'}):
        Config.ALLOWED_CHATS.add(chat.get("_id"))
    _pm = await SAVED_SETTINGS.find_one({'_id': 'PM GUARD STATUS'})
    if _pm:
        allowAllPms = bool(_pm.get('data'))
    _pmMsg = await SAVED_SETTINGS.find_one({'_id': 'CUSTOM NOPM MESSAGE'})
    if _pmMsg:
        noPmMessage = _pmMsg.get('data')


@userbot.on_cmd(
Esempio n. 8
0
import base64
import asyncio

import aiofiles
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
from pyrogram import Message as RawMessage
from pyrogram.errors.exceptions import FileIdInvalid, FileReferenceEmpty
from pyrogram.errors.exceptions.bad_request_400 import BadRequest

from userbot import userbot, Filters, Message, Config, get_collection
from userbot.utils import SafeDict, progress, take_screen_shot

THUMB_PATH = Config.DOWN_PATH + "thumb_image.jpg"

WELCOME_COLLECTION = get_collection("welcome")
LEFT_COLLECTION = get_collection("left")
WELCOME_CHATS = Filters.chat([])
LEFT_CHATS = Filters.chat([])


async def _init() -> None:
    async for i in WELCOME_COLLECTION.find({'on': True}, {'_id': 1}):
        WELCOME_CHATS.add(i.get('_id'))
    async for i in LEFT_COLLECTION.find({'on': True}, {'_id': 1}):
        LEFT_CHATS.add(i.get('_id'))


@userbot.on_cmd("setwelcome", about={
    'header': "Creates a welcome message in current chat",
    'options': {