This commit is contained in:
Alexander Popov 2022-09-24 16:11:40 +03:00
parent 181633e610
commit 5fedd53075
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
2 changed files with 27 additions and 0 deletions

View File

@ -5,3 +5,6 @@
- [IO::TimeoutError](prompt_timeout.cr) - Установка тайм-аута на пользовательский ввод
- [ENV["..."]](env_variable.cr) - Переменные среды
- [Colorize](Colorize.cr) - Цветной вывод в консоль
## Stuff
- [`irc_bot.cr`](irc_bot.cr) - Реализация клиента (бота) для IRC

24
~/Crystal/irc_bot.cr Normal file
View File

@ -0,0 +1,24 @@
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