示例#1
0
def verify(update, context):
    """Adds user from reply message to verified list"""
    reply = update.message.reply_to_message
    if update.effective_user.id in get_admin_ids(context.bot,
                                                 update.message.chat_id):
        if reply is not None:
            conn = create_connection()
            db_cursor = conn.cursor()
            user_id_number = int(reply.from_user.id)
            chat_id = int(reply.chat_id)
            db_cursor.execute(
                "SELECT services FROM verified WHERE chat_id = %s and user_id = %s",
                (chat_id, user_id_number))
            result = db_cursor.fetchall()
            details = ''
            if context.args and context.args[0] != '':
                details = ' '.join(context.args)
            if result is None or len(result) == 0:
                names = func.get_all_names(reply)
                input_names = func.get_all_names(update.message)
                db_cursor.execute(
                    "INSERT INTO verified (chat_id, user_id, services, username, first_name, input_id, "
                    "input_username, input_first_name) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
                    (chat_id, user_id_number, details[:25], names[0], names[1],
                     update.effective_user.id, input_names[0], input_names[1]))
                conn.commit()
                update.message.reply_text("Verified services: " +
                                          details[:25] +
                                          "\n Feel free to sign up to be a "
                                          "merchant on https://" + site_tld)
            else:
                if 'remove' in details.lower().strip():
                    db_cursor.execute(
                        "DELETE FROM verified where chat_id = %s and user_id = %s",
                        (chat_id, user_id_number))
                    conn.commit()
                    conn.close()
                    update.message.reply_text("Removed verified user")
                else:
                    db_cursor.execute(
                        "UPDATE verified SET services = %s where chat_id = %s and user_id = %s",
                        (details[:25], chat_id, user_id_number))
                    conn.commit()
                    conn.close()
                    update.message.reply_text(
                        "Updated services: " + details[:25] +
                        "\n Feel free to sign up to be a "
                        "merchant on "
                        "https://" + site_tld)
    else:
        if context.args[0].lower() == "help":
            send_message = "In a reply to the user in question list the services they are verified for."
        else:
            send_message = "For security please use this command in a reply to the user in question"
        context.bot.send_message(chat_id=update.effective_message.chat_id,
                                 text=send_message)
    context.bot.delete_message(chat_id=update.message.chat_id,
                               message_id=update.message.message_id)
示例#2
0
def advert_warning(update, context):
    """Gives warning and deletes message if user is advertising without permission. Bans on second warning."""
    reply = update.message.reply_to_message
    if update.effective_user.id in get_admin_ids(context.bot, update.message.chat_id) and reply is not None and \
            reply.from_user.id not in get_admin_ids(context.bot, update.message.chat_id):
        conn = create_connection()
        db_cursor = conn.cursor()
        user_id_number = int(reply.from_user.id)
        chat_id = int(reply.chat_id)
        db_cursor.execute(
            "SELECT services FROM verified WHERE chat_id = %s AND user_id = %s",
            (update.message.chat_id, int(reply.from_user.id)))
        fetch = db_cursor.fetchone()
        if fetch is None:
            names = func.get_all_names(reply)
            db_cursor.execute(
                "SELECT * FROM warnings WHERE user_id = %s AND chat_id = %s",
                (user_id_number, chat_id))
            result_set = db_cursor.fetchall()
            if len(result_set) < 1:
                send_message = "@" + func.get_username_from_message(
                    reply
                ) + ". You must be /verified in order to advertise. This is your ONLY warning!"
                db_cursor.execute(
                    "INSERT INTO warnings (chat_id, user_id, username, first_name, reason) VALUES (%s,"
                    "%s,%s,%s, 'advert')",
                    (chat_id, user_id_number, names[0], names[1]))
                conn.commit()
            else:
                try:
                    db_cursor.execute(
                        "INSERT INTO warnings (chat_id, user_id, username, first_name, reason) VALUES ("
                        "%s,%s,%s,%s, 'advert')",
                        (chat_id, user_id_number, names[0], names[1]))
                    conn.commit()
                    context.bot.kick_chat_member(chat_id=reply.chat_id,
                                                 user_id=user_id_number)
                    send_message = func.get_username_from_message(
                        reply) + " has been banned."
                except:
                    context.bot.send_message(
                        chat_id=update.effective_message.chat_id,
                        text="Cannot kick member")
                    send_message = func.get_username_from_message(
                        reply) + " has not been banned."
            try:
                context.bot.delete_message(chat_id=reply.chat_id,
                                           message_id=reply.message_id)
            except:
                context.bot.send_message(
                    chat_id=update.effective_message.chat_id,
                    text="Cannot delete message")
        else:
            send_message = "User is verified"
        context.bot.send_message(chat_id=update.effective_message.chat_id,
                                 text=send_message)
        conn.close()
    context.bot.delete_message(chat_id=update.message.chat_id,
                               message_id=update.message.message_id)
