Explorar o código

alter poll command and include help

Kylie Jo Swistak %!s(int64=6) %!d(string=hai) anos
pai
achega
81987cd9b4
Modificáronse 2 ficheiros con 15 adicións e 14 borrados
  1. 9 12
      app/responses/poll.rb
  2. 6 2
      bot.rb

+ 9 - 12
app/responses/poll.rb

@@ -1,24 +1,21 @@
-def new_poll_embed(event, options)
+def new_poll_embed(event, question, options)
     fields = []
-    optionsArray = options.split(",")
     name = event.author.nickname || event.author.name
 
-    a = optionsArray.count
-
-    for b in 1..a-1 do            
-        fields.push(name: Emoji::LETTERS[b-1], value: optionsArray[b] + "\n" + CharAppResponses::INLINE_SPACE , inline:true)
+    options.map.with_index do |option, index|
+      fields.push({ name: "#{Emoji::LETTERS[index]} #{option}", value: CharAppResponses::INLINE_SPACE, inline: true })
     end
 
     chat_embed = Embed.new(
-        title:  optionsArray[0],
+        title:  question,
         description: "Created by : #{name}",
-        color: event.author.color.combined,
         fields: fields
     )
 
-    msg = event.send_embed("", chat_embed)
+    chat_embed.color = event.author.color.combined
 
-    for b in 1..a-1 do            
-        msg.react(Emoji::LETTERS[b-1])
+    poll = event.send_embed("", chat_embed)
+    options.each.with_index do |_, index|
+      poll.react(Emoji::LETTERS[index])
     end
-  end
+  end

+ 6 - 2
bot.rb

@@ -135,8 +135,12 @@ app = Command.new(:app, "Everything to do with character applications", opts) do
   end
 end
 
-poll = Command.new(:poll) do |event, options|
-  new_poll_embed(event, options)
+opts = { "question | option1, option2, etc" => "Creates a poll for the specified question with the given options"}
+poll = Command.new(:poll, "Creates a dynamic poll in any channel", opts) do |event, question, options|
+  options_array = options.split(/\s?,\s?/) if options
+  new_poll_embed(event, question, options_array) if options
+
+  command_error_embed("There was an error creating your poll!", poll) unless question && options
 end
 
 # ---