Пример #1
0
    def adding_steps(self, bot, update):
        chat = update.message.chat_id
        step = self.user_data[chat][0]
        doc = self.user_data[chat][1]
        key = self.user_data[chat][2]
        fields_bd = func_data.lists[key + "_bd"]
        fields = func_data.lists[key]

        if step < len(fields):
            text = update.message.text
            doc[fields_bd[step]] = int(text) if utils.is_int(text) else text
            step += 1
            self.user_data[chat][0] += 1
            if step < len(fields):
                bot.send_message(chat_id=chat, text="Enter {}".format(fields[step]))
            else:
                text = func_data.sample_messages['correctness_' + key].format(**doc)
                bot.send_message(chat_id=chat, text=text, reply_markup=RKM(self.keyboard_dict["reg_confirm"], True))
        elif step == len(fields):
            if update.message.text == "All is correct✅":
                self.controller.add_document(doc, key)
                self.location[chat] = 'main'
                bot.send_message(chat_id=chat, text="Document has been added",
                                 reply_markup=RKM(self.keyboard_dict["admin"], True))
            elif update.message.text == "Something is incorrect❌":
                self.user_data[chat] = [0, {}, key]
                bot.send_message(chat_id=chat, text="Enter title", reply_markup=RKR([[]]))
Пример #2
0
    def show_retreats_prompt(self, bot, game, player):
        try:
            t = next(t1 for t1, k, t2 in player.retreat_choices if t2 is None)
        except StopIteration:
            message = "The following retreats will be attempted:\n\n"

            for t1, k, t2 in player.retreat_choices:
                message += "{}-{}\n".format(t1, t2)

            message += "\nIs this correct"

            keyboard = [
                ["Yes", "No"],
            ]

            bot.send_message(player.id, message, reply_markup=RKM(keyboard))

            return

        keyboard = make_grid(sorted(player.retreats[t], key=str.casefold))

        keyboard.append(["Disband"])

        if next(t2 for t1, k, t2 in player.retreat_choices) is not None:
            keyboard.append(["Back"])

        bot.send_message(player.id,
                         "Where should {} retreat to?".format(t),
                         reply_markup=RKM(keyboard))
Пример #3
0
    def reg_steps(self, bot, update):
        chat = update.message.chat_id
        step, user = self.user_data[chat]
        fields = func_data.lists["reg_fields"]

        if step < len(fields):
            text = update.message.text
            user[fields[step]] = text
            step += 1
            self.user_data[chat][0] += 1
            if step < len(fields):
                keyboard = RKM(self.keyboard_dict["status"], True) if fields[step] == "status" else None
                bot.send_message(chat_id=update.message.chat_id, text="Enter your {}".format(fields[step]),
                                 reply_markup=keyboard)
            else:
                text_for_message = func_data.sample_messages['correctness'].format(**user)
                bot.send_message(chat_id=chat, text=text_for_message,
                                 reply_markup=RKM(self.keyboard_dict["reg_confirm"], True))
        elif step == len(fields):
            if update.message.text == "All is correct✅":
                is_incorrect = utils.data_checker(self.user_data[chat][1])
                if is_incorrect[0]:
                    bot.send_message(chat_id=chat, text=is_incorrect[1],
                                     reply_markup=RKM(self.keyboard_dict["unauth"], True))
                else:
                    self.controller.registration(user)
                    bot.send_message(chat_id=chat, text="Your request has been sent.\n Wait for librarian confirmation",
                                     reply_markup=RKM(self.keyboard_dict["unconf"], True))
                    self.main_menu(bot, update)
            elif update.message.text == "Something is incorrect❌":
                self.user_data[chat] = [0, {"id": chat}]
                bot.send_message(chat_id=chat, text="Enter your name", reply_markup=RKR([[]]))
