coding utf-8 require socket require activesupport require iconv requir

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-
require 'socket'
require 'activesupport'
require 'iconv'
require 'jcode'
class IRCbot
def initialize
@servername = 'razlogoff.org'
@host = '82.146.59.188'
@port = 6667
@nick = 'botloshpek'
@agent = 'ibot'
@channel = '#drama'
@get = 222222
end
def connect
@s = TCPSocket.open(@host, @port)
end
def login
request = 'USER'+' '+@nick+' '+@nick+' '+@servername+' '+':'+@agent
@s.puts(request)
request = 'NICK'+' '+@nick
@s.puts(request)
end
def join
request = 'JOIN'+' '+@channel
@s.puts(request)
end
def privmsg
request = 'PRIVMSG'+' R <bot_loshpek> привет мир'
request = Iconv.conv('cp1251', 'utf-8', request)
@s.puts(request)
end
def analyze line
if line =~ /\APING/
request = "PONG "+@servername
@s.puts request
elsif line =~ /huest/
request = 'PRIVMSG'+' R <bot_loshpek> хуест'
request = Iconv.conv('cp1251', 'utf-8', request)
@s.puts request
elsif line =~ /!pozitiv/
pozit
elsif line =~ /!combo/
combo line
elsif (line =~ /bottestnya/ and line =~ /JOIN/)
answertobot
elsif line =~ /#{@get-1}:/
getget
end
end
def answertobot
request = 'PRIVMSG #drama bottestnya: пошел на хуй!'
request = Iconv.conv('cp1251', 'utf-8', request)
@s.puts request
end
def getget
request = 'PRIVMSG'+' R '+@get.to_s+'-доброгет!'
request = Iconv.conv('cp1251', 'utf-8', request)
@s.puts request
end
def pozit
20.times do
sleep(3)
request = 'PRIVMSG'+' R ПозИтиФФФФчег!'
request = Iconv.conv('cp1251', 'utf-8', request)
@s.puts request
end
end
def combo line
line = line.sub(/.*!combo/,"").lstrip
line = Iconv.conv('cp1251', 'utf-8', line)
line = line.split('')
line.each_index do |i|
sleep(3)
request = 'PRIVMSG'+' R '+line[i]
@s.puts request
end
end
def loop
while line = @s.gets
line = Iconv.conv('utf-8', 'cp1251', line)
puts line.chop
analyze(line)
end
end
end
bot = IRCbot.new
bot.connect
bot.login
bot.join
#bot.privmsg
bot.loop