浏览代码

Raffle Command

Raffle Command
Neiro 6 年之前
父节点
当前提交
bcfddfb91b
共有 2 个文件被更改,包括 37 次插入1 次删除
  1. 12 0
      app/responses/generic.rb
  2. 25 1
      bot.rb

+ 12 - 0
app/responses/generic.rb

@@ -0,0 +1,12 @@
+def new_generic_embed(event, title, text)
+    name = event.author.nickname || event.author.name
+
+    chat_embed = Embed.new(
+        title:  title,
+        description: text
+    )
+
+    chat_embed.color = event.author.color.combined
+
+    raffle = event.send_embed("", chat_embed)
+  end

+ 25 - 1
bot.rb

@@ -143,6 +143,29 @@ poll = Command.new(:poll, "Creates a dynamic poll in any channel", opts) do |eve
   command_error_embed("There was an error creating your poll!", poll) unless question && options
 end
 
+opts = { "participants" => "May accept Everyone, Here, or a comma seperated list of names"}
+raffle = Command.new(:raffle, "Creates a raffle and picks a winner", opts) do |event, participant|
+  user_channel = event.author.dm
+
+  case participant
+  when 'everyone'
+    participants = event.server.members
+    participant = participants[rand(0...participants.count)]
+    participant = participant.nickname || participant.username
+  when 'here'
+    participants = event.message.channel.users
+    participant = participants[rand(0...participants.count)]
+    participant = participant.nickname || participant.username
+  else
+    participants = participant.split(/\s?,\s?/)
+    participant = participants[rand(0...participants.count)]
+  end
+
+  new_generic_embed(event, "Raffle Results!", "Winner: " + participant) if participant
+
+  command_error_embed("There was an error creating your raffle!", raffle) unless participant
+end
+
 # ---
 
 commands = [
@@ -150,7 +173,8 @@ commands = [
   matchup,
   app,
   help,
-  poll
+  poll,
+  raffle
 ]
 
 # This will trigger on every message sent in discord