Example #1
0
def ban_user(user_list, ban=True):
    session = DBSession()
    for user_data in user_list:
        session.merge(
            User(id=user_data.id, isban=ban, username=user_data.username))
    session.commit()
    session.close()
Example #2
0
def run(bot, update, chat_data):
    """Run bot filter function
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return:
    """
    if chat_data.get(ChatData.RUN):
        bot.send_message(chat_id=update.message.chat_id, text=BOT_RUN_MSG)
        return
    bot_id = bot.id
    group_info = bot.get_chat_member(update.message.chat_id, bot_id)
    if group_info['status'] != ChatMember.ADMINISTRATOR:
        bot.send_message(chat_id=update.message.chat_id, text=BOT_NO_ADMIN_MSG)
        return
    session = DBSession()
    if update.message.chat.type == Chat.SUPERGROUP:
        group_link = bot.export_chat_invite_link(
            chat_id=update.message.chat_id)
    else:
        group_link = ""
    group = Group(id=update.message.chat_id,
                  title=update.message.chat.title,
                  link=group_link)
    session.merge(group)
    session.commit()
    session.close()
    chat_data[ChatData.RUN] = True
    bot.send_message(chat_id=update.message.chat_id, text=BOT_IS_ADMIN_MSG)
Example #3
0
def update_ban_list():
    logging.debug('update ban list ing')
    session = DBSession()
    db_admin = session.query(User).filter_by(isban=True).all()
    global ban_list
    ban_list = [int(user.id) for user in db_admin]
    logging.debug(f"ban list {ban_list}")
    session.close()
Example #4
0
def update_admin_list():
    logging.debug('update admin list ing')
    session = DBSession()
    db_admin = session.query(User.id).filter_by(isadmin=True).all()
    global admin_list
    admin_list = ADMIN + [int(user.id) for user in db_admin]
    logging.debug(f"admin list {admin_list}")
    session.close()
Example #5
0
def forward_group(bot, update):
    session = DBSession()
    users = session.query(Group).all()
    for user in users:
        update.message.forward(user.id)
        sleep(SEND_SLEEP)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
Example #6
0
 def wrapper(bot, update, *args, **kwargs):
     session = DBSession()
     user = session.query(User).filter(
         User.id == update.message.chat_id).first()
     session.close()
     if user is None:
         bot.send_message(
             chat_id=update.message.chat_id,
             text=NO_BIND_MSG)
         return
     return func(bot, update,  *args, **kwargs)
Example #7
0
def start(bot, update):
    """
    send start info
    """
    bot.send_message(chat_id=update.message.chat_id, text=START_MSG)
    session = DBSession()
    user = session.query(User).filter_by(
        id=update.message.from_user['id']).first()
    if user is None:
        session.add(User(id=update.message.from_user['id']))
    session.commit()
    session.close()
Example #8
0
def send_user(bot, update):
    session = DBSession()
    users = session.query(User).all()
    if not (Filters.text(update.message) | Filters.sticker(update.message)
            | Filters.photo(update.message) | Filters.video(update.message)
            | Filters.document(update.message)):
        bot.send_message(chat_id=update.message.id, text=NO_SUPPORT_FORMAT)
        return
    send_admin_msg(users=users, bot=bot, update=update)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
Example #9
0
def send_group(bot, update):
    """
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return
    """
    session = DBSession()
    groups = session.query(Group).all()
    send_admin_msg(users=groups, bot=bot, update=update)
    bot.send_message(chat_id=update.message.chat_id, text=USER_FORWARD_STOP)
    session.close()
    return ConversationHandler.END
Example #10
0
def bind(bot, update, args):
    """
    usage: /bind username password
    """
    if len(args) != 2:
       bot.send_message(
    chat_id=update.message.chat_id,
    text=getdoc(
        globals()[
            getframeinfo(
                currentframe()).function]))
       return
    session = DBSession()
    user = User(id=update.message.chat_id, username=args[0], password=args[1])
    session.merge(user)
    session.commit()
    session.close()
    bot.send_message(chat_id=update.message.chat_id, text=BIND_OK_MSG)
Example #11
0
def globalban_list(bot, update):
    """
    show globalban user list
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return:
    """
    session = DBSession()
    datas = session.query(User).filter_by(isban=True).all()
    ret_text = ""
    for data in datas:
        ret_text = ret_text + GLOBAL_BAN_FORMAT.format(user_id=data.id)
    session.close()
    if ret_text == "":
        bot.send_message(chat_id=update.message.chat_id, text=NO_INFO_MSG)
        return
    bot.send_message(chat_id=update.message.chat_id,
                     text=ret_text,
                     parse_mode=ParseMode.MARKDOWN)
Example #12
0
def get_groups(bot, update):
    """
    :param bot:
    :type bot: Bot
    :param update:
    :type update: Update
    :return:
    """
    session = DBSession()
    groups = session.query(Group).all()
    if groups is None:
        bot.send_message(chat_id=update.message.chat_id, text=NO_INFO_MSG)
        session.close()
        return
    ret_text = ""
    for group in groups:
        ret_text = ret_text + GROUP_FORMAT.format(
            group_title=group.title, group_id=group.id, group_link=group.link)
    bot.send_message(chat_id=update.message.chat_id,
                     text=ret_text,
                     parse_mode=ParseMode.MARKDOWN)
    session.close()
Example #13
0
def add_admin(bot, update, args):
    """
    add admin
    :param bot:
    :param update:
    :param args:
    :return:
    """
    if not len(args):
        bot.send_message(chat_id=update.message.chat_id, text=ARG_ERROR_MSG)
        return
    session = DBSession()
    for user_id in args:
        if not user_id.isdigit():
            bot.send_message(chat_id=update.message.chat_id,
                             text=USERID_ERROR_MSG)
            return
        user = User(id=user_id, isadmin=True)
        session.merge(user)
    session.commit()
    session.close()
    update_admin_list()
    bot.send_message(chat_id=update.message.chat_id, text=ADD_ADMIN_OK_MSG)