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 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 #4
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)