Skip to content

Commit

Permalink
Permission fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 12, 2017
1 parent 12e7de6 commit dac6cb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions commandrb.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'commandrb'
s.version = '0.4.1'
s.date = '2017-10-31'
s.version = '0.4.2'
s.date = '2017-11-12'
s.summary = 'Commandrb'
s.description = 'A customisable and easy to use Commands System for Discordrb.'
s.authors = ['Erisa Komuro (Seriel)']
Expand Down
42 changes: 26 additions & 16 deletions lib/commandrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,42 @@ def initialize(init_hash)
code_error: false
)
)
@finished = true
break
end
end

# If the command is configured to catch all errors, thy shall be done.
if !command[:catch_errors] || @config['catch_errors']
# Run the command code!
command[:code].call(event, args, rawargs)
else
# Run the command code, but catch all errors and output accordingly.
begin
command[:code].call(event, args, rawargs)
rescue Exception => e
event.respond("❌ An error has occured!! ```ruby\n#{e}```Please contact the bot owner with the above message for assistance.")
end
end

unless command[:required_permissions].nil?
command[:required_permissions].each { |x|
if event.user.on(event.server).permission?(x,event.channel)
event.respond('❌ You don\'t have permission for that!')
unless event.user.on(event.server).permission?(x,event.channel)
event.channel.send_message('', false,
Helper.error_embed(
error: "You don't have permission for that!\nPermission required: `#{x.to_s}`",
footer: "Command: `#{event.message.content}`",
colour: 0xFA0E30,
code_error: false
)
)
@finished = true
next
break
end
}
end

unless @finished
# If the command is configured to catch all errors, thy shall be done.
if !command[:catch_errors] || @config['catch_errors']
# Run the command code!
command[:code].call(event, args, rawargs)
else
# Run the command code, but catch all errors and output accordingly.
begin
command[:code].call(event, args, rawargs)
rescue Exception => e
event.respond("❌ An error has occured!! ```ruby\n#{e}```Please contact the bot owner with the above message for assistance.")
end
end
end

# All done here.
puts "Finished!! Executed command: #{@chosen}" if @debug_mode
Expand Down

0 comments on commit dac6cb0

Please sign in to comment.