Skip to content

Commit

Permalink
Implement :owner_override
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Dec 23, 2017
1 parent a8ec929 commit be8563f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 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.3'
s.date = '2017-11-15'
s.version = '0.4.4'
s.date = '2017-12-23'
s.summary = 'Commandrb'
s.description = 'A customisable and easy to use Commands System for Discordrb.'
s.authors = ['Erisa Komuro (Seriel)']
Expand Down
42 changes: 21 additions & 21 deletions lib/commandrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def initialize(init_hash)

if @config[:token].nil? or init_hash[:token] == ''
raise 'No token supplied in init hash!'
return false
end

init_parse_self = init_hash[:parse_self] rescue nil
Expand All @@ -55,7 +54,6 @@ def initialize(init_hash)
if init_type == :bot
if init_hash[:client_id].nil?
raise 'No client ID or invalid client ID supplied in init hash!'
return false
end
end

Expand Down Expand Up @@ -105,31 +103,33 @@ def initialize(init_hash)
puts "Prefix matched! #{@activator}" if @debug_mode

# Continue only if you've already chosen a choice.
unless @chosen.nil?
if @chosen.nil?
puts "First match obtained!" if @debug_mode
@continue = true
@chosen = @activator
else
# If the new activator begins with the chosen one, then override it.
# Example: sh is chosen, shell is the new one.
# In this example, shell would override sh, preventing ugly bugs.
if @activator.start_with?(@chosen)
puts "#{@activator} just overrode #{@chosen}" if @debug_mode
@chosen = @activator
# Otherwhise, just give up.
# Otherwhise, just give up.
else
puts "Match failed..." if @debug_mode
next
end
# If you haven't chosen yet, get choosing!
else
puts "First match obtained!" if @debug_mode
@continue = true
@chosen = @activator
# If you haven't chosen yet, get choosing!
end
end
}

puts "Result: #{@chosen}" if @debug_mode

next if !@continue
puts "Final esult: #{@chosen}" if @debug_mode
unless @continue
next
end
puts "Final result: #{@chosen}" if @debug_mode

break if @config[:selfbot] && event.user.id != @bot.profile.id

Expand All @@ -140,19 +140,20 @@ def initialize(init_hash)
command[:server_only] = false if command[:server_only].nil?
command[:typing] = @config[:typing_default] if command[:typing_default].nil?
command[:delete_activator] = @config[:delete_activators] if command[:delete_activator].nil?
command[:owner_override] = false if command[:owner_override].nil?

# If the command is set to owners only and the user is not the owner, show error and abort.
puts "[DEBUG] Command being processed: '#{command}'" if @debug_mode
puts "[DEBUG] Owners only? #{command[:owners_only]}" if @debug_mode
if command[:owners_only]
if !@config[:owners].include?(event.user.id)
unless @config[:owners].include?(event.user.id)
event.channel.send_message('', false,
Helper.error_embed(
error: "You don't have permission for that!\nOnly owners are allowed to access this command.",
footer: "Command: `#{event.message.content}`",
colour: 0xFA0E30,
code_error: false
)
Helper.error_embed(
error: "You don't have permission for that!\nOnly owners are allowed to access this command.",
footer: "Command: `#{event.message.content}`",
colour: 0xFA0E30,
code_error: false
)
)
puts 'Were returning!'
@finished = true
Expand Down Expand Up @@ -216,7 +217,6 @@ def initialize(init_hash)
# Check the number of args for the command.
unless command[:max_args].nil?
if command[:max_args] > 0 && args.length > command[:max_args]
# May be replaced with an embed.
event.channel.send_message('', false,
Helper.error_embed(
error: "Too many arguments! \nMax arguments: `#{command[:max_args]}`",
Expand All @@ -232,7 +232,7 @@ def initialize(init_hash)

unless command[:required_permissions].nil?
command[:required_permissions].each { |x|
unless event.user.on(event.server).permission?(x,event.channel)
unless event.user.on(event.server).permission?(x,event.channel) || (command[:owner_override] && @config[:owners].include?(event.user.id) )
event.channel.send_message('', false,
Helper.error_embed(
error: "You don't have permission for that!\nPermission required: `#{x.to_s}`",
Expand All @@ -246,7 +246,7 @@ def initialize(init_hash)
end
}
end

unless @finished
# If the command is configured to catch all errors, thy shall be done.
if !command[:catch_errors] || @config['catch_errors']
Expand Down

0 comments on commit be8563f

Please sign in to comment.