<commit_before>package me.mrkirby153.KirBot.command.executors.polls

import me.mrkirby153.KirBot.command.Command
import me.mrkirby153.KirBot.command.executors.CommandExecutor
import me.mrkirby153.KirBot.user.Clearance
import net.dv8tion.jda.core.Permission
import net.dv8tion.jda.core.entities.Message
import java.awt.Color
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

@Command(name = "poll", description = "Create polls!", clearance = Clearance.USER, requiredPermissions = arrayOf(Permission.MESSAGE_ADD_REACTION))
class CommandPoll : CommandExecutor() {

    val time = mutableMapOf<String, Int>()

    init {
        time.clear()
        time.put("s", 1)
        time.put("m", 60)
        time.put("h", 3600)
        time.put("d", 86400)
        time.put("w", 604800)
    }

    override fun execute(message: Message, args: Array<String>) {
        // !poll 10m :dog:
        val duration = timeOffset(args[0])
        val options = args.drop(1).joinToString(" ").split(",").map(String::trim)

        if (options.size <= 1) {
            message.send().error("Please provide more than one option for the poll!").queue()
            return
        }

        message.send().embed("Poll") {
            description = "Vote by clicking the reactions on the choices below! Results will be final in ${localizeTime(duration)}"
            field("Options") {
                buildString {
                    options.forEachIndexed { index, option ->
                        appendln("${'\u0030' + (index+1)}\u20E3 **$option**")
                    }
                }
            }
        }.rest().queue {
            for(index in 0..options.size - 1){
                it.addReaction("${'\u0030' + (index+1)}\u20E3").queue()
            }

            it.editMessage(it.embeds[0].edit().apply {
                description = "Voting ended!"
                clearFields()
            }.build()).queueAfter(duration.toLong(), TimeUnit.SECONDS) {
                it.send().embed("Poll Results") {
                    color = Color.CYAN
                    description = "Voting has ended! Here are the results!"

                    var topVotes = 0
                    val winners = mutableListOf<Int>()

                    field("Results") {
                        buildString {
                            it.reactions.forEach { reaction ->
                                val value = reaction.emote.name[0] - '\u0030'
                                if (value !in 0..options.size - 1) return@forEach
<commit_msg>Update poll command to pin polls and not remove options when voting ends<commit_after>package me.mrkirby153.KirBot.command.executors.polls

import me.mrkirby153.KirBot.command.Command
import me.mrkirby153.KirBot.command.executors.CommandExecutor
import me.mrkirby153.KirBot.user.Clearance
import net.dv8tion.jda.core.Permission
import net.dv8tion.jda.core.entities.Message
import java.awt.Color
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

@Command(name = "poll", description = "Create polls!", clearance = Clearance.USER, requiredPermissions = arrayOf(Permission.MESSAGE_ADD_REACTION))
class CommandPoll : CommandExecutor() {

    val time = mutableMapOf<String, Int>()

    init {
        time.clear()
        time.put("s", 1)
        time.put("m", 60)
        time.put("h", 3600)
        time.put("d", 86400)
        time.put("w", 604800)
    }

    override fun execute(message: Message, args: Array<String>) {
        // !poll 10m :dog:
        val duration = timeOffset(args[0])
        val options = args.drop(1).joinToString(" ").split(",").map(String::trim)

        if (options.size <= 1) {
            message.send().error("Please provide more than one option for the poll!").queue()
            return
        }

        if(options.size > 9){
            message.send().error("You can only have 9 options in a poll!").queue()
            return
        }

        message.send().embed("Poll") {
            description = "Vote by clicking the reactions on the choices below! Results will be final in ${localizeTime(duration)}"
            field("Options") {
                buildString {
                    options.forEachIndexed { index, option ->
                        appendln("${'\u0030' + (index+1)}\u20E3 **$option**")
                    }
                }
            }
        }.rest().queue {
            val m = it
            m.pin().queue()
            for(index in 0..options.size - 1){
                it.addReaction("${'\u0030' + (index+1)}\u20E3").queue()
            }

            it.editMessage(it.embeds[0].edit().apply {
                description = "**Voting ended**! Check new message for results"
            }.build()).queueAfter(duration.toLong(), TimeUnit.SECONDS) {
                m.unpin().queue()
                it.send().embed("Poll Results") {
                    color = Color.CYAN
                    description = "Voting has ended! Here are the results!"

                    var topVotes = 0
                    val winners = mutableListOf<Int>()

                    field("Results") {
                        buildString {
                            it.reactions.forEach { reaction ->
                                val value = reaction.emote.name[0] - '\u0030'
                                if (value !in 0..options.size - 1) return@forEach

{'fraction_non_alphanumeric': 0.12688652878703185, 'fraction_numerical': 0.02422209800633501, 'mean_word_length': 1.822292323869611, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3753344', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1471, 'n_words': 325}