Skip to content

Commit

Permalink
This should fix piping behavior without breaking sudo
Browse files Browse the repository at this point in the history
Moved the break clause higher to avoid garbage returns when piping a sudo command
  • Loading branch information
ldelelis committed Dec 3, 2017
1 parent cfe0e6e commit 128e881
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Admin
to_delete = event.channel.history(args.empty? ? 100 : args[0].to_i + 1)
event.channel.delete_messages(to_delete)
else
event.channel.send_message('Permission denied.')
'Permission denied.'
end
end

Expand All @@ -32,7 +32,7 @@ module Admin
Process.detach(time_out)
return
else
event.channel.send_message('Permission denied.')
'Permission denied.'
end
end
end
22 changes: 11 additions & 11 deletions lib/fun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ module Fun
command(:aesthic,
description: 'Makes a message A E S T H E T I C',
usage: '[text to convert]',
min_args: 1) do |event, *args|
event.channel.send_message(args.join(' ').to_fullwidth)
min_args: 1) do |_event, *args|
args.join(' ').to_fullwidth
end

command(:step,
description: 'Show your soles to someone or something',
usage: '[text]',
min_args: 1) do |event, *args|
args.to_a.delete_at(0) if args.include?('on')
event.channel.send_message("<@#{event.author.id}> steps on #{args.join(' ')}")
"<@#{event.author.id}> steps on #{args.join(' ')}"
end

command(:slap,
description: 'Hit someone or something',
usage: '[text]') do |event, *args|
event.channel.send_message("<@#{event.author.id}> slaps #{args.join(' ')} around a bit with a large trout")
"<@#{event.author.id}> slaps #{args.join(' ')} around a bit with a large trout"
end

command(:figlet,
description: 'Turns a message into big ASCII art letters',
usage: '[text]',
min_args: 1) do |event, *args|
event.channel.send_message('```' + $figlet[args.join('')] + '```')
min_args: 1) do |_event, *args|
'```' + $figlet[args.join('')] + '```'
end

command(:cowsay,
description: 'Wraps a message with an ASCII art cow',
usage: '[text]',
min_args: 1) do |event, *args|
min_args: 1) do |_event, *args|
input_text = args.join(' ').gsub('```', '')
rendered_text = Cowsay.say(input_text, 'cow')
chunked_text = ''
Expand All @@ -47,19 +47,19 @@ module Fun
chunked_text << "```\n" + rendered_text.slice!(0..last_index) + "\n```" \
+ ' ' * last_line.length + "\n"
end
event.channel.send_message(chunked_text)
chunked_text
end

command(:me,
description: 'Executes a self action',
usage: '[text]',
min_args: 1) do |event, *args|
event.channel.delete_message(event.channel.history(1)[0])
event.channel.send_message("<@#{event.user.id}> *#{args.join(' ')}*")
"<@#{event.user.id}> *#{args.join(' ')}*"
end

command(:fortune,
description: 'Outputs a random fortune / divination / bad joke') do |event|
event.channel.send_message('```' + FortuneGem.give_fortune + '```')
description: 'Outputs a random fortune / divination / bad joke') do |_event|
'```' + FortuneGem.give_fortune + '```'
end
end
20 changes: 8 additions & 12 deletions lib/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@ module Utilities
command(:echo,
description: 'Echoes text.',
usage: '[text to echo]',
min_args: 1) do |event, *args|
event.channel.send_message(args.join(' '))
min_args: 1) do |_event, *args|
args.join(' ')
end

command(:lusers,
description: 'Prints the amount of lusers currently online.',
usage: '!lusers') do |event|
event.channel.send_message('Amount of lusers currently ' \
"#{$config['lusersList'].sample}:" \
"#{event.server.online_users(include_idle: true).length}")
"Amount of lusers currently #{$config['lusersList'].sample}:" \
"#{event.server.online_users(include_idle: true).length}"
end

command(:checksudo,
description: "Prints if you're a sudoer",
usage: '!checksudo') do |event|
event.channel.send_message('You are a ' \
"#{event.user.roles.include?($config['sudoersRole']) ? 'sudoer' : 'regular user'}.")
"You are a #{event.user.roles.include?($config['sudoersRole']) ? 'sudoer' : 'regular user'}."
end

command(:getrole,
Expand All @@ -59,14 +57,12 @@ module Utilities
role = args.join('')
if $config['selfRoles'].key?(role)
if event.author.role?(role)
event.channel.send_message('This user has already assigned that role to himself!')
return
'This user has already assigned that role to himself!'
end
event.author.add_role($config['selfRoles'][role])
event.channel.send_message("<@#{event.author.id}> was assigned the role #{role}!")
"<@#{event.author.id}> was assigned the role #{role}!"
else
event.channel.send_message("Error: role #{role} does not exist.\nAvailable roles are: " +
$config['selfRoles'].keys.join(', '))
"Error: role #{role} does not exist.\nAvailable roles are: $config['selfRoles'].keys.join(', ')"
end
end
end
4 changes: 2 additions & 2 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
$user_type = 'sudoer'
$bot.execute_command(run_command.to_sym, event, args)
$user_type = 'normal'
break # Avoids garbage messages
end
break # Avoids garbage messages
end

$pasta.keys.each do |pasta| # Slightly improved
Expand All @@ -63,7 +63,7 @@
end
end
end
event.channel.send_message(message)
message
end
end
end
Expand Down

0 comments on commit 128e881

Please sign in to comment.