Пример #4
0
 def conf_user(self, bot, ids, user_id, action):
     if action == 'accept':
         self.controller.confirm_user(user_id)
         bot.edit_message_text(text="This user was confirmed", chat_id=ids[0], message_id=ids[1])
         bot.send_message(chat_id=user_id, text="Your application was confirmed",
                          reply_markup=RKM(self.keyboard_dict[self.types[2]], True))
     elif action == 'reject':
         self.controller.delete_user(user_id)
         bot.edit_message_text(text="This user was rejected", chat_id=ids[0], message_id=ids[1])
         bot.send_message(chat_id=user_id, text="Your application was rejected",
                          reply_markup=RKM(self.keyboard_dict[self.types[0]], True))
Пример #5
0
 def main_menu(self, bot, update):
     chat = update.message.chat_id
     user_type = self.controller.user_type(chat)
     keyboard = self.keyboard_dict[self.types[user_type]]
     self.location[chat] = 'main'
     self.user_data[chat] = []
     bot.send_message(chat_id=chat, text="Main menu", reply_markup=RKM(keyboard, True))
Пример #6
0
    def get_keyboard(self):
        ntf = self.next_to_fill()

        try:
            return self.basic_keyboards[ntf](self)
        except KeyError:
            pass

        try:
            hint = self.hints[ntf](self)
        except KeyError:
            return None

        if self.more:
            hint = territories - hint

        keyboard = make_grid(sorted(hint, key=str.casefold))

        keyboard.append(["More..."])

        if ntf == "TERR" and self.terrs:
            if not self.terr_remove:
                keyboard.append(["Remove"])
            else:
                keyboard.append(["Add"])

            keyboard.append(["Done"])

        keyboard.append(["Back"])

        return RKM(keyboard)
 def verification(self, bot, update, args):
     if args and args[0] == open('Bot/key.txt').read():
         self.controller.upto_librarian(update.message.chat_id)
         bot.send_message(chat_id=update.message.chat_id,
                          text="You have been update to Librarian",
                          reply_markup=RKM(self.keyboard_dict["admin"],
                                           True))
         utils.key_gen()
Пример #8
0
    def show_build_prompt(self, bot, game, player):
        try:
            t, k, c = player.units_choices[-1]
        except IndexError:
            t, k, c = True, True, True

        if not k:
            message = "What kind of unit do you want to build?"
            keyboard = [["Army", "Fleet"], ["Back"]]

        elif not c and t in split_coasts and k == "F":
            message = "On which coast?"
            keyboard = [["North", "South"], ["Back"]]

        elif not player.units_delta or player.units_done:
            if not player.units_choices:
                message = "No new units will be built."

            elif len(player.units_choices) == 1:
                message = ("This new unit will be built:\n\n" +
                           self.format_build(player.units_choices))

            else:
                message = ("These new units will be built:\n\n" +
                           self.format_build(player.units_choices))

            message += "\nAre you sure?"

            keyboard = [["Yes", "No"]]

        else:
            keyboard = make_grid(
                sorted(player.units_options -
                       {t
                        for t, k, c in player.units_choices},
                       key=str.casefold))

            keyboard.append(["Done"])

            if not player.units_choices:
                message = "Where do you want to build?"

            else:
                message = ("Currently building:\n\n" +
                           self.format_build(player.units_choices) +
                           "\nWhat else?")

                keyboard.append(["Back"])

        bot.send_message(player.id, message, reply_markup=RKM(keyboard))
Пример #9
0
	def ls(self, bot):
		"""
		Send all the text, images and files on the
		current directory.
		"""
		# Put a back button if not in root
		back = [[KB(args['back_label'])] *
		  (not os.path.samefile(self.data['path'], args['root']))]
		dirs = smartsort(glob(self.data['path']+'/*/'))
		keyboard = RKM([[KB(a)] for a in dirs] + back)
		files = [*filter(os.path.isfile, glob(self.data['path']+'/*.*'))]
		pars = {'chat_id': self.data['id'], 'reply_markup': keyboard}
		for filepath in files:
			self.send(filepath, bot, pars)
		if not files:
			# No file has been sent. Standard message here.
			bot.send_message(text=args['standard-message'], **pars)
