snipplets.dev/code/Crystal/irc_bot.cr

25 lines
483 B
Crystal
Raw Normal View History

2022-09-24 16:11:40 +03:00
require "socket"
puts "Connecting..."
irc = TCPSocket.new("iiiypuk.me", 6667)
irc << "USER crystal localhost localhost :This is a bot!\n"
irc << "NICK crystal\r\n"
irc << "JOIN #admin\r\n"
irc << "PRIVMSG #admin :!time\r\n"
while true
response = irc.gets
puts response
if response.to_s.includes?("PING")
irc << "PONG #{response.to_s.split[1]}\r\n"
end
if response.to_s.includes?("!time")
irc << "PRIVMSG #admin :#{Time.local.to_unix}\r\n"
end
end
irc.close