Commit 33d85ef1 authored by Cool Fire's avatar Cool Fire
Browse files

Clean up code a little & better CI

parent 259fcfb2
Pipeline #105 passed with stages
in 1 minute and 18 seconds
syntax:
---
stages:
- syntax
- linting
ruby_21:
image: ruby:2.1
stage: syntax
tags:
- ruby
script:
- find . -name '*\.rb' -exec bash -c 'echo -ne "{}\t\t\t" && ruby -c {}' \;
- find . -name "*\.rb" -print0 | xargs -I {} -0 -n1 sh -c "ls {}; ruby -c {}"
ruby_22:
image: ruby:2.2
stage: syntax
tags:
- ruby
script:
- find . -name "*\.rb" -print0 | xargs -I {} -0 -n1 sh -c "ls {}; ruby -c {}"
ruby_23:
image: ruby:2.3
stage: syntax
tags:
- ruby
script:
- find . -name "*\.rb" -print0 | xargs -I {} -0 -n1 sh -c "ls {}; ruby -c {}"
ruby_24:
image: ruby:2.4
stage: syntax
tags:
- ruby
script:
- find . -name "*\.rb" -print0 | xargs -I {} -0 -n1 sh -c "ls {}; ruby -c {}"
rubocop:
stage: linting
tags:
- ruby
script:
- gem install rubocop --no-ri --no-rdoc
- rubocop -l -f simple --except UnusedMethodArgument,RescueException,Eval,AssignmentInCondition
Tested with Ruby versions (Other versions may still work but have not been tested):
Ruby 1.9
Ruby 1.9.1
Ruby 1.9.2
Ruby 1.9.3
Ruby 2.0.0
Ruby 2.1.2
Ruby 2.1.5
jruby 1.1 (SSL)
jruby 1.6.5
Rubinius 2.0.0dev
maglev 1.0.0 (SSL)(T)
(SLL) = SSL isn't supported or doesn't work properly
(T) = Threading doesn't work properly
Due to backward compatiblity issues starting in Ruby 2.1.x we've broken backward compatibility with the Ruby 1.8 branch.
\ No newline at end of file
......@@ -65,7 +65,7 @@ class Commands
# Delay or drop command
if( @timeout[ user+host ] > 0 && @timeout[ user+host ] < @config.floodcut )
@irc.notice( nick, "Delaying by #{@timeout[ user+host ].to_s} seconds. If delay goes over #{@config.floodcut} seconds the command will be dropped.", true )
@irc.notice( nick, "Delaying by #{@timeout[ user+host ]} seconds. If delay goes over #{@config.floodcut} seconds the command will be dropped.", true )
sleep( @timeout[ user+host ] )
elsif ( @timeout[ user+host ] > @config.floodcut )
Thread.exit
......@@ -94,7 +94,7 @@ class Commands
# Parse function call
if( !rest.nil? && !rest.empty? )
function, arguments = rest.split(' ', 2)
function, _arguments = rest.split(' ', 2)
sanitize( function )
# See if such a method exists in this plugin and isn't protected, if so, call it
......@@ -131,7 +131,7 @@ class Commands
ans = STDIN.gets.chomp
end
if( ans =~ /^y$/i || !con )
cmd, message = msg.split( ' ', 2 )
_cmd, message = msg.split( ' ', 2 )
if( message == nil )
@irc.quit( @config.nick + " was instructed to quit.", true )
......@@ -155,7 +155,7 @@ class Commands
# Load modules
def load( nick, user, host, from, msg, auto = false )
if( @config.auth( host, con ) )
cmd, plugin = msg.split( ' ', 2 )
_cmd, plugin = msg.split( ' ', 2 )
if( plugin != nil )
# Clean variable
sanitize( plugin, 1, 1 )
......@@ -171,7 +171,6 @@ class Commands
eval( "loadfile './#{@config.plugindir}/#{plugin}.rb'" )
@output.debug( "Load was successful.\n" )
object = nil
# Try to create an object
eval( "object = #{plugin.capitalize}.new( @status, @config, @output, @irc, @timer )" )
@output.debug( "Object was created.\n" )
......@@ -223,7 +222,7 @@ class Commands
# Unload module
def unload( nick, user, host, from, msg )
if( @config.auth( host, con ) )
cmd, plugin = msg.split( ' ', 2 )
_cmd, plugin = msg.split( ' ', 2 )
if( plugin != nil )
# Clean variable
sanitize( plugin, 1, 1 )
......@@ -331,7 +330,5 @@ class Commands
@irc.notice( nick, output )
output = nil
end
contents = nil
plugins = nil
end
end
......@@ -14,7 +14,7 @@ class Configuration
@server = "irc.insomnia247.nl" # IPv4 address
@server6 = "irc6.insomnia247.nl" # IPv6 address
@port = 6667 # Normal port
@sslport = 6697 # SSL port
@sslport = 8000 # SSL port
@serverpass = "" # Server connect password
@connectopt = "" # Extra stuff to send on connect
......@@ -27,7 +27,7 @@ class Configuration
@data = "data" # Data directory
@plugins = "plugins" # Plugin directory
#@autoload = [ "core", "ddg", "help", "identified", "login", "seen", "shells", "toolbox", "translate", "twitter" ]
@autoload = [ "core", "toolbox" ]
@autoload = [ "core", "toolbox", "title" ]
# Plugin autoload list
@antiflood = true # Attempt to mitigate people flooding bot with commands
......@@ -76,10 +76,6 @@ class Configuration
return @user
end
def pass
@pass
end
def version
return @version
end
......
......@@ -55,7 +55,7 @@ class Console
end
else
# Fallback to STDIO console
while true do
loop do
print( "#{@config.nick}# " )
STDOUT.flush
@cmd.process( "", "", "", "", STDIN.gets.chomp )
......
......@@ -9,7 +9,7 @@ target = ARGV.first
port = 0
# Load config
if File.exists?( configfile )
if File.exist?( configfile )
jsonline = ""
File.open( configfile ) do |file|
......@@ -33,7 +33,6 @@ if File.exists?( configfile )
end
# Start socket
sock = TCPSocket
sock = TCPSocket.open( target, port )
# Start SSL
......
......@@ -175,7 +175,7 @@ class IRC
# Function for queued sending thread
def processqueues
while true do
loop do
line = nil
@signal.pop
if( !@high.empty? )
......
......@@ -28,7 +28,7 @@ class IRCParser
# Main parser loop
begin
while( true )
loop do
# Set IRC timeout
Timeout::timeout( @config.pingtimeout ) do
......
......@@ -96,7 +96,6 @@ class IRCSubs
if( !@status.autoload )
tmp = Commands.new( @status, @config, @output, @irc, @timer, 1 )
tmp.autoload
tmp = nil
@status.autoload( 1 )
end
end
......
......@@ -21,7 +21,6 @@ status.giveConfig( config )
# Process commandline options
parser = ArgumentParser.new( status, config, output, $0 )
parser.parse( ARGV )
parser = nil
# Display banner
output.special( "Starting " + config.version + "\n\n" );
......@@ -37,8 +36,6 @@ startup.checkoutputqueuing
startup.checkdirectoryplugins
startup.checkdirectorydata
startup = nil
# Show configuration, if desired.
config.show
......
......@@ -38,22 +38,22 @@ class Btc
diff = result[ 'ask' ].to_f - result[ 'last' ].to_f
diff = ( diff * 1000 ).round / 1000.0
if( diff > 0 )
diff = "+#{diff.to_s}"
diff = "+#{diff}"
else
diff = "#{diff.to_s}"
diff = "#{diff}"
end
# Calculate delta from last !btc
ldiff = result[ 'ask' ].to_f - @bits_last
ldiff = ( ldiff * 1000 ).round / 1000.0
if( ldiff > 0 )
ldiff = "+#{ldiff.to_s}"
ldiff = "+#{ldiff}"
else
ldiff = "#{ldiff.to_s}"
ldiff = "#{ldiff}"
end
@bits_last = result[ 'ask' ].to_f
line = "Bitstamp rate: $#{result[ 'ask' ]} #{diff.to_s} (#{ldiff} since last !btc)"
line = "Bitstamp rate: $#{result[ 'ask' ]} #{diff} (#{ldiff} since last !btc)"
if( con )
@output.c( line + "\n" )
......@@ -82,22 +82,22 @@ class Btc
diff = result[ 'data' ][ 'sell' ][ 'value' ].to_f - result[ 'data' ][ 'last' ][ 'value' ].to_f
diff = ( diff * 1000 ).round / 1000.0
if( diff > 0 )
diff = "+#{diff.to_s}"
diff = "+#{diff}"
else
diff = "#{diff.to_s}"
diff = "#{diff}"
end
# Calculate delta from last !btc
ldiff = result[ 'data' ][ 'sell' ][ 'value' ].to_f - @last
ldiff = ( ldiff * 1000 ).round / 1000.0
if( ldiff > 0 )
ldiff = "+#{ldiff.to_s}"
ldiff = "+#{ldiff}"
else
ldiff = "#{ldiff.to_s}"
ldiff = "#{ldiff}"
end
@last = result[ 'data' ][ 'sell' ][ 'value' ].to_f
line = "Mtgox rate: #{result[ 'data' ][ 'sell' ][ 'display' ]} (#{result[ 'data' ][ 'sell' ][ 'value' ]}) #{diff.to_s} (#{ldiff} since last !btc mtgox)"
line = "Mtgox rate: #{result[ 'data' ][ 'sell' ][ 'display' ]} (#{result[ 'data' ][ 'sell' ][ 'value' ]}) #{diff} (#{ldiff} since last !btc mtgox)"
end
if( con )
......@@ -115,7 +115,6 @@ class Btc
# Check if ltc plugin is loaded
ratio = ""
ltcv = nil
if( @status.checkplugin( "ltc" ) )
plugin = @status.getplugin( "ltc" )
ltcv = plugin.main( nick, user, host, from, nil, nil, false )
......
......@@ -411,7 +411,6 @@ class Core
else
@irc.notice( nick, output )
end
output = nil
uptime( nick, user, host, from, msg, arguments, con )
end
......@@ -423,7 +422,6 @@ class Core
else
@irc.notice( nick, uptime )
end
uptime = nil
end
def nick( nick, user, host, from, msg, arguments, con )
......
......@@ -39,7 +39,7 @@ class Debiansecurity
private
def check_rss
while true
loop do
begin
agent = Mechanize.new
......@@ -53,7 +53,6 @@ class Debiansecurity
xml = agent.get( @feed_url ).body
xml = Nokogiri::XML( xml )
# Parse out info
title, link = "", ""
title = xml.css( 'item title' ).first.text
link = xml.css( 'item link' ).first.text
......@@ -78,7 +77,7 @@ class Debiansecurity
end
rescue Exception => e
# Silently fail
@output.debug( "Failure while retrieving rss feed: #{e.to_s}\n" )
@output.debug( "Failure while retrieving rss feed: #{e.message}\n" )
end
# Wait for a bit before fetching again
......
......@@ -42,7 +42,7 @@ class Debug
Thread.list.each do |thr|
if( thr.to_s =~ /#{arguments}/ )
thr.backtrace.each do |level|
@output.info( "#{level.to_s}\n" )
@output.info( "#{level}\n" )
end
@output.info( "\n" )
end
......@@ -63,7 +63,7 @@ class Debug
if( @config.auth( host, con ) )
Thread.list.each do |thr|
if( thr.to_s =~ /#{arguments}/ )
@output.info( "#{thr.kill.to_s}\n\n" )
@output.info( "#{thr.kill}\n\n" )
end
end
else
......
......@@ -36,9 +36,9 @@ class Dogecoin
ldiff = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] ) - @last
if( ldiff > 0 )
ldiff = "+#{ldiff.to_s}"
ldiff = "+#{ldiff}"
else
ldiff = "#{ldiff.to_s}"
ldiff = "#{ldiff}"
end
@last = BigDecimal.new( result[ 'return' ][ 'markets' ][ 'DOGE' ][ 'lasttradeprice' ] )
......
......@@ -54,7 +54,7 @@ class Hackerthreads
# Thread to check for new posts
def check_rss
while true
loop do
begin
# Grab rss
xml = Net::HTTP.get( @rss_host, @rss_path )
......@@ -93,7 +93,7 @@ class Hackerthreads
# Check posts pending approval
def check_pending
while true
loop do
begin
base_url = @conf_pending['phpbb']['url']
......@@ -177,7 +177,7 @@ class Hackerthreads
# Load config for pending post checks
def load_config
if File.exists?( @config.datadir + '/' + @conf_file )
if File.exist?( @config.datadir + '/' + @conf_file )
jsonline = ""
File.open( @config.datadir + '/' + @conf_file ) do |file|
......
......@@ -102,6 +102,5 @@ class Help
@irc.notice( nick, line )
end
end
tmp = nil
end
end
......@@ -25,7 +25,7 @@ class Identified
def noticed( nick, user, host, to, message )
nick.downcase!
if( nick == "nickserv" )
cmd, subject, status = message.split( ' ', 3 )
_cmd, subject, status = message.split( ' ', 3 )
if( status == "3" )
@irc.mode( @channel, "+v" ,subject, true )
......
......@@ -82,10 +82,10 @@ class Login
# Function to load marshaled password on startup
def loadpass
# Check if a password is stored on disk
if File.exists?( @config.datadir + '/' + @filename )
if File.exist?( @config.datadir + '/' + @filename )
# Read password from file
File.open( @config.datadir + '/' + @filename ) do |file|
File.open( @config.datadir + '/' + @filename ) do |file|
@password = Marshal.load( file )
end
end
......
......@@ -36,24 +36,24 @@ class Ltc
diff = result[ 'ticker' ][ 'sell' ].to_f - result[ 'ticker' ][ 'last' ].to_f
diff = ( diff * 1000 ).round / 1000.0
if( diff > 0 )
diff = "+#{diff.to_s}"
diff = "+#{diff}"
else
diff = "#{diff.to_s}"
diff = "#{diff}"
end
# Calculate delta from last !btc
ldiff = result[ 'ticker' ][ 'sell' ].to_f - @last
ldiff = ( ldiff * 1000 ).round / 1000.0
if( ldiff > 0 )
ldiff = "+#{ldiff.to_s}"
ldiff = "+#{ldiff}"
else
ldiff = "#{ldiff.to_s}"
ldiff = "#{ldiff}"
end
@last = result[ 'ticker' ][ 'sell' ].to_f
rounded = "$#{( result[ 'ticker' ][ 'sell' ].to_f * 100 ).round / 100.0}"
line = "Btc-e rate: #{rounded} (#{result[ 'ticker' ][ 'sell' ]}) #{diff.to_s} (#{ldiff} since last !ltc)"
line = "Btc-e rate: #{rounded} (#{result[ 'ticker' ][ 'sell' ]}) #{diff} (#{ldiff} since last !ltc)"
if( con )
@output.c( line + "\n" )
......@@ -66,7 +66,7 @@ class Ltc
return result[ 'ticker' ][ 'sell' ].to_f
end
end
# Function to send help about this plugin (Can also be called by the help plugin.)
def help( nick, user, host, from, msg, arguments, con )
help = [
......
......@@ -156,7 +156,7 @@ class Netsplit
# Load config from file
def load_config
if File.exists?( @cnffile )
if File.exist?( @cnffile )
jsonline = ""
File.open( @cnffile ) do |file|
......@@ -181,7 +181,7 @@ class Netsplit
# Periodic checking function
def checker
while true
loop do
sleep( @wait )
@receiv = 0
@irc.raw( "MAP" )
......
......@@ -39,7 +39,7 @@ class Oraclesecurity
private
def check_rss
while true
loop do
begin
agent = Mechanize.new
......@@ -53,7 +53,6 @@ class Oraclesecurity
xml = agent.get( @feed_url ).body
xml = Nokogiri::XML( xml )
# Parse out info
title, link = "", ""
title = xml.css( 'item title' ).first.text
link = xml.css( 'item link' ).first.text
......@@ -78,7 +77,7 @@ class Oraclesecurity
end
rescue Exception => e
# Silently fail
@output.debug( "Failure while retrieving rss feed: #{e.to_s}\n" )
@output.debug( "Failure while retrieving rss feed: #{e.message}\n" )
end
# Wait for a bit before fetching again
......
......@@ -38,7 +38,7 @@ class Redhatsecurity
private
def check_rss
while true
loop do
begin
agent = Mechanize.new
......@@ -46,7 +46,6 @@ class Redhatsecurity
xml = agent.get( @feed_url ).body
xml = Nokogiri::XML( xml )
# Parse out info
title, link = "", ""
title = xml.css( 'item title' ).last.text
link = xml.css( 'item link' ).last.text
......@@ -70,7 +69,7 @@ class Redhatsecurity
@irc.message( @channel, " " )
rescue Exception => e
# Silently fail
@output.debug( "Failure while retrieving rss feed: #{e.to_s}\n" )
@output.debug( "Failure while retrieving rss feed: #{e.message}\n" )
end
# Wait for a bit before fetching again
......
......@@ -115,15 +115,12 @@ class Search
else
return "Book title: #{title.text}"
end
# Mark object for garbage collection
xmldoc = nil
end
# Load API key for ISBNdb
def loadisbndbapikey()
# Check if a appid is stored on disk
if File.exists?( @config.datadir + '/' + @isbndbapifile )
if File.exist?( @config.datadir + '/' + @isbndbapifile )
# Make sure there's a variable instance
apikey = ""
......@@ -131,7 +128,7 @@ class Search
# Read database from file
file = File.open( @config.datadir + '/' + @isbndbapifile )
file.each do |line|
file.each do |line|
apikey << line
end
apikey.gsub!( /[:blank:\n\r]/, "" )
......@@ -145,7 +142,7 @@ class Search
end
# Load google custom search api config
def loadgoogleconfig
if File.exists?( @config.datadir + '/' + @googleapiconf )
if File.exist?( @config.datadir + '/' + @googleapiconf )
jsonline = ""
File.open( @config.datadir + '/' + @googleapiconf ) do |file|
......
......@@ -229,10 +229,10 @@ class Seen
data = {}
# Check if a database is stored on disk
if File.exists?( @config.datadir + '/' + @filename )
if File.exist?( @config.datadir + '/' + @filename )
# Read database from file
File.open( @config.datadir + '/' + @filename ) do |file|
File.open( @config.datadir + '/' + @filename ) do |file|
data = Marshal.load( file )
end
......
......@@ -253,7 +253,6 @@ class Seen
if( @status.checkplugin( "whereis" ) )
plugin = @status.getplugin( "whereis" )
lines[0] = "#{lines[0]} | You are most likely to find this user here: #{plugin.main( arguments )}"
plugin = nil
end
else
......@@ -265,7 +264,6 @@ class Seen
lines[0] = "No log for #{arguments}. Did you mean '#{suggestion}'? (Log goes back #{logtime}.)"
end
end
data = nil
else
lines[0] = "Error: No nickname specified."
end
......@@ -278,7 +276,6 @@ class Seen
@irc.message( from, line )
end
end
lines = nil
end
# Function that shows some statistics
......@@ -301,15 +298,12 @@ class Seen
warmup = ( warmup * 10 ).round / 10.0
line = "Cache warmup: #{warmup}% | Cache hit rate: #{@cache_rate}% | Events: #{@events} | Records: #{@records} | Db writes: #{@writes}"
warmup = nil
if( con )
@output.cinfo( line )
else
@irc.message( from, line )
end
line = nil
end