Example #1
0
    def private(self, call):
        user = ModelManager(self.db, User).get_object(
            filter={
                "telegram_id": call.message.chat.id
            })
        chat = ModelManager(self.db, Chat).get_object(
            filter={
                "id": call.data
            })

        participation = ModelManager(self.db, Participation).get_object(
            filter={
                "user": user,
                "chat": chat
            }
        )

        self.bot.register_next_step_handler(
            self.bot.send_message(
                call.message.chat.id,
                f"Hello, What are you hobbies? {self.get_old_data(participation.hobby)}"
            ),
            self.set_hobby,
            participation=participation
        )
Example #2
0
File: stop.py Project: ada0l/amigo
    def private(self, message):
        was_deleted = ModelManager(
            self.db, User).delete(filter={"telegram_id": message.chat.id})

        if was_deleted:
            self.bot.reply_to(message, "Bot is stopped")
        else:
            self.bot.reply_to(
                message, "Something went wrong. Maybe the bot wasn't started")
Example #3
0
    def group(self, message):
        chat, was_created = ModelManager(self.db, Chat).create(
            allow_duplication=False,
            args={
                "telegram_id": message.chat.id
            }
        )

        if was_created:
            self.bot.reply_to(message, "Chat is started")
        else:
            self.bot.reply_to(message, "Chat already started")
Example #4
0
    def set_address(self, message, participation, skip=False):
        if skip is False:
            ModelManager(self.db, Participation).update_obj(
                obj=participation,
                values={
                    "address": message.text
                })

        self.bot.send_message(
            message.chat.id,
            "OK, I filled in all the data."
        )
Example #5
0
File: edit.py Project: ada0l/amigo
    def private(self, message):
        markup = telebot.types.InlineKeyboardMarkup(row_width=2)
        chats = ModelManager(self.db, Participation).get_objects(
            filter={
                "user":
                ModelManager(self.db, User).get_object(
                    filter={"telegram_id": message.from_user.id})
            })

        if not chats:
            self.bot.reply_to(message, "You dont participate in any group")
            return

        list_of_chats = []
        for item in chats:
            list_of_chats.append(
                telebot.types.InlineKeyboardButton(
                    self.bot.get_chat(chat_id=item.chat.telegram_id).title,
                    callback_data=item.chat.id))
        markup.add(*list_of_chats)
        self.bot.reply_to(message, "Choose some chat:", reply_markup=markup)
Example #6
0
File: join.py Project: ada0l/amigo
    def group(self, message):
        chat = ModelManager(self.db, Chat).get_object(filter={
            "telegram_id": message.chat.id
        })

        if not chat:
            self.bot.reply_to(message, "Chat is not started")
            return

        if chat.status != ChatStatus.STARTED:
            self.bot.reply_to(
                message,
                "Something went wrong. Chat status is not correct for "
                "this action"
            )
            return

        user, _ = ModelManager(self.db, User).create(
            allow_duplication=False,
            args={
                "telegram_id": message.from_user.id,
                "username": message.from_user.username
            })

        part, was_created = ModelManager(self.db, Participation).create(
            allow_duplication=False,
            args={
                "user": user,
                "chat": chat
            }
        )

        if was_created:
            self.bot.reply_to(message, "You are joined")
        else:
            self.bot.reply_to(message, "You are already joined")
Example #7
0
    def group(self, message):
        chat = ModelManager(
            self.db, Chat).get_object(filter={"telegram_id": message.chat.id})

        if not chat:
            self.bot.reply_to(message, "Chat is not started")
            return

        participants = ModelManager(
            self.db, Participation).get_objects(filter={"chat": chat})

        not_filled_count = 0

        for participant in participants:
            if participant.hobby == "" or \
                    participant.wishes == "" or \
                    participant.not_wishes == "" or \
                    participant.address == "":
                not_filled_count += 1

        self.bot.reply_to(
            message, "Chat is started.\n"
            "The number of filled forms: "
            f"{len(participants) - not_filled_count}/{len(participants)}")
Example #8
0
    def set_not_wishes(self, message, participation, skip=False):
        if skip is False:
            ModelManager(self.db, Participation).update_obj(
                obj=participation,
                values={
                    "not_wishes": message.text
                })

        self.bot.register_next_step_handler(
            self.bot.send_message(
                message.chat.id,
                f"OK, What is your address? {self.get_old_data(participation.address)}"
            ),
            self.set_address,
            participation=participation
        )
Example #9
0
    def set_hobby(self, message, participation, skip=False):
        if skip is False:
            ModelManager(self.db, Participation).update_obj(
                obj=participation,
                values={
                    "hobby": message.text
                })

        self.bot.register_next_step_handler(
            self.bot.send_message(
                message.chat.id,
                f"OK, what do you want to get? {self.get_old_data(participation.wishes)}"
            ),
            self.set_wishes,
            participation=participation
        )
Example #10
0
    def private(self, message):
        user, was_created = ModelManager(self.db, User).create(
            allow_duplication=False,
            args={
                "telegram_id": message.from_user.id,
                "username": message.from_user.username
            })


        answer=""
        if was_created:
            answer += 'Bot is started.'
        else:
            answer += 'Bot is already started.'

        answer += " Write /edit to fill in the data for any chat."
        self.bot.reply_to(message, answer)
Example #11
0
File: send.py Project: ada0l/amigo
    def group(self, message):
        chat = ModelManager(
            self.db, Chat).get_object(filter={"telegram_id": message.chat.id})
        if not chat:
            self.bot.reply_to(message, "You dont started bot")
            return

        if chat.status != ChatStatus.STARTED:
            self.bot.reply_to(message, "Forms have already been sent ")
            return

        participants = ModelManager(
            self.db, Participation).get_objects(filter={"chat": chat})

        if len(participants) < 2:
            self.bot.reply_to(message, "There aren't enough participants")
            return

        chat_title = self.bot.get_chat(chat_id=chat.telegram_id).title

        all_complete = True

        not_filled_users = ""
        for participant in participants:
            if participant.hobby == "" or \
                    participant.wishes == "" or \
                    participant.not_wishes == "" or \
                    participant.address == "":
                all_complete = False
                not_filled_users += f"@{participant.user.username} "
                try:
                    self.bot.send_message(
                        participant.user.telegram_id,
                        "you didn't fill in the fields for the "
                        f"{chat_title} group ")
                except Exception as _:
                    pass

        if not all_complete:
            self.bot.reply_to(message, "Not all participants filled in "
                              f"the data. {not_filled_users}.",
                              reply_markup=self.get_markup_with_link_to_me())
            return

        random.shuffle(participants)

        all_info = ""
        for i in range(len(participants)):
            receiving: Participation = participants[i]
            giving: Participation = participants[(i + 1) % len(participants)]
            all_info += f"@{receiving.user.username} -> @{giving.user.username}\n"
            self.bot.send_message(
                giving.user.telegram_id, f"User: @{receiving.user.username}\n"
                f"My hobby is: {receiving.hobby}\n"
                f"I want to get: {receiving.wishes}\n"
                f"I don't want to get: {receiving.not_wishes}\n"
                f"My address: {receiving.address}\n")

        if chat.organizer is not None:
            self.bot.send_message(chat.organizer.telegram_id, all_info)

        ModelManager(self.db,
                     Chat).update(filter={"telegram_id": chat.telegram_id},
                                  values={"status": ChatStatus.RECORDS_SENT})