示例#3
0
def verify(update, context):
    """Adds user from reply message to verified list"""
    reply = update.message.reply_to_message
    if update.effective_user.id in get_admin_ids(context.bot, update.message.chat_id):
        if reply is not None:
            with create_connection(main_db_file) as conn:
                mycursor = conn.cursor()
                user_id_number = int(reply.from_user.id)
                chat_id = int(reply.chat_id)
                mycursor.execute("SELECT services FROM verified WHERE chat_id = %s and user_id = %s" %
                                 (chat_id, user_id_number))
                result = mycursor.fetchall()
                details = ''
                if context.args and context.args[0] != '':
                    details = ' '.join(context.args)
                if result is None or len(result) == 0:
                    names = func.get_all_names(reply)
                    input_names = func.get_all_names(update.message)
                    mycursor.execute(
                        "INSERT INTO verified (chat_id, user_id, services, username, first_name, input_id, input_username, input_first_name) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)" %
                        (chat_id, user_id_number, details[:25], names[0], names[1], update.effective_user.id,
                         input_names[0],
                         input_names[1]))
                    db.commit()
                    update.message.reply_text("Verified services: " + details[:25])
                else:
                    mycursor.execute("UPDATE verified SET services = %s where chat_id = %s and user_id = %s" %
                                     (details[:25], chat_id, user_id_number))
                    db.commit()
                    update.message.reply_text("Updated services: " + details[:25])
        else:
            if context.args[0].lower() == "help":
                send_message = "In a reply to the user in question list the services they are verified for."
            else:
                send_message = "For security please use this command in a reply to the user in question"
            context.bot.send_message(chat_id=update.effective_message.chat_id, text=send_message)
示例#4
0
def warn(update, context):
    """Assigns warning to user and kicks after 3 warnings"""
    if update.effective_user.id in get_admin_ids(context.bot,
                                                 update.message.chat_id):
        reply = update.message.reply_to_message
        reason = ""
        send_message = "@" + func.get_username_from_message(reply)
        if context.args and context.args[0] is not None:
            reason = ' '.join(context.args)[:150]
        if reply is not None and reply.from_user.id not in get_admin_ids(
                context.bot, update.message.chat_id):
            conn = create_connection()
            db_cursor = conn.cursor()
            user_id_number = int(reply.from_user.id)
            chat_id = int(reply.chat_id)
            names = func.get_all_names(reply)
            db_cursor.execute(
                "SELECT * FROM warnings WHERE user_id = %s AND chat_id = %s",
                (user_id_number, chat_id))
            fetch = db_cursor.fetchall()
            print(len(fetch))
            if len(fetch) == 0:
                send_message += " has been warned 1/3 times."
            elif len(fetch) == 1:
                send_message += " has been warned 2/3 times."
            elif len(fetch) == 2:
                try:
                    context.bot.kick_chat_member(chat_id=reply.chat_id,
                                                 user_id=user_id_number)
                    send_message = func.get_username_from_message(
                        reply) + " has 3/3 warnings and has been banned."
                except:
                    context.bot.send_message(
                        chat_id=update.effective_message.chat_id,
                        text="Cannot kick member")
                    send_message = func.get_username_from_message(
                        reply) + " has 3/3 warnings but could not be banned."
            if reason is not "":
                send_message += " Reason: " + reason
            db_cursor.execute(
                "INSERT INTO warnings (chat_id, user_id, username, first_name, reason) VALUES (%s,%s,%s,%s,%s)",
                (chat_id, user_id_number, names[0], names[1], reason))
            conn.commit()
            context.bot.send_message(chat_id=update.effective_message.chat_id,
                                     text=send_message)
            conn.close()
    context.bot.delete_message(chat_id=update.message.chat_id,
                               message_id=update.message.message_id)
