Skip to content

Instantly share code, notes, and snippets.

@GarrisonJ
Created December 28, 2013 23:37
Show Gist options
  • Save GarrisonJ/8165688 to your computer and use it in GitHub Desktop.
Save GarrisonJ/8165688 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "socket"
require "openssl"
# Variables
@help_msg = ""
@server = "irc.cat.pdx.edu"
@port = "6697"
@nick = "spark"
@channel = "#robots"
@channelPass = "password"
# Connect
@socket = TCPSocket.open(@server, @port)
@ssl_context = OpenSSL::SSL::SSLContext.new()
@irc_server = OpenSSL::SSL::SSLSocket.new(@socket, @ssl_context)
@irc_server.connect
@irc_server.puts "USER Spark 0 Spark :I iz a bot"
@irc_server.puts "NICK #{@nick}"
@irc_server.puts "JOIN #{@channel} #{@channelPass}"
def can_I_spark_this? (astring)
if astring.class == String
parts = astring.split("!spark")
else
return nil
end
if parts.empty? == false
((parts[0]).delete "1234567890").chomp.length == 0 and
astring.include? "!spark"
else
nil
end
end
def spark_it (nums)
if nums
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = nums.delete(" ").split(//).map { |x| x.to_f }
p values
min, range, scale = values.min, values.max - values.min, @ticks.length - 1
if !(range == 0)
values.map { |x| @ticks[(((x - min) / range) * scale).round] }.join
else
values.map { |x| @ticks[1] }.join
end
end
end
until @irc_server.eof? do
msg = @irc_server.gets
calc = msg.split(":")[2]
result = nil
if can_I_spark_this? calc
result = spark_it calc.delete("!spark").chomp
end
if result
@irc_server.puts "PRIVMSG #{@channel} :" + result.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment