Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
0
def init_repo_data():
    import arrow
    import uuid
    session = DBSession()
    for i in range(1, 10):
        f = FileRouteModule()
        f.id = int(i)
        f.src_path = '/Users/Kevin/workspace/distributionfile/data'
        f.src_name = i
        f.src_extension = 'txt'
        f.retry_times = 0
        f.retry_interval = 0
        f.create_dt = arrow.utcnow().to('local').naive
        f.update_dt = arrow.utcnow().to('local').naive
        f.valid_from = arrow.utcnow().to('local').naive
        f.valid_to = arrow.utcnow().to('local').replace(days=365).naive
        f.tar_path = 'tmp/'
        f.tar_name = '{file}_{YMD}'.format(file=i, YMD='{YMD}')
        f.transtype = 'SFTP'
        f.ftpname = '10.8.4.116'
        session.add(f)

    f = session.query(FileRouteModule).get(9)
    f.tar_name = '9_{YM}'

    session.commit()
    session.close()
Example #7
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 #8
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 #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 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 #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 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 #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)
Example #14
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 #15
0
    def _blocked(self):
        self._p, self._f = os.path.split(self._filepath)
        self._f, self._ext = os.path.splitext(self._f)
        self._ext = self._ext.lower().replace('.', '')

        session = DBSession()

        logger.debug('Path:{path} File:{file}.{ext}'.format(
            path=self._p, file=self._f, ext=self._ext))

        tempate_f = getKeyName(self._f)

        if tempate_f:
            try:
                f = session.query(FileRouteModule).filter(FileRouteModule.src_path == self._p,
                                                          FileRouteModule.src_name == tempate_f).first()
                logger.debug(f)
                if f is None:
                    self.blocked = True
                    _f = session.query(FileRouteModule).filter(FileRouteModule.src_path == self._p,
                                                               FileRouteModule.src_name == '*', FileRouteModule.src_extension == self._ext).first()
                    if _f:
                        self.transtype = _f.transtype
                        self.ftpname = _f.ftpname
                        self.tar_path = _f.tar_path
                        self.tar_name = '{filenme}.{ext}'.format(
                            filename=self._f, ext=self._ext)
                        self.blocked = False
                elif f and f.src_extension.lower() != self._ext:
                    self.blocked = True
                else:
                    self.blocked = False

                    utcdt = arrow.utcnow().to('local')

                    # 目标目录生成
                    try:
                        tar_folder_dt_format_list = f.tar_folder_dt_format.split(
                            ',')
                        tar_folder_dt_format = tar_folder_dt_format_list[0]
                        tar_folder_dt_diff = int(tar_folder_dt_format_list[1])
                    except ValueError:
                        tar_folder_dt_diff = 0
                    except IndexError:
                        tar_folder_dt_diff = 0

                    if tar_folder_dt_format:
                        folder_timestamp = f.tar_path.format(DT=utcdt.replace(
                            days=tar_folder_dt_diff).format(tar_folder_dt_format))
                    else:
                        folder_timestamp = f.tar_path

                    self.tar_path = folder_timestamp

                    logger.debug(f.tar_name)
                    logger.debug(f.tar_dt_format)

                    # 目标文件名生成
                    try:
                        tar_dt_format_list = f.tar_dt_format.split(',')
                        tar_dt_format = tar_dt_format_list[0]
                        tar_dt_diff = int(tar_dt_format_list[1])
                    except ValueError:
                        tar_dt_diff = 0
                    except IndexError:
                        tar_dt_diff = 0
                    file_timestamp = f.tar_name.format(
                        DT=utcdt.replace(days=tar_dt_diff).format(tar_dt_format))
                    try:
                        file_timestamp = file_timestamp.decode('gbk')
                    except UnicodeDecodeError:
                        file_timestamp = unicode(file_timestamp).decode('gbk')
                    logger.debug(file_timestamp)
                    self.tar_name = '{filename}.{ext}'.format(
                        filename=file_timestamp, ext=f.src_extension)

                    self.transtype = f.transtype
                    self.ftpname = f.ftpname
            except:
                session.close()
                raise
            else:
                session.close()
        else:
            self.blocked = True
            logger.debug(
                'thi file name [{filename}] can re'.format(filename=self._f))