Przeglądaj źródła

Merge branch 'Polling' of PMD/rotom_bot into master

kjswis 6 lat temu
rodzic
commit
dae68a3f4b
2 zmienionych plików z 31 dodań i 1 usunięć
  1. 21 0
      app/responses/poll.rb
  2. 10 1
      bot.rb

+ 21 - 0
app/responses/poll.rb

@@ -0,0 +1,21 @@
+def new_poll_embed(event, question, options)
+    fields = []
+    name = event.author.nickname || event.author.name
+
+    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:  question,
+        description: "Created by : #{name}",
+        fields: fields
+    )
+
+    chat_embed.color = event.author.color.combined
+
+    poll = event.send_embed("", chat_embed)
+    options.each.with_index do |_, index|
+      poll.react(Emoji::LETTERS[index])
+    end
+  end

+ 10 - 1
bot.rb

@@ -135,13 +135,22 @@ app = Command.new(:app, "Everything to do with character applications", opts) do
   end
 end
 
+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
+
 # ---
 
 commands = [
   hello,
   matchup,
   app,
-  help
+  help,
+  poll
 ]
 
 # This will trigger on every message sent in discord