forked from dinoex/iroffer-dinoex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby-sample.rb
executable file
·133 lines (115 loc) · 3.34 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
#!/usr/local/bin/ruby -w
# Write something in a logfile with date and time.
def write_log( *args )
f = File.open( "ruby-dump.txt", "a+" )
f.write Time.now.to_s
f.write " "
f.write args.join(' ')
f.write "\n"
f.flush
f.close
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 )
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 )
# trigger on text somewhere in the message
if /iroffer-dinoex/.match( 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 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 = 1
while true do
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"
pack += 1
next
end
command( "remove", pack )
next
end
seen[ file ] = pack
pack += 1
end
end
end
# eof