Exemple #1
0
def prompt_create_poll(connection):
    poll_title = input("Enter poll title: ")
    poll_owner = input("Enter poll owner: ")
    options = []

    while (new_option := input(NEW_OPTION_PROMPT)):
        options.append(new_option)

        database.create_poll(connection, poll_title, poll_owner, options)
Exemple #2
0
 def save(self):
     connection = pool.getconn(
     )  #pool is an instance of a psycopg2.SimpleConnectionPool-Class
     new_poll_id = database.create_poll(connection, self.title, self.owner)
     pool.putconn(
         connection)  #add connection that is not used anymore back to pool
     self.id = new_poll_id
5) Select a random winner from a poll option
6) Exit

Enter your choice: """
NEW_OPTION_PROMPT = "Enter new option text (or leave empty to stop adding options): "


def prompt_create_poll(connection):
    poll_title = input("Enter poll title: ")
    poll_owner = input("Enter poll owner: ")
    options = []

    while (new_option := input(NEW_OPTION_PROMPT)):
        options.append(new_option)

    database.create_poll(connection, poll_title, poll_owner, options)


def list_open_polls(connection):
    polls = database.get_polls(connection)

    for _id, title, owner in polls:
        print(f"{_id}: {title} (created by {owner})")


def prompt_vote_poll(connection):
    poll_id = int(input("Enter poll would you like to vote on: "))

    poll_options = database.get_poll_details(connection, poll_id)
    _print_poll_options(poll_options)
Exemple #4
0
 def save(self):
     with get_connection() as connection:
         new_poll_id = database.create_poll(connection, self.title,
                                            self.owner)
         self.id = new_poll_id
Exemple #5
0
def handle_voteban(bot, message, reason):
    if not (message.chat.type == "supergroup"):
        return False

    user_can_poll = can_poll(bot, message)

    if user_can_poll["error"] == "no_reply":
        bot.reply_to(
            message=message,
            text=voteban_error_no_reply,
            parse_mode="markdown",
        )
        return False

    accused_id = message.reply_to_message.from_user.id
    accused_full_name = "{} {}".format(
        message.reply_to_message.from_user.first_name,
        message.reply_to_message.from_user.last_name,
    )
    accuser_id = message.from_user.id
    accuser_full_name = "{} {}".format(
        message.from_user.first_name,
        message.from_user.last_name,
    )

    if user_can_poll["error"] == "poll_already_created":
        bot.send_message(
            chat_id=message.chat.id,
            text=voteban_error_poll_already_created.format(
                accused_full_name,
                accused_id,
            ),
            reply_to_message_id=user_can_poll["message"],
            parse_mode="markdown",
        )
        return False

    if user_can_poll["error"] == "self_complaint":
        bot.reply_to(
            message=message,
            text=voteban_error_self_complaint,
            parse_mode="markdown",
        )
        return False

    if user_can_poll["error"] == "bot_complaint":
        bot.reply_to(
            message=message,
            text=voteban_error_bot_complaint,
            parse_mode="markdown",
        )
        return False

    if user_can_poll["error"] == "admin_complaint":
        bot.reply_to(
            message=message,
            text=voteban_error_admin_complaint,
            parse_mode="markdown",
        )
        return False

    if not user_can_poll["error"]:
        sended_message = bot.send_message(
            chat_id=message.chat.id,
            text=poll_message.format(
                accuser_full_name,
                accuser_id,
                accused_full_name,
                accused_id,
                "Спам" if reason == "spam" else "-",
                message.reply_to_message.text if reason != "spam" else "-",
            ),
            parse_mode="markdown",
            reply_markup=create_poll_keyboard())

        user_message = message.reply_to_message.text

        database.create_poll(
            chat_id=sended_message.chat.id,
            message_id=sended_message.message_id,
            accuser_id=accuser_id,
            accused_id=accused_id,
            accused_message=user_message if user_message else "-",
            accused_message_id=message.reply_to_message.message_id,
            reason=reason,
        )
        return True

    return False
Exemple #6
0
 def save(self):
     connection = create_connection()
     new_poll_id = database.create_poll(connection, self.title, self.owner)
     connection.close()
     self.id = new_poll_id
 def save(self):
     connection = pool.getconn()
     new_poll_id = database.create_poll(connection, self.title, self.owner)
     pool.putconn(connection)
     self.id = new_poll_id