示例#5
0
def add_giveaway(update, context):
    """Function to add, remove, and participate in give aways"""
    if context.args and len(context.args) > 0:
        names = func.get_all_names(update.effective_message)
        user_id = update.effective_user.id
        chat_id = update.message.chat_id
        conn = create_connection()
        db_cursor = conn.cursor()
        details = ' '.join(context.args)[:100]
        sql = "SELECT * FROM giveaways WHERE user_id = %s AND chat_id = %s AND status = 'active'"
        db_cursor.execute(sql, (
            user_id,
            chat_id,
        ))
        myresult = db_cursor.fetchall()
        if len(myresult) > 0:
            sql = "UPDATE giveaways SET giveaway_details = %s WHERE user_id = %s AND chat_id = %s AND status = 'status'"
            db_cursor.execute(sql, (
                details,
                user_id,
                chat_id,
            ))
            send_message = 'Giveaway updated'
        else:
            sql = "INSERT INTO giveaways (user_id, chat_id, username, first_name, giveaway_details) VALUES (%s,%s,%s," \
                  "%s,%s) "
            db_cursor.execute(sql,
                              (user_id, chat_id, names[0], names[1], details))
            send_message = 'Giveaway added'
        conn.commit()
        conn.close()
        update.message.reply_text(send_message)
    else:
        send_message_delayed_delete(update, context,
                                    'Missing giveaway details', 30)
        context.bot.delete_message(chat_id=update.message.chat_id,
                                   message_id=update.message.message_id)
示例#6
0
def enter(update, context):
    """Quickly enter last giveaway"""
    global users_talking
    user_id = update.effective_user.id
    chat_id = update.message.chat_id
    users_talking[str(chat_id)] = []
    names = func.get_all_names(update.message)
    conn = create_connection()
    db_cursor = conn.cursor()
    sql = "SELECT giveaway_id, user_id, giveaway_details FROM giveaways WHERE status = 'active' and chat_id = %s"
    db_cursor.execute(sql, (chat_id, ))
    giveaways_result = db_cursor.fetchall()
    if len(giveaways_result) == 0:
        send_message_delayed_delete(update, context, "No active giveaways", 30)
        return
    if context.args and len(context.args) > 0 and ''.join(
            context.args).isdigit():
        number = int(''.join(context.args)) - 1
        if 0 <= number < len(giveaways_result):
            giveaway_id = giveaways_result[number][0]
            giveaway_name = str(
                func.get_username_from_chat_id(
                    context.bot.getChat(giveaways_result[number][1])))
            giveaway_details = giveaways_result[number][2]
        else:
            send_message_delayed_delete(update, context,
                                        "I don't think that giveaway exists.",
                                        30)
            context.bot.delete_message(chat_id=update.message.chat_id,
                                       message_id=update.message.message_id)
            return
    else:
        sql = "SELECT settings.last_giveaway, giveaways.user_id, giveaway_details FROM settings join giveaways ON " \
              "settings.last_giveaway = giveaway_id WHERE settings.chat_id = %s AND giveaways.status = 'active' "
        db_cursor.execute(sql, (chat_id, ))
        result = db_cursor.fetchone()
        if result is None or result[0] is None:
            send_message_delayed_delete(
                update, context,
                "No recent giveaway, or most recent giveaway closed.", 30)
            context.bot.delete_message(chat_id=update.message.chat_id,
                                       message_id=update.message.message_id)
            return
        giveaway_id = result[0]
        giveaway_name = str(
            func.get_username_from_chat_id(context.bot.getChat(result[1])))
        giveaway_details = result[2]
    sql = "SELECT * FROM participants WHERE giveaway_id = %s and chat_id = %s and user_id = %s"
    db_cursor.execute(sql, (
        giveaway_id,
        chat_id,
        user_id,
    ))
    giveaways_result = db_cursor.fetchall()
    if len(giveaways_result) == 0:
        sql = "UPDATE settings SET last_giveaway = %s WHERE chat_id = %s"
        db_cursor.execute(sql, (giveaway_id, chat_id))
        conn.commit()
        sql = "INSERT INTO participants (giveaway_id, user_id, chat_id, username, first_name) VALUES (%s,%s,%s,%s,%s)"
        db_cursor.execute(sql,
                          (giveaway_id, user_id, chat_id, names[0], names[1]))
        conn.commit()

        if names[0] is not None and names[0] is not '':
            name = names[0]
        else:
            name = names[1]
        sql = "SELECT * FROM participants WHERE giveaway_id = %s and chat_id = %s"
        db_cursor.execute(sql, (
            giveaway_id,
            chat_id,
        ))
        giveaways_result = db_cursor.fetchall()
        message = "Use /enter to join " + name + " and " + str(
            len(giveaways_result)
        ) + "others for a chance to win " + giveaway_name + "'s giveaway of " + giveaway_details
        limit_messages(update, context, message, 'enter', True)
    else:
        send_message_delayed_delete(
            update, context,
            "Pretty sure you're already in this giveaway. (Or maybe one of us made a mistake!)",
            30)
    conn.close()
    context.bot.delete_message(chat_id=update.message.chat_id,
                               message_id=update.message.message_id)