Пример #10
0
    def show_disband_prompt(self, bot, game, player):
        if not player.units_delta:
            message = ("These units will be disbanded: {}\n"
                       "Are you sure?".format(", ".join(player.units_choices)))

            keyboard = [["Yes", "No"]]

        else:
            keyboard = make_grid(
                sorted(player.units_options.difference(player.units_choices),
                       key=str.casefold))

            if not player.units_choices:
                message = "Which unit should be disbanded{}?".format(
                    " first" if len(player.units_options) > 1 else "")

            else:
                message = "Disbanding {}. Who else?".format(", ".join(
                    player.units_choices))

                keyboard.append(["Back"])

        bot.send_message(player.id, message, reply_markup=RKM(keyboard))
Пример #11
0
 def user_manage(self, bot, update):
     keyboard = self.keyboard_dict["user_management"]
     self.location[update.message.chat_id] = 'user_management'
     bot.send_message(chat_id=update.message.chat_id,
                      text="Choose option",
                      reply_markup=RKM(keyboard, True))
Пример #12
0
class API:
    def __init__(self, app, controller, dbmanager, notification):
        self.blueprint = Blueprint('api', __name__)
        self.init_handlers()
        self.app = app
        self.dbmanager = dbmanager
        self.app.register_blueprint(self.blueprint)
        self.controller = controller
        self.notification = notification
        self.is_have_notification = notification is not None
        self.notification_id = []

    def init_handlers(self):
        add_rule = self.blueprint.add_url_rule
        add_rule('/signin', 'signin', self.signin_post, methods=['POST'])
        add_rule('/signup', 'signup', self.signup_post, methods=['POST'])
        add_rule('/signout', 'signout', self.signout_get, methods=['GET'])
        add_rule('/api/get_account_info',
                 'get_account_info',
                 self.get_account_info,
                 methods=['POST'])
        add_rule('/api/get_verification_links',
                 'get_verification_links',
                 self.get_verification_links,
                 methods=['POST'])
        add_rule('/api/generate_invite_link',
                 'generate_invite_link',
                 self.generate_verification_string,
                 methods=['POST'])
        add_rule('/api/get_telegram_verification_message',
                 'get_telegram_verification_message',
                 self.get_verification_message_post,
                 methods=['POST'])
        add_rule('/api/get_all_unconfirmed',
                 'get_all_unconfirmed',
                 self.get_all_unconfirmed_post,
                 methods=['POST'])
        add_rule('/api/confirm_user',
                 'confirm_user',
                 self.confirm_user_post,
                 methods=['POST'])
        add_rule('/api/modify_user',
                 'modify_user',
                 self.modify_user_post,
                 methods=['POST'])
        add_rule('/api/delete_user',
                 'delete_user',
                 self.delete_user_post,
                 methods=['POST'])
        add_rule('/api/get_all_patrons',
                 'get_all_patrons',
                 self.get_all_patrons_post,
                 methods=['POST'])
        add_rule('/api/get_all_librarians',
                 'get_all_librarians',
                 self.get_all_librarians_post,
                 methods=['POST'])
        add_rule('/api/get_librarian_by_name',
                 'get_librarian_by_name',
                 self.get_librarian_by_name_post,
                 methods=['POST'])
        add_rule('/api/get_user',
                 'get_user',
                 self.get_user_post,
                 methods=['POST'])
        add_rule('/api/get_user_by_name',
                 'get_user_by_name',
                 self.get_user_by_name_post,
                 methods=['POST'])
        add_rule('/api/reject_order',
                 'reject_order',
                 self.reject_order_post,
                 methods=['POST'])
        add_rule('/api/user_get_doc',
                 'user_get_doc',
                 self.user_get_doc_post,
                 methods=['POST'])
        add_rule('/api/return_doc',
                 'return_doc',
                 self.return_doc_post,
                 methods=['POST'])
        add_rule('/api/get_user_orders',
                 'get_user_orders',
                 self.get_user_orders_post,
                 methods=['POST'])
        add_rule('/api/get_user_history',
                 'get_user_history',
                 self.get_user_history_post,
                 methods=['POST'])
        add_rule('/api/get_order',
                 'get_order',
                 self.get_order_post,
                 methods=['POST'])
        add_rule('/api/get_all_orders',
                 'get_all_orders',
                 self.get_all_orders_post,
                 methods=['POST'])
        add_rule('/api/get_all_active_orders',
                 'get_all_active_orders',
                 self.get_all_active_orders_post,
                 methods=['POST'])
        add_rule('/api/get_all_waiting_doc',
                 'get_all_waiting_doc',
                 self.get_all_waiting_doc_post,
                 methods=['POST'])
        add_rule('/api/get_all_returned_doc',
                 'get_all_returned_doc',
                 self.get_all_returned_doc,
                 methods=['POST'])
        add_rule('/api/add_document',
                 'add_document',
                 self.add_document_post,
                 methods=['POST'])
        add_rule('/api/modify_document',
                 'modify_document',
                 self.modify_docment_post,
                 methods=['POST'])
        add_rule('/api/add_copies_of_doc',
                 'add_copies_of_doc',
                 self.add_copies_of_doc_post,
                 methods=['POST'])
        add_rule('/api/delete_document',
                 'delete_document',
                 self.delete_document_post,
                 methods=['POST'])
        add_rule('/api/get_document',
                 'get_document',
                 self.get_document_post,
                 methods=['POST'])
        add_rule('/api/get_all_doctype',
                 'get_all_doctype',
                 self.get_all_doctype_post,
                 methods=['POST'])
        add_rule('/api/get_documents_by_title',
                 'get_documents_by_title',
                 self.get_documents_by_title_post,
                 methods=['POST'])
        add_rule('/api/get_documents_by_authors',
                 'get_documents_by_authors',
                 self.get_documents_by_authors_post,
                 methods=['POST'])
        add_rule('/api/get_queue_on_document',
                 'get_queue_on_document',
                 self.get_queue_on_documnent_post,
                 methods=['POST'])
        add_rule('/api/outstanding',
                 'outstanding',
                 self.outstanding_post,
                 methods=['POST'])

    def signin_post(self):
        login = request.values.get('login')
        passwd = md5_hash(request.values.get('password').encode('utf-8'))
        if self.dbmanager.get_user(login, passwd) is None:
            response = self.app.make_response(redirect('/signin'))
            response.set_cookie('error', 'Login error')
            return response
        response = self.app.make_response(redirect('/'))
        response.set_cookie('session_id',
                            create_session(login, passwd, self.dbmanager))
        return response

    @security_decorator_maker(3)
    def generate_verification_string(self):
        if 'privilege' in request.values:
            string = md5_hash(generate_sault())
            self.dbmanager.insert_verification_string(
                string, request.values.get('privilege'))
            return string
        else:
            return 'Need privilege value'

    @security_decorator_maker(3)
    def get_verification_links(self):
        if int(port) == 80:
            link = 'http://{}/signup?verification_string='.format(inet_addr)
        elif int(port) == 443:
            link = 'https://{}/signup?verification_string='.format(inet_addr)
        else:
            link = 'http://{}:{}/signup?verification_string='.format(
                inet_addr, port)
        ver_strings = self.dbmanager.all_verification_strings(1)
        pattern = '<a href="#">%s{}</a> -------- Privilege level: {}' % link
        if ver_strings:
            output = [
                pattern.format(
                    string[0],
                    self.dbmanager.get_privilege_by_verification_string(
                        string[0])[0] + 1) for string in ver_strings
            ]
            return jsonify(output)
        else:
            return jsonify([])

    @security_decorator_maker(0)
    def get_verification_message_post(self):
        session_id = request.cookies.get('session_id')
        user_id = self.dbmanager.get_user_id_by_session(session_id)
        ver_val = self.dbmanager.get_verification_string(user_id)
        pattern = 'Write to telegram bot(<a href="https://t.me/{}">https://t.me/{}</a>) this line</br> /verification {}'
        return pattern.format(telegram_alias, telegram_alias, ver_val[0])

    def signup_post(self):
        values = request.values
        ver_str = 'verification_string'
        if ver_str in values and self.dbmanager.if_verification_string_exist(
                values.get(ver_str), 1):
            keys = ['login', 'name', 'phone', 'address']
            user = dict(zip(keys, [values.get(key) for key in keys]))
            user['passwd'] = md5_hash(values.get('password').encode('utf-8'))
            user[
                'privilege'] = self.dbmanager.get_privilege_by_verification_string(
                    values.get(ver_str))
            self.dbmanager.create_user(user)
            response = self.app.make_response(redirect('/'))
            session_id = create_session(user['login'], user['passwd'],
                                        self.dbmanager)
            response.set_cookie('session_id', session_id)
            user_id = self.dbmanager.get_user_id_by_session(session_id)
            self.dbmanager.activate_verification_string(
                values.get(ver_str), user_id)
            return response
        else:
            return 'Please write to another librarian to get signup link.'

    def signout_get(self):
        session_id = request.cookies['session_id']
        self.dbmanager.delete_session(session_id)
        response = self.app.make_response(redirect('/'))
        response.set_cookie('session_id', '', expires=0)
        return response

    def get_account_info(self):
        session_id = request.cookies['session_id']
        user_id = self.dbmanager.get_user_id_by_session(session_id)[0]
        user = tuple_to_dict('account', self.dbmanager.get_user_by_id(user_id))
        user.pop('passwd', 0)
        user.pop('chat_id', 0)
        return jsonify(user)

    @security_decorator_maker(0)
    def get_all_unconfirmed_post(self):
        return jsonify(self.controller.get_all_unconfirmed())

    @security_decorator_maker(1)
    @notification_decorator_maker("Your application was confirmed",
                                  RKM(keyboard_dict["auth"], True))
    def confirm_user_post(self):
        if 'user_id' in request.values:
            user_id = request.values.get('user_id')
            librarian_id = self.dbmanager.get_user_id_by_session(
                request.cookies.get('session_id'))[0]
            success = self.controller.confirm_user(user_id, librarian_id)
            if success:
                self.notification_id = [user_id]
            return 'OK' if success else "Something went wrong"
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    @notification_decorator_maker("You information was updated")
    def modify_user_post(self):
        keys = ['id', 'name', 'phone', 'address', 'status']
        user = {
            key: request.values.get(key)
            for key in keys if key in request.values
        }
        if not ('id' in user):
            return 'Need id'
        librarian_id = self.dbmanager.get_user_id_by_session(
            request.cookies.get('session_id'))[0]
        self.controller.modify_user(user, librarian_id)
        self.notification_id = [user['id']]
        return 'OK'

    @security_decorator_maker(2)
    @notification_decorator_maker("Your account was deleted",
                                  RKM(keyboard_dict["unauth"], True))
    def delete_user_post(self):
        if 'user_id' in request.values:
            self.notification_id = [request.values.get('user_id')]
            return str(
                self.controller.delete_user(request.values.get('user_id')))
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    def get_all_patrons_post(self):
        return jsonify(self.controller.get_all_patrons())

    @security_decorator_maker(0)
    def get_all_librarians_post(self):
        librarians_list = [
            dict(zip(['id', 'name', 'phone', 'address', 'privilege'], tup))
            for tup in self.dbmanager.get_users()
        ]

        return jsonify(librarians_list)

    @security_decorator_maker(0)
    def get_librarian_by_name_post(self):
        librarians_list = tuple_to_dict(
            'librarians',
            self.dbmanager.get_user_by_name(request.values.get('name')))
        return jsonify(librarians_list)

    @security_decorator_maker(0)
    def get_user_post(self):
        if 'user_id' in request.values:
            return jsonify(
                self.controller.get_user(request.values.get('user_id')))
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    def get_user_by_name_post(self):
        if 'name' in request.values:
            return jsonify(
                self.controller.get_user_by_name(request.values.get('name')))
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    def reject_order_post(self):
        if 'order_id' in request.values:
            self.controller.delete_waiting_order(
                request.values.get('order_id'))
            return 'OK'
        else:
            return 'Need id of order'

    @security_decorator_maker(0)
    def user_get_doc_post(self):
        if 'order_id' in request.values:
            self.controller.user_get_doc(request.values.get('order_id'))
            return 'OK'
        else:
            return 'Need id of order'

    @security_decorator_maker(0)
    @notification_decorator_maker('You returned document')
    def return_doc_post(self):
        if 'order_id' in request.values:
            *_, self.notification_id = self.controller.return_doc(
                request.values.get('order_id'))
        else:
            return 'Need id of order'

    @security_decorator_maker(0)
    def get_user_orders_post(self):
        if 'user_id' in request.values:
            return jsonify(
                self.controller.get_user_orders(request.values.get('user_id')))
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    def get_user_history_post(self):
        if 'user_id' in request.values:
            return jsonify(
                self.controller.get_user_history(
                    request.values.get('user_id')))
        else:
            return 'Need id of user'

    @security_decorator_maker(0)
    def get_order_post(self):
        if 'order_id' in request.values:
            return jsonify(
                self.controller.get_order(request.values.get('order_id')))
        else:
            return 'Need id of order'

    @security_decorator_maker(0)
    def get_all_orders_post(self):
        return jsonify(self.controller.get_all_orders())

    @security_decorator_maker(0)
    def get_all_active_orders_post(self):
        return jsonify(self.controller.get_all_active_orders())

    @security_decorator_maker(0)
    def get_all_waiting_doc_post(self):
        return jsonify(self.controller.get_all_waiting_doc())

    @security_decorator_maker(0)
    def get_all_returned_doc(self):
        return jsonify(self.controller.get_all_returned_orders())

    @security_decorator_maker(1)
    def add_document_post(self):
        values = request.values
        keys = [
            'title', 'description', 'authors', 'count', 'price', 'keywords',
            'best_seller', 'free_count'
        ]
        doc_type = values.get('type')
        if doc_type == 'article':
            keys.extend(['journal', 'issue', 'editors', 'date'])
        if all([key in values for key in keys]):
            document = dict(zip(keys, [values.get(key) for key in keys]))
            document['best_seller'] = int(document['best_seller'])
            librarian_id = self.dbmanager.get_user_id_by_session(
                request.cookies.get('session'))[0]
            self.controller.add_document(document, doc_type, librarian_id)
            return 'OK'
        else:
            print([key for key in values.keys()])
            return 'Not enough keys'

    @security_decorator_maker(0)
    def modify_docment_post(self):
        values = request.values
        keys = [
            'id', 'title', 'authors', 'description', 'price', 'best_seller',
            'keywords', 'journal', 'issue', 'editors', 'date'
        ]
        doc = {key: values.get(key) for key in keys if key in values}
        if not ('id' in doc):
            return 'Need id'
        if not ('type' in values):
            return 'Need type'
        librarian_id = self.dbmanager.get_user_id_by_session(
            request.cookies.get('session'))[0]
        self.controller.modify_document(doc, values.get('type'), librarian_id)
        return 'OK'

    @security_decorator_maker(0)
    @notification_decorator_maker("You can get the document")
    def add_copies_of_doc_post(self):
        values = request.values
        if not ('id' in values):
            return 'Need id'
        if not ('delta_count' in values):
            return 'Need delta count'
        if not ('type' in values):
            return 'Need type'
        queue = self.controller.get_document_queue(values.get('type'),
                                                   values.get('id'))
        if int(values.get('delta_count')) > 0:
            for i in range(min([len(queue), int(values.get('delta_count'))])):
                self.notification_id.append(queue[i]['id'])
                self.controller.delete_user_queue(queue[i]['id'],
                                                  values.get('type'),
                                                  values.get('id'))
        self.controller.add_copies_of_document(values.get('type'),
                                               values.get('id'),
                                               int(values.get('delta_count')))
        return 'OK'

    @security_decorator_maker(2)
    def delete_document_post(self):
        values = request.values
        if not ('id' in values):
            return 'Need id'
        if not ('type' in values):
            return 'Need type'
        self.controller.delete_document(values.get('id'), values.get('type'))
        return 'OK'

    @security_decorator_maker(0)
    def get_document_post(self):
        values = request.values
        if not ('id' in values):
            return 'Need id'
        if not ('type' in values):
            return 'Need type'
        return jsonify(
            self.controller.get_document(values.get('id'), values.get('type')))

    @security_decorator_maker(0)
    def get_all_doctype_post(self):
        if not ('type' in request.values):
            return 'Need type'
        return jsonify(
            self.controller.get_all_doctype(request.values.get('type')))

    @security_decorator_maker(0)
    def get_documents_by_title_post(self):
        values = request.values
        if not ('title' in values):
            return 'Need title'
        if not ('type' in values):
            return 'Need type'
        return jsonify(
            self.controller.get_documents_by_title(values.get('title'),
                                                   values.get('type')))

    @security_decorator_maker(0)
    def get_documents_by_authors_post(self):
        values = request.values
        if not ('authors' in values):
            return 'Need authors'
        if not ('type' in values):
            return 'Need type'
        return jsonify(
            self.controller.get_documents_by_title(values.get('authors'),
                                                   values.get('type')))

    @security_decorator_maker(0)
    def get_queue_on_documnent_post(self):
        values = request.values
        if not ('doc_id' in values):
            return 'Need id'
        if not ('type' in values):
            return 'Need type'
        return jsonify(
            self.controller.get_document_queue(values.get('type'),
                                               values.get('doc_id')))

    @security_decorator_maker(1)
    @notification_decorator_maker("You are removed from queue.")
    def outstanding_post(self):
        values = request.values
        if not ('doc_id' in values):
            return 'Need id'
        if not ('type' in values):
            return 'Need type'
        title_book = self.controller.get_document(values.get('doc_id'),
                                                  values.get('type'))['title']
        f, self.notification_id = self.controller.outstanding_request(
            values.get('doc_id'), values.get('type'))
        return "OK"
Пример #13
0
 def library(self, bot, update):
     self.location[update.message.chat_id] = 'library'
     bot.send_message(chat_id=update.message.chat_id, text="Choose type of material",
                      reply_markup=RKM(self.keyboard_dict["lib_main"], True))
Пример #14
0
 def get_kind_keyboard():
     return RKM([["Hold"], ["Move (attack)"], ["Support to Hold"],
                 ["Support to Move"], ["Convoy"], ["Back"]])
Пример #15
0
 def mat_manage(self, bot, update):
     reply_markup = RKM(self.keyboard_dict["mat_management"], True)
     self.location[update.message.chat_id] = 'material_management'
     bot.send_message(chat_id=update.message.chat_id, text="Choose option", reply_markup=reply_markup)
Пример #16
0
 def get_coasts_keyboard():
     return RKM([["North", "South"], ["Back"]])
Пример #17
0
    def user_flip(self, bot, ids, action, args):
        chat, message_id = ids
        user_id = args[1]
        if action == 'orders':
            orders = self.controller.get_user_orders(user_id)
            keyboard = [[
                IKB(str(i + 1),
                    callback_data='order {} {} {} users'.format(*args, i))
                for i in range(len(orders))
            ]]
            orders = func_data.text_gen(orders, "orders")
            keyboard += [[
                IKB('Cancel️',
                    callback_data='cancel {} {} users'.format(*args))
            ]]
            bot.edit_message_text(text=orders,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'edit':
            callback = ['e{} {} {} users'.format(i, *args) for i in range(4)]
            keyboard = [
                [
                    IKB("Name", callback_data=callback[0]),
                    IKB("Phone", callback_data=callback[1])
                ],
                [
                    IKB("Address", callback_data=callback[2]),
                    IKB("Status", callback_data=callback[3])
                ],
                [
                    IKB('Cancel️',
                        callback_data='cancel {} {} users'.format(*args))
                ]
            ]
            text = "Choose edited parameter or press cancel"
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'delete':
            self.controller.delete_user(user_id)
            text = "User card has been deleted"
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id)
            bot.send_message(text="Your user card was deleted.",
                             chat_id=user_id,
                             reply_markup=RKM(self.keyboard_dict['unauth'],
                                              True))
        elif action in ['e0', 'e1', 'e2', 'e3']:
            user = self.controller.get_user(user_id)
            keyboard = [[
                IKB("Cancel", callback_data='cancel {} {} users'.format(*args))
            ]]
            params = dict(
                zip(['e0', 'e1', 'e2', 'e3'], func_data.lists["reg_fields"]))
            text = 'Enter new {}.\nOld value - {}.'.format(
                params[action], user[params[action]])
            self.location[chat] = "user_modify"
            self.user_data[chat] = [user, params[action]]
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'order':
            self.user_data[chat] = user_id
            user = self.controller.get_user(user_id)
            order = self.controller.get_user_orders(user_id)[int(args[-1])]
            doc, order_id, active = order['doc'], order['id'], order['active']
            doc_type, time, time_out = order['table'], order['time'], order[
                'time_out']

            text = "User name: {name}\nPhone: {phone}\nStatus: {status}\n\n".format(
                **user)
            text += "Document title: {title}\nAuthors: {authors}\nType of document: {dt}\n\n".format(
                **doc, dt=doc_type)
            text += "Date of taking: {}\nDate of returning: {}".format(
                time, time_out)

            if int(active) == 0:
                keyboard = [[
                    IKB("Activate order",
                        callback_data='activate {} {} {} users'.format(*args)),
                    IKB("Decline order",
                        callback_data='decline {} {} {} users'.format(*args)),
                    IKB('Cancel️',
                        callback_data='cancel {} {} users'.format(*args[:-1]))
                ]]
            elif int(active) == 1:
                keyboard = [[
                    IKB("Book return",
                        callback_data='return {} {} {} users'.format(*args)),
                    IKB("Send notification",
                        callback_data='notice {} {} {} users'.format(*args)),
                    IKB('Cancel️',
                        callback_data='cancel {} {} users'.format(*args[:-1]))
                ]]
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'activate':
            order = self.controller.get_user_orders(user_id)[int(args[-1])]
            self.controller.user_get_doc(order['id'])
            keyboard = [[
                IKB("Return to the list",
                    callback_data='cancel {} {} users'.format(*args))
            ]]

            bot.edit_message_text(text='Document was taken',
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'decline':
            order = self.controller.get_user_orders(user_id)[int(args[-1])]
            self.controller.return_doc(order['id'])
            keyboard = [[
                IKB("Return to the list",
                    callback_data='cancel {} {} users'.format(*args))
            ]]
            bot.edit_message_text(text='Order was declined',
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'notice':
            self.location[chat] = "notice"
            keyboard = [[
                IKB('Cancel️',
                    callback_data='cancel {} {} users'.format(*args))
            ]]
            text = "Enter message to user"
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
        elif action == 'return':
            order = self.controller.get_user_orders(user_id)[int(args[-1])]
            result = self.controller.return_doc(order['id'])
            if result[0]:
                if result[1] != 0:
                    bot.send_message(
                        text="Please pay fine, because you returned it late : {}"
                        .format(result[1]),
                        chat_id=user_id)
                    text = "User have fine: {}".format(result[1])
                else:
                    bot.send_message(
                        text=
                        "Book was returned.Thank you, that you use our service",
                        chat_id=user_id)
                    text = "User have not fine"
            if result[3]:
                bot.send_message(text='You can take "{}"'.format(
                    order['doc_id']['title']),
                                 chat_id=result[4])
            text = 'Document was returned.' + text
            keyboard = [[
                IKB("Return to the list",
                    callback_data='cancel {} {} users'.format(*args))
            ]]
            bot.edit_message_text(text=text,
                                  chat_id=chat,
                                  message_id=message_id,
                                  reply_markup=IKM(keyboard))
Пример #18
0
 def get_yesno_keyboard():
     return RKM([["Yes", "No"], ["Back"]])