示例#1
0
    InlineKeyboardMarkup,
    Message,
    ParseMode,
    User,
)
from telegram.error import BadRequest
from telegram.ext import CommandHandler, Filters
from telegram.utils.helpers import escape_markdown

from ferbot import dispatcher
from ferbot.modules.no_sql import get_collection
from ferbot.modules.helper_funcs.alternate import typing_action
from ferbot.modules.helper_funcs.chat_status import user_admin
from ferbot.modules.helper_funcs.string_handling import markdown_parser

RULES_DATA = get_collection("RULES")


@typing_action
def get_rules(update, context):
    chat_id = update.effective_chat.id
    send_rules(update, chat_id)


# Do not async - not from a handler
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:
示例#2
0
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Global bans utils."""

from ferbot.modules.no_sql import get_collection

GBAN_USER = get_collection("GBANS")
GBAN_SETTINGS = get_collection("GBAN_SETTINGS")
GBANNED_LIST = set()
GBANSTAT_LIST = set()


def gban_user(user_id, name, reason=None) -> None:
    GBAN_USER.insert_one({
        '_id': user_id,
        'name': name,
        'reason': reason,
    })
    __load_gbanned_userid_list()


def update_gban_reason(user_id, name, reason) -> str:
示例#3
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import html
from typing import Optional

from telegram import MAX_MESSAGE_LENGTH, Message, ParseMode, User
from telegram.utils.helpers import escape_markdown

from ferbot import DEV_USERS, dispatcher
from ferbot.modules.disable import DisableAbleCommandHandler
from ferbot.modules.no_sql import get_collection
from ferbot.modules.helper_funcs.alternate import typing_action
from ferbot.modules.helper_funcs.extraction import extract_user

USER_INFO = get_collection("USER_INFO")
USER_BIO = get_collection("USER_BIO")


@typing_action
def about_me(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args
    user_id = extract_user(message, args)

    if user_id:
        user = context.bot.get_chat(user_id)
    else:
        user = message.from_user

    info = USER_INFO.find_one({'_id': user.id})
示例#4
0
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Chat blacklist database."""

from ferbot.modules.no_sql import get_collection

BL = get_collection("BLACKLIST")
BL_SETTING = get_collection("BLACKLIST_SETTINGS")

CHAT_BLACKLISTS = {}
CHAT_SETTINGS_BLACKLISTS = {}


def add_to_blacklist(chat_id, trigger):
    BL.find_one_and_update({
        'chat_id': chat_id,
        'trigger': trigger
    }, {"$set": {
        'chat_id': chat_id,
        'trigger': trigger
    }},
                           upsert=True)
示例#5
0
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""User database utils."""

from ferbot import dispatcher
from ferbot.modules.no_sql import get_collection

USERS_DB = get_collection("USERS")
CHATS_DB = get_collection("CHATS")
CHAT_MEMBERS_DB = get_collection("CHAT_MEMBERS")


def ensure_bot_in_db():
    USERS_DB.update_one(
        {'_id': dispatcher.bot.id},
        {"$set": {
            'username': dispatcher.bot.username
        }},
        upsert=True,
    )


def update_user(user_id, username, chat_id=None, chat_name=None):
示例#6
0
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""User(s) AFK database."""

from ferbot.modules.no_sql import get_collection

AFK_USERS = get_collection("AFK_USERS")
AFK_LIST = set()


def is_afk(user_id) -> bool:
    return user_id in AFK_LIST


def check_afk_status(user_id) -> dict:
    data = AFK_USERS.find_one({'_id': user_id})
    return data


def set_afk(user_id, reason: str = "") -> None:
    AFK_USERS.update_one({'_id': user_id}, {"$set": {
        'reason': reason
示例#7
0
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Group disabled commands database."""

from ferbot.modules.no_sql import get_collection

DISABLED_COMMANDS = get_collection("DISABLED_COMMANDS")

DISABLED = {}


def disable_command(chat_id, disable) -> bool:
    data = DISABLED_COMMANDS.find_one(
        {'chat_id': chat_id, 'command': disable})
    if not data:
        DISABLED.setdefault(str(chat_id), set()).add(disable)

        DISABLED_COMMANDS.insert_one(
            {'chat_id': chat_id, 'command': disable})
        return True
    return False
示例#8
0
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Channel log database."""

from ferbot.modules.no_sql import get_collection


LOG_DATA = get_collection("LOG_CHANNELS")

CHANNELS = {}


def set_chat_log_channel(chat_id, log_channel):
    LOG_DATA.update_one(
        {'chat_id': chat_id},
        {"$set": {'log_channel': log_channel}},
        upsert=True
    )
    CHANNELS[str(chat_id)] = log_channel


def get_chat_log_channel(chat_id) -> int:
    return CHANNELS.get(str(chat_id))
示例#9
0
    MessageHandler,
)
from telegram.utils.helpers import mention_html

from ferbot import LOGGER, dispatcher
from ferbot.modules.helper_funcs.alternate import typing_action
from ferbot.modules.helper_funcs.chat_status import (
    user_admin,
    user_not_admin,
)
from ferbot.modules.log_channel import loggable
from ferbot.modules.no_sql import get_collection

REPORT_GROUP = 5

USER_REPORT_SETTINGS = get_collection("USER_REPORT_SETTINGS")
CHAT_REPORT_SETTINGS = get_collection("CHAT_REPORT_SETTINGS")


@user_admin
@typing_action
def report_setting(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

    if chat.type == chat.PRIVATE:
        if len(args) >= 1:
            if args[0] in ("yes", "on", "true"):
                USER_REPORT_SETTINGS.update_one(
                    {'user_id': int(chat.id)},
示例#10
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import time

import requests
from telegram import ParseMode, error
from telegram.ext import CommandHandler

from ferbot import LASTFM_API_KEY, dispatcher
from ferbot.modules.no_sql import get_collection
from ferbot.modules.disable import DisableAbleCommandHandler
from ferbot.modules.helper_funcs.alternate import typing_action

LASTFM_USER = get_collection("LAST_FM")


@typing_action
def set_user(update, context):
    msg = update.effective_message
    args = context.args
    if args:
        user = update.effective_user.id
        username = "******".join(args)
        if LASTFM_USER.find_one({'_id': user}):
            LASTFM_USER.find_one_and_update({'_id': user},
                                            {"$set": {
                                                'username': username
                                            }})
            del_msg = msg.reply_text(f"Username updated to {username}!")