· 6 years ago · Feb 08, 2020, 07:13 AM
1#!/usr/local/bin/ruby -w
2
3require 'net/http'
4require 'httparty'
5
6# Write something in a logfile with date and time.
7def write_log( *args )
8 f = File.open( "ruby-dump.txt", "a+" )
9
10 f.write Time.now.to_s
11 f.write " "
12 f.write args.join(' ')
13 f.write "\n"
14 f.flush
15 f.close
16end
17
18# Do not change the name of this class.
19class IrofferEvent
20
21 # callend on each server line
22 def on_server
23 write_log( "SERVER on", network, inputline )
24 end
25
26 # called on each notice
27 def on_notice
28 write_log( "NOTICE from", hostmask, "in", channel, "on", network, message )
29 end
30
31 # called on each privms, including channel posts
32 def on_privmsg
33
34 write_log( "PRIVMSG from", hostmask, "in", channel, "on", network, message )
35
36 #roboirc
37 # ignore !find or @find directly
38 # return true if /^.find/ =~ message
39 # return true ends the code.
40 if message == "!list"
41 # send text to user
42 command("msg", channel, "!list triggered in: " << channel)
43 command("msg", nick, "Welcome to " << irconfig("owner_nick") << "'s iroffer server")
44 command("msg", nick, "Want to access files on XDCC? Follow this guide: " << "https://wiki.xertion.org/w/XDCC_Commands")
45 command("msg", nick, "Using this guide: https://pastebin.com/api")
46 command("msg", nick, "Must have an account at pastebin.com to get your own API key!")
47
48 Thread.new {
49 response = HTTParty.post("https://pastebin.com/api/api_post.php", body: { api_dev_key: "71d8a0e7fa326aded6e8c5c393f360fd", api_option: "paste", api_paste_code: "test", api_paste_format: "text"})
50
51 command("msg", nick, "File listing is at : " + response.body.to_s)
52 }
53
54
55 #can configure config file variables by:
56 #command( "CONFIG", "slotsmax", "20" )
57
58 # sends a file to user:
59 #command("SEND", nick, -1, network)
60
61
62 end
63
64 # trigger on text somewhere in the message
65 if /@find/ =~ message
66
67 array = message.split("@find ")
68 search_keyword = array[1]
69 # send text to user
70 privmsg( nick, "Searching for \"" << search_keyword << "\" ...")
71
72 end
73
74 # trigger on text somewhere in the message
75=begin
76 if /iroffer-dinoex/ =~ message
77 msg = "Thanks for using iroffer."
78 # send text to user
79 privmsg( nick, msg )
80 # log a warning in the iroffer logfile
81 warning( nick + " uses iroffer in " + channel + " on " + network )
82 # give voice to user in channel
83 mode( channel, "+v " + nick )
84 end
85=end
86
87 # irconfig gives value for the given key from the iroffer config file
88 # trigger on exact text
89 if message == '!autoadd'
90 # execute admin command
91 command( "msg", irconfig( "owner_nick" ), "!autoadd was triggered" )
92 command( "autoadd" )
93 end
94
95=begin
96 # trigger on exact text
97 if message == '!hop'
98 # execute admin command
99 command( "HOP", channel, network )
100 end
101 end
102=end
103
104 # called on add / rename / remove
105 def on_packlist
106 command( "AMSG", "Packlist has been updated" )
107 end
108
109 # called on each pack added
110 def on_added
111 write_log( "Added pack nr", added_pack, "with file", added_file )
112
113 group = info_pack(added_pack, "group" )
114 desc = info_pack(added_pack, "desc" )
115 bytes = info_pack(added_pack, "bytes" )
116 megabytes = info_pack(added_pack, "size" ) # human readable
117 crc = info_pack(added_pack, "crc32" )
118 md5 = info_pack(added_pack, "md5sum" )
119 xtime = info_pack(added_pack, "xtime" ) # added_time
120 write_log( "group:", group, "desc:", desc, "size:", bytes )
121
122 # generate a trigger for each new pack.
123 command( "CHTRIGGER", added_pack.to_s, "#{group}#{added_pack}" )
124
125 # backup pack to a some other bots
126 command( "BATCH", "XDCC|Archiv1", added_pack.to_s )
127 command( "BATCH", "XDCC|Archiv2", added_pack.to_s )
128
129 # custom announce
130 text = "\"Added "
131 text << "\00304" # color red
132 text << desc
133 text << "\003\017" # end color
134 text << " - "
135 text << megabytes.to_s
136 if not group.nil?
137 text << " in "
138 text << group
139 end
140 text << " CRC "
141 text << crc
142 text << " - /MSG "
143 text << mynick
144 text << "XDCC SEND "
145 text << added_pack.to_s
146 text << "\""
147 command( "AMSG", text )
148 end
149
150 # Admin Command: RUBY action nick msg
151 def action( nick, msg )
152 command( "msg", nick, "\001ACTION #{msg}\001" )
153 end
154
155 # Admin Command: RUBY rmdup [ test | remove ]
156 def rmdup( remove = nil )
157 seen = Hash.new
158 pack = 1
159 while true do
160 file = info_pack(pack, "file" )
161 if file.nil?
162 break
163 end
164 file.sub!( /^.*\//, '' )
165 if seen.has_key?( file )
166 warning("duplicate file in pack #{pack} first pack #{seen[ file ]}: #{file}" )
167 if remove != "remove"
168 pack += 1
169 next
170 end
171 command( "remove", pack )
172 next
173 end
174 seen[ file ] = pack
175 pack += 1
176 end
177 end
178
179
180
181
182end
183
184# eof