Prechádzať zdrojové kódy

Merge branch 'Raffle' of PMD/rotom_bot into master

kjswis 6 rokov pred
rodič
commit
a91715bc97
3 zmenil súbory, kde vykonal 69 pridanie a 25 odobranie
  1. 25 24
      app/models/char_app_responses.rb
  2. 12 0
      app/responses/generic.rb
  3. 32 1
      bot.rb

+ 25 - 24
app/models/char_app_responses.rb

@@ -1,24 +1,25 @@
-# frozen_string_literal: true
-
-module CharAppResponses
-  GRAMMAR = "Please check your grammar and\ncapitalization"
-  UNITS = "Please specify your units in\nImperial or Metric"
-  IMAGE = "Your image is inappropriate for\ndefault use"
-  LORE = "One or more responses are\nconflicting with server lore"
-  UNDER_AGE = "Your age conflicts with the\nspecified rating"
-  INVALID = "One or more responses are\ninvalid"
-  VULGAR = "Your application is too vulgar,\nor conflicts with server rules"
-  DM_NOTES = "Please elaborate on your\nDM Notes"
-  INLINE_SPACE = "------------------------------------"
-
-  REJECT_MESSAGES = {
-    Emoji::SPEECH_BUBBLE => GRAMMAR,
-    Emoji::SCALE => UNITS,
-    Emoji::PICTURE => IMAGE,
-    Emoji::BOOKS => LORE,
-    Emoji::BABY => UNDER_AGE,
-    Emoji::SKULL => INVALID,
-    Emoji::VULGAR => VULGAR,
-    Emoji::NOTE => DM_NOTES
-  }
-end
+# frozen_string_literal: true
+require_relative '../../lib/emoji.rb'
+
+module CharAppResponses
+  GRAMMAR = "Please check your grammar and\ncapitalization"
+  UNITS = "Please specify your units in\nImperial or Metric"
+  IMAGE = "Your image is inappropriate for\ndefault use"
+  LORE = "One or more responses are\nconflicting with server lore"
+  UNDER_AGE = "Your age conflicts with the\nspecified rating"
+  INVALID = "One or more responses are\ninvalid"
+  VULGAR = "Your application is too vulgar,\nor conflicts with server rules"
+  DM_NOTES = "Please elaborate on your\nDM Notes"
+  INLINE_SPACE = "------------------------------------"
+
+  REJECT_MESSAGES = {
+    Emoji::SPEECH_BUBBLE => GRAMMAR,
+    Emoji::SCALE => UNITS,
+    Emoji::PICTURE => IMAGE,
+    Emoji::BOOKS => LORE,
+    Emoji::BABY => UNDER_AGE,
+    Emoji::SKULL => INVALID,
+    Emoji::VULGAR => VULGAR,
+    Emoji::NOTE => DM_NOTES
+  }
+end

+ 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

+ 32 - 1
bot.rb

@@ -143,6 +143,36 @@ 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
+
+  participants =
+    case participant
+    when /^everyone$/i
+      event.server.members
+    when /^here$/i
+      event.message.channel.users
+    else
+      participant.split(/\s?,\s?/)
+    end
+
+  winner = participants.sample
+  winner_name = 
+    case winner
+    when String
+      winner
+    else
+      winner.nickname || winner.username
+    end
+
+    if winner_name
+      new_generic_embed(event, "Raffle Results!", "Winner: " + winner_name)
+    else
+      command_error_embed("There was an error creating your raffle!", raffle)
+    end
+end
+
 # ---
 
 commands = [
@@ -150,7 +180,8 @@ commands = [
   matchup,
   app,
   help,
-  poll
+  poll,
+  raffle
 ]
 
 # This will trigger on every message sent in discord