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()
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)
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()
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()
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)
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)