Kylie Jo Swistak 6 gadi atpakaļ
vecāks
revīzija
116adf00ab
3 mainītis faili ar 36 papildinājumiem un 20 dzēšanām
  1. 1 1
      app/responses/errors.rb
  2. 22 17
      app/responses/help.rb
  3. 13 2
      bot.rb

+ 1 - 1
app/responses/errors.rb

@@ -28,6 +28,6 @@ def command_error_embed(title, command)
     footer: {
       text: "For more help, feel free to ask a Moderator or Guildmaster"
     },
-    fields: command_usage(command)
+    fields: usage_embed(command)
   )
 end

+ 22 - 17
app/responses/help.rb

@@ -1,44 +1,49 @@
 HELP_BLUE = "#4976ca"
 
-def all_commands_embed(commands)
+def command_list_embed(commands, restriction = nil, title = nil)
   fields = []
   desc = "To learn more about any of the listed commands," +
     " use `pkmn-help [command]`"
 
-  commands.each do |command|
-    fields.push({name: "pkmn-#{command.name}", value: command.description})
+  commands.each do |cmd|
+    fields.push({name: "pkmn-#{cmd.name}", value: cmd.description})
   end
 
+  desc = "#{restriction}\n#{desc}" if restriction
+
   Embed.new(
-    title: "Commands",
+    title: title || "Commands",
     description: desc,
     color: HELP_BLUE,
     fields: fields
   )
 end
 
-def command_embed(command)
-  fields = command_usage(command)
+def command_embed(command, restriction = nil)
+  fields = usage_embed(command)
+  title = "Usage"
 
-  Embed.new(
-    title: "pkmn-#{command.name}",
-    description: command.description,
+  title += ": #{restriction}" if restriction
+
+  embed = Embed.new(
+    title: title,
     color: HELP_BLUE,
+    footer: {
+      text: "Questions? Ask a Guildmaster!"
+    },
     fields: fields
   )
+
+  embed.description = command.description if command.description
+  embed
 end
 
-def command_usage(command)
+def usage_embed(command)
   fields = []
 
-  unless command.options.empty?
-    usage = "```bash\n"
-    command.options.map do |option, description|
-      usage += "##{description}\npkmn-#{command.name} #{option}\n\n"
-    end
-    usage += "```"
+  command.options.map do |option, desc|
+    fields.push({name: desc, value: "```pkmn-#{command.name} #{option}```"})
   end
 
-  fields.push({name: "Usage", value: usage}) if command.options
   fields
 end

+ 13 - 2
bot.rb

@@ -43,6 +43,7 @@ bot = Discordrb::Bot.new(token: token)
 
 # Commands: structure basic bot commands here
 commands = []
+pm_commands = []
 
 hello = Command.new(:hello, "Says hello!") do |event|
   user = event.author.nickname || event.author.name
@@ -74,12 +75,22 @@ help = Command.new(:help, desc, opts) do |event, command|
     short = /pkmn-(\w+)/.match(command)
     command = short ? short[1] : command
     cmd = commands.detect { |c| c.name == command.to_sym }
+    pm_cmd = pm_commands.detect { |pc| pc.name == command.to_sym }
   end
 
   if command && cmd
     command_embed(cmd)
+  elsif command && pm_cmd
+    command_embed(pm_cmd, "PM Command")
   elsif !command
-    all_commands_embed(commands)
+    embed = command_list_embed(
+      pm_commands,
+      "Can only be used in a pm with the bot",
+      "PM Commands"
+    )
+
+    event.send_embed("", embed)
+    command_list_embed(commands)
   else
     command_error_embed("Command not found!", help)
   end
@@ -188,7 +199,7 @@ opts = {
   "name | keyword" => "display image",
   "name" => "list all images"
 }
-desc = "Edit your characters' images"
+desc = "View, add and edit your characters' images"
 image = Command.new(:image, desc, opts) do |event, name, keyword, tag, url|
   user = event.author