-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathruby-sample.rb
executable file
·185 lines (161 loc) · 4.67 KB
/
ruby-sample.rb
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/local/bin/ruby
# Author:: Dirk Meyer
# Copyright:: Copyright (c) 2008 - 2021 Dirk Meyer
# License:: Distributes under the same terms as Ruby
# SPDX-FileCopyrightText: 2008-2021 Dirk Meyer
# SPDX-License-Identifier: Ruby
require 'resolv'
require 'date'
# Write something in a logfile with date and time.
def write_log( *args )
f = File.open( "ruby-dump.txt", "a+" )
f.write DateTime.now.to_s
f.write " "
f.write args.join(' ')
f.write "\n"
f.flush
f.close
end
# Get the first IPv4 for a nameserver
def getipv4server( hostname )
dns = Resolv::DNS.new
dns.each_address(hostname) do |address|
text = address.to_s
next if text.include?( ":" )
return text
end
nil
end
# Get my own IPv4 from then nameserver
def getipfromdns( nameserver, hostname )
dns = Resolv::DNS.new(
:nameserver => [ getipv4server( nameserver ) ],
:search => [''],
:ndots => 1
)
dns.getaddress( hostname ).to_s
end
# Do not change the name of this class.
class IrofferEvent
# callend on each server line
def on_server
write_log( "SERVER on", network, inputline )
input = inputline.split( ' ' )
case input[1]
when '001' # welcome
# pick one of the services:
# @dnsserver = [ 'ns1-1.akamaitech.net', 'whoami.akamai.net' ]
@dnsserver = [ 'resolver1.opendns.com', 'myip.opendns.com' ]
new = getipfromdns( *@dnsserver )
write_log( "getipfromdns", new )
usenatip( new )
end
end
# called on each notice
def on_notice
write_log( "NOTICE from", hostmask, "in", channel, "on", network, message )
end
# called on each privms, including channel posts
def on_privmsg
write_log( "PRIVMSG from", hostmask, "in", channel, "on", network, message )
# ignore !find or @find directly
return true if /^.find/ =~ message
# trigger on text somewhere in the message
if /iroffer-dinoex/ =~ message
msg = "Thanks for using iroffer."
# send text to user
privmsg( nick, msg )
# log a warning in the iroffer logfile
warning( nick + " uses iroffer in " + channel + " on " + network )
# give voice to user in channel
mode( channel, "+v " + nick )
end
# trigger on exact text
if message == '!autoadd'
# execute admin command
command( "msg", irconfig( "owner_nick" ), "!autoadd was triggered" )
command( "autoadd" )
end
# trigger on exact text
if message == '!hop'
# execute admin command
command( "HOP", channel, network )
end
end
# called on add / rename / remove
def on_packlist
command( "AMSG", "Packlist has been updated" )
end
# called on a completed upload
def on_upload_completed
command( "msg", irconfig( "owner_nick" ), "upload is finished" )
end
# called on each pack added
def on_added
write_log( "Added pack nr", added_pack, "with file", added_file )
group = info_pack(added_pack, "group" )
desc = info_pack(added_pack, "desc" )
bytes = info_pack(added_pack, "bytes" )
megabytes = info_pack(added_pack, "size" ) # human readable
crc = info_pack(added_pack, "crc32" )
# md5 = info_pack(added_pack, "md5sum" )
# xtime = info_pack(added_pack, "xtime" ) # added_time
write_log( "group:", group, "desc:", desc, "size:", bytes )
# generate a trigger for each new pack.
command( "CHTRIGGER", added_pack.to_s, "#{group}#{added_pack}" )
# backup pack to a some other bots
command( "BATCH", "XDCC|Archiv1", added_pack.to_s )
command( "BATCH", "XDCC|Archiv2", added_pack.to_s )
# custom announce
text = "\"addded "
text << "\00304" # color red
text << desc
text << "\003\017" # end color
text << " - "
text << megabytes.to_s
if not group.nil?
text << " in "
text << group
end
text << " CRC "
text << crc
text << " - /MSG "
text << mynick
text << "XDCC SEND "
text << added_pack.to_s
text << "\""
command( "AMSG", text )
end
# Admin Command: RUBY action nick msg
def action( nick, msg )
command( "msg", nick, "\001ACTION #{msg}\001" )
end
# Admin Command: RUBY rmdup [ test | remove ]
def rmdup( remove = nil )
seen = Hash.new
pack = 0
while true do
pack += 1
file = info_pack(pack, "file" )
if file.nil?
break
end
file.sub!( /^.*\//, '' )
if seen.has_key?( file )
warning("duplicate file in pack #{pack} first pack #{seen[ file ]}: #{file}" )
if remove != "remove"
next
end
command( "remove", pack )
next
end
seen[ file ] = pack
end
end
# Admin Command: RUBY version
def version
puts irconfig( "version" )
puts irconfig( "features" )
end
end
# eof