-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from tadeokondrak/devel-devops
Added SelfRoles functionality and Rubocop compliance
- Loading branch information
Showing
8 changed files
with
143 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
inherit_from: | ||
- https://raw.githubusercontent.com/meew0/discordrb/master/.rubocop.yml | ||
|
||
Metrics/LineLength: | ||
Max: 119 | ||
|
||
Style/GlobalVars: | ||
AllowedVariables: | ||
- $config | ||
- $pasta | ||
- $figlet | ||
- $user_type | ||
- $bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
source "https://rubygems.org" do | ||
gem 'fullwidth' | ||
gem 'discordrb' | ||
gem 'figlet' | ||
gem 'cowsay' | ||
gem 'fortune_gem' | ||
gem 'pry' | ||
source 'https://rubygems.org' do | ||
gem 'cowsay' | ||
gem 'discordrb' | ||
gem 'figlet' | ||
gem 'fortune_gem' | ||
gem 'fullwidth' | ||
gem 'pry' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
# Implements administration commands that are unavailable to regular users. | ||
module Admin | ||
extend Discordrb::Commands::CommandContainer | ||
|
||
command(:clear, | ||
description: "Clears N amount of messages. If no arguments are " \ | ||
"specified, 100 messages will be cleared. " \ | ||
"Requires superuser", | ||
help_available: false) \ | ||
do |event, *args| | ||
unless $userType != 'sudoer' | ||
event.channel.send_message("Invalid amount") && | ||
break if args[0].to_i > 100 | ||
toDelete = event.channel.history(args.empty? ? 100 : args[0].to_i+1) | ||
event.channel.delete_messages(toDelete) | ||
"Clearing..." | ||
description: 'Clears N amount of messages. If no arguments are ' \ | ||
'specified, 100 messages will be cleared. ' \ | ||
'Requires superuser', | ||
help_available: false) do |event, *args| | ||
if $user_type == 'sudoer' | ||
event.channel.send_message('Invalid amount') && break if args[0].to_i > 100 | ||
to_delete = event.channel.history(args.empty? ? 100 : args[0].to_i + 1) | ||
event.channel.delete_messages(to_delete) | ||
else | ||
"Permission denied." | ||
'Permission denied.' | ||
end | ||
end | ||
|
||
command(:timeout, | ||
description: "Times out a user for N seconds. Requires superuser", | ||
description: 'Times out a user for N seconds. Requires superuser', | ||
min_args: 2, | ||
usage: "[user to timeout] [seconds of timeout]", | ||
help_available: false) \ | ||
do |event, *args| | ||
unless $userType != 'sudoer' | ||
timeOut = fork do | ||
usage: '[user to timeout] [seconds of timeout]', | ||
help_available: false) do |event, *args| | ||
if $user_type == 'sudoer' | ||
time_out = fork do | ||
user = event.message.mentions[0].on($config['serverID']) | ||
user.add_role($config['timeoutRole']) | ||
sleep args[1].to_i | ||
user.remove_role($config['timeoutRole']) | ||
"#{user.name} timed out for #{args[1].to_i}" | ||
event.channel.send_message("#{user.name} timed out for #{args[1].to_i}") | ||
end | ||
puts Process.detach(timeOut) #This puts is imporant so the thread ID | ||
else #Doesn't get outputted by the bot | ||
"Permission denied." | ||
Process.detach(time_out) | ||
return | ||
else | ||
'Permission denied.' | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,65 @@ | ||
# Implements fluff commands that serve no real use | ||
module Fun | ||
extend Discordrb::Commands::CommandContainer | ||
|
||
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| | ||
description: 'Makes a message A E S T H E T I C', | ||
usage: '[text to convert]', | ||
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| | ||
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.author.id.to_s}> 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.to_s}> slaps " \ | ||
"#{args.join(' ')} around a bit with a large trout") | ||
description: 'Hit someone or something', | ||
usage: '[text]') do |event, *args| | ||
"<@#{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| | ||
"```" + $figlet[args.join('')] + "```" | ||
description: 'Turns a message into big ASCII art letters', | ||
usage: '[text]', | ||
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| | ||
inputtext = args.join(' ').gsub("```", ''); | ||
renderedtext = Cowsay.say(inputtext, 'cow') | ||
chunkedtext = "" | ||
until renderedtext.empty? | ||
sliced = renderedtext.slice(0..1990) | ||
lastindex = sliced.length - 1 | ||
lastline = sliced.lines.last | ||
unless lastline.end_with? '\n' or renderedtext.length == sliced.length | ||
lastindex -= lastline.length | ||
description: 'Wraps a message with an ASCII art cow', | ||
usage: '[text]', | ||
min_args: 1) do |_event, *args| | ||
input_text = args.join(' ').gsub('```', '') | ||
rendered_text = Cowsay.say(input_text, 'cow') | ||
chunked_text = '' | ||
until rendered_text.empty? | ||
sliced = rendered_text.slice(0..1990) | ||
last_index = sliced.length - 1 | ||
last_line = sliced.lines.last | ||
unless last_line.end_with?('\n') || rendered_text.length == sliced.length | ||
last_index -= last_line.length | ||
end | ||
chunkedtext << "```\n" + renderedtext.slice!(0..lastindex)+ "\n```" \ | ||
+ " " * lastline.length + "\n" | ||
chunked_text << "```\n" + rendered_text.slice!(0..last_index) + "\n```" \ | ||
+ ' ' * last_line.length + "\n" | ||
end | ||
chunkedtext | ||
chunked_text | ||
end | ||
|
||
command(:me, | ||
description: "Executes a self action", | ||
usage: "[text]", | ||
min_args: 1) \ | ||
do |event, *args| | ||
description: 'Executes a self action', | ||
usage: '[text]', | ||
min_args: 1) do |event, *args| | ||
event.channel.delete_message(event.channel.history(1)[0]) | ||
"<@#{event.user.id.to_s}> *#{args.join(' ')}*" | ||
"<@#{event.user.id}> *#{args.join(' ')}*" | ||
end | ||
|
||
command(:fortune, | ||
description: "Outputs a random fortune / divination / bad joke") \ | ||
do |event| | ||
"```" + FortuneGem.give_fortune + "```" | ||
description: 'Outputs a random fortune / divination / bad joke') do |_event| | ||
'```' + FortuneGem.give_fortune + '```' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,68 @@ | ||
# Implements utility commands for everyone's use | ||
module Utilities | ||
extend Discordrb::Commands::CommandContainer | ||
|
||
command(:random, | ||
description: "Picks a random number.", | ||
usage: "<min> <max>", | ||
min_args: 2) \ | ||
do |event| | ||
description: 'Picks a random number.', | ||
usage: '<min> <max>', | ||
min_args: 2) do |event| | ||
# Parse the message and keep all parts but the command | ||
# ["::random 1 2 4 5 -5"] => ["1", "2", "4", "5", "-5"] | ||
args = (event.message.content.split (' '))[1 .. -1] | ||
args = event.message.content.split(' ')[1..-1] | ||
|
||
# Args to integer | ||
input = Array.new(args.size){ |i| args[i].to_i } | ||
input = Array.new(args.size) { |i| args[i].to_i } | ||
|
||
case input.size | ||
when 0 | ||
# Integer "limits" (there's no such thing in ruby though) | ||
min = -(2**(0.size * 8 -2)) | ||
min = -(2**(0.size * 8 - 2)) | ||
max = min.abs | ||
when 1 | ||
min = 0 | ||
max = 0 | ||
# If one args is given, the result will be of the same sign as the arg | ||
input[0] >= 0? max = input[0] : min = input[0] | ||
input[0] >= 0 ? max = input[0] : min = input[0] | ||
else | ||
min = input.min | ||
max = input.max | ||
end | ||
rand(min .. max) | ||
rand(min..max) | ||
end | ||
|
||
command(:echo, | ||
description: "Echoes text.", | ||
usage: "[text to echo]", | ||
min_args: 1) \ | ||
do |event, *args| | ||
description: 'Echoes text.', | ||
usage: '[text to echo]', | ||
min_args: 1) do |_event, *args| | ||
args.join(' ') | ||
end | ||
|
||
command(:lusers, | ||
description: "Prints the amount of lusers currently online.", | ||
usage: "!lusers") \ | ||
do |event| | ||
"Amount of lusers currently #{$config['lusersList'].sample}: #{event.server.online_users(include_idle: true).length.to_s}" | ||
description: 'Prints the amount of lusers currently online.', | ||
usage: '!lusers') do |event| | ||
"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| | ||
"You are a #{event.user.roles.include?($config['sudoersRole'])?'sudoer':'regular user'}." | ||
usage: '!checksudo') do |event| | ||
"You are a #{event.user.roles.include?($config['sudoersRole']) ? 'sudoer' : 'regular user'}." | ||
end | ||
|
||
command(:getrole, | ||
description: 'Adds a self-assignable role', | ||
usage: '<role to request>', | ||
max_args: 1) do |event, *args| | ||
role = args.join('') | ||
if $config['selfRoles'].key?(role) | ||
if event.author.role?(role) | ||
'This user has already assigned that role to himself!' | ||
end | ||
event.author.add_role($config['selfRoles'][role]) | ||
"<@#{event.author.id}> was assigned the role #{role}!" | ||
else | ||
"Error: role #{role} does not exist.\nAvailable roles are: $config['selfRoles'].keys.join(', ')" | ||
end | ||
end | ||
end |
Oops, something went wrong.