View difference between Paste ID: nReKnSkT and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | |
2 | # <speechles> Scripts are like children. They grow up to take | |
3 | # on lives of their own, along with all their parents time. | |
4 | ||
5 | # <speechles> Bots are so obedient, like a wife you never need to slap. | |
6 | ||
7 | #---------------------------------------------------------------# | |
8 | # UNOFFICIAL incith:google v2.0.0c # | |
9 | # # | |
10 | # performs various methods of Google searches # | |
11 | # tested on: # | |
12 | # eggdrop v1.6.17 GNU/LINUX with Tcl 8.4 # | |
13 | # windrop v1.6.17 CYGWIN_NT with Tcl 8.4 (http.tcl v2.5) # | |
14 | # - http.tcl included - Linux/BSD users should NOT need this # | |
15 | # # | |
16 | # UNOFFICIAL NEWS:............................................. # | |
17 | # # | |
18 | # As of 1.9, I (speechless) have rewritten and added several # | |
19 | # pieces of this script, fixing various regexp's, adding # | |
20 | # more search sites to it, added a gamefaqs upcoming list # | |
21 | # for gamers and much much more. # | |
22 | # See the Egghelp forum for info or help you may need: # | |
23 | # http://forum.egghelp.org/viewtopic.php?t=13586 # | |
24 | # # | |
25 | # OFFICIAL NEWS:............................................... # | |
26 | # # | |
27 | # As of v1.6, I (madwoota) have taken over the development of # | |
28 | # incith:google. If you have any feature req's, bugs, ideas, # | |
29 | # etc, please dont hesitate to send them to me. # | |
30 | # My contact details have replaced incith's, but if you wish # | |
31 | # to approach him directly about anything, I can point you # | |
32 | # in the right direction. # | |
33 | # See the Egghelp forum for inciths handover and all the latest# | |
34 | # info on this script: # | |
35 | # http://forum.egghelp.org/viewtopic.php?t=10175 # | |
36 | # # | |
37 | # BASIC USAGE GUIDE:........................................... # | |
38 | # # | |
39 | # .chanset #channel +google # | |
40 | # !google [.google.country.code] [define:|spell:] # | |
41 | # <search terms> <1+1> <1 cm in ft> <patent ##> # | |
42 | # <weather city|zip> <??? airport> # | |
43 | # !images [.google.country.code] <search terms> # | |
44 | # !groups [.google.country.code] <search terms> # | |
45 | # !news [.google.country.code] <search terms> # | |
46 | # !local [.google.country.code] <what> near <where> # | |
47 | # !book [.google.country.code] <search terms> # | |
48 | # !video [.google.country.code] <search terms> # | |
49 | # !fight <word(s) one> vs <word(s) two> # | |
50 | # !youtube [.google.country.code] <search terms> # | |
51 | # !trans region@region <text> # | |
52 | # !gamespot <search terms> # | |
53 | # !gamefaqs <system> in <region> # | |
54 | # !blog [.google.country.code] <search terms> # | |
55 | # !ebay [.ebay.country.code] <search terms> # | |
56 | # !ebayfight <word(s) one> vs <word(s) two> # | |
57 | # !wikipedia [.2-digit-country-code] <search terms>[#subtag] # | |
58 | # !wikimedia [.www.wikisite.org[/wiki]] <search terms>[#subtag] | |
59 | # !locate <ip or hostmask> # | |
60 | # !review <gamename> [@ <system>] # | |
61 | # !torrent <search terms> # | |
62 | # !best <system> # | |
63 | # !worst <system> # | |
64 | # !dailymotion <search terms> # | |
65 | # !ign <search terms> # | |
66 | # !myspace <search terms> # | |
67 | # !trends [.google.country.code] <YYYY-MM-DD> # | |
68 | # # | |
69 | # CHANGE LOG:.................................................. # | |
70 | # # | |
71 | # 1.0: first public release # | |
72 | # 1.1: improved bolding of search terms, compatible with # | |
73 | # chopped descriptions # | |
74 | # supports 'define: <word>' lookups # | |
75 | # supports calculator. !google (4+3) * 2 - 1 # | |
76 | # - converts, too. !google 1 lb in ounces # | |
77 | # image lookups coded, !images <search> # | |
78 | # 'spell: word1 word2' function added # | |
79 | # - don't rely on this, it's not a dictionary, just # | |
80 | # corrects common typos. # | |
81 | # flood protection added # | |
82 | # 1.2: will wrap long lines (yay, a worthy solution!) # | |
83 | # allowed setting of the seperator instead of a ' | ' by # | |
84 | # default. If you set this to "\n" then you will get # | |
85 | # each result on a seperate line instead of one line # | |
86 | # will display 'did you mean' if no results # | |
87 | # [PDF] links will be parsed/included now # | |
88 | # fixed a bug when no data was returned from google such # | |
89 | # is the case when you search for """""""""""""""""" # | |
90 | # 1.3: can return results in multiple languages now # | |
91 | # fixed quotes being displayed around links # | |
92 | # private messages support added (for /msg !google) # | |
93 | # video.google.com seems impossible, Google Video Viewer # | |
94 | # is required to view videos, etc # | |
95 | # 1.4: bit of a different output, easier to click links now # | |
96 | # local lookups coded, use !local <what> near <where> # | |
97 | # seems google does currency the same way my exchange # | |
98 | # script does (!g 1 usd in cad) # | |
99 | # "patent ##" will return the patent link if it exists # | |
100 | # bugfix in private messages # | |
101 | # sorry to all whom grabbed a borked copy on egghelp :-( # | |
102 | # 1.5: fix for !local returning html on 'Unverified listing's # | |
103 | # "madwoota" has supplied some nice code updates for us! # | |
104 | # - "answer" matches, eg: !g population of japan # | |
105 | # - !g <upc code> # | |
106 | # - google groups (!gg), google news (!gn) # | |
107 | # - movie: review lookups # | |
108 | # - area code lookups (!g 780) # | |
109 | # - print.google lookups (!gp !print) # | |
110 | # reworked binds to fix horrible bug allowing !g !gi !gp # | |
111 | # case insensitive binds (!gi, !GI, !gI, !Gi, etc) # | |
112 | # .1: fix for double triggers/bad binds # | |
113 | # .2: fix involving "can't read link" error # | |
114 | #-madwoota: # | |
115 | # 1.6: fixed google search returning no results # | |
116 | # fixed descriptions getting cut short on 'answers' # | |
117 | # fixed bug where some urls were returned invalid # | |
118 | # fixed google local searches returning no results # | |
119 | # fixed google print searches returning invalid links # | |
120 | # changed 'did you means' to get returned first as well # | |
121 | # added google weather: !g weather <city|zip> # | |
122 | # - note: US weather only (blame google!) # | |
123 | # added travel info, eg: !g sfo airport | !g united 134 # | |
124 | # added config option to send output via /notice # | |
125 | # added initial attempt at parsing google video (!gv) # | |
126 | # 1.7: added option to force all replies as private (req) # | |
127 | # fixed google groups returning no results # | |
128 | # fixed define: errors on no results # | |
129 | # fixed google print errors on no results/typos # | |
130 | # fixed movie review errors on no results/typos # | |
131 | # fixed some characters not usable as command_chars on # | |
132 | # one of regular eggdrop or windrop+cygwin # | |
133 | # fixed occasional weird response for travel info # | |
134 | # updated requirements to http package 2.4 # | |
135 | # loads of other internal changes # | |
136 | # .1: fixed search parameters not being parsed correctly # | |
137 | # - resulted in some bogus "no results" replies. # | |
138 | # .2: fixed main google search returning rubbish results # | |
139 | # - google changed their source again # | |
140 | # changed all methods of parsing the search results to # | |
141 | # *hopefully* cope better with any source changes # | |
142 | # changed output queue to stop the bot from flooding # | |
143 | # .3: fixed some urls being returned with spaces in them # | |
144 | # - makes them unusable in most irc clients # | |
145 | # fixed google groups occasionally returning junk due to # | |
146 | # changes in 1.7.2 (will revisit this later) # | |
147 | # 1.8: added option to turn on "safe" searches # | |
148 | # added channel user level filtering option (+v/+o only) # | |
149 | # added google fight! !gf or !fight <blah> vs <blah> # | |
150 | # - inspired by www.googlefight.com # | |
151 | # added ability to do any custom mode to descs & links # | |
152 | # - i'll just apologise now for this one :) # | |
153 | # removed variable underline_links (superseded by above) # | |
154 | # removed use of 'tcl_endOfWord' to stop windrop breaking# | |
155 | # fixed excess %20's appearing in some results # | |
156 | # fixed "translate this" only returns ? (i think) # | |
157 | # stopped local from returning ad spam on first result # | |
158 | #-speechless # | |
159 | # 1.9: updated various regexp's and regsub's in almost all # | |
160 | # procs to fix non functioning html parsing. # | |
161 | # added !localuk option to display United Kingdom. # | |
162 | # added !youtube for searching videos on youtube. # | |
163 | # added !atomfilms for searching videos on atomfilms. # | |
164 | # added !trans for searching videos on trans. # | |
165 | # added !gamespot for searching games, etc. # | |
166 | # added !gamefaqs, it is able to parse multiple systems # | |
167 | # and regions, still a work in progress, all bugs have # | |
168 | # been squashed. # | |
169 | # added !test proc to help debug and dump html for # | |
170 | # future parsing projects. # | |
171 | # .1: added !blog for searching blogsearch.google # | |
172 | # added !ebay for searching ebay auctions. # | |
173 | # added !ebayfight for amusement, same as googlefight. # | |
174 | # fixed various miscellaneous minor annoyances in parts. # | |
175 | # finally fixed !book (aka print) to work with # | |
176 | # books.google # | |
177 | # added !ign for searching movies, games, etc.. # | |
178 | # .2: added support for total_search to show total results # | |
179 | # or not. :) # | |
180 | # added support for link_only (requested). # | |
181 | # added back complete support for desc/link modes # | |
182 | # they will now affect results properly. # | |
183 | # (note: doesn't affect gamefaqs or locate) # | |
184 | # added !locate for dns location information. # | |
185 | # .3: added !wiki for searching wikipedia for things, very # | |
186 | # much a work-in-progress, don't expect it to be # | |
187 | # perfect.. it just reads very top heading <h*> so # | |
188 | # sometimes it returns next to nothing.. like I said # | |
189 | # it's WIP so don't bitch, thx. # | |
190 | # added !review for searching gamefaqs and pulling a # | |
191 | # games review, ranking, score, etc.. works similarly # | |
192 | # to the way !wiki does, has same problem, so this # | |
193 | # is also WIP.. thx # | |
194 | # .4: fixed a few regexp parsers to correct broken (no # | |
195 | # results returned) messages in some procs. # | |
196 | # changed google populations to return only 1st desc # | |
197 | # this fixes a small bug where excess html was shown. # | |
198 | # ie. !g population japan || !g population of japan # | |
199 | # fixed google define: links with quick regsub hacks. # | |
200 | # problem with recent ign changing to javascripted html # | |
201 | # so removed their advertising.. too bad for them. # | |
202 | # fixed review and wikipedia to almost perfect. # | |
203 | # note: review does not use forms submittal, instead # | |
204 | # I chose to a single query and field matching on the # | |
205 | # first page returned. I may later use forms submital # | |
206 | # at some later time. # | |
207 | # added two gamerankings triggers (!top/!popular) # | |
208 | # added a mininova torrent search parser. # | |
209 | # fixed parser for !blog by removing quotes. "g" -> g # | |
210 | # beefed up the wikipedia parser so can intelligently # | |
211 | # move to html#subtags to display info. # | |
212 | # removed atomfilms trigger because no one was using. # | |
213 | # added dailymotion trigger for searching tv episodes # | |
214 | # since youtube/google seem to remove those too # | |
215 | # often. # | |
216 | # wikipedia now has ability to properly handle internal # | |
217 | # redirects intelligently as well. # | |
218 | # youtube needed its regexp/regsub parsers tweaked a bit # | |
219 | # to handle new html design. # | |
220 | # google changed format and updated search regexp/sub # | |
221 | # accordingly. # | |
222 | # fixed !local lookups, removed !localuk as it was # | |
223 | # redundant since !local covers UK region now. # | |
224 | # corrected !book to actually produce an output again # | |
225 | # i left broken intentionally earlier because of # | |
226 | # lack of interest, but a guy named Zircon sparked # | |
227 | # my interest again. enjoy. # | |
228 | # gamespot injects paid crap into their html design now # | |
229 | # so found a way to scrape around it.. muahah # | |
230 | # requested by a few people that somehow wikipedia is # | |
231 | # multi-lingual so a fast hack is provided at the # | |
232 | # moment which lacks input checking.. will fix later # | |
233 | # requested by a british friend was the ability as well # | |
234 | # for ebay to work from different countries server. # | |
235 | # this also lacks input checking.. will fix later. # | |
236 | # added error catching for erroneous url's in both # | |
237 | # wikipedia and ebay, this way bad user countries # | |
238 | # will be reported with socket errors. thx rosc2112 # | |
239 | # .5: major modification of script to allow for dynamic # | |
240 | # language selection of _all_ google sites. # | |
241 | # (search,image,news,local,video,book,blog) # | |
242 | # google group is still broken, will fix later :P # | |
243 | # added !trans for google translate. enjoy. # | |
244 | # added stock quotes (supplied by madwoota) # | |
245 | # fixed translation to convertto foreign charsets. # | |
246 | # fixes display of russian and arabic languages. # | |
247 | # corrected google area code map results. # | |
248 | # added google zip code map results. # | |
249 | # corrected google movie review lookups, now works! # | |
250 | # search totals was incorrect on some country google # | |
251 | # lookups. it was using elapsed search time as the # | |
252 | # total results, so now a fallback (else) corrects # | |
253 | # it by replace total results with 'google' in # | |
254 | # those instances. # | |
255 | # youtube undergoing major html changing to keep bots # | |
256 | # from indexing, so changed some parsers to work. # | |
257 | # added back !ign trigger for scraping ign's search # | |
258 | # page for results. # | |
259 | # google answers needed fixing to show correct results. # | |
260 | # added !myspace trigger for searching their video # | |
261 | # content. # | |
262 | # corrected zipcode/areacode/airport. # | |
263 | # corrected all google query possibilities by spending a # | |
264 | # few hours fine tuning everything. Most languages # | |
265 | # should work exactly as planned. Some languages # | |
266 | # "may" display incorrectly, but this is by design # | |
267 | # rather than an error, as the script presently uses # | |
268 | # unicode for everything except google translations. # | |
269 | # major work done to !local fixing it for every possible # | |
270 | # query result in almost every language, try it out # | |
271 | # feeding it nonsense and try to find a flaw. # | |
272 | # small bug concerning !google patent ##### .. wasn't # | |
273 | # being caught as results, now all is well again. # | |
274 | # corrected ebay parser with small change to eliminate # | |
275 | # excess html in 'buy-it-now' parsing. # | |
276 | # UPC codes work again.. yay.. how many use this? 1 guy? # | |
277 | # Ebay, Wikipedia and Google needed minor fixes to # | |
278 | # correct remaining bits that were left untranslated # | |
279 | # now all output will be in language chosen. # | |
280 | # Gamespot changed html design of their page layots for # | |
281 | # reviews, so quick fix to !review proc to handle # | |
282 | # their new design :) # | |
283 | # Corrected 'results' message displayed with totals to # | |
284 | # also be displayed in language searched in, makes # | |
285 | # the output look much more professional. r0x hard. # | |
286 | # All Google triggers are now 100% dialect perfect. # | |
287 | # Fixed small problem with wikipedia's 'no result' # | |
288 | # message being longer than neccessary. # | |
289 | # Added multi-language ability to youtube because it # | |
290 | # now supports it, new default variable for setting # | |
291 | # language default for it as well. enjoy. # | |
292 | # Changed myspace parser query making it less prone to # | |
293 | # breaking. # | |
294 | # Added new trigger !trends to get top search results # | |
295 | # for any date (this is limited by google cache, # | |
296 | # not by the script) and also can be given country # | |
297 | # switches. This is new, at present I cannot go # | |
298 | # back beyond May 2007-05-15 .. # | |
299 | # Added dual results to !ebay trigger for price/bids # | |
300 | # to account for the fact buy-it-now allows bids as # | |
301 | # well... # | |
302 | # Fixed the tiny bug in google answers lookup which # | |
303 | # allowed for cruft to be given as 2nd result. # | |
304 | # Fixed the tiny bug in wikipedia articles that left # | |
305 | # parts of tables in the results. # | |
306 | # Added forced subtagging ability to wikipedia results # | |
307 | # using their standard sub-tag #this so you can now # | |
308 | # force certain sections to being your results and # | |
309 | # it must only begin with the term doesn't need to # | |
310 | # be entire term to force a sub-tag redirect. # | |
311 | # .6: Added !mediawiki trigger following same abilities as # | |
312 | # the wikipedia trigger. This is beta at the moment # | |
313 | # and the reason this script has a revision change. # | |
314 | # Corrected small issue regarding parsing original search# | |
315 | # results which makes this now compatabile with # | |
316 | # every mediawiki page. # | |
317 | # Fixed problem parsers; Groups, News, Book # | |
318 | # Problems with some procs sorted, Gamefaqs modified to # | |
319 | # work with new php site design. # | |
320 | # Fixed issues with stubborn always changing google # | |
321 | # based searches. Now hopefully all triggers work # | |
322 | # again. # | |
323 | # Added prepend ability (Requested) so now each of your # | |
324 | # lines, can be prepended with whatever you desire. # | |
325 | # Added 'time in' feature to google search, allows you # | |
326 | # to find out the time in any region, works like # | |
327 | # population and date. # | |
328 | # Added wiki_line option to expand results. # | |
329 | # .7: Added input/output encoding conversion to better # | |
330 | # realize the multi-language side of this script. # | |
331 | # Corrected mistake in input/output encoding handlers. # | |
332 | # Added a triple lookup for youtube to include all # | |
333 | # possible results and not miss any. # | |
334 | # Corrected issue with wikipedia/wikimedia incorrectly # | |
335 | # removing some elements as page markups. # | |
336 | # Added ability for bold to be seen in wikipedia/wikimedia | |
337 | # results again, removed stripcodes. # | |
338 | # .7a: Expanded Wikimedia and Wikipedia for allowing multi- # | |
339 | # language as well as regional dialects. This also # | |
340 | # allows for expanded custom encoding coverage. # | |
341 | # .7b: Corrected google to return useful results once again. # | |
342 | # broken was define, no_search, did_u_mean, and # | |
343 | # weather. # | |
344 | # Ebay now expanded upon to allow 'store' results to # | |
345 | # appear as well as functional 'did you mean' # | |
346 | # messaging. # | |
347 | # .7c: Added remaining onebox results to google results. # | |
348 | # .8: New features corrected longstanding shortcomings: # | |
349 | # * Wikipedia/Wikimedia now fully decode and encode # | |
350 | # on the fly and translate subtags seamlessly. # | |
351 | # * Main encoding routine now includes a smart URL # | |
352 | # encoder for those using language other than # | |
353 | # english. # | |
354 | # Corrected problem with script handling tcl special # | |
355 | # characters as part of user input. # | |
356 | # .8a: All did you mean messages now report from page exactly # | |
357 | # as they appear. All sites that allow this now # | |
358 | # handle this ability if no results are found. # | |
359 | # .8b: Corrected deficiencies in !translate, it should now # | |
360 | # function better regarding encodings and html # | |
361 | # markups. thx perplexa. # | |
362 | # Corrected minor problem regarding wikipedia's recent # | |
363 | # template change. Now uses similar style as # | |
364 | # wikimedia to prevent issues. # | |
365 | # .8c: Corrected google video as well as added the whois # | |
366 | # onebox to regular google searches. # | |
367 | # Corrected way define: links are handled so encodings # | |
368 | # are dealt with properly. # | |
369 | # .8d: Corrects issue with myspace and regional IP bases. # | |
370 | # .8e: Corrects google video to produce results. # | |
371 | # .8f: Added vocabulary aversion. # | |
372 | # Corrected flaw with wikimedia's encoding process, # | |
373 | # improved overall functionality. # | |
374 | # .8g: Added domain detection for wikimedia domain's which # | |
375 | # aren't using the standard subdomain /wiki. # | |
376 | # .8h: Corrected !torrent # | |
377 | # .8i: Corrected google zipcodes and google video. # | |
378 | # .8j: Corrected youtube and google groups. # | |
379 | # .8k: Corrects some urlencoding problems regarding eggdrops # | |
380 | # complete inability to distinguish between utf-8 # | |
381 | # and iso8859-1. Now requires http 2.5 which allows # | |
382 | # setting the -urlencoding flag. # | |
383 | # Corrects entire script which now uses the -urlencoding # | |
384 | # flag in some way to hopefully force eggdrop to # | |
385 | # understand the differences and force proper # | |
386 | # detections. # | |
387 | # * requirements upped, now requries http 2.5 * # | |
388 | # .8l: Corrects google search (calculations, did_you_mean,etc)# | |
389 | # Corrects google book # | |
390 | # -- experimental version -- # | |
391 | # Adds "automagic" detection to google translations # | |
392 | # Possiblity for more automagic detection in the future # | |
393 | # support procedures in place to allow this already. # | |
394 | # .8m: Adds more "automagic" detection and a more robust # | |
395 | # debugging display. # | |
396 | # Corrected minor display problems. # | |
397 | # .8n: Corrects Googles embolding placement within results, # | |
398 | # can now interpret <em> tags as bold. # | |
399 | # .8o: Added correct support for a true utf-8 workaround. # | |
400 | # .8p: Added proper redirect support. # | |
401 | # Corrected Youtube behavior. # | |
402 | # .8q: Corrected Dailymotion, added multilanguage support to # | |
403 | # it and extended it's capabilities. # | |
404 | # .8r: Corrected minor youtube url inconsitancy. # | |
405 | # .8s: Corrected result totals to appear again for all google # | |
406 | # sites, also corrected other google anamolies. # | |
407 | # Corrected local as well to work with custom locations. # | |
408 | # Added mediawiki customized triggers to allow access # | |
409 | # to mediawiki sites without so much input required. # | |
410 | # .8t: Google template changed, <div class=g -> <li class=g # | |
411 | # .8u: Added full support for session cookies as well as # | |
412 | # unlimited redirect support. This allows adding # | |
413 | # the secondary ebay template for their store server # | |
414 | # and allows ebay to function 100% again. # | |
415 | # .8v: Added back support for !game and !review and elaborated# | |
416 | # upon the amount of information displayed. # | |
417 | # .8w: Added new abilities to both !locate and !trans now # | |
418 | # allows much less input from the user and default # | |
419 | # behavior. # | |
420 | # Also correct other slight anomalies. # | |
421 | # .8x: Corrected ebay finally, yay! also added sorry detection# | |
422 | # to google so users experiencing this can tell. Also # | |
423 | # fixed the html cruft in gamespot review replies. # | |
424 | # .8y: Corrected youtube, now more compliant with all templates | |
425 | # returned # | |
426 | # .8z: Corrected video and group functionality. # | |
427 | # Added scholar for parsing scholar.google.* # | |
428 | # .9: Corrected video and youtube to work with website # | |
429 | # re-designs. # | |
430 | # Other minor tweaks here and there. # | |
431 | # .9a: Corrected local, google define and google did-you-mean # | |
432 | # .9b: Corrected more problems with parsing, might still be # | |
433 | # a few. This is just a test version to see if this # | |
434 | # does solve them. # | |
435 | # .9c: Addded a crude work around to allow youtube to remain # | |
436 | # in the language chosen, even tho redirecting is # | |
437 | # occuring. # | |
438 | # .9e: Corrected ability to split lines and now keeps bolding # | |
439 | # and underlining intact perfectly. # | |
440 | # Corrected !news to return results again. # | |
441 | # Modified all procs in some way to allow the split line # | |
442 | # correction noted above, no longer should \017 ever # | |
443 | # be used. # | |
444 | # Corrected !scholar to return accurate results. # | |
445 | # Added short_answers config variable for google results.# | |
446 | # .9e: Corrected !google weather replies. # | |
447 | # Removed !top and !pop, gamerankings removed support. # | |
448 | # Added !best and !worst, gamerankings added support. # | |
449 | # Added support for color splitting and color themes. # | |
450 | # .9f: Corrected split routine for those using \n as seperator# | |
451 | # .9g: Added custom triggers with phrasing. # | |
452 | # .9h: Corrected bug in custom triggers, now works properly. # | |
453 | # Corrected color theme enforcement (not everything was # | |
454 | # following it correctly, now it does) # | |
455 | # .9i: Corrected slight bugs in some procs. # | |
456 | # Corrected !news and !video. # | |
457 | # Combined custom wiki into custom trigger phrases. # | |
458 | # .9j: Corrected google weather. # | |
459 | # Corrected remaining bugs with themes. # | |
460 | # .9k: Corrected !local # | |
461 | # .9l: Corrected !local again.. stop it google :P # | |
462 | # Corrected !torrent no-search results message appears # | |
463 | # along with it's did-you-mean results. # | |
464 | # Corrected issue regarding setting results to zero # | |
465 | # and some commands still triggering. # | |
466 | # Corrected small bug with google weather replies when # | |
467 | # custom themes are in use. # | |
468 | # .9m: Corrected alot of broken things, fixed a few things. # | |
469 | # Basically forgot what these were as this was done # | |
470 | # over the course of several weeks and I didn't # | |
471 | # document any of it.. DOH! # | |
472 | # .9n: Corrected google weather and cruft html elements within# | |
473 | # some google no-results-found messages. # | |
474 | # .9o: Corrected bug within google video display and fixed # | |
475 | # ebay parsing. # | |
476 | # .9p: Added input/output encoding abilities for google # | |
477 | # translations. This appears to corrects accented # | |
478 | # character problem and misdetected encodings. # | |
479 | # .9q: Added HD filter switch for youtube videos. # | |
480 | # Added proxy support for main fetch_html routine. # | |
481 | # Added Gzip support for wikipedia/media. # | |
482 | # Corrected Google define mechanism. # | |
483 | # .9r: Added full support for gzipped downloading of webpages # | |
484 | # this should be sorta faster as well as less to # | |
485 | # download doing all this, enjoy. # | |
486 | # .9s: Added ability to enable/disable gzipped support as this# | |
487 | # breaks functionality (eggdrop's utf-8 bug) for some # | |
488 | # languages. # | |
489 | # Corrected youtube and ebay. # | |
490 | # .9t: Corrected google's zipcode and time queries. # | |
491 | # Corrected utf-8 output, all queries should now appear # | |
492 | # correct and in proper utf-8.. yay! # | |
493 | # .9u: Corrected google results, fight, video, youtube, news # | |
494 | # and some other things I forgot about. # | |
495 | # Corrected short_answers, created new option skip_self # | |
496 | # to deal with google self-injecting results. # | |
497 | # Corrected google did_you_mean and no_results messages # | |
498 | # once again. Stop changing so often google, jeez.. # | |
499 | # .9v: Corrected wikipedia/wikimedia #achor lookup method, it # | |
500 | # it's now more accurate and much faster. # | |
501 | # Corrected minor inconsistancies with some procedures. # | |
502 | # Corrected google weather for multilanguage replies. # | |
503 | # .9w: Corrected google weather yet again! stop changing things | |
504 | # so often google, jeez.. # | |
505 | # Corrected translate to use new templates. yes, google # | |
506 | # was busy updating all their templates :( # | |
507 | # Added new feature to custom trigger phrasing: # | |
508 | # * ability to query by index as well as entire # | |
509 | # sentence.. # | |
510 | # .9x: Corrected google "spell" to always return results or # | |
511 | # did-you-mean. # | |
512 | # Added "special searches" to google searching. # | |
513 | # Corrected population/public_data searches to use new # | |
514 | # template created for these. Is not given as a google | |
515 | # "answer" anymore. # | |
516 | # .9y: Corrected: !news !game !review -- gamespot added # | |
517 | # backslash escape protection to it's ajax replies to# | |
518 | # prevent injection from happening with chars.. # | |
519 | # .9r1: Corrected too many things to list, google went on a # | |
520 | # spree and changed templates on lots of different # | |
521 | # things causing lots of functionality to break. # | |
522 | # suffice to say it's fixed. Most of it. Good show # | |
523 | # google, but it's now your move again. This game of # | |
524 | # chess is certainly fun.. # | |
525 | # .9r2: Corrected Google's oneboxes, specifically time and # | |
526 | # maps. # | |
527 | # .9r3: Corrected !ebay, !dailymotion, !ign, !myspace . # | |
528 | # Deprecated functions: !scholar / !google movie:* # | |
529 | # !scholar will be removed, and changed to something # | |
530 | # else google-y. # | |
531 | # !google movie:* will be re-incorporated later. # | |
532 | # 2.00a: alot corrected, broken regexps, and more.. # | |
533 | # # | |
534 | # TODO:........................................................ # | |
535 | # # | |
536 | # Fix broken parsers, this is a never-ending battle! # | |
537 | # -- This is always #1 priority over anything else -- # | |
538 | # # | |
539 | # Correct error detection mechanisms to use exact same as # | |
540 | # "webby". # | |
541 | # # | |
542 | # Solve inconsitancies in some countries total results and # | |
543 | # inaccurate parsing due to differing html templates. # | |
544 | # This includes missing result totals, condense entire # | |
545 | # result grabbing to it's own procedure eventually akin # | |
546 | # to fetch_html but for parsing total results, easier to # | |
547 | # maintain that way then spread out individually amongst # | |
548 | # each procedure. # | |
549 | # # | |
550 | # Once everything above is done we can start on these: # | |
551 | # Clean-up code where obvious hacks were left in, code them # | |
552 | # correctly, remove debugging code from procs which is # | |
553 | # presently commented out. # | |
554 | # Clean-up overly messy code that can be solved by coding # | |
555 | # cleaner modules and not reusing so much code. # | |
556 | # # | |
557 | # For this UNOFFICIAL version please direct any and all # | |
558 | # Suggestions/Thanks/Bugs to the forum link below: # | |
559 | # --> http://forum.egghelp.org/viewtopic.php?t=13586 <-- # | |
560 | # # | |
561 | # LICENSE:..................................................... # | |
562 | # # | |
563 | # This code comes with ABSOLUTELY NO WARRANTY. # | |
564 | # # | |
565 | # This program is free software; you can redistribute it # | |
566 | # and/or modify it under the terms of the GNU General Public # | |
567 | # License as published by the Free Software Foundation; # | |
568 | # either version 2 of the License, or (at your option) any # | |
569 | # later version. # | |
570 | # # | |
571 | # This program is distributed in the hope that it will be # | |
572 | # useful, but WITHOUT ANY WARRANTY; without even the implied # | |
573 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # | |
574 | # PURPOSE. See the GNU General Public License for more # | |
575 | # details. (http://www.gnu.org/copyleft/library.txt) # | |
576 | # # | |
577 | # CREDITS:..................................................... # | |
578 | # # | |
579 | # ..Officially: # | |
580 | # Copyright (C) 2005, Jordan (Incith) # | |
581 | # Currently maintained by madwoota # | |
582 | # google@woota.net # | |
583 | # # | |
584 | # ..Unofficially: # | |
585 | # Copyleft (C) 2006-2010, Speechless # | |
586 | # http://ereader.kiczek.com/scripts # | |
587 | # v2.0.0c - September 9th, 2o11 - speechles <#roms-isos@efnet> # | |
588 | #---------------------------------------------------------------# | |
589 | ||
590 | # EVERYTHING IN THIS SECTION IS USER CUSTOMIZABLE. | |
591 | # BEST SETTINGS ARE DEFAULT, YOU MAY HAVE OTHER IDEAS OF WHAT IS BEST. | |
592 | # | |
593 | # NOTE: some config options won't list how to enable/disable, but | |
594 | # 0 will typically disable an option (turn it off), otherwise a | |
595 | # value 1 or above will enable it (turn it on). | |
596 | # ------ | |
597 | # start of configuration - make your changes in this section | |
598 | # ------ | |
599 | namespace eval incith { | |
600 | namespace eval google { | |
601 | # set this to the command character you want to use for the binds | |
602 | # ------ | |
603 | variable command_char "!" | |
604 | ||
605 | # set these to your preferred binds ("one two three etc etc" - space delimited!) | |
606 | # ------ | |
607 | variable google_binds "g google goog" | |
608 | variable image_binds "i gi image images" | |
609 | variable local_binds "l gl local" | |
610 | variable group_binds "gg group groups" | |
611 | variable news_binds "n gn news" | |
612 | variable print_binds "gb book books" | |
613 | variable video_binds "v gv video" | |
614 | variable scholar_binds "s sc scholar" | |
615 | variable fight_binds "f fight googlefight" | |
616 | variable youtube_binds "y youtube" | |
617 | variable locate_binds "geo loc locate" | |
618 | variable gamespot_binds "gs game gamespot" | |
619 | variable trans_binds "tr trans translate" | |
620 | variable daily_binds "dm daily dailymotion" | |
621 | variable gamefaq_binds "gf gamefaq gamefaqs" | |
622 | variable blog_binds "b blog blogsearch" | |
623 | variable ebay_binds "e ebay" | |
624 | variable efight_binds "ef ebayfight" | |
625 | variable popular_binds "best great bestest" | |
626 | variable rev_binds "r review" | |
627 | variable wiki_binds "w wiki wikipedia" | |
628 | variable wikimedia_binds "wm wikim wikimedia" | |
629 | variable recent_binds "worst crap" | |
630 | variable mininova_binds "t torrent mininova" | |
631 | variable ign_binds "ign igame" | |
632 | variable myspacevids_binds "m myspace myvids" | |
633 | variable trends_binds "gtr trends" | |
634 | variable helpbot_binds "help bot" | |
635 | ||
636 | # to restrict input queries to Ops (+o), Halfops (+h) or Voiced (+v) users on | |
637 | # any +google channel, use this setting. | |
638 | # set the variable to one of the following to achieve the desired filtering: | |
639 | # at least Op -> 3 (obvious) | |
640 | # at least Halfop -> 2 (will also allow ops) | |
641 | # at least Voice -> 1 (will also allow halfops and ops) | |
642 | # everyone -> 0 (no filtering) | |
643 | # | |
644 | # note: this does NOT apply to private messages, use the below setting for them. | |
645 | # ------ | |
646 | variable chan_user_level 0 | |
647 | ||
648 | # if you want to allow users to search via private /msg, enable this | |
649 | # ------ | |
650 | variable private_messages 1 | |
651 | ||
652 | # as per emailed & forum requests, use the next two variables together | |
653 | # to determine the output type like so: | |
654 | # notice_reply 1 & force_private 1 = private notice reply only (this is as requested) | |
655 | # notice_reply 0 & force_private 1 = private msg reply only | |
656 | # notice_reply 1 & force_private 0 = regular channel OR private NOTICE | |
657 | # notice_reply 0 & force_private 0 = regular channel OR private MSG (default) | |
658 | # set to 1 to enable a /notice reply instead, 0 for normal text | |
659 | # ------ | |
660 | variable notice_reply 0 | |
661 | ||
662 | # set to 1 to force all replies to be private | |
663 | # ------ | |
664 | variable force_private 0 | |
665 | ||
666 | # set this to the language you want results in! use 2 letter form. | |
667 | # "all" is the default/standard google.com search. | |
668 | # see http://www.google.com/advanced_search for a list. You have to use | |
669 | # the 'Language' dropdown box, perform a search, and find a line in the URL | |
670 | # that looks like "&lr=lang_en" (for English). "en" is your language code. | |
671 | # popular Ones: it (italian), da (danish), de (german), es (spanish), fr (french) | |
672 | # please note, this does not 'translate', it searches Google in a | |
673 | # language of choice, which means you can still get English results. | |
674 | # ------ | |
675 | # NOTE: Changing this from "all" will effectively disable some of the | |
676 | # multi-language features of this script, doing so is not advised. | |
677 | # ------ | |
678 | variable language "all" | |
679 | ||
680 | # set this to "on" to let google filter "adult content" from any of your search results | |
681 | # "off" means results will not be filtered at all | |
682 | # note: this is only applicable to !google, !images and !groups | |
683 | # ------ | |
684 | variable safe_search "off" | |
685 | ||
686 | # number of search results/image links to return, 'define:' is always 1 as some defs are huge | |
687 | # ------ | |
688 | variable search_results 3 | |
689 | variable image_results 4 | |
690 | variable local_results 4 | |
691 | variable group_results 3 | |
692 | variable news_results 3 | |
693 | variable print_results 3 | |
694 | variable video_results 4 | |
695 | variable scholar_results 4 | |
696 | variable youtube_results 0 | |
697 | variable locate_results 1 | |
698 | variable gamespot_results 3 | |
699 | variable trans_results 1 | |
700 | variable daily_results 4 | |
701 | variable gamefaq_results 20 | |
702 | variable blog_results 3 | |
703 | variable ebay_results 3 | |
704 | variable popular_results 10 | |
705 | variable rev_results 1 | |
706 | variable wiki_results 1 | |
707 | variable wikimedia_results 1 | |
708 | variable recent_results 10 | |
709 | variable mininova_results 3 | |
710 | variable ign_results 3 | |
711 | variable myspacevids_results 3 | |
712 | variable trends_results 25 | |
713 | variable helpbot_results 1 | |
714 | ||
715 | # This part was requested to be added so now here it is, it has | |
716 | # various prepends you may wish to have preceed each function. | |
717 | # To use this, just change what you see below from nothing to | |
718 | # something...ie, if you want [ GOOGLE ] to prepend google | |
719 | # search results change the search_prepend to "\[GOOGLE\]". You | |
720 | # can do the same with all of the following prepends, they will | |
721 | # start the output for each line. If you don't wish to use this, | |
722 | # leave them as "". Keep in mind tcl special characters MUST be | |
723 | # escaped or will cause tcl errors, and/or crash your bot. This | |
724 | # is your own problem, just be aware. Read about them if possible. | |
725 | # | |
726 | # Note 1: Prepends will increase your line length, and won't be | |
727 | # accommodated for in the max line length setting, so you may | |
728 | # find you need to lower your max line length setting if your | |
729 | # prepends are lengthy or contain lots of escape sequences. If | |
730 | # you don't you may find the bots replys may get cut short or | |
731 | # cut completely by the ircd your using. | |
732 | # | |
733 | # Note 2: To use color, bold, etc.. simply use the proper escape | |
734 | # sequence to generate it here, make sure to properly CLOSE your | |
735 | # sequence (\003 for color, \002 for bold, etc) or you will see | |
736 | # the effect of the prepend bleed thru into your output as well. | |
737 | # ------ | |
738 | variable search_prepend "" | |
739 | variable image_prepend "" | |
740 | variable local_prepend "" | |
741 | variable group_prepend "" | |
742 | variable news_prepend "" | |
743 | variable print_prepend "" | |
744 | variable video_prepend "" | |
745 | variable scholar_prepend "" | |
746 | variable youtube_prepend "" | |
747 | variable locate_prepend "" | |
748 | variable gamespot_prepend "" | |
749 | variable fight_prepend "" | |
750 | variable ebayfight_prepend "" | |
751 | variable trans_prepend "" | |
752 | variable dailymotion_prepend "" | |
753 | variable gamefaqs_prepend "" | |
754 | variable blog_prepend "" | |
755 | variable ebay_prepend "" | |
756 | variable popular_prepend "" | |
757 | variable rev_prepend "" | |
758 | variable wiki_prepend "" | |
759 | variable wikimedia_prepend "" | |
760 | variable recent_prepend "" | |
761 | variable mininova_prepend "" | |
762 | variable ign_prepend "" | |
763 | variable myspacevids_prepend "" | |
764 | variable trends_prepend "" | |
765 | ||
766 | # set this to 0 to turn google fight off (it is a tad slow after all ...) | |
767 | # this also disables or enables ebay fights (it's even slower ...) | |
768 | # ------ | |
769 | variable google_fight 1 | |
770 | ||
771 | # ** this is not an optional setting, if a string is too long to send, it won't be sent! ** | |
772 | # it should be set to the max amount of characters that will be received in a public | |
773 | # message by your IRC server. If you find you aren't receiving results, try lowering this. | |
774 | # ------ | |
775 | variable split_length 410 | |
776 | ||
777 | # trimmed length of returned descriptions, only for standard searches. | |
778 | # ------ | |
779 | variable description_length 80 | |
780 | ||
781 | # amount of lines you want your wiki* results to span, the more lines the more | |
782 | # of the wiki article or section you will see, some get cut short if so raise this. | |
783 | # this affects both wikipedia and wikimedia results. | |
784 | # ------ | |
785 | variable wiki_lines 2 | |
786 | ||
787 | # short answers? when google search encounters an answer this | |
788 | # option will make only it show, no other results. this also skips | |
789 | # showing image/news/etc results from other google sites as results. | |
790 | # ------ | |
791 | variable short_answers 1 | |
792 | ||
793 | # skip links to self? google sometimes uses links to it's own | |
794 | # services within normal google searches. This will skip _any_ google | |
795 | # links from appearing within google search results. For some | |
796 | # queries this will omit obvious replies which is normal. | |
797 | # ------ | |
798 | variable skip_self 0 | |
799 | ||
800 | # replace search terms appearing in the description as bolded words? | |
801 | # -> does not bold entire description, just the matching search words | |
802 | # -> this is ignored if desc_modes contains the Bold mode below. | |
803 | # ------ | |
804 | variable bold_descriptions 1 | |
805 | ||
806 | # set this to 0 to turn off total results appearing with searches. | |
807 | # ------ | |
808 | variable total_results 1 | |
809 | ||
810 | # set this to 1 to remove descriptions and set only links to show | |
811 | # ------ | |
812 | variable link_only 0 | |
813 | ||
814 | # set this to the default country you would like *.wikipedia to use when | |
815 | # no country is specified. default is "en". country is 2-letter wiki code. | |
816 | # http://*.wikipedia.org/ - en, de, it, es, fr, these are examples. | |
817 | # ------ | |
818 | variable wiki_country "en" | |
819 | ||
820 | # set this to the default website you would like wikimedia to use when | |
821 | # no website is specified. | |
822 | # ------ | |
823 | variable wikimedia_site "wiki.gbatemp.net/wiki" | |
824 | ||
825 | # Wikimedia URL detection | |
826 | # remove double entries from urls? would remove a '/wikisite' from this | |
827 | # type of url @ http://yoursite.com/wikisite/wikisite/search_term | |
828 | # if you have issues regarding url capture with wikimedia, enable this. | |
829 | # /wiki/wiki/ problems are naturally averted, a setting of 0 already | |
830 | # stops these type. | |
831 | # -------- | |
832 | variable wiki_domain_detect 1 | |
833 | ||
834 | # Customized Trigger Phrasing? | |
835 | # allow customized triggers to be attached to custom phrasing | |
836 | # Anything other than 0 will enable and will use the list below. | |
837 | variable my_custom 1 | |
838 | ||
839 | # Custom Trigger Phrasing | |
840 | # This is used to customize triggers and for | |
841 | # constructing phrases to pass, format is: | |
842 | # "custom-trigger:trigger-to-associate-with:phrase-to-pass" | |
843 | # within the phrase-to-pass, %search% = the users input.. but, | |
844 | # if this is passed onto another custom trigger it will become | |
845 | # the enitre phrase which was passed from the trigger before it. | |
846 | # hopefully people understand how to use these, and remember | |
847 | # to read the lines below this at least twice before | |
848 | # constructiong your phrasing... | |
849 | # DO NOT USE YOUR COMMAND CHAR IN THESE IT IS ASSUMED. | |
850 | # special tcl characters MUST be escaped for you to acheive greatness. | |
851 | variable my_customs { | |
852 | "ch:g:%search% +site:computerhope.com" | |
853 | "eh:g:%search% +site:egghelp.org" | |
854 | "mi:g:%search% +site:mircscripts.org" | |
855 | "rw:wm:.wiki.roms-isos.com %search%" | |
856 | "gw:wm:.wiki.gbatemp.net/wiki %search%" | |
857 | "ed:wm:.encyclopediadramatica.ch %search%" | |
858 | "un:wm:.uncyclopedia.wikia.com %search%" | |
859 | "wq:wm:.en.wikiquote.org/wiki %search%" | |
860 | "lw:wm:.lyricwiki.org %search%" | |
861 | "wk:wm:.en.wiktionary.org/wiki %search%" | |
862 | "bible:wm:.biblewiki.be/wiki %search%" | |
863 | "znc:wm:.en.znc.in/wiki %search%" | |
864 | "gbr:g:.com.br %search%" | |
865 | "got:g:%search% +ext:torrent" | |
866 | "rs:g:%search% +inurl:rapidshare" | |
867 | "rsmp3 r3 rs3:rs:%search% inurl:mp3" | |
868 | "kiczek:gf:%search% in usa" | |
869 | "mysite:g:+site:%%1%% +ext:%%2%% %%3-end%%" | |
870 | "cg:g:+inurl:%%1%%.craigslist +%%2-end%%" | |
871 | "kt:g:%search% +site:kotaku.com" | |
872 | "gay:f:%search% +ass +gay vs %search% +vagina -gay" | |
873 | "yt:g:%search% site:youtube.com" | |
874 | "ts:g:%search% site:twitter.com" | |
875 | "ft:wm:.futurama.wikia.com %search%" | |
876 | "fg:wm:.familyguy.wikia.com %search%" | |
877 | "ad:wm:.americandad.wikia.com %search%" | |
878 | "sp:wm:.southpark.wikia.com %search%" | |
879 | "sw:wm:.starwars.wikia.com %search%" | |
880 | "na:wm:.naruto.wikia.com %search%" | |
881 | "in:wm:.inuyasha.wikia.com %search%" | |
882 | "gr:wm:.gremlins.wikia.com %search%" | |
883 | "wow:wm:.wowwiki.com %search%" | |
884 | "smf:wm:.smurfs.wikia.com %search%" | |
885 | "sm:wm:.sailormoon.wikia.com %search%" | |
886 | "pk:wm:.pokemon.wikia.com %search%" | |
887 | "ss:wm:.strawberryshortcake.wikia.com %search%" | |
888 | "mlp:wm:.mlp.wikia.com %search%" | |
889 | "lps:wm:.lps.wikia.com %search%" | |
890 | "ant:wm:.ants.wikia.com %search%" | |
891 | "gm:wm:.gaming.wikia.com %search%" | |
892 | "nt:wm:.nothing.wikia.com %search%" | |
893 | "ff:wm:.finalfantasy.wikia.com %search%" | |
894 | "ok:wm:.openkinect.org/wiki %search%" | |
895 | "bl:wm:.borderlands.wikia.com %search%" | |
896 | } | |
897 | ||
898 | # this controls custom trigger phrasing query control. | |
899 | # with this you can split the users search into individual | |
900 | # words, and use these with your custom trigger above. | |
901 | # suppose the user types your custom trigger | |
902 | # <user> !rsmp3 tupac mama | |
903 | # you can reference this in your custom trigger as: | |
904 | # %search% to get the entire text: tupac mama | |
905 | # but, suppose you want individual words, tupac and mama | |
906 | # well now you can reference these too as %%1%% and %%2%%. | |
907 | # you can also use ranges %%1-4%% %%1-end%%. Unlike eggdrop | |
908 | # 1 is the starting index of the users input, not 0. | |
909 | # this works in combination with %search%, but for indexes | |
910 | # you _MUST_ reference within %%'s (double percents).. | |
911 | # hopefully you understand how this functions.. ;) | |
912 | # any setting 1 or higher enables, 0 or lower disables | |
913 | # ------ | |
914 | # NOTE: Leaving this enabled is advised if you use any double | |
915 | # percent variables (%%1%% %%etc%%) in your my_customs list above. | |
916 | # ------ | |
917 | variable custom_words 1 | |
918 | ||
919 | # set this to the proxy you wish the main html fetching procedure to | |
920 | # use. set both proxy_host and proxy_port. if you don't wish to use | |
921 | # a proxy. set proxy_host "" | |
922 | # ------ | |
923 | variable proxy_host "" | |
924 | variable proxy_port "" | |
925 | ||
926 | # set this to the default country you would like ebay.* to use when no | |
927 | # country is specified. default is "com". country is ebay extension | |
928 | # http://ebay.*/ - co.uk, de, es, com, com.au, these are examples. | |
929 | # ------ | |
930 | variable ebay_country "com" | |
931 | ||
932 | # set this to the default country you would like *.google.* sites to use when | |
933 | # no country is specified. default is "com". country is google extension. | |
934 | # http://google.*/ - co.uk, de, es, com, com.au, these are examples. | |
935 | # ------ | |
936 | variable google_country "com" | |
937 | ||
938 | # set this to the default country you would like dailymotion to use when | |
939 | # no country is specified. default is "en" for international. | |
940 | # http://dailymotion.com/*/ - en, us, es, fr, nl, pt, da, el, it, pl, ro, sv, tr, ja, ko, zh, these are examples. | |
941 | # ------ | |
942 | variable daily_country "en" | |
943 | ||
944 | # set this to the default country you would like *.youtube to use when | |
945 | # no country is specified. default is "com". country is youtube code. | |
946 | # http://*.youtube.com/ - com, us, ie, fr, it, nl, br, gb, jp, de, es, pl, these are examples. | |
947 | # ------ | |
948 | variable youtube_country "com" | |
949 | ||
950 | # enable this to allow youtube links to lead to higher definition videos | |
951 | # rather than their stream optimized lower quality setting. | |
952 | # to disable use 0, anything else enables. | |
953 | # ------ | |
954 | variable youtube_highquality 1 | |
955 | ||
956 | # set this to the switch you want to use for youtube to filter content | |
957 | # and display only high-definition videos. | |
958 | # ------ | |
959 | variable youtube_highdef "@hd" | |
960 | ||
961 | # set your default translation language here, this is what will be assumed | |
962 | # if the user omits the 'translate to' portion of their input. | |
963 | # en, es, it, nl, de, etc.. these are merely some examples, there are more available. | |
964 | # ------ | |
965 | variable trans "en" | |
966 | ||
967 | # Google translation input/output encodings | |
968 | # set these below to either: | |
969 | # 0 for automatic encoding | |
970 | # 1 for utf-8 | |
971 | # You may use switches to inverse this behavior on-the-fly. Set them | |
972 | # below as well. | |
973 | # ------ | |
974 | variable trans_input 1 | |
975 | variable trans_output 0 | |
976 | variable trans_input_t "--swapi" | |
977 | variable trans_output_t "--swapo" | |
978 | ||
979 | # Channel filter | |
980 | # this is for users who already have a google script running, but would | |
981 | # like to use the other functions of this script. You can filter out google | |
982 | # requests in any of the channels listed below. | |
983 | # default is "". To add them use: "#chan1 #CHAN2 #cHaN3 #EtC", case is irrelevant. | |
984 | # ------ | |
985 | variable filtered "" | |
986 | ||
987 | # COLOR THEME - THESE CAN BE SHARED WITH OTHERS ON EGGHELP! :P | |
988 | # use these settings below to set your preferred color theme. | |
989 | # the following modes apply and you can use any combination of them: (NO SPACES!) | |
990 | # | |
991 | # Bold = \002 | |
992 | # Underline = \037 | |
993 | # Reverse = \026 | |
994 | # Colours: #RGB/Html code: | |
995 | # White = \00300 #FFFFFF | |
996 | # Black = \00301 #000000 | |
997 | # Blue = \00302 #00007F | |
998 | # Green = \00303 #008F00 | |
999 | # Light Red = \00304 #FF0000 | |
1000 | # Brown = \00305 #7F0000 | |
1001 | # Purple = \00306 #9F009F | |
1002 | # Orange = \00307 #FF7F00 | |
1003 | # Yellow = \00308 #F0FF00 | |
1004 | # Light Green = \00309 #00F700 | |
1005 | # Cyan = \00310 #008F8F | |
1006 | # Light Cyan = \00311 #00F7FF | |
1007 | # Light Blue = \00312 #0000FF | |
1008 | # Pink = \00313 #FF00FF | |
1009 | # Grey = \00314 #7F7F7F | |
1010 | # Light Grey = \00315 #CFCFCF | |
1011 | # | |
1012 | # this example will do Bold, Underline and Light Blue: "\002\037\00312" | |
1013 | # note: this will affect *ALL* descs, links, totals and errors. also | |
1014 | # don't forget to use the \ too ! note: abusing this will heavily increase | |
1015 | # the number of characters per line, so your output lines will increase accordingly. | |
1016 | # | |
1017 | # COLOR CODES MUST CONSIST OF 2 DIGITS, IF YOU WISH TO USE 0-9 PREFIX | |
1018 | # IT WITH 0 ACCORDINGLY. IE, \00304 for red... | |
1019 | # IF YOU WISH TO USE BACKGROUNDS, THIS IS ALLOWED; IE, \00304,02... | |
1020 | # TO DEMODE A COLOR YOU MUST USE \00399 RATHER THAN SIMPLY \003 | |
1021 | # | |
1022 | # use *_modes to enable each color, bold, underline. | |
1023 | # use *_demodes to undo this back to plain text. | |
1024 | # if you do not use the proper modes/demodes here your color theme will look | |
1025 | # horrible... | |
1026 | # ------ | |
1027 | # description mode/demode | |
1028 | variable desc_modes "" | |
1029 | variable desc_demodes "" | |
1030 | # link mode/demode | |
1031 | variable link_modes "" | |
1032 | variable link_demodes "" | |
1033 | # totals mode/demode | |
1034 | variable total_modes "" | |
1035 | variable total_demodes "" | |
1036 | # error mode/demode | |
1037 | variable error_modes "" | |
1038 | variable error_demodes "" | |
1039 | ||
1040 | # break, seperator and split_char need more than modes | |
1041 | # you also enter the appropriate character you wish used. | |
1042 | variable break " @ " | |
1043 | variable seperator " | " | |
1044 | # if using "\n" within the seperator above, you may want to change | |
1045 | # the below setting to possibly to ", " or "; " | |
1046 | variable split_char " | " | |
1047 | ||
1048 | # number of minute(s) to ignore flooders, 0 to disable flood protection | |
1049 | # ------ | |
1050 | variable ignore 1 | |
1051 | ||
1052 | # how many requests in how many seconds is considered flooding? | |
1053 | # by default, this allows 3 queries in 10 seconds, the 4th being ignored | |
1054 | # and ignoring the flooder for 'variable ignore' minutes | |
1055 | # ------ | |
1056 | variable flood 4:10 | |
1057 | ||
1058 | # would you like to use vocabulary aversion? | |
1059 | # this will replace swear words with more appropriate words | |
1060 | # and the query returned will be aversion free. | |
1061 | # 0 disables, anything else enables | |
1062 | #---------- | |
1063 | variable aversion_vocabulary 0 | |
1064 | ||
1065 | # set your aversion vocabulary below if desired: | |
1066 | # remember to enable, keep the setting above at 1. | |
1067 | #---------- | |
1068 | variable aversion { | |
1069 | cunt:cock | |
1070 | cock:cunt | |
1071 | anal:internet | |
1072 | "hell:a hot place" | |
1073 | sex:troll | |
1074 | "fred:wasn't he a flintstone?" | |
1075 | *fuck*:nice | |
1076 | bitches:women | |
1077 | bitch:woman | |
1078 | "analsex:true love" | |
1079 | "supergear:licorice and pancakes" | |
1080 | "tecra:I LIKE LARGE POSTERIORS AND I CANNOT PREVARICATE!" | |
1081 | {word:"fuck you"} | |
1082 | } | |
1083 | ||
1084 | #---> NOTE: | |
1085 | #---> IF YOUR PRIMARY LANGUAGE ISN'T ENGLISH YOU MUST CHANGE THIS SECTION BELOW POSSIBLY | |
1086 | # this is the help list generated by the bot to help users become familiar with the script. | |
1087 | # you can change these here to affect the language used when help is asked for. | |
1088 | # there MUST be 28 entries in this list, the first must be the word for ALL. | |
1089 | # this list MUST be kept entirely lowercase. | |
1090 | # ------ | |
1091 | variable helplist "all google images groups news local book video fight youtube translate gamespot gamefaqs blog ebay ebayfight wikipedia wikimedia locate review torrent top popular dailymotion ign myspace trends scholar" | |
1092 | ||
1093 | # english words within the help phrases, spacing must be kept as it is below. | |
1094 | # ------ | |
1095 | variable helpmsg1 "Help is only available for the following:" | |
1096 | variable helpmsg2 "is disabled." | |
1097 | variable helpmsg3 "with " | |
1098 | variable helpmsg4 " results." | |
1099 | ||
1100 | # the help messages given. | |
1101 | # ------ | |
1102 | variable help1 "\[.google.country.code\] \[define:|spell:\] <search terms> <1+1> <1 cm in ft> <patent ##> <weather city|zip> <??? airport>" ;#google | |
1103 | variable help2 "\[.google.country.code\] <search terms>" ;#images | |
1104 | variable help3 "\[.google.country.code\] <search terms>" ;#groups | |
1105 | variable help4 "\[.google.country.code\] <search terms>" ;#news | |
1106 | variable help5 "\[.google.country.code\] <what> near <where>" ;#local | |
1107 | variable help6 "\[.google.country.code\] <search terms>" ;#book | |
1108 | variable help7 "\[.google.country.code\] <search terms>" ;#video | |
1109 | variable help8 "<word(s) one> vs <word(s) two>" ;#fight | |
1110 | variable help9 "\[.youtube.country.code\] <search terms>" ;#youtube | |
1111 | variable help10 "region@region <text>" ;#translate | |
1112 | variable help11 "<search terms>" ;#gamespot | |
1113 | variable help12 "<system> in <region>" ;#gamefaqs | |
1114 | variable help13 "\[.google.country.code\] <search terms>" ;#blog | |
1115 | variable help14 "\[.ebay.country.code\] <search terms>" ;#ebay | |
1116 | variable help15 "<word(s) one> vs <word(s) two>" ;#ebayfight | |
1117 | variable help16 "\[.wiki-country-code\] <search terms>\[#subtag\]" ;#wikipedia | |
1118 | variable help17 "\[.www.wikisite.org\[/wiki\]\] <search terms>\[#subtag\]" ;#wikimedia | |
1119 | variable help18 "<ip or hostmask>" ;#locate | |
1120 | variable help19 "<gamename> \[@ <system>\]" ;#review | |
1121 | variable help20 "<search terms>" ;#torrent | |
1122 | variable help21 "<system>" ;#top | |
1123 | variable help22 "<system>" ;#popular | |
1124 | variable help23 "<search terms>" ;#dailymotion | |
1125 | variable help24 "<search terms>" ;#ign | |
1126 | variable help25 "<search terms>" ;#myspace | |
1127 | variable help26 "\[.google.country.code\] <YYYY-MM-DD>" ;#trends | |
1128 | variable help27 "\[.google.country.code\] <search terms>" ;#scholar | |
1129 | #---> END OF NOTE: | |
1130 | ||
1131 | # enable encoding conversion, set this to 1 to enable. | |
1132 | # with this enabled it will follow the format of encoding conversions listed | |
1133 | # below. these will affect both input and output and will follow country switch. | |
1134 | # ------ | |
1135 | variable encoding_conversion_input 0 | |
1136 | variable encoding_conversion_output 1 | |
1137 | ||
1138 | # enable dirty decoding? This attempts to use the regular "dirty" method | |
1139 | # of rendering html elements which works well with iso8859-1 and other | |
1140 | # latin variants. This does not work well at all with russian, japanese, | |
1141 | # and any other non-latin variants. So keep this at 0 if you want a truly | |
1142 | # multi-language bot, but keep in mind you may see unrendered &x12345; html | |
1143 | # elements. This is because I don't know of a method to transcode these | |
1144 | # to proper utf-8 characters yet.. :P | |
1145 | # ------ | |
1146 | # NOTE: If you bot is properly utf-8 patched, setting this to 1 is recommened. | |
1147 | # ------ | |
1148 | variable dirty_decode 1 | |
1149 | ||
1150 | # enable gzip compression for bandwidth savings? Keep in mind | |
1151 | # this semi-breaks some of the present utf-8 work-arounds and | |
1152 | # eggdrop may mangle encodings when gzip compression that it | |
1153 | # doesn't when uncompressed html it used (default). A setting | |
1154 | # of 0 defaults to uncompressed html, a 1 or higher gzip. | |
1155 | # ------ | |
1156 | # NOTE: If you do not have Trf or zlib packages setting this | |
1157 | # to 0 is recommened. Leaving it at 1 is fine as well, as the | |
1158 | # script will attempt to find these commands or packages every | |
1159 | # rehash or restart. But to keep gzip from ever being used it | |
1160 | # is best to set the below variable to 0. | |
1161 | # NOTE2: If you have Trf or zlib packages present, then this | |
1162 | # should always be set to 1. You save enormous bandwidth and | |
1163 | # time using this. If your bot is patched and you have Trf/zlib | |
1164 | # then you should definitely leave this at 1 and you will never | |
1165 | # suffer issues. | |
1166 | # ------ | |
1167 | variable use_gzip 0 | |
1168 | ||
1169 | # THIS IS TO BE USED TO DEVELOP A BETTER LIST FOR USE BELOW. | |
1170 | # To work-around certain encodings, it is now necessary to allow | |
1171 | # the public a way to trouble shoot some parts of the script on | |
1172 | # their own. To use these features involves the two settings below. | |
1173 | # -- DEBUG INFORMATION GOES BELOW -- | |
1174 | # set debug and administrator here | |
1175 | # this is used for debugging purposes | |
1176 | # ------ | |
1177 | variable debug 1 | |
1178 | variable debugnick speechles | |
1179 | ||
1180 | # AUTOMAGIC | |
1181 | # with this set to 1, the bottom encode_strings setting will become | |
1182 | # irrelevant. This will make the script follow the charset encoding | |
1183 | # the site is telling the bot it is. | |
1184 | # This DOES NOT affect wiki(media/pedia), it will not encode automatic. | |
1185 | # Wiki(media/pedia) still requires using the encode_strings section below. | |
1186 | # ------ | |
1187 | # NOTE: If your bot is utf-8 pathced, leave this option at 1, the only | |
1188 | # time to change this to 0 is if your having rendering problems. | |
1189 | # ------ | |
1190 | variable automagic 1 | |
1191 | ||
1192 | # UTF-8 Work-Around (for eggdrop, this helps automagic) | |
1193 | # If you use automagic above, you may find that any utf-8 charsets are | |
1194 | # being mangled. To keep the ability to use automagic, yet when utf-8 | |
1195 | # is the charset defined by automagic, this will make the script instead | |
1196 | # follow the settings for that country in the encode_strings section below. | |
1197 | # ------ | |
1198 | # NOTE: If you bot is utf-8 patched, set this to 0. Everyone else, use 1. | |
1199 | # ------ | |
1200 | variable utf8workaround 1 | |
1201 | ||
1202 | # encoding conversion lookups | |
1203 | # here is where you can correct language encoding problems by pointing their | |
1204 | # abbreviation towards an encoding. if you want more, feel free to add more. | |
1205 | # this is a somewhat poor example below, there are possibly hundreds of additions | |
1206 | # that need to be added to this section, this is just something to see if this | |
1207 | # indeed is a work around, enjoy and merry christmas ;P | |
1208 | # ------ | |
1209 | # NOTE: If your bot is utf-8 patched, the below list is irrevelevant. | |
1210 | # NOTE2: If your bot isn't utf-8 patched and Trf/zlib are found and used, the below | |
1211 | # list is used to correct latin encodings, this is how the list starts by default. | |
1212 | # NOTE3: If your bot isn't utf-8 patched, and Trf/zlib are NOT found, the below | |
1213 | # list is to correct utf-8 encodings, as well as various latin encodings. You | |
1214 | # may need to add things to this list possibly to correct rendering problems. | |
1215 | # ------ | |
1216 | variable encode_strings { | |
1217 | ||
1218 | } | |
1219 | } | |
1220 | } | |
1221 | ||
1222 | # ------ | |
1223 | # end of configuration, script begins - changes beyond this section aren't advised. | |
1224 | # ------ | |
1225 | # *** DO NOT CHANGE THINGS BEYOND THIS POINT UNLESS YOU KNOW WHAT YOUR DOING *** | |
1226 | # If you know what your doing, well by all means, change anything and everything, | |
1227 | # but do so with the understanding that all modifications are bound by the | |
1228 | # GNU General Public license agreement found above regarding credit for authors | |
1229 | # and general copyrights. | |
1230 | # ------ | |
1231 | ||
1232 | # requires http package | |
1233 | package require http 2.5 | |
1234 | ||
1235 | # if gzip requested, Trf or zlib required. | |
1236 | if {$::incith::google::use_gzip > 0} { | |
1237 | if {([lsearch [info commands] zlib] == -1) && ([catch {package require zlib} error] !=0)} { | |
1238 | if {([catch {package require Trf} error] == 0) || ([lsearch [info commands] zip] != -1)} { | |
1239 | putlog "Incith:Google compression test successful, found Trf package! Gzip enabled." | |
1240 | set incith_trf 1 | |
1241 | set incith_hdr "Accept-Encoding gzip,deflate" | |
1242 | } else { | |
1243 | putlog "Incith:Google unable to find zlib or trf package! Gzip disabled." | |
1244 | putlog "Incith:Google requires gzip decompression with wikipedia and Wikimedia. As a result, every article will not work for you." | |
1245 | set incith_nozlib 1 | |
1246 | set incith_hdr "" | |
1247 | } | |
1248 | } else { | |
1249 | putlog "Incith:Google compression test successful, found zlib package! Gzip enabled." | |
1250 | set incith_hdr "Accept-Encoding gzip,deflate" | |
1251 | } | |
1252 | } else { | |
1253 | set incith_nozlib 1 | |
1254 | set incith_hdr "" | |
1255 | } | |
1256 | ||
1257 | # set flag per channel use | |
1258 | setudef flag google | |
1259 | ||
1260 | # initialize | |
1261 | namespace eval incith { | |
1262 | namespace eval google { | |
1263 | variable version "incith:google-2.0.0c" | |
1264 | variable encode_strings [split $encode_strings] | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | # bind the public binds | |
1269 | bind pubm -|- "*" incith::google::public_message | |
1270 | ||
1271 | # bind the private message binds, if wanted | |
1272 | if {$incith::google::private_messages >= 1} { | |
1273 | bind msgm -|- "*" incith::google::private_message | |
1274 | } | |
1275 | ||
1276 | namespace eval incith { | |
1277 | namespace eval google { | |
1278 | ||
1279 | # performs a search on google. | |
1280 | # | |
1281 | proc google {input} { | |
1282 | # local variable initialization | |
1283 | set results 0 ; set calc 0 ; set break 0 ; set spell 0 ; set output ""; set match "" | |
1284 | set populate 0 ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen "" | |
1285 | ||
1286 | # can't be moved to fetch_html since $spell isn't global | |
1287 | if {[string match -nocase "*spell:*" $input] == 1} { | |
1288 | set spell 1 | |
1289 | } | |
1290 | ||
1291 | # fetch the html | |
1292 | set html [fetch_html $input 1] | |
1293 | ||
1294 | # this isn't global, so we need to keep ctry (country) here | |
1295 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen input | |
1296 | if {$titen == ""} { | |
1297 | set titen "${incith::google::google_country}" | |
1298 | } else { | |
1299 | set titen [lindex [split $titen /] 0] | |
1300 | } | |
1301 | ||
1302 | # standard fetch_html error catcher | |
1303 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
1304 | regsub {(.+?)\|} $html {} html | |
1305 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
1306 | } | |
1307 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
1308 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
1309 | } | |
1310 | ||
1311 | regsub -- {<div id=ss-box>.*?</div><div>} $html {} html | |
1312 | # strip out 'did you mean?' first | |
1313 | # what do we call 'no search results in any language?' | |
1314 | if {![regexp -nocase -- {</div><div id=res class=med>(.+?)<p style} $html - no_search]} { | |
1315 | if {![regexp -nocase -- {</div><div id=res class=med>(.+?)<p style} $html - no_search]} { | |
1316 | if {![regexp -nocase -- {</script><div id=res>(.+?)<br><br>} $html - no_search]} { | |
1317 | if {![regexp -nocase -- {<div id=res class=med>.*?<p>(.+?)<p style} $html - no_search]} { | |
1318 | if {![regexp -nocase -- { </div><div class=med.*?>(.*?)\.<br><br>} $html - no_search]} { | |
1319 | if {![regexp -nocase -- {<p class=sp_cnt>(.*?)<a id} $html - no_search]} { | |
1320 | regexp -nocase -- {<div class=med><p style=.*?>(.*?)<a id} $html - no_search | |
1321 | } | |
1322 | } | |
1323 | } | |
1324 | } | |
1325 | } | |
1326 | } | |
1327 | if {$no_search != ""} { | |
1328 | regsub -- {^.*?</h2>} $no_search "" no_search | |
1329 | regsub -- {</a>.*?<div class=med style=.*?>} $no_search "</a>" no_search | |
1330 | regexp -- {^(.+?)</td></tr>} $no_search - no_search | |
1331 | regsub -- {</a>} $no_search "? " no_search | |
1332 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
1333 | while {[string match "* *" $no_search]} { | |
1334 | regsub -all -- { } $no_search " " no_search | |
1335 | } | |
1336 | if {$incith::google::bold_descriptions == 0} { | |
1337 | regsub -all -- "\002" $no_search {} no_search | |
1338 | } | |
1339 | set no_search [string trim $no_search] | |
1340 | } | |
1341 | ||
1342 | # give results an output header with result tally. | |
1343 | if {![regexp -- {<div id=prs>.*?</div><p>(.+?)\s\002(.+?)\(\002} $html - titem match]} { | |
1344 | if {![regexp -- {<p id=resultStats> (.*?) (.*?)\(\002} $html - titem match]} { | |
1345 | if {[regexp -- {<div id=resultStats>(.*?)\(} $html - match]} { | |
1346 | set match [split [string trim $match]] | |
1347 | set titem [lindex $match end] | |
1348 | set match [lindex $match end-1] | |
1349 | } else { | |
1350 | set match "Google" | |
1351 | set titem "" | |
1352 | } | |
1353 | } | |
1354 | } | |
1355 | regsub -all -- {<(.+?)>} $match {} match | |
1356 | regsub -all -- {<(.+?)>} $titem {} titem | |
1357 | # format output according to variables. | |
1358 | if {$incith::google::total_results != 0 && $spell == 0} { | |
1359 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
1360 | if {$incith::google::bold_descriptions == 0} { | |
1361 | regsub -all -- "\002" $output {} output | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | # parse the html | |
1366 | while {$results < $incith::google::search_results} { | |
1367 | # the regexp grabs the data and stores them into their variables, while | |
1368 | # the regsub removes the data, for the next loop to grab something new. | |
1369 | ||
1370 | # check if there was an alternate spelling first | |
1371 | if {([string match "*<p class=ssp>*" $html] || [string match "*<p class=sp_cnt>*" $html] || [string match "*</div><div id=res class=med><p>*" $html] || [string match "*</div><div id=res class=med>*<li><p>*" $html])&& [string match "define:*" $input] == 0 && [string match "*&nocalc=1\">*" $html] == 0} { | |
1372 | if {[regexp -nocase -- {</div><div id=res class=med><p>(.+?)<a href=.*?>(.+?)</a>} $html - titem did_you_mean]} { | |
1373 | regsub -all -nocase -- {</div><div id=res class=med><p>(.+?)</a>} $html {} html | |
1374 | regexp -- {^(.*?)</h2>} $titem - titem | |
1375 | } elseif {[regexp -nocase -- {</div><div id=res class=med><h2 class=hd>.*?<p>(.+?)<a href=.*?>(.+?)</a>} $html - titem did_you_mean]} { | |
1376 | regsub -all -nocase -- {</div><div id=res class=med><h2 class=hd>.*?<p>.+?<a href=.*?>.+?</a>} $html {} html | |
1377 | } elseif {[regexp -nocase -- {</div><div id=res class=med><!--a--><h2 class.+?>.*?<p>(.*?)<a href=.*?>(.+?)</a>} $html - titem did_you_mean]} { | |
1378 | regsub -all -nocase -- {</div><div id=res class=med><!--a--><h2 class.+?>.*?</a>} $html {} html | |
1379 | } elseif {[regexp -nocase -- {<td id=rhspad></table><div id=res class=med><p>(.+?)<a href=.*?>(.+?)</a>} $html - titem did_you_mean]} { | |
1380 | regsub -all -nocase -- {<td id=rhspad></table><div id=res class=med><p>.+?<a href=.*?>.+?</a>} $html {} html | |
1381 | } elseif {[regexp -nocase {<p class=sp_cnt>(.*?)<a href=.*?>(.*?)</a>} $html - titem did_you_mean]} { | |
1382 | regsub -all -nocase -- {<p class=sp_cnt>} $html {} html | |
1383 | } elseif {[regexp -nocase {<p class=ssp>(.*?)<a href=.*?>(.*?)</a>} $html - titem did_you_mean]} { | |
1384 | regsub -all -nocase -- {<p class=ssp>} $html {} html | |
1385 | } | |
1386 | # sometimes calculator results are mixed into our alternate spelling. | |
1387 | # we want to show these like we do our 'did you mean' | |
1388 | if {[string match "*<img src=/images/calc_img*" $titem] == 1} { | |
1389 | regexp -nocase -- {calc_img.+?nowrap.*?>(.+?)</td></tr>} $titem - titem | |
1390 | set desc $titem | |
1391 | if {$::incith::google::short_answers > 0 } { | |
1392 | regsub -all -- {<(.+?)>} $desc "" desc | |
1393 | return "${::incith::google::desc_modes}$desc" | |
1394 | } | |
1395 | } else { | |
1396 | set desc "$::incith::google::total_modes$titem$incith::google::total_demodes$incith::google::desc_modes$did_you_mean$incith::google::desc_demodes" | |
1397 | } | |
1398 | if {$incith::google::bold_descriptions == 0 && [string match "\002" $incith::google::desc_modes] == 1} { | |
1399 | regsub -all -- "\002" $desc {} desc | |
1400 | } | |
1401 | regexp -- {^(.+?)</td></tr>} $desc - desc | |
1402 | regsub -all -- {<(.+?)>} $desc "" desc | |
1403 | # did you mean and calculate have no link | |
1404 | set link "" | |
1405 | ||
1406 | ### ONEBOX RESULTS ### | |
1407 | ||
1408 | # answers | |
1409 | # } elseif {[string match "*<div id=res class=med role=main><div class=e><h3 class=r><a href=*" $html]} { | |
1410 | if {![regexp -- {<div id=res class=med role=main><div class=e><h3 class=r><a href="http\://www.google.com/url\?q=(.+?)\&ei=.*?">(.*?)</h3><div} $html - link desc]} { | |
1411 | if {![regexp -- {<h3 class=r.*?<a href="(.*?)\&hl=.*?<div style=.*?>(.*?)</div>.*?<cite>(.*?)</cite>} $html - link desc url]} { | |
1412 | if {[regexp -- {<div class=e><h3 class=r><a href="(.*?)".*?>(.*?)</a>} $html - link desc]} { set url "www.google.${titen}" } | |
1413 | } | |
1414 | set link "http://$url$link" | |
1415 | } | |
1416 | regsub -- {<div id=res class=med><div class=e><h3 class=r><a href=.+?</h3><div} $html "" html | |
1417 | if {[info exists desc]} { | |
1418 | regsub -- {<(.+?)>} $desc "" desc | |
1419 | if {$::incith::google::short_answers > 0 } { | |
1420 | if {[info exists link]} { | |
1421 | return "${::incith::google::desc_modes}[descdecode $desc]$incith::google::desc_demodes$::incith::google::break${::incith::google::link_modes}$link${::incith::google::link_demodes}" | |
1422 | } else { | |
1423 | return "${::incith::google::desc_modes}[descdecode $desc]$incith::google::desc_demodes" | |
1424 | } | |
1425 | } | |
1426 | } | |
1427 | # more answers | |
1428 | } elseif {[string match "*\{google.rrep('answersrep'*" $html]} { | |
1429 | regexp -- {<div id=res class=med role=main>.*?<h3 class=r>(.*?)</h3>} $html - desc | |
1430 | regsub -all -- {google.rrep\('answersrep'} $html {} html | |
1431 | if {$::incith::google::short_answers > 0 } { return "${::incith::google::desc_modes}[descdecode [string map {\002 ""} $desc]]$incith::google::desc_demodes" } | |
1432 | # area codes | |
1433 | } elseif {[string match "*/images/map_icon2.gif*" $html] == 1} { | |
1434 | regexp -- {<div class=e>.+?<a href="(.+?)".+?">(.+?)</a>} $html - link desc | |
1435 | regsub -- {/images/map_icon2.gif} $html {} html | |
1436 | if {[info exists link] == 1 && $link != ""} { | |
1437 | set link [urldecode $link] | |
1438 | if {[string match "/url?q=http*" $link] == 1} { | |
1439 | regexp -- {/url\?q=(.+?q=.+?)&} $link - link | |
1440 | } | |
1441 | } | |
1442 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]$::incith::google::desc_demodes$::incith::google::break${::incith::google::link_modes}$link${::incith::google::link_demodes}" } | |
1443 | # zip codes | |
1444 | } elseif {[string match "*&oi=geocode_result*" $html] == 1} { | |
1445 | if {![regexp -nocase -- {oi=geocode_result.*?">(.*?)</a>.*?<tr valign=.*?><td valign=.*?><a href="(.+?)"} $html - desc link]} { | |
1446 | regexp -- {<h3 class=r><a href="(.+?)".*?>(.+?)</a>} $html - link desc | |
1447 | } | |
1448 | regsub -all {\&oi=geocode_result} $html {} html | |
1449 | if {[info exists link] == 1 && $link != ""} { | |
1450 | set link "[urldecode $link]" | |
1451 | if {[string match "/url?q=http*" $link] == 1} { | |
1452 | regexp -- {/url\?q=(.+?q=.+?)&} $link - link | |
1453 | } | |
1454 | } | |
1455 | if {[string equal [string index $link 0] "/"]} { set link "http://maps.google.$titen$link" } | |
1456 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]$::incith::google::desc_demodes$::incith::google::break${::incith::google::link_modes}$link${::incith::google::link_demodes}" } | |
1457 | # music | |
1458 | } elseif {[string match "*&oi=music&ct=result*" $html] == 1} { | |
1459 | regexp -- {</td><td valign=top><h2 class=r><a href=(.+?musica\?aid=.+?)\&.+?>(.+?)\002(.+?)\002} $html - link desc | |
1460 | regsub -- {\&oi=music\&ct=result} $html {} html | |
1461 | if {[info exists link] == 1 && $link != ""} { | |
1462 | set link "[urldecode $link]" | |
1463 | if {[string match "/url?q=http*" $link] == 1} { | |
1464 | regexp -- {/url\?q=(.+?q=.+?)&} $link - link | |
1465 | } | |
1466 | } | |
1467 | if {$::incith::google::short_answers > 0} { return "$::incith::google::desc_modes[descdecode $desc]$::incith::google::desc_demodes$::incith::google::break${::incith::google::link_modes}$link${::incith::google::link_demodes}" } | |
1468 | # travel info | |
1469 | } elseif {[string match "*/images/airplane.gif*" $html] ==1} { | |
1470 | regexp -- {<div class=e>.*?/images/airplane.gif.*?<td.+?valign=top.*?>(.*?)<a.+?href="(.+?)"(?:.*?)>(.+?)</a>} $html - d1 link d2 | |
1471 | regsub -- {<div class=e>.*?/images/airplane.gif.*?</a>} $html "" html | |
1472 | set desc "$d1 $d2" | |
1473 | # UPC codes | |
1474 | } elseif {[string match "*/images/barcode.gif*" $html] ==1} { | |
1475 | regexp -- {<td valign=top><h3 class=r><a href="(.+?)".*?>(.+?)</a>} $html - link desc | |
1476 | regsub -- {<div class=e>.*?/images/barcode.gif.*?</a>} $html "" html | |
1477 | # time | |
1478 | } elseif {[regexp -- {<h3 class=r></h3><tr><td valign=top width=100%><div><table cellspacing=0><tr><td style="font-size:medium">(.*?)</table>} $html - desc]} { | |
1479 | regsub -- {<h3 class=r></h3><tr><td valign=top width=100%><div><table cellspacing=0><tr><td style="font-size:medium">.*?</table>} $html "" html | |
1480 | regsub -all -- {<tr><td>} [string trim $desc] "; " desc | |
1481 | regsub -all -- {<.*?>} [string trim $desc] "" desc | |
1482 | if {$::incith::google::short_answers > 0} { | |
1483 | return "$::incith::google::desc_modes[descdecode $desc]$::incith::google::desc_demodes" | |
1484 | } | |
1485 | # weather! | |
1486 | } elseif {[string match "*/onebox/weather*" $html] == 1} { | |
1487 | regexp -- {<h3 class=r>(.+?)</h3>.+?<table.+?<td.*?rowspan=2>(.+?)<td.+?<tr.+?<tr.+?<td.*?>(.+?)<td.+?<tr.*?><td.*?>(.+?)<td.+?<tr.*?><td.*?>(.+?)<td} $html - w1 w2 w3 w4 w5 | |
1488 | regexp -- {%<td.*?>(.+?)<.+?>(.+?)<.+?>(.+?)<.+?>(.+?)<.+?>(.+?)<.+?>(.+?)<.+?>(.+?)<.+?>(.+?)</table>} $html - f1 f2 f3 f4 f5 f6 f7 f8 | |
1489 | regsub -- {<h3 class=r>(.*?)</table} $html {} html | |
1490 | # not all weather stations report 5 results at all times | |
1491 | # this make up for when we only get 4, and does it gracefully | |
1492 | if {[regexp {[0-9a-zA-Z]} $w3]} { set w3 ", $w3" } | |
1493 | if {[regexp {[0-9a-zA-Z]} $w4]} { set w4 ", $w4" } | |
1494 | if {![regexp {[0-9a-zA-Z]} $w5]} { | |
1495 | set w5 "" | |
1496 | } else { | |
1497 | set w5 "; $w5" | |
1498 | } | |
1499 | #Take our F temp and turn to C. Does this always start as F without a cookie? Could be bad in metric countries | |
1500 | # regexp -- {([0-9]+)} $w2 {} far | |
1501 | # set cel "%.1f" | |
1502 | # set cel [format $cel [expr {0.5556 * ($far-32)}]] | |
1503 | # set desc "$w1\: $w2/$cel°C; Current: $w3; $w4; $w5" | |
1504 | set desc "$w1\: $w2$w3$w4$w5; $f1/$f2 $f3/$f4 $f5/$f6 $f7/$f8" | |
1505 | regsub -all -- {°} $desc {°} desc | |
1506 | set link "" | |
1507 | regsub -all -- {weather} $input {} input | |
1508 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" } | |
1509 | # time: | |
1510 | } elseif {[string match "*src=\"http://www.google.com/chart*chc=localtime*" $html] == 1} { | |
1511 | regexp -nocase -- {src="http://www.google.com/chart\?chs=.*?chc=localtime.*?><td valign=[a-z]+>(.+?)</table>} $html - desc | |
1512 | regsub -- {<br>} $desc ". " desc | |
1513 | regsub -all {<.*?>} $desc "" desc | |
1514 | regsub -- {chc=localtime} $html {} html | |
1515 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" } | |
1516 | set link "" | |
1517 | # public_data: | |
1518 | } elseif {[string match "*/publicdata</div></div>*" $html]} { | |
1519 | regexp -nocase -- {valign=top><h3 class=r><a href=.*?>(.*?)</a>.*?<tr><td style.*?><a href="(.*?)".*?<td valign=top.*?>(.*?)<br>} $html - tit link des | |
1520 | regsub -all {<.*?>} $des "" des | |
1521 | regsub -- {/publicdata</div></div>} $html "" html | |
1522 | set desc "$tit: $des" | |
1523 | if {[info exists link] == 1 && $link != ""} { | |
1524 | if {[string match "*\&sa\=X*" $link]} { | |
1525 | regexp -- {(^.+?)&sa\=} [urldecode $link] - link | |
1526 | } | |
1527 | if {[string match "\/url\?q=*" $link]} { | |
1528 | regexp -- {\/url\?q=(.*?)$} $link - link | |
1529 | } | |
1530 | regexp -- {(.+?)\&ei=} $link - link | |
1531 | } | |
1532 | if {$::incith::google::short_answers > 0 } { | |
1533 | return "${::incith::google::desc_modes}[descdecode ${desc}]${::incith::google::desc_demodes}" | |
1534 | } | |
1535 | # define: | |
1536 | } elseif {[string match "*<ul type=*" $html]} { | |
1537 | #[string match "*define:*" $input] == 1 | |
1538 | set output "" | |
1539 | regexp -- {<ul type=.+?<li>(.+?)(?=\s*<li>|<br>).*<a href.*(http.+?)">} $html - desc link | |
1540 | regsub -- {<u1 type=.+?><li>(.+?)(?=\s*<li>|<br>)} $html {} html | |
1541 | regsub -all -- {\+} $input {%2B} define_input | |
1542 | regsub -all -- { } $define_input {+} define_input | |
1543 | if {[info exists link] == 1 && $link != ""} { | |
1544 | regexp -- {(.+?)\&sig=} $link - link | |
1545 | regexp -- {(.+?)\&usg=} $link - link | |
1546 | regexp -- {(.+?)\&ei=} $link - link | |
1547 | regexp -- {(.+?)\&sa=} $link - link | |
1548 | set link "[urldecode $link]" | |
1549 | regsub -all " " $link "%20" link | |
1550 | append link " ( http://www.google.${titen}/search?q=${define_input} )" | |
1551 | } else { | |
1552 | if {![regexp -- {</div><div class=med style=".*?"><p>(.+?)\.<br><br>} $html - no_def]} { | |
1553 | if {![regexp -- {<div class=med style=".*?"><br>(.+?)<br><br>} $html - no_def]} { | |
1554 | if {![regexp -- {<!--z--><p>(.*?)<br>} $html - no_def]} { | |
1555 | set no_def "Houston, we have a problem. Aborting lift-off!" | |
1556 | } | |
1557 | } | |
1558 | } | |
1559 | regsub -- {</a>} $no_def "." no_def | |
1560 | regsub -all -- {<(.+?)>} $no_def "" no_def | |
1561 | return "${::incith::google::desc_modes}${no_def}${::incith::google::desc_demodes}" | |
1562 | } | |
1563 | } elseif {[string match "*oi=define*" $html]} { | |
1564 | if {[string match "*oi=spell*" $html]} { | |
1565 | regexp -- {</div><div class=med style=.*?><p>(.*?)<p>(.*?)<p>} $html - desc link | |
1566 | regsub -- {</a>} $desc "?" desc | |
1567 | regsub -all -- {<.*?>} $desc "" desc | |
1568 | regsub -all -- {<.*?>} $link "" link | |
1569 | return "${::incith::google::desc_modes}${desc} ${link}${::incith::google::desc_demodes}" | |
1570 | } | |
1571 | regexp -- {<div class=med style=.*?><p>(.*?)<br>.*?<a href=.*?>(.*?)</a>} $html - desc link | |
1572 | regsub -- {<div class=med style=.*?><p>.*?<br>.*?<a href=.*?>.*?</a>} $html "" html | |
1573 | regsub -all -- {<(.+?)>} [string map {"<li>" " "} $desc] "" desc | |
1574 | if {![string match "http*" $link]} { set link "http://$link" } | |
1575 | regsub -all -- {\+} $input {%2B} define_input | |
1576 | regsub -all -- { } $define_input {+} define_input | |
1577 | set link "${link} ( http://www.google.${titen}/search?q=${define_input} )" | |
1578 | return "${::incith::google::desc_modes}${desc}${incith::google::break}${link}${::incith::google::desc_demodes}" | |
1579 | # finance / stock quotes | |
1580 | } elseif {[string match "*<a href=\"/url\?q=http://finance.google.com/finance%3Fclient%3D*" $html] == 1} { | |
1581 | # this has to be one of the worst regexps ever written ! | |
1582 | regexp -- {<a href="/url\?q=http://finance.google.com/finance%3Fclient%3D.*?">(.*?)</a>(.*?)<.*?<td colspan=3 nowrap>(.+?)</td>.*?Mkt Cap:.*?<td.*?>(.+?)</td>} $html - tick name price mktcap | |
1583 | regsub -- {<div class=e><div><a href="/url\?q=http://finance.google.com/finance%3Fclient%3D.*?">(.*?)</a>(.*?)<.*?<td colspan=3 nowrap>(.+?)</td>.*?Mkt Cap:.*?<td.*?>(.+?)</td>} $html {} html | |
1584 | if {[info exists tick] == 1 && [info exists name] == 1 && [info exists price] == 1} { | |
1585 | set desc "$tick: $name = $$price" | |
1586 | set link "http://finance.google.com/finance?q=$tick" | |
1587 | regsub -all -- "\002" $link {} link | |
1588 | if {[info exists mktcap] == 1} { append desc " Mkt Cap: $mktcap" } | |
1589 | unset tick ; unset name ; unset price ; unset mktcap | |
1590 | } | |
1591 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" } | |
1592 | # patents | |
1593 | } elseif {[string match "*/images/magnifier.gif*" $html] ==1} { | |
1594 | regexp -- {<td valign=top><a href="(http://patft.uspto.gov/.+?)".+?">(.+?)</a>} $html - link desc | |
1595 | regsub -- {/images/magnifier.gif} $html {} html | |
1596 | # calculator | |
1597 | } elseif {[string match "*<img src=/images/calc_img*" $html] || [string match "*<img src=\"/images/icons/onebox/calculator*" $html]} { | |
1598 | set calc 1 | |
1599 | # remove bold codes from the html, not necessary here. | |
1600 | regexp -nocase -- {/calc.*?<h2 class=.*?>(.+?)</h2>} $html - desc | |
1601 | regsub -all -- {<(.+?)>} $desc "" desc | |
1602 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" } | |
1603 | set link "" | |
1604 | # conversion | |
1605 | } elseif {[string match "*oi=currency_onebox*" $html] == 1} { | |
1606 | set calc 1 | |
1607 | regexp -nocase -- {<h3 class=r>(.*?)<} $html - desc | |
1608 | regsub -nocase -- {oi=currency_onebox} $html {} html | |
1609 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" } | |
1610 | set link "" | |
1611 | # whois | |
1612 | } elseif {[string match "*\002Whois\002 record for*" $html] == 1} { | |
1613 | if {[regexp -- {<h3 class=r.*?<a href="(.*?)".*?>(.*?)</a>.*?<tr><td>(.*?)<tr>} $html - link desc descwho]} { | |
1614 | regsub -- {<h3 class=r.*?<a href=".+?".*?>.+?</a>.*?<tr>.*?<tr>} $html "" html | |
1615 | append desc " \(${descwho}\)" | |
1616 | } | |
1617 | if {[info exists link] == 1 && $link != ""} { | |
1618 | if {[string match "*\&sa\=X*" $link]} { | |
1619 | regexp -- {(^.+?)&} $link - link | |
1620 | } | |
1621 | if {[string match "\/url\?q=*" $link]} { | |
1622 | regexp -- {\/url\?q=(.*?)$} $link - link | |
1623 | } | |
1624 | } | |
1625 | if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]$::incith::google::desc_demodes$::incith::google::break${::incith::google::link_modes}$link${::incith::google::link_demodes}" } | |
1626 | ### END ONEBOX ### | |
1627 | ||
1628 | # spell: # special query - not onebox | |
1629 | } elseif {$spell == 1} { | |
1630 | if {[regexp {<div id=res class=med><p>(.*?)</a>} $html - titem]} { | |
1631 | regsub -all {<.*?>} $titem "" titem | |
1632 | set desc "$incith::google::total_modes${titem}$incith::google::total_demodes$incith::google::desc_modes${did_you_mean}$incith::google::desc_demodes" | |
1633 | } else { | |
1634 | if {$match != "Google"} { | |
1635 | return "${::incith::google::total_modes}\002${match}\002 ${titem}" | |
1636 | } else { | |
1637 | return "$incith::google::total_modes$did_you_mean$incith::google::total_demodes$incith::google::desc_modes$no_search" | |
1638 | } | |
1639 | } | |
1640 | if {[string len $desc] < 2} { | |
1641 | set desc "$incith::google::desc_modes$no_search$incith::google::desc_demodes" | |
1642 | } | |
1643 | set link "" | |
1644 | # regular search | |
1645 | } else { | |
1646 | if {![regexp -- {class=g(?!b).*?<a href="(.+?)".*?>((?!<).+?)</a>} $html - link desc]} { | |
1647 | if {[regexp -- {class=r.*?<a href="(.+?)".*?>((?!<).+?)</a>} $html - link desc ]} { | |
1648 | regsub -- {class=r.*?<a href=".+?".*?>(?!<).+?</a>} $html "" html | |
1649 | } | |
1650 | } else { | |
1651 | regsub -- {class=g(?!b).*?<a href=".+?".*?>.+?</a>} $html "" html | |
1652 | } | |
1653 | ||
1654 | if {[info exists link] == 1} { | |
1655 | if {[string match "*\&sa\=X*" $link]} { | |
1656 | regexp -- {(^.+?)&} $link - link | |
1657 | } | |
1658 | } | |
1659 | if {[info exists link] == 1} { | |
1660 | if {[string match "*http*" $link] == 0} { | |
1661 | set link "" | |
1662 | } elseif {[string match *.pdf $link] == 1} { | |
1663 | set desc "\[PDF\] $desc" | |
1664 | } | |
1665 | } | |
1666 | if {($::incith::google::skip_self > 0) && ([info exists link])} { | |
1667 | if {[string match "*.google.*" $link]} { | |
1668 | unset link ; unset desc ; set spell 0 ; set calc 0 ; set break 0 | |
1669 | continue | |
1670 | } | |
1671 | } | |
1672 | # trim the description | |
1673 | if {[info exists desc] == 1 && $incith::google::description_length > 0} { | |
1674 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
1675 | } | |
1676 | } | |
1677 | ||
1678 | # make sure we have something to send | |
1679 | if {[info exists desc] == 0} { | |
1680 | if {$match == "Google"} { | |
1681 | if {[string match "*<img src=/images/calc_img*" $titem] == 1} { | |
1682 | regexp -nocase -- {calc_img.+?nowrap>(.+?)</} $titem - desc | |
1683 | regexp -- {^(.+?)</td></tr>} $desc - desc | |
1684 | set reply "${desc}" | |
1685 | } else { | |
1686 | set reply "${no_search}" | |
1687 | } | |
1688 | return "$incith::google::desc_modes$reply" | |
1689 | } | |
1690 | return $output | |
1691 | } | |
1692 | ||
1693 | if {[info exists link] == 1} { | |
1694 | if {[string match "*http*" $link] == 0} { | |
1695 | set link "" | |
1696 | } | |
1697 | } | |
1698 | set desc [string trim $desc] | |
1699 | regsub -all "%20" $desc " " desc | |
1700 | regsub -all "<br>" $desc " " desc | |
1701 | ||
1702 | # add the search result | |
1703 | if {$calc == 0 && $spell == 0 && $populate == 0} { | |
1704 | if {[info exists link] && $link != ""} { | |
1705 | if {![string match "*define:*" $input]} { | |
1706 | set link [urldecode $link] | |
1707 | regsub -all " " $link "%20" link | |
1708 | } | |
1709 | # added because of recent google changes, needed to clean-up *.google.* links | |
1710 | if {[string match "*url\?*" $link]} { | |
1711 | regexp -- {url\?q=(.+?)$} $link - link | |
1712 | regexp -- {(.+?)\&sig=} $link - link | |
1713 | regexp -- {(.+?)\&usg=} $link - link | |
1714 | regexp -- {\?url=(.+?)$} $link - link | |
1715 | } | |
1716 | # top result may be news, at the moment it is too close to regular | |
1717 | # search results to cull this out.. so in the meantime, this hack | |
1718 | # will at least remove the 10,000 google tags at the end of the url | |
1719 | # to keep it from spanning 2 lines of results. | |
1720 | if {[string match "http://news.google*" $link]} { | |
1721 | regexp -- {^(.+?)&hl=} $link - link | |
1722 | } | |
1723 | regsub -all "(?:\x93|\x94|"|\")" $link {} link | |
1724 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
1725 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
1726 | if {$incith::google::link_only == 1} { | |
1727 | append output "${link}${incith::google::seperator}" | |
1728 | } else { | |
1729 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
1730 | } | |
1731 | } else { | |
1732 | append output "[descdecode $desc]${incith::google::seperator}" | |
1733 | } | |
1734 | } else { | |
1735 | set output "[descdecode $desc]" | |
1736 | } | |
1737 | ||
1738 | # I've hard-coded it to only fetch one result for define lookups, and | |
1739 | # spell shouldn't ever have to loop. | |
1740 | if {[string match "define:*" $input] == 1 || $spell == 1 || $calc == 1 || $break == 1 } { | |
1741 | break | |
1742 | } | |
1743 | ||
1744 | # increase the results, clear the variables for the next loop | |
1745 | unset link ; unset desc ; set spell 0 ; set calc 0 ; set break 0 | |
1746 | incr results | |
1747 | } | |
1748 | ||
1749 | # make sure we have something to send | |
1750 | if {$output == "" && ![string match "*:*" $input] && ![string match "*<img src=/images/calc_img*" $html] } { | |
1751 | set reply "${no_search}" | |
1752 | return "$::incith::google::desc_modes$reply" | |
1753 | } | |
1754 | return $output | |
1755 | } | |
1756 | ||
1757 | # IMAGES | |
1758 | # fetches a list of links to images from images.google. | |
1759 | # | |
1760 | proc images {input} { | |
1761 | ; set results 0 ; set output ""; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" | |
1762 | ||
1763 | # fetch the html | |
1764 | set html [fetch_html $input 2] | |
1765 | ||
1766 | # user input causing errors? | |
1767 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
1768 | regsub {(.+?)\|} $html {} html | |
1769 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
1770 | } | |
1771 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
1772 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
1773 | } | |
1774 | ||
1775 | # strip out 'did you mean?' first | |
1776 | # what do we call 'no search results in any language?' | |
1777 | if {![regexp -- {--></script><div>(.+?)<br><br>} $html - no_search]} { | |
1778 | if {![regexp -- {</a></div><div><p>(.+?)<br><br>} $html - no_search]} { | |
1779 | regexp -- {<table border=0 cellpadding=0 cellspacing=0><tr><td class=j><br>(.+?)<br><br>} $html - no_search | |
1780 | } | |
1781 | } | |
1782 | if {$no_search != ""} { | |
1783 | regsub -- {</a>} $no_search "? " no_search | |
1784 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
1785 | while {[string match "* *" $no_search]} { | |
1786 | regsub -all -- { } $no_search " " no_search | |
1787 | } | |
1788 | set no_search [string trim $no_search] | |
1789 | } | |
1790 | ||
1791 | # give results an output header with result tally. | |
1792 | regexp -- {align=right nowrap id=.*?>(.+?)\s\002(.+?)\(} $html - titem match | |
1793 | if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} { | |
1794 | set match "Google" | |
1795 | set titem "" | |
1796 | } | |
1797 | regsub -all -- {<(.+?)>} $match {} match | |
1798 | # format output according to variables. | |
1799 | if {$incith::google::total_results != 0 && $match > 0} { | |
1800 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
1801 | if {$incith::google::bold_descriptions == 0} { | |
1802 | regsub -all -- "\002" $output {} output | |
1803 | } | |
1804 | } | |
1805 | ||
1806 | # parse the html | |
1807 | while {$results < $incith::google::image_results} { | |
1808 | if {[regexp -- {\["/imgres\?imgurl\\x3d(.*?)\\x26imgrefurl\\x3d.*?\\x26h\\x3d(.*?)\\x26w\\x3d(.*?)\\x26sz\\x3d(.*?)\\x26.*?",.*?,.*?,.*?,.*?,.*?,"(.*?)","(.*?)"} $html - link h w size desc d2]} { | |
1809 | regsub -- {\["/imgres\?imgurl\\x3d(.+?)\\x26imgrefurl\\x3d.*?\\x26h\\x3d.*?\\x26w\\x3d.*?\\x26sz\\x3d.*?\\x26} $html {} html | |
1810 | # google now makes it very hard to parse titles out, this solves the dilemma. | |
1811 | if {[string is integer -strict $desc]} { set desc $d2 } | |
1812 | #set desc [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $desc] | |
1813 | regsub -all -- {\\x([[:xdigit:]]{1,2})} $desc {[format %c [scan "\1" %x]]} desc | |
1814 | set desc [descdecode [subst $desc]] | |
1815 | regsub -all -- {(?:<b>|</b>)} $desc "\002" desc | |
1816 | } | |
1817 | # if there's no link, return or stop looping, depending | |
1818 | if {[info exists link] == 0} { | |
1819 | if {$results == 0} { | |
1820 | set reply $no_search | |
1821 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
1822 | } else { | |
1823 | break | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | # prevent duplicate results is mostly useless here, but will at least | |
1828 | # ensure that we don't get the exact same picture. | |
1829 | if {[string match "*$link*" $output] == 1} { | |
1830 | break | |
1831 | } | |
1832 | append desc " ($h x $w - ${size}k)" | |
1833 | if {$incith::google::desc_modes != ""} { set desc "$incith::google::desc_modes${desc}$incith::google::desc_demodes" } | |
1834 | if {$incith::google::link_modes != ""} { set link "$incith::google::link_modes${link}$incith::google::link_demodes" } | |
1835 | ||
1836 | # add the search result | |
1837 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
1838 | ||
1839 | # increase the results, clear the variables for the next loop just in case | |
1840 | unset link | |
1841 | incr results | |
1842 | } | |
1843 | ||
1844 | # make sure we have something to send | |
1845 | if {$match == ""} { | |
1846 | set reply "${no_search}" | |
1847 | return "$::incith:google::desc_modes$reply$::incith::google::desc_demodes" | |
1848 | } | |
1849 | return $output | |
1850 | } | |
1851 | ||
1852 | # LOCAL | |
1853 | # fetches a list of address & phone numbers from local.google. | |
1854 | # -speechless updated | |
1855 | proc local {input} { | |
1856 | ; set results 0 ; set output ""; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen "" | |
1857 | ||
1858 | # fetch the html | |
1859 | set html [fetch_html $input 3] | |
1860 | regsub -all {‎} $html "" html | |
1861 | ||
1862 | # this isn't global, so we need to keep ctry (country) here | |
1863 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen input | |
1864 | if {$titen == ""} { | |
1865 | set titen "${incith::google::google_country}" | |
1866 | } | |
1867 | ||
1868 | # user input causing errors? | |
1869 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
1870 | regsub {(.+?)\|} $html {} html | |
1871 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
1872 | } | |
1873 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
1874 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
1875 | } | |
1876 | ||
1877 | # strip out 'did you mean?' first | |
1878 | # what do we call 'no search results in any language?' | |
1879 | if {![regexp -- {<div class=spacer></div></div></div><br><p>(.+?)</p>} $html - no_search]} { | |
1880 | if {[regexp -- {<table cellpadding=0 cellspacing=0><tr valign=top><td>(.+?)<br><br>} $html - no_search]} { | |
1881 | set no_search [string map {"<br>" "; "} $no_search] | |
1882 | regsub -all -- {<.*?>} $no_search "" no_search | |
1883 | set no_search [string trim $no_search "; "] | |
1884 | } elseif {[regexp -- {<div class="suggest noprint">(.*?)</a>} $html - no_search]} { | |
1885 | regsub -all -- {<.*?>} $no_search "" no_search | |
1886 | } elseif {[regexp -- {<div id=refsec class="suggest noprint">(.*?)<div class=ref>(.*?)<div id=bottomads} $html - did extra]} { | |
1887 | foreach {- m} [regexp -all -inline {<a href=.*?>(.*?)</a>} $extra] { lappend matches $m } | |
1888 | set no_search "$did [join $matches "; "]" | |
1889 | } | |
1890 | } | |
1891 | if {[regexp -- {<div class="noprint res">.*?<p>(.*?)</p>} $html - more]} { | |
1892 | append no_search "$more" | |
1893 | } | |
1894 | ||
1895 | # give results an output header with result tally. | |
1896 | if {![regexp -- {<form name="qmod".*?<br/>(.+?)\s\002(.+?)</form>} $html - titem match]} { | |
1897 | if {![regexp -- {<form name="qmod".*?>(.+?)\s\002(.+?)</form>} $html - titem match]} { | |
1898 | if {![regexp -- {<div id=contentpanel>.*?<form name=qmod>(.+?)\s\002(.+?)</form>} $html - match titem]} { | |
1899 | if {[regexp -- {<div class="noprint">(.*?)</div>} $html - match]} { | |
1900 | regsub -all -- {<.*?>} $match "" match | |
1901 | set match [split [string trim $match]] ; set titem [lindex $match end] ; set match [lindex $match end-1] | |
1902 | if {![string length [string trim $match]]} { set match "Google" ; set titem "" } | |
1903 | } else { | |
1904 | set match "Google" | |
1905 | set titem "" | |
1906 | } | |
1907 | } | |
1908 | } | |
1909 | } | |
1910 | regsub -all -- {<(.+?)>} $match {} match | |
1911 | # format output according to variables. | |
1912 | if {$incith::google::total_results != 0} { | |
1913 | set output "${::incith::google::total_modes}[string trim ${match}] [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
1914 | if {$incith::google::bold_descriptions == 0} { | |
1915 | regsub -all -- "\002" $output {} output | |
1916 | } | |
1917 | } | |
1918 | # parse the html | |
1919 | while {$results < $incith::google::local_results} { | |
1920 | if {[regexp -nocase {class="name lname.*?<a.*?>(.*?)</a>.*?href=".*?cid=(.*?)\&q.*?</a></nobr>.*?</div> <div>(.*?)<div>} $html - loc url add1 desc]} { | |
1921 | regsub -nocase {class="name lname.*?<a.*?>.*?</a>.*?href=".*?cid=.*?\&q.*?</a></nobr>.*?</div> <div>.*?<div>} $html "" html | |
1922 | } elseif {[regexp -nocase {<div class=lname>.*?href=(.*?) .*?">(.*?)</a></div></div><div class=atxt dir=ltr>(.*?)</div>(.*?)<} $html - url loc add1 desc]} { | |
1923 | regsub {<div class=lname>.*?href=(.*?) .*?">(.*?)</a></div></div><div class=atxt dir=ltr>(.*?)</div>} $html "" html | |
1924 | } | |
1925 | #regsub -nocase {<div class="name.*?href=.*?>.*?</a>.*?<div><div>.*?</div>.*?<div align=left>.*?</div>.*?<a class=f href=(.*?)>} $html "" html | |
1926 | if {[info exists url]} { | |
1927 | if {![string match -nocase "*maps.google*" $url]} { | |
1928 | regexp -- {^/local.*?q=(.*?)(?:$| )} $url - url | |
1929 | regsub -- {^/maps} $url "http://maps.google.$titen/maps" url | |
1930 | regexp -- {^(.*?)&dq=} $url - url | |
1931 | } | |
1932 | regexp -- {^(.*?) } $url - url | |
1933 | } | |
1934 | # if there's no link, return or stop looping, depending | |
1935 | if {![info exists loc]} { | |
1936 | if {$results == 0} { | |
1937 | set reply $no_search | |
1938 | return "$incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
1939 | } else { | |
1940 | return $output | |
1941 | break | |
1942 | } | |
1943 | } | |
1944 | regsub -all -- "<.*?nobr>" $add1 {} add1 | |
1945 | regsub -all -- "‎" $add1 {} add1 | |
1946 | if {$incith::google::desc_modes != ""} { set loc "$incith::google::desc_modes${loc}$incith::google::desc_demodes" } | |
1947 | if {$incith::google::link_modes != ""} { set link "$incith::google::link_modes${add1}$incith::google::link_demodes" } { set link $add1 } | |
1948 | ||
1949 | # add the search result | |
1950 | if {$incith::google::link_only == 1} { | |
1951 | append output "${link} ${incith::google::seperator}" | |
1952 | } else { | |
1953 | append output "[descdecode ${loc}]$::incith::google::break${link}${incith::google::seperator}" | |
1954 | } | |
1955 | ||
1956 | # increase the results, clear the variables for the next loop just in case | |
1957 | unset loc ; unset link ; unset desc | |
1958 | incr results | |
1959 | } | |
1960 | return $output | |
1961 | } | |
1962 | ||
1963 | # GROUPS | |
1964 | # fetches a list of threads from groups.google. | |
1965 | # -speechless updated | |
1966 | ||
1967 | proc groups {input} { | |
1968 | ; set results 0 ; set output "" ; set match "" ; set no_search "" ; set titem "" ; set titen "" | |
1969 | ||
1970 | # this isn't global, so we need to keep ctry (country) here | |
1971 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy | |
1972 | if {$titen == ""} { | |
1973 | set titen "${incith::google::google_country}" | |
1974 | } | |
1975 | ||
1976 | # fetch the html | |
1977 | set html [fetch_html $input 4] | |
1978 | ||
1979 | # user input causing errors? | |
1980 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
1981 | regsub {(.+?)\|} $html {} html | |
1982 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
1983 | } | |
1984 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
1985 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
1986 | } | |
1987 | ||
1988 | # strip out 'did you mean?' first | |
1989 | # what do we call 'no search results in any language?' | |
1990 | regexp -- {<div id=res><p>(.+?)</div><div>} $html - no_search | |
1991 | if {$no_search != ""} { | |
1992 | regsub -- {</a>} $no_search "? " no_search | |
1993 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
1994 | while {[string match "* *" $no_search]} { | |
1995 | regsub -all -- { } $no_search " " no_search | |
1996 | } | |
1997 | set no_search [string trim $no_search] | |
1998 | } | |
1999 | ||
2000 | # give results an output header with result tally. | |
2001 | regexp -- {</td><td align="right".*?>(.+?)\s\002(.+?)(\[|<)} $html - titem match | |
2002 | if {![regexp -- {1\002\s-\s.+?\002.+?\002(.+?)\002} $match - match]} { | |
2003 | set match "Google" | |
2004 | set titem "" | |
2005 | } | |
2006 | regsub -all -- {<(.+?)>} $match {} match | |
2007 | # format output according to variables. | |
2008 | if {$incith::google::total_results != 0 && $match > 0} { | |
2009 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2010 | if {$incith::google::bold_descriptions == 0} { | |
2011 | regsub -all -- "\002" $output {} output | |
2012 | } | |
2013 | } | |
2014 | ||
2015 | # parse the html | |
2016 | while {$results < $incith::google::group_results} { | |
2017 | # this grabs a google group if one exists | |
2018 | # this grabs a usenet group if one exists | |
2019 | if {[regexp -- {<div class="gdrr"><a\s+href="(.+?)".*?>(.+?)</a>.+?</td></tr></table>} $html {} thread desc]} { | |
2020 | regsub -- {<div class="gdrr">(.+?)</td></tr></table>} $html "" html | |
2021 | if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} { | |
2022 | regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread | |
2023 | set thread [urldecode $thread] | |
2024 | if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} { | |
2025 | regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread | |
2026 | set thread [urldecode $thread] | |
2027 | } | |
2028 | } | |
2029 | } elseif {[regexp -- {<div class="g".*?href="(.+?)".*?>(.+?)</a>} $html - thread desc]} { | |
2030 | regsub -- {div class="g".*?href=".+?".*?>(.+?)</td></tr>} $html "" html | |
2031 | if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} { | |
2032 | regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread | |
2033 | set thread [urldecode $thread] | |
2034 | if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} { | |
2035 | regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread | |
2036 | set thread [urldecode $thread] | |
2037 | } | |
2038 | } | |
2039 | } | |
2040 | ||
2041 | # if there's no desc, return or stop looping, depending | |
2042 | if {[info exists desc] == 0} { | |
2043 | if {$results == 0} { | |
2044 | set reply $no_search | |
2045 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2046 | } else { | |
2047 | break | |
2048 | } | |
2049 | } | |
2050 | ||
2051 | if {[info exists desc] == 1 && $incith::google::description_length > 0} { | |
2052 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
2053 | set desc [string trim $desc] | |
2054 | } | |
2055 | ||
2056 | # make the link valid because we only got a partial href result, not a full url | |
2057 | set link $thread | |
2058 | ||
2059 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2060 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2061 | ||
2062 | # add the search result | |
2063 | if {$incith::google::link_only == 1} { | |
2064 | append output "${link}${incith::google::seperator}" | |
2065 | } else { | |
2066 | append output "[descdecode $desc] $::incith::google::break${link}${incith::google::seperator}" | |
2067 | } | |
2068 | ||
2069 | # increase the results, clear the variables for the next loop just in case | |
2070 | unset link; unset desc | |
2071 | incr results | |
2072 | } | |
2073 | ||
2074 | # make sure we have something to send | |
2075 | if {$match == ""} { | |
2076 | set reply $no_search | |
2077 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2078 | } | |
2079 | return $output | |
2080 | } | |
2081 | ||
2082 | # NEWS | |
2083 | # fetches the news from news.google. | |
2084 | # -madwoota supplied, speechless updated | |
2085 | # | |
2086 | proc news {input} { | |
2087 | ; set results 0 ; set output ""; set match "" | |
2088 | ; set no_search "" ; set titem "" | |
2089 | ||
2090 | # fetch the html | |
2091 | set html [fetch_html $input 5] | |
2092 | ||
2093 | # user input causing errors? | |
2094 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
2095 | regsub {(.+?)\|} $html {} html | |
2096 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
2097 | } | |
2098 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
2099 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
2100 | } | |
2101 | # strip out 'did you mean?' first | |
2102 | # what do we call 'no search results in any language?' | |
2103 | if {![regexp -- {<div class="spelling-correction">(.+?)</p><p>} $html - no_search]} { | |
2104 | regexp -- {<div class="no-results">(.+?)</p>} $html - no_search | |
2105 | } | |
2106 | if {$no_search != ""} { | |
2107 | regsub -- {</a>} $no_search "? " no_search | |
2108 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
2109 | while {[string match "* *" $no_search]} { | |
2110 | regsub -all -- { } $no_search " " no_search | |
2111 | } | |
2112 | set no_search [string trim $no_search] | |
2113 | } | |
2114 | ||
2115 | # give results an output header with result tally. | |
2116 | regexp -- {<div class="results-stats">(.+?)\s\002(.+?)\(\002} $html - titem match | |
2117 | if {![regexp -- {1\002\s–\s\002.+?\002.+?\002(.+?)\002} $match - match]} { | |
2118 | set match "Google" | |
2119 | set titem "" | |
2120 | } | |
2121 | regsub -all -- {<(.+?)>} $match {} match | |
2122 | # format output according to variables. | |
2123 | if {$incith::google::total_results != 0 && $match > 0} { | |
2124 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2125 | if {$incith::google::bold_descriptions == 0} { | |
2126 | regsub -all -- "\002" $output {} output | |
2127 | } | |
2128 | } | |
2129 | ||
2130 | # We have to do a single regsub first to get down to the rough area in the html we need because | |
2131 | # its just *not* very elegant attempting doing this in a single regexp. (Read: unreliable) | |
2132 | #regsub -- {<html>(.+?)</div>} $html {} html | |
2133 | ||
2134 | # parse the html | |
2135 | while {$results < $incith::google::news_results} { | |
2136 | # somewhat extenuated regexp due to allowing that there *might* be | |
2137 | # an image next to the story | |
2138 | # <h2 class="title">.*?<a class.*?>.*?<a.*?href="(.+?)".*?>(.+?)</a>.+?<div class="sub-title">(.+?)</div> | |
2139 | if {[regexp -- {<h2 class="title">.*?<a target.*?href="(.+?)".*?>(.+?)</a>.+?<div class="sub-title">(.+?)</div>} $html {} link desc time]} { | |
2140 | regsub -all -- {<.*?>} $time "" time | |
2141 | } | |
2142 | regsub -- {<h2 class="title">.*?<a.*?href=".+?".*?>.+?</a>.+?<div class="sub-title">.+?</div>} $html {} html | |
2143 | ||
2144 | # if there's no desc, return or stop looping, depending | |
2145 | if {[info exists desc] == 0} { | |
2146 | if {$results == 0} { | |
2147 | set reply $no_search | |
2148 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2149 | } else { | |
2150 | break | |
2151 | } | |
2152 | } | |
2153 | ||
2154 | if {[info exists desc] == 1 && $incith::google::description_length > 0} { | |
2155 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
2156 | set desc [descdecode [string trim $desc]] | |
2157 | } | |
2158 | ||
2159 | # prevent duplicate results is mostly useless here, but will at least | |
2160 | # ensure that we don't get the exact same article. | |
2161 | if {[string match "*$link*" $output] == 1} { | |
2162 | break | |
2163 | } | |
2164 | ||
2165 | if {[info exists desc]} { set desc "$incith::google::desc_modes$desc$incith::google::desc_demodes" } | |
2166 | if {[info exists time]} { set time "$incith::google::desc_modes[descdecode [string trim $time]]$incith::google::desc_demodes" } | |
2167 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2168 | # add the search result | |
2169 | if {$incith::google::link_only == 1} { | |
2170 | append output "${link}${incith::google::seperator}" | |
2171 | } else { | |
2172 | append output "$desc \($time\)$::incith::google::break${link}${incith::google::seperator}" | |
2173 | } | |
2174 | ||
2175 | # increase the results, clear the variables for the next loop just in case | |
2176 | unset link; unset desc | |
2177 | incr results | |
2178 | } | |
2179 | ||
2180 | # make sure we have something to send | |
2181 | if {$match == ""} { | |
2182 | set reply $no_search | |
2183 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2184 | } | |
2185 | return $output | |
2186 | } | |
2187 | ||
2188 | ||
2189 | # fetches book titles from books.google. | |
2190 | # -madwoota supplied, -broken- | |
2191 | # -speechless updated, fixed no longer using print.google | |
2192 | # | |
2193 | proc print {input} { | |
2194 | ; set results 0 ; set output "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen "" | |
2195 | ; set match "" | |
2196 | ||
2197 | # this isn't global, so we need to keep ctry (country) here | |
2198 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy | |
2199 | if {$titen == ""} { | |
2200 | set titen "${incith::google::google_country}" | |
2201 | } | |
2202 | ||
2203 | # fetch the html | |
2204 | set html [fetch_html $input 6] | |
2205 | ||
2206 | # user input causing errors? | |
2207 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
2208 | regsub {(.+?)\|} $html {} html | |
2209 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
2210 | } | |
2211 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
2212 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
2213 | } | |
2214 | ||
2215 | # strip out 'did you mean?' first | |
2216 | # what do we call 'no search results in any language?' | |
2217 | regexp -- {<td id="main_content">(.*?)</p>} $html - no_search | |
2218 | ||
2219 | # if we have a no search results message, let's format it for displaying possibly. | |
2220 | if {$no_search != ""} { | |
2221 | #regsub -all -- {\002\002} $no_search "\002" no_search | |
2222 | regsub -- {</a></div>} $no_search "? " no_search | |
2223 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
2224 | while {[string match "* *" $no_search]} { | |
2225 | regsub -all -- { } $no_search " " no_search | |
2226 | } | |
2227 | set no_search [string trim $no_search] | |
2228 | } | |
2229 | ||
2230 | # give results an output header with result tally. | |
2231 | regexp -- {<td align=right>(.+?)\s\002(.+?)\(\002} $html - titem match | |
2232 | if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} { | |
2233 | set match "Google" | |
2234 | set titem "" | |
2235 | } | |
2236 | ||
2237 | regsub -all -- {<(.+?)>} $match {} match | |
2238 | # format output according to variables. | |
2239 | if {$incith::google::total_results != 0 && $match > 0} { | |
2240 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2241 | if {$incith::google::bold_descriptions == 0} { | |
2242 | regsub -all -- "\002" $output {} output | |
2243 | } | |
2244 | } | |
2245 | ||
2246 | while {$results < $incith::google::print_results} { | |
2247 | if {[regexp -- {<div class=resbdy><h2 class="resbdy">(.*?)</table>} $html - snippet]} { | |
2248 | if {![regexp -- {<a.*?href=".+?id=(.+?)&pg=(.*?)&.*?".*?>(.+?)</a></h2>(.+?)<br} $snippet - id page desc author]} { | |
2249 | regexp -- {<a.*?href=".+?id=(.+?)&.*?".*?>(.+?)</a></h2>(.+?)<br} $snippet - id desc author | |
2250 | } | |
2251 | regsub -- {<div class=resbdy><h2 class="resbdy"><a.*?href=(.+?)</table>} $html "" html | |
2252 | } | |
2253 | ||
2254 | # if there's no desc, return or stop looping, depending | |
2255 | if {![info exists desc]} { | |
2256 | if {$results == 0} { | |
2257 | set reply $no_search | |
2258 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2259 | } else { | |
2260 | break | |
2261 | } | |
2262 | } | |
2263 | ||
2264 | # this cleans up perhaps bad html cuts | |
2265 | if {[info exists desc]} { | |
2266 | regsub -all -- {<(.+?)>} $desc "" desc | |
2267 | set desc [string trim $desc] | |
2268 | } | |
2269 | ||
2270 | if {[info exists desc]} { | |
2271 | regsub -all -- {<(.+?)>} $author "" author | |
2272 | set author [string trim $author] | |
2273 | } | |
2274 | ||
2275 | # make link by appending book id | |
2276 | if {[info exists page]} { set page "&pg=$page" } { set page "" } | |
2277 | set link "http://books.google.${titen}?id=${id}${page}" | |
2278 | ||
2279 | # prevent duplicate results is mostly useless here, but will at least | |
2280 | # ensure that we don't get the exact same article. | |
2281 | #if {[string match "*$link*" $output] == 1} { | |
2282 | # break | |
2283 | #} | |
2284 | append desc " (${author})" | |
2285 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2286 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2287 | ||
2288 | # add the search result | |
2289 | if {$incith::google::link_only == 1} { | |
2290 | append output "${link}${incith::google::seperator}" | |
2291 | } else { | |
2292 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
2293 | } | |
2294 | ||
2295 | # increase the results, clear the variables for the next loop just in case | |
2296 | unset link ; unset desc ; unset page | |
2297 | incr results | |
2298 | } | |
2299 | ||
2300 | # make sure we have something to send | |
2301 | if {![info exists output]} { | |
2302 | set reply $no_search | |
2303 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2304 | } | |
2305 | return $output | |
2306 | } | |
2307 | ||
2308 | # GeoBytes | |
2309 | # Fetches IP Location information | |
2310 | # -speechless supplied | |
2311 | # | |
2312 | proc locate {input} { | |
2313 | ; set results 0 ; set output "" | |
2314 | ; set city "" ; set region "" ; set country "" | |
2315 | ; set certainty "" ; set timezone "" ; set population "" | |
2316 | ; set currency "" ; set proxy "" ; set curr "" ; | |
2317 | ||
2318 | # fetch the html | |
2319 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
2320 | set http [::http::config -useragent $ua] | |
2321 | set url "http://www.geobytes.com/IpLocator.htm?GetLocation" | |
2322 | set query [::http::formatQuery ipaddress $input] | |
2323 | set http [::http::geturl $url -query $query -headers $::incith_hdr -timeout [expr 1000 * 10]] | |
2324 | upvar #0 $http state | |
2325 | set html [ungzip [::http::data $http] $state(meta)] | |
2326 | ::http::cleanup $http | |
2327 | ||
2328 | # is site broken? if it is, say so | |
2329 | if {![string match "*<html>*" $html]} { | |
2330 | return "$::incith::google::error_modes\002 GeoBytes Error:\002 Unable to access site. www.geobytes.com seems to be down.$::incith::google::error_demodes" | |
2331 | } | |
2332 | ||
2333 | #strip html tags | |
2334 | regsub -all "\t" $html "" html | |
2335 | regsub -all "\n" $html "" html | |
2336 | regsub -all "\r" $html "" html | |
2337 | regsub -all "\v" $html "" html | |
2338 | regsub -all "'" $html "'" html | |
2339 | ||
2340 | #parse html | |
2341 | regexp -- {input.+?name="ro-no_bots_pls13".+?value="(.+?)".+?size} $html {} country | |
2342 | regexp -- {input.+?name="ro-no_bots_pls15".+?value="(.+?)".+?size} $html {} region | |
2343 | regexp -- {input.+?name="ro-no_bots_pls17".+?value="(.+?)".+?size} $html {} city | |
2344 | regexp -- {input.+?name="ro-no_bots_pls18".+?value="(.+?)".+?size} $html {} certainty | |
2345 | regexp -- {input.+?name="ro-no_bots_pls9".+?value="(.+?)".+?size} $html {} timezone | |
2346 | regexp -- {input.+?name="ro-no_bots_pls3".+?value="(.+?)".+?size} $html {} population | |
2347 | regexp -- {input.+?name="ro-no_bots_pls1".+?value="(.+?)".+?size} $html {} currency | |
2348 | #currency sometimes has a trailing space, let's fix that with a dirty hack. | |
2349 | set currency [string trim $currency] | |
2350 | regexp -- {input.+?name="ro-no_bots_pls11".+?value="(.+?)".+?size} $html {} proxy | |
2351 | regexp -- {input.+?name="ro-no_bots_pls".+?value="(.+?)".+?size} $html {} curr | |
2352 | ||
2353 | #in case we get blocked, say we did | |
2354 | if {[string match "*temporarily blocked*" $html] == 1} { | |
2355 | set output "$::incith::google::error_modes\002GeoBytes Error:\002 (${input}) Reasonable usage limit has been exceeded. This bot has been temporarily blocked from accessing services. Please try back again later.$::incith::google::error_demodes" | |
2356 | } | |
2357 | ||
2358 | #if we can't read a country, assume there was nothing to lookup. | |
2359 | if {$country == "" && $output == ""} { | |
2360 | set output "$::incith::google::error_modes\002GeoBytes Error:\002 (${input}) Undefined IP. Nothing to LookUp.$::incith::google::error_demodes" | |
2361 | } elseif {$output == ""} { | |
2362 | set output "$::incith::google::total_modes\002GeoBytes Location:\002$::incith::google::total_demodes$::incith::google::desc_modes (${input})$::incith::google::desc_demodes$::incith::google::break$incith::google::link_modes${city}, ${region}, ${country} (${certainty}%) \[\002GMT:\002${timezone}\|\002Proxy:\002${proxy}\|${currency}\|${curr}\]$incith::google::link_demodes" | |
2363 | } | |
2364 | if {$incith::google::bold_descriptions != 1 && [string match "\002" $incith::google::desc_modes] != 1} { | |
2365 | regsub -all -- "\002" $output {} output | |
2366 | } | |
2367 | return $output | |
2368 | } | |
2369 | ||
2370 | # VIDEO | |
2371 | # fetches links to video with search data in it (video.google.com) | |
2372 | # -madwoota supplied, speechless updated | |
2373 | # | |
2374 | proc video {input} { | |
2375 | ; set results 0 ; set output ""; set match ""; set ded "" | |
2376 | ; set titen "" ; set titem "" ; set no_search "" ; set did_you_mean "" | |
2377 | ||
2378 | # this isn't global, so we need to keep ctry (country) here | |
2379 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy | |
2380 | if {$titen == ""} { | |
2381 | set titen "${incith::google::google_country}" | |
2382 | } | |
2383 | ||
2384 | # fetch the html | |
2385 | set html [fetch_html $input 7] | |
2386 | ||
2387 | # user input causing errors? | |
2388 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
2389 | regsub {(.+?)\|} $html {} html | |
2390 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
2391 | } | |
2392 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
2393 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
2394 | } | |
2395 | ||
2396 | # strip out 'did you mean?' first | |
2397 | # what do we call 'no search results in any language?' | |
2398 | if {[regexp -- {<div class=med><p style=.*?>(.*?)<p style} $html - no_search]} { | |
2399 | #regsub -all -- {(<strong>|</strong>)} $no_search "\002" no_search | |
2400 | #regsub -- {</a>} $no_search "? " no_search | |
2401 | #regsub -- {</td>} $no_search ". " no_search | |
2402 | regsub -all -- {<(.+?)>} $no_search "" no_search | |
2403 | set no_search [string trim $no_search] | |
2404 | } | |
2405 | ||
2406 | # give results an output header with result tally. | |
2407 | if {![regexp -- {<div id=resultStats>(.+?)<nobr>} $html - match]} { | |
2408 | set match "Google" | |
2409 | set titem "" | |
2410 | } else { | |
2411 | regsub -all -- {<(.+?)>} $match {} match | |
2412 | regexp -- {([0-9].*?)$} $match - match | |
2413 | set match "\002[join [lrange [split $match] 0 end-1]]\002 [lindex [split $match] end]" | |
2414 | } | |
2415 | # format output according to variables. | |
2416 | if {$incith::google::total_results != 0} { | |
2417 | set output "${::incith::google::total_modes}[string trim ${match}]${::incith::google::total_demodes}${incith::google::seperator}" | |
2418 | if {$incith::google::bold_descriptions == 0} { | |
2419 | regsub -all -- "\002" $output {} output | |
2420 | } | |
2421 | } | |
2422 | ||
2423 | # parse the html | |
2424 | while {$results < $incith::google::video_results} { | |
2425 | # somewhat extenuated regexp due to allowing that there might be an image next to the title | |
2426 | regexp -- {<h3 class=r>.*?href="(.*?)".*?>(.*?)</a>.*?<span class=f>(.*?)</span><br>(.*?)<br>} $html {} link desc ded ded2 | |
2427 | regsub -- {<h3 class=r>.*?href=".*?".*?>.*?</a>.*?<span class=f>.*?</span><br>.*?<br>} $html "" html | |
2428 | ||
2429 | # if there's no desc, return or stop looping, depending | |
2430 | if {[info exists desc] == 0} { | |
2431 | if {$results == 0} { | |
2432 | set reply $no_search | |
2433 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2434 | } else { | |
2435 | break | |
2436 | } | |
2437 | } | |
2438 | ||
2439 | set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]] | |
2440 | # append narration to description for more detail unless its identical | |
2441 | # keep description from becoming too lengthy and clean up trailing spaces | |
2442 | regsub -all {<div class=description.+?</div>} $ded "" ded | |
2443 | regexp {(.+?)\)--} $ded - ded | |
2444 | regsub { -} $ded " - " ded | |
2445 | regsub {<span class=rl-domain>} $ded " - " ded | |
2446 | regsub -all {<(.*?)>} $ded "" ded | |
2447 | if {[string length $ded2]} { | |
2448 | set ded2 "\([descdecode [string range $ded2 0 [expr $incith::google::description_length - 1]]]\)" | |
2449 | } | |
2450 | set desc "[descdecode $desc] $ded2\([descdecode [string trim $ded]]\)" | |
2451 | ||
2452 | # make the link valid because we were only given a partial href result, not a full url | |
2453 | if {[string match [string range $link 0 0] "/"]} { | |
2454 | regsub -- {&.+?$} $link "" link | |
2455 | set link "http://video.google.${titen}${link}" | |
2456 | } | |
2457 | ||
2458 | # prevent duplicate results is mostly useless here, but will at least | |
2459 | # ensure that we don't get the exact same article. | |
2460 | if {[string match "*$link*" $output] == 1} { | |
2461 | break | |
2462 | } | |
2463 | # quick and dirty double-space remover | |
2464 | while {[string match "* *" $desc]} { | |
2465 | regsub -all -- { } $desc " " desc | |
2466 | } | |
2467 | set desc [string trim $desc] | |
2468 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2469 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2470 | ||
2471 | # add the search result | |
2472 | if {$incith::google::link_only == 1} { | |
2473 | append output "${link}${incith::google::seperator}" | |
2474 | } else { | |
2475 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
2476 | } | |
2477 | ||
2478 | # increase the results, clear the variables for the next loop just in case | |
2479 | unset link; unset desc | |
2480 | incr results | |
2481 | } | |
2482 | ||
2483 | # make sure we have something to send | |
2484 | if {$match == ""} { | |
2485 | set reply $no_search | |
2486 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2487 | } | |
2488 | return $output | |
2489 | } | |
2490 | ||
2491 | # FIGHT | |
2492 | # google fight ! | |
2493 | # | |
2494 | proc fight {input} { | |
2495 | set output ""; set winner 0; set match1 0; set match2 0 | |
2496 | ||
2497 | if {![regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input]} { | |
2498 | set country "${incith::google::google_country}" | |
2499 | } | |
2500 | regexp -nocase -- {^(.+?) vs (.+?)$} $input - word1 word2 | |
2501 | if {![regexp -nocase -- {^\.(.+?)\s(.+?)$} $word2 - country2 word2]} { | |
2502 | set country2 "${incith::google::google_country}" | |
2503 | } | |
2504 | ||
2505 | # fetch the first result | |
2506 | set html [fetch_html ".$country $word1" 8] | |
2507 | # parse the html | |
2508 | if {![regexp -nocase {<div id=prs>.*?</div><p>(.+?)(?:\(\002|\[)} $html - matches1]} { | |
2509 | if {![regexp -- {<div id=resultStats> (.*?) (.*?)\(\002} $html - titem matches1]} { | |
2510 | if {[regexp -- {<div id=resultStats>(.*?)\(} $html - match]} { | |
2511 | set matches1 [lindex [split [string trim $match]] end-1] | |
2512 | } | |
2513 | } | |
2514 | } | |
2515 | if {[info exists matches1]} { | |
2516 | regsub -- {(?:\002|\s)1\002 - \0021\002} $matches1 "" matches1 | |
2517 | regsub -- {(?:\002|\s)1\002-\0021\002} $matches1 "" matches1 | |
2518 | regsub -nocase { of about } $matches1 "" matches1 | |
2519 | regsub -nocase -all {<a href.*?>} $matches1 "" matches1 | |
2520 | regsub -nocase -all {</a>} $matches1 "" matches1 | |
2521 | set match1 $matches1 | |
2522 | regsub -all -- {[\., ]} $match1 "" match1 | |
2523 | } else { set matches1 "0" } | |
2524 | if {![string is digit $match1]} { | |
2525 | regexp -- {\002(.+?)\002.*?\002(.+?)\002} $matches1 - dummy match1 | |
2526 | if {[string match $match1 $word1]} { | |
2527 | regexp -- {\002(.+?)\002} $matches1 - match1 | |
2528 | } | |
2529 | } | |
2530 | ||
2531 | # fetch the second result | |
2532 | set html [fetch_html ".$country2 $word2" 8] | |
2533 | # parse the html | |
2534 | if {![regexp -nocase {<div id=prs>.*?</div><p>(.+?)(?:\(\002|\[)} $html - matches2]} { | |
2535 | if {![regexp -- {<div id=resultStats> (.*?) (.*?)\(\002} $html - titem matches2]} { | |
2536 | if {[regexp -- {<div id=resultStats>(.*?)\(} $html - match]} { | |
2537 | set matches2 [lindex [split [string trim $match]] end-1] | |
2538 | } | |
2539 | } | |
2540 | } | |
2541 | if {[info exists matches2]} { | |
2542 | regsub -- {(?:\002|\s)1\002 - \0021\002} $matches2 "" matches2 | |
2543 | regsub -- {(?:\002|\s)1\002-\0021\002} $matches2 "" matches2 | |
2544 | regsub -nocase { of about } $matches2 "" matches2 | |
2545 | regsub -nocase -all {<a href.*?>} $matches2 "" matches2 | |
2546 | regsub -nocase -all {</a>} $matches2 "" matches2 | |
2547 | set match2 $matches2 | |
2548 | } else { set matches2 "0" } | |
2549 | if {![string is digit $match2]} { | |
2550 | regexp -- {\002(.+?)\002.*?\002(.+?)\002} $matches2 - dummy match2 | |
2551 | if {[string match $match2 $word2]} { | |
2552 | regexp -- {\002(.+?)\002} $matches2 - match2 | |
2553 | } | |
2554 | } | |
2555 | ||
2556 | if {![string match $country $country2]} { set country "$country and Google.$country2" } | |
2557 | if {![info exists match1]} { | |
2558 | set match1 "0" | |
2559 | set match1expr "0" | |
2560 | } else { | |
2561 | regsub -all {(?:\.|,| )} $match1 "" match1expr | |
2562 | } | |
2563 | ||
2564 | if {![info exists match2]} { | |
2565 | set match2 "0" | |
2566 | set match2expr "0" | |
2567 | } else { | |
2568 | regsub -all {(?:\.|,| )} $match2 "" match2expr | |
2569 | } | |
2570 | ||
2571 | if {[expr $match2expr < $match1expr]} { | |
2572 | set winner 1 | |
2573 | } elseif {[string match $match2expr $match1expr]} { | |
2574 | set winner 3 | |
2575 | } else { | |
2576 | set winner 2 | |
2577 | } | |
2578 | ||
2579 | if {$incith::google::bold_descriptions > 0 && $incith::google::desc_modes == ""} { | |
2580 | set word1 "\002$word1\002"; set word2 "\002$word2\002" | |
2581 | set match1 "\002 $matches1\002"; set match2 "\002 $matches2\002" | |
2582 | } elseif {$incith::google::desc_modes != ""} { | |
2583 | set word1 "\002$word1\002"; set word2 "\002$word2\002" | |
2584 | set match1 " $matches1"; set match2 " $matches2" | |
2585 | } else { | |
2586 | set match1 " $matches1"; set match2 " $matches2" | |
2587 | } | |
2588 | ||
2589 | if {$winner == 1} { | |
2590 | set output "${::incith::google::total_modes}By results on Google.$country:$::incith::google::total_demodes$::incith::google::desc_modes $word1 beats $word2 by$match1 to$match2!$::incith::google::desc_demodes" | |
2591 | } elseif {$winner == 2} { | |
2592 | set output "${::incith::google::total_modes}By results on Google.$country:$::incith::google::total_demodes$::incith::google::desc_modes $word2 beats $word1 by$match2 to$match1!$::incith::google::desc_demodes" | |
2593 | } else { | |
2594 | set output "${::incith::google::total_modes}Google.$country could not determine the winner.$::incith::google::total_demodes$::incith::google::desc_modes $word2 ties $word1 with$match1 results.$::incith::google::desc_demodes" | |
2595 | } | |
2596 | ||
2597 | # make sure we have something to send | |
2598 | if {[info exists output] == 0} { | |
2599 | set reply "${::incith::google::desc_modes}Sorry, no search results were found. Something is wrong...$::incith::google::desc_demodes" | |
2600 | return $reply | |
2601 | } | |
2602 | return $output | |
2603 | } | |
2604 | ||
2605 | # YOUTUBE | |
2606 | # fetches links to video with search data in it (youtube.com) | |
2607 | # -speechless supplied | |
2608 | # | |
2609 | proc youtube {input} { | |
2610 | ||
2611 | ; set results 0 ; set output "" ; set ded ""; set match "" ; set titem "" ; set titen "" | |
2612 | if {[regsub -nocase -all -- "$::incith::google::youtube_highdef" $input "" dummy]} { set hd 1 } | |
2613 | # this isn't global, so we need to keep ctry (country) here | |
2614 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy | |
2615 | if {$titem == ""} { | |
2616 | set titem "${incith::google::youtube_country}" | |
2617 | } | |
2618 | ||
2619 | # fetch the html | |
2620 | set html [fetch_html $input 9] | |
2621 | ||
2622 | # user input causing errors? | |
2623 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
2624 | regsub {(.+?)\|} $html {} html | |
2625 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
2626 | } | |
2627 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
2628 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
2629 | } | |
2630 | ||
2631 | # give results an output header with result tally. | |
2632 | if {![regexp -- {<div id="search-num-results" class="name">(.*?)</div} $html - match]} { | |
2633 | set match "YouTube" | |
2634 | set titen "results" | |
2635 | } else { | |
2636 | regsub -all {\s+} [string trim $match] " " match | |
2637 | set match [split $match] | |
2638 | set titen [lindex $match end-6] | |
2639 | set match [lindex $match end] | |
2640 | } | |
2641 | # format output according to variables. | |
2642 | if {$incith::google::total_results != 0 && $match != ""} { | |
2643 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titen]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2644 | if {$incith::google::bold_descriptions == 0} { | |
2645 | regsub -all -- "\002" $output {} output | |
2646 | } | |
2647 | } | |
2648 | if {[regexp -nocase {<div class="marT10">(.+?)(</div></div>|</div><div>|</a></div>|<\!--)} $html - reply]} { | |
2649 | regsub -all -nocase {<div class="marT10">.+?(</div></div>|</div><div>|</a></div>|<\!--)} $html "" html | |
2650 | regsub -all {<td>} $reply ". " reply | |
2651 | regsub -all -- {<.*?>} $reply "" reply | |
2652 | } elseif {[regexp -nocase {id="search-no-results-message">(.*?)</div>} $html - reply]} { | |
2653 | regsub -all -- {<.*?>} $reply "" reply | |
2654 | } elseif {[regexp -nocase {id="results-main-.*?>.*?<img.*?>(.*?)<br>} $html - reply]} { | |
2655 | regsub -all -- {<.*?>} $reply "" reply | |
2656 | } else { set reply "" } | |
2657 | ||
2658 | # parse the html | |
2659 | while {$results < $incith::google::youtube_results} { | |
2660 | # somewhat extenuated regexp due to allowing that there might be an image next to the title | |
2661 | if {[regexp -nocase {<span class="video-time">(.*?)</span.*?id="video-long.*?href="/watch\?v=(.+?)".+?title=".+?">(.+?)</a>.*?id="video\-description.*?">(.*?)</p.*?class="video\-date\-added">(.+?)</span.*?class="video\-view\-count">(.+?)</span} $html - ded4 cid desc ded ded2 ded3]} { | |
2662 | if {[string match "*</span>*" $desc]} { | |
2663 | regexp -nocase {<span class="video-time">(.*?)</span.*?id="video-long.*?href="/watch\?v=(.+?)".+?title="(.*?)">.*?id="video\-description.*?">(.*?)</p.*?class="video\-date\-added">(.+?)</span.*?class="video\-view\-count">(.+?)</span} $html - ded4 cid desc ded ded2 ded3 | |
2664 | } | |
2665 | regsub -nocase {<span class="video-time">.*?</span.*?class="video\-view\-count">.*?</span} $html "" html | |
2666 | } | |
2667 | if {[info exists desc] == 0} { | |
2668 | if {$results == 0} { | |
2669 | append output "[descdecode [string trim $reply]]${incith::google::seperator}" | |
2670 | return "$incith::google::desc_modes[descdecode $reply]$::incith::google::desc_demodes" | |
2671 | } else { | |
2672 | break | |
2673 | } | |
2674 | } | |
2675 | ||
2676 | # keep description from becoming too lengthy and clean up trailing spaces | |
2677 | if {[info exists desc]} { | |
2678 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
2679 | set desc [descdecode [string trim $desc]] | |
2680 | } | |
2681 | ||
2682 | # append length to description for more detail | |
2683 | if {[info exists ded] && [info exists desc]} { | |
2684 | if {![string equal "<" [string index $ded 0]]} { | |
2685 | set ded " ([descdecode [string trim [string range $ded 0 [expr $incith::google::description_length - 1]]]]) " | |
2686 | } else { set ded " " } | |
2687 | if {[string match " ($desc) " $ded]} { set ded " " } | |
2688 | if {[info exists ded4]} { | |
2689 | append desc "${ded}(${ded4}; ${ded2}; ${ded3})" | |
2690 | } else { | |
2691 | append desc "${ded}" | |
2692 | } | |
2693 | } | |
2694 | ||
2695 | # make the link valid because we were only given a partial href result, not a full url | |
2696 | if {$titem == "com" } { | |
2697 | set link "http://youtube.com/watch?v=${cid}&hl=en" | |
2698 | } else { | |
2699 | set link "http://${titem}.youtube.com/watch?v=${cid}&hl=${titem}" | |
2700 | } | |
2701 | # fullscreen window link - http://youtube.com/v/${cid} | |
2702 | ||
2703 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2704 | if {[info exists link]} { | |
2705 | if {[info exists hd]} { | |
2706 | set link [string map {"&hd=1" "&fmt=22"} $link] | |
2707 | } elseif {$incith::google::youtube_highquality != 0} { | |
2708 | append link "&fmt=18" | |
2709 | } | |
2710 | set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" | |
2711 | } | |
2712 | ||
2713 | # add the search result | |
2714 | if {$incith::google::link_only == 1} { | |
2715 | append output "${link}${incith::google::seperator}" | |
2716 | } else { | |
2717 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
2718 | } | |
2719 | ||
2720 | # increase the results, clear the variables for the next loop just in case | |
2721 | unset link; unset desc ; set ded "" | |
2722 | incr results | |
2723 | } | |
2724 | return $output | |
2725 | } | |
2726 | ||
2727 | # MYSPACEVIDS | |
2728 | # fetches links to video with search data in it (videosearch.myspace.com) | |
2729 | # -speechless supplied | |
2730 | # | |
2731 | proc myspacevids {input} { | |
2732 | ||
2733 | ; set results 0 ; set output "" ; set ded ""; set match "" ; set rating "" | |
2734 | ||
2735 | # fetch the html | |
2736 | set html [fetch_html $input 11] | |
2737 | ||
2738 | # give results an output header with result tally. | |
2739 | regexp -nocase -- {class="resultsInfo">.*?1-.*?\s.*?\s(.*?)\s(.*?)\s} $html - match videos | |
2740 | ||
2741 | # format output according to variables. | |
2742 | if {$incith::google::total_results != 0 && $match != ""} { | |
2743 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $videos]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2744 | if {$incith::google::bold_descriptions == 0} { | |
2745 | regsub -all -- "\002" $output {} output | |
2746 | } | |
2747 | } | |
2748 | ||
2749 | # parse the html | |
2750 | while {$results < $incith::google::myspacevids_results} { | |
2751 | # somewhat extenuated regexp due to allowing that there might be an image next to the title | |
2752 | regexp -nocase -- {a class="taggedlink.*?href=.*?videoid=(.*?)\&.*?>(.*?)</a>.*?<a class=.*?>(.*?)</a>.*?<ul class="videoData group">(.*?)</ul>} $html - cid desc ded rating | |
2753 | regsub -nocase -- {a class="taggedlink.*?href=.*?videoid=.*?\&.*?>.*?</a>.*?<a class=.*?>.*?</a>.*?<ul class="videoData group">.*?</ul>} $html {} html | |
2754 | # if there's no desc, return or stop looping, depending | |
2755 | if {![info exists desc]} { | |
2756 | if {$results == 0} { | |
2757 | if {[regexp -- {class="displayingSummary">(.+?)</div>} $html - reply]} { | |
2758 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2759 | } elseif {[regexp -- {<p id="displaySummary" class="resultsInfo">(.*?)</p>} $html - reply]} { | |
2760 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2761 | } | |
2762 | } else { | |
2763 | break | |
2764 | } | |
2765 | } | |
2766 | ||
2767 | # duplicate link filter, clumsy indeed.. will remove soon and fix properly | |
2768 | if {[string match "*${cid}*" $output] == 1} { | |
2769 | break | |
2770 | } | |
2771 | if {[info exists rating]} { | |
2772 | regsub -all {</li>} [string map {" " "" "\002" ""} $rating] ";" rating | |
2773 | regsub -all {<.*?>} $rating "" rating | |
2774 | regsub -all {\s+} $rating " " rating | |
2775 | regsub -all { ;} $rating ";" rating | |
2776 | } | |
2777 | if {[info exists ded]} { | |
2778 | regsub -all {<.*?>} [string trim $ded] "" ded | |
2779 | if {[string length $ded]} { set ded "(by $ded)" } | |
2780 | } | |
2781 | # keep description from becoming too lengthy and clean up trailing spaces | |
2782 | if {[info exists desc]} { | |
2783 | set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]] | |
2784 | set desc "${desc} ${ded}([string trim ${rating} "; "])" | |
2785 | } | |
2786 | ||
2787 | # make the link valid because we were only given a partial href result, not a full url | |
2788 | set link "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=${cid}" | |
2789 | ||
2790 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2791 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2792 | ||
2793 | # add the search result | |
2794 | if {$incith::google::link_only == 1} { | |
2795 | append output "${link}${incith::google::seperator}" | |
2796 | } else { | |
2797 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
2798 | } | |
2799 | ||
2800 | # increase the results, clear the variables for the next loop just in case | |
2801 | unset link; unset desc | |
2802 | incr results | |
2803 | } | |
2804 | ||
2805 | # make sure we have something to send | |
2806 | if {$match == ""} { | |
2807 | regexp -- {class="displayingSummary">(.+?)</div>} $html - reply | |
2808 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
2809 | } | |
2810 | if {$incith::google::bold_descriptions != 0} { | |
2811 | regsub -all -- "(<mark>|</mark>)" $output "\002" output | |
2812 | } else { regsub -all -- "(<mark>|</mark>)" $output "" output } | |
2813 | return $output | |
2814 | } | |
2815 | ||
2816 | # trans | |
2817 | # google translation -(www.google.com\translate_t?) | |
2818 | # -speechless supplied | |
2819 | # | |
2820 | proc trans {input where} { | |
2821 | global incithcharset | |
2822 | ; set results 0 ; set output ""; set match "" ; set titem "" | |
2823 | if {[regsub -nocase -all -- $incith::google::trans_input_t $input "" input]} { set y 0 } | |
2824 | if {[regsub -nocase -all -- $incith::google::trans_output_t $input "" input]} { set z 0 } | |
2825 | # split up stuff | |
2826 | regexp -nocase -- {^(.+?)@(.+?)\s(.+?)$} $input - link desc titem | |
2827 | # fetch the html | |
2828 | set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3" | |
2829 | if {$::incith::google::trans_input > 0} { | |
2830 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
2831 | } else { | |
2832 | set http [::http::config -useragent $ua -urlencoding ""] | |
2833 | } | |
2834 | set url "http://translate.google.com/translate_t?" | |
2835 | if {$::incith::google::trans_input > 0} { | |
2836 | if {![info exists y]} { | |
2837 | set ie "&ie=utf-8" | |
2838 | } else { | |
2839 | set ie "" | |
2840 | } | |
2841 | } else { | |
2842 | if {![info exists y]} { | |
2843 | set ie "" | |
2844 | } else { | |
2845 | set ie "&ie=utf-8" | |
2846 | } | |
2847 | } | |
2848 | if {$::incith::google::trans_output > 0} { | |
2849 | if {![info exists z]} { | |
2850 | set oe "&oe=utf-8" | |
2851 | } else { | |
2852 | set oe "" | |
2853 | } | |
2854 | } else { | |
2855 | if {![info exists z]} { | |
2856 | set oe "" | |
2857 | } else { | |
2858 | set oe "&oe=utf-8" | |
2859 | } | |
2860 | } | |
2861 | if {![info exists y]} { | |
2862 | set query "text=[urlencode $titem 0 "utf-8"]&sl=${link}&tl=${desc}$ie$oe" | |
2863 | } else { | |
2864 | set query "text=[urlencode $titem 0]&sl=${link}&tl=${desc}$ie$oe" | |
2865 | } | |
2866 | catch {set http [::http::geturl "$url" -query $query -headers $::incith_hdr -timeout [expr 1000 * 10]]} error | |
2867 | ||
2868 | # CHECK CHECK | |
2869 | upvar #0 $http state | |
2870 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
2871 | if {$incith::google::debug > 0} { | |
2872 | putserv "privmsg $incith::google::debugnick :\002url:\002 $url$query \002\037charset:\002\037 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset]" | |
2873 | } | |
2874 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
2875 | return "${::incith::google::error_modes}Socket Error accessing '${url}' .. Does it exist?${::incith::google::error_demodes}" | |
2876 | } | |
2877 | if { [::http::status $http] == "timeout" } { | |
2878 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
2879 | } | |
2880 | set html [ungzip [::http::data $http] $state(meta)] | |
2881 | if {[info exists z]} { set html [incithencode $html] } | |
2882 | ::http::cleanup $http | |
2883 | ||
2884 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
2885 | regsub -all -nocase {<font.+?>} $html "" html | |
2886 | regsub -all -nocase {</font>} $html "" html | |
2887 | regsub -all -nocase {<span.*?>} $html "" html | |
2888 | regsub -all -nocase {</span>} $html "" html | |
2889 | regsub -all -nocase {<input.+?>} $html "" html | |
2890 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
2891 | regsub -all -nocase {<i style.*?>} $html "" html | |
2892 | regsub -all "\t" $html " " html | |
2893 | regsub -all "\n" $html " " html | |
2894 | regsub -all "\r" $html " " html | |
2895 | regsub -all "\v" $html " " html | |
2896 | regsub -all "</li>" $html ". " html | |
2897 | regsub -all ";;>" $html "" html | |
2898 | # make sure everything is lowercase. | |
2899 | # make sure everything is lowercase. | |
2900 | set desc [string tolower $desc] | |
2901 | set link [string tolower $link] | |
2902 | if {![regexp -- {<h3 id=headingtext.*?>(.+?)</h3>} $html {} detect]} {set detect ""} { regsub -all {<.*?>} $detect "" detect} | |
2903 | if {[regexp -- {</h3>.*?</object></div>(.+?)</div>} $html - match]} { regsub -all {<.*?>} $match "" match } | |
2904 | if {[string length $match]} { | |
2905 | put_output $where "${::incith::google::total_modes}Google\:$::incith::google::total_demodes$::incith::google::desc_modes \(${link}\-\>${desc}\)\ [descdecode $detect]" | |
2906 | put_output $where [descdecode [descdecode ${match}]] | |
2907 | } else { | |
2908 | put_output $where "${::incith::google::error_modes}Translation error\:$::incith::google::error_demodes$::incith::google::desc_modes \(${link}\-\>${desc}\)\ [descdecode "$detect."]$::incith::google::desc_demodes" | |
2909 | } | |
2910 | } | |
2911 | ||
2912 | # MININOVA TORRENT HUNT | |
2913 | # fetches torrent links from mininova. (mininova.com) | |
2914 | # -speechless supplied | |
2915 | # | |
2916 | proc mininova {input} { | |
2917 | ||
2918 | ; set results 0 ; set output ""; set match "" ; set ebcSP "" ; set match2 "" | |
2919 | ||
2920 | #regsub -all {-} $input { } input | |
2921 | # fetch the html | |
2922 | set html [fetch_html $input 51] | |
2923 | ||
2924 | # give results an output header with result tally. | |
2925 | regexp -- {<h1>(?!No).*?\((.+?)\s(.+?)\)} $html - match match2 | |
2926 | # format output according to variables. | |
2927 | if {$incith::google::total_results != 0} { | |
2928 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $match2]]${::incith::google::total_demodes}${incith::google::seperator}" | |
2929 | if {$incith::google::bold_descriptions == 0} { | |
2930 | regsub -all -- "\002" $output {} output | |
2931 | } | |
2932 | } | |
2933 | regsub {<tr.*?>(.+?)</tr>} $html "" html | |
2934 | ||
2935 | # parse the html | |
2936 | while {$results < $incith::google::mininova_results && $match != ""} { | |
2937 | # this could break any second, its cumbersome and long..i know, but for now it works. | |
2938 | regexp -nocase {<tr.*?>(.+?)</tr>} $html - htm | |
2939 | regsub {<tr.*?>(.+?)</tr>} $html "" html | |
2940 | regexp -nocase {<td>(.+?)</td><td><a href="/cat.+?>(.+?)</a>.+?<a href="/get/(.*?)".+?">.+?<a href="/tor.+?">(.+?)</a>} $htm - ebcU ebcI ebcBid ebcPR | |
2941 | regexp -nocase {<td align="right">(.+?)</td><td align="right">(.+?)</td><td align="right">(.+?)</td>} $htm - ebcShpNew ebcTim ebcCheck | |
2942 | regexp -nocase {title="Tracker URL: (.+?)"} $htm - ebcSP | |
2943 | if {$ebcSP != ""} { | |
2944 | set ebcSP "\037${ebcSP}\037 " | |
2945 | } | |
2946 | # keep torrent name from becoming too lengthy | |
2947 | if {[info exists ebcPR]} { | |
2948 | set ebcPR [string range $ebcPR 0 [expr $incith::google::description_length - 1]] | |
2949 | set ebcPR [string trim $ebcPR] | |
2950 | } | |
2951 | ||
2952 | # check results are more than 0, return or stop looping, depending | |
2953 | if {$match < 1 } { | |
2954 | if {$results == 0} { | |
2955 | regexp -nocase {<h1>(.+?)</h1>} $html - reply | |
2956 | if {![regexp -nocase {</h1><p>(.+?)</p>} $html - reply2]} { set reply2 "" } { | |
2957 | if {![string match *Didn't* $reply2]} { regsub -all -- {<(.+?)>} $reply2 "" reply2 ; set reply2 ". $reply2" } { set reply2 "" } | |
2958 | } | |
2959 | regsub -all -- {<(.+?)>} $reply "" reply | |
2960 | return "$::incith::google::desc_modes$reply$reply2$::incith::google::desc_demodes" | |
2961 | } else { | |
2962 | break | |
2963 | } | |
2964 | } | |
2965 | ||
2966 | # make the link valid because we were only given a partial href result, not a full url | |
2967 | set link "http://mininova.org/get/${ebcBid}" | |
2968 | ||
2969 | # prevent duplicate results is mostly useless here, but will at least | |
2970 | # ensure that we don't get the exact same article. | |
2971 | if {[string match "*$link*" $output] == 1} { | |
2972 | break | |
2973 | } | |
2974 | ||
2975 | # fix up our variables so the output looks purdy. | |
2976 | set desc "${ebcU}/${ebcI} ${ebcSP}\002${ebcPR}\002 (${ebcShpNew}, ${ebcTim}s, ${ebcCheck}p)" | |
2977 | ||
2978 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
2979 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
2980 | ||
2981 | # add the search result | |
2982 | if {$incith::google::link_only == 1} { | |
2983 | append output "${link}${incith::google::seperator}" | |
2984 | } else { | |
2985 | append output "$desc$::incith::google::break${link}${incith::google::seperator}" | |
2986 | } | |
2987 | ||
2988 | # increase the results, clear the variables for the next loop just in case | |
2989 | unset link ; set ebcCheck "" ; set ebcU "" ; set ebcSP "" | |
2990 | incr results | |
2991 | } | |
2992 | ||
2993 | # make sure we have something to send | |
2994 | if {$match == ""} { | |
2995 | regexp -nocase {<h1>(.+?)</h1>} $html - reply | |
2996 | if {![regexp -nocase {</h1><p>(.+?)</p>} $html - reply2]} { set reply2 "" } { | |
2997 | if {![string match *Didn't* $reply2]} { regsub -all -- {<(.+?)>} $reply2 "" reply2 ; set reply2 ". $reply2" } { set reply2 "" } | |
2998 | } | |
2999 | regsub -all -- {<(.+?)>} $reply "" reply | |
3000 | return "$::incith::google::desc_modes$reply$reply2$::incith::google::desc_demodes" | |
3001 | } | |
3002 | ||
3003 | regsub -all -- " " $input "+" input | |
3004 | append output "www.mininova.org/search/${input}/seeds" | |
3005 | #append output "www.mininova.org/search/?search=${input}" | |
3006 | return $output | |
3007 | } | |
3008 | ||
3009 | # DAILYMOTION | |
3010 | # fetches links to video with search data in it (dailymotion.com) | |
3011 | # -speechless supplied | |
3012 | # | |
3013 | proc dailymotion {input} { | |
3014 | ||
3015 | ; set results 0 ; set output "" ; set titem "" | |
3016 | ||
3017 | # this isn't global, so we need to keep ctry (country) here | |
3018 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy | |
3019 | if {$titem == ""} { | |
3020 | set titem "${incith::google::daily_country}" | |
3021 | } | |
3022 | ||
3023 | # fetch the html | |
3024 | set html [fetch_html $input 14] | |
3025 | ||
3026 | # user input causing errors? | |
3027 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
3028 | regsub {(.+?)\|} $html {} html | |
3029 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
3030 | } | |
3031 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
3032 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
3033 | } | |
3034 | ||
3035 | if {[regexp -- {<div class="dmco_text foreground2">(.*?)</div>} $html - nope]} { | |
3036 | regsub -all -- {</a>} $nope "." nope | |
3037 | regsub -all -- {<br/>} $nope " " nope | |
3038 | regsub -all -- {<.*?>} $nope "" nope | |
3039 | set reply "${::incith::google::desc_modes}$nope$::incith::google::desc_demodes" | |
3040 | return $reply | |
3041 | } | |
3042 | ||
3043 | set output "DailyMotion${incith::google::seperator}" | |
3044 | if {$incith::google::bold_descriptions != 0} { | |
3045 | set output "$::incith::google::total_modes\002DailyMotion\002$::incith::google::total_demodes${incith::google::seperator}" | |
3046 | } | |
3047 | # parse the html | |
3048 | while {$results < $incith::google::daily_results} { | |
3049 | # somewhat extenuated regexp due to allowing that there might be an image next to the title | |
3050 | regexp -nocase -- {<div class="dmco_text duration">(.*?)<.*?<a class=.+?href=.*?/video/(.*?)_.*?">(.*?)<.*?<div class="dmpi_video_description foreground.*?>.*?<div>(.*?)<} $html - snatch cid desc vote | |
3051 | regsub -nocase -- {<div class="dmco_text duration">.*?<h4 class="dmco_title.*?>.*?<a class=.+?href=.*?/video/.+?_.*?">.*?div class="dmco_date">(.*?)<} $html "" html | |
3052 | ||
3053 | # if there's no desc, return or stop looping, depending | |
3054 | if {[info exists desc] == 0} { | |
3055 | if {$results == 0} { | |
3056 | set reply "Sorry, no search results were found." | |
3057 | return "${::incith::google::desc_modes}$reply$::incith::google::desc_demodes" | |
3058 | } else { | |
3059 | break | |
3060 | } | |
3061 | } | |
3062 | set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]] | |
3063 | set vote [string trim [string range $vote 0 [expr $incith::google::description_length - 1]]] | |
3064 | set desc "${desc} (${snatch}) ([string trim $vote])" | |
3065 | ||
3066 | # make the link valid because we were only given a partial href result, not a full url | |
3067 | set link "http://www.dailymotion.com/${titem}/video/${cid}" | |
3068 | ||
3069 | # prevent duplicate results is mostly useless here, but will at least | |
3070 | # ensure that we don't get the exact same article. | |
3071 | if {[string match "*$link*" $output] == 1} { | |
3072 | break | |
3073 | } | |
3074 | ||
3075 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
3076 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
3077 | ||
3078 | # add the search result | |
3079 | if {$incith::google::link_only == 1} { | |
3080 | append output "${link}${incith::google::seperator}" | |
3081 | } else { | |
3082 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
3083 | } | |
3084 | ||
3085 | # increase the results, clear the variables for the next loop just in case | |
3086 | unset link; unset desc ; unset cid | |
3087 | incr results | |
3088 | } | |
3089 | ||
3090 | # make sure we have something to send | |
3091 | if {[info exists output] == 0} { | |
3092 | set reply "Sorry, no search results were found." | |
3093 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
3094 | } | |
3095 | return $output | |
3096 | } | |
3097 | ||
3098 | # GAMEFAQS | |
3099 | # fetches upcoming game list variable by system and region (gamefaqs.com) | |
3100 | # this is far better than any gamefaqs procedure you've seen before, this is looooong, but very simple | |
3101 | # in it's approach. I learned alot coding it. | |
3102 | # -speechless supplied | |
3103 | # | |
3104 | proc gamefaqs {system region} { | |
3105 | ||
3106 | ; set results 0 ; set output "" ; set html "" ; set match 0 ; set game "" ; set date "" | |
3107 | ||
3108 | # strip excessive spaces from region and system desired. | |
3109 | regsub -all " " $system "" system | |
3110 | regsub -all " " $region "" region | |
3111 | ||
3112 | # this is where most of the work is done | |
3113 | # parsing systems and regions to create an output header | |
3114 | # and cut the html down to the specified region | |
3115 | ||
3116 | if {[string match -nocase "nds" $system] == 1} { | |
3117 | if {[string match -nocase "usa" $region] == 1} { | |
3118 | set html [fetch_html "/region-1" 15] | |
3119 | set output "\002NDS North America (USA)\002" | |
3120 | } | |
3121 | if {[string match -nocase "jap" $region] == 1} { | |
3122 | set html [fetch_html "/region-2" 15] | |
3123 | set output "\002NDS Asia (JAPAN)\002" | |
3124 | } | |
3125 | if {[string match -nocase "eur" $region] == 1} { | |
3126 | set html [fetch_html "/region-3" 15] | |
3127 | set output "\002NDS Europe (UK)\002" | |
3128 | } | |
3129 | if {[string match -nocase "aus" $region] == 1} { | |
3130 | set html [fetch_html "/region-4" 15] | |
3131 | set output "\002NDS Australia (AUS)\002" | |
3132 | } | |
3133 | } | |
3134 | ||
3135 | if {[string match -nocase "3ds" $system] == 1} { | |
3136 | if {[string match -nocase "usa" $region] == 1} { | |
3137 | set html [fetch_html "/region-1" 56] | |
3138 | set output "\0023DS North America (USA)\002" | |
3139 | } | |
3140 | if {[string match -nocase "jap" $region] == 1} { | |
3141 | set html [fetch_html "/region-2" 56] | |
3142 | set output "\0023DS Asia (JAPAN)\002" | |
3143 | } | |
3144 | if {[string match -nocase "eur" $region] == 1} { | |
3145 | set html [fetch_html "/region-3" 56] | |
3146 | set output "\0023DS Europe (UK)\002" | |
3147 | } | |
3148 | if {[string match -nocase "aus" $region] == 1} { | |
3149 | set html [fetch_html "/region-4" 56] | |
3150 | set output "\002NDS Australia (AUS)\002" | |
3151 | } | |
3152 | } | |
3153 | ||
3154 | if {[string match -nocase "iphone" $system] == 1} { | |
3155 | if {[string match -nocase "usa" $region] == 1} { | |
3156 | set html [fetch_html "/region-1" 16] | |
3157 | set output "\002iPhone North America (USA)\002" | |
3158 | } | |
3159 | if {[string match -nocase "jap" $region] == 1} { | |
3160 | set html [fetch_html "/region-2" 16] | |
3161 | set output "\002iPhone Asia (JAPAN)\002" | |
3162 | } | |
3163 | if {[string match -nocase "eur" $region] == 1} { | |
3164 | set html [fetch_html "/region-3" 16] | |
3165 | set output "\002iPhone Europe (UK)\002" | |
3166 | } | |
3167 | if {[string match -nocase "aus" $region] == 1} { | |
3168 | set html [fetch_html "/region-4" 16] | |
3169 | set output "\002iPhone Australia (AUS)\002" | |
3170 | } | |
3171 | } | |
3172 | ||
3173 | if {[string match -nocase "psp" $system] == 1} { | |
3174 | if {[string match -nocase "usa" $region] == 1} { | |
3175 | set html [fetch_html "/region-1" 17] | |
3176 | set output "\002PSP North America (USA)\002" | |
3177 | } | |
3178 | if {[string match -nocase "jap" $region] == 1} { | |
3179 | set html [fetch_html "/region-2" 17] | |
3180 | set output "\002PSP Asia (JAPAN)\002" | |
3181 | } | |
3182 | if {[string match -nocase "eur" $region] == 1} { | |
3183 | set html [fetch_html "/region-3" 17] | |
3184 | set output "\002PSP Europe (UK)\002" | |
3185 | } | |
3186 | if {[string match -nocase "aus" $region] == 1} { | |
3187 | set html [fetch_html "/region-4" 17] | |
3188 | set output "\002PSP Australia (AUS)\002" | |
3189 | } | |
3190 | } | |
3191 | ||
3192 | if {[string match -nocase "x360" $system] == 1} { | |
3193 | if {[string match -nocase "usa" $region] == 1} { | |
3194 | set html [fetch_html "/region-1" 18] | |
3195 | set output "\002XBOX360 North America (USA)\002" | |
3196 | } | |
3197 | if {[string match -nocase "jap" $region] == 1} { | |
3198 | set html [fetch_html "/region-2" 18] | |
3199 | set output "\002XBOX360 Asia (JAPAN)\002" | |
3200 | } | |
3201 | if {[string match -nocase "eur" $region] == 1} { | |
3202 | set html [fetch_html "/region-3" 18] | |
3203 | set output "\002XBOX360 Europe (UK)\002" | |
3204 | } | |
3205 | if {[string match -nocase "aus" $region] == 1} { | |
3206 | set html [fetch_html "/region-4" 18] | |
3207 | set output "\002XBOX360 Australia (AUS)\002" | |
3208 | } | |
3209 | } | |
3210 | ||
3211 | if {[string match -nocase "xbox" $system] == 1} { | |
3212 | if {[string match -nocase "usa" $region] == 1} { | |
3213 | set html [fetch_html "/region-1" 19] | |
3214 | set output "\002XBOX North America (USA)\002" | |
3215 | } | |
3216 | if {[string match -nocase "jap" $region] == 1} { | |
3217 | set html [fetch_html "/region-2" 19] | |
3218 | set output "\002XBOX Asia (JAPAN)\002" | |
3219 | } | |
3220 | if {[string match -nocase "eur" $region] == 1} { | |
3221 | set html [fetch_html "/region-3" 19] | |
3222 | set output "\002XBOX Europe (UK)\002" | |
3223 | } | |
3224 | if {[string match -nocase "aus" $region] == 1} { | |
3225 | set html [fetch_html "/region-4" 19] | |
3226 | set output "\002XBOX Australia (AUS)\002" | |
3227 | } | |
3228 | } | |
3229 | ||
3230 | if {[string match -nocase "gc" $system] == 1} { | |
3231 | if {[string match -nocase "usa" $region] == 1} { | |
3232 | set html [fetch_html "/region-1" 20] | |
3233 | set output "\002GAMECUBE North America (USA)\002" | |
3234 | } | |
3235 | if {[string match -nocase "jap" $region] == 1} { | |
3236 | set html [fetch_html "/region-2" 20] | |
3237 | set output "\002GAMECUBE Asia (JAPAN)\002" | |
3238 | } | |
3239 | if {[string match -nocase "eur" $region] == 1} { | |
3240 | set html [fetch_html "/region-3" 20] | |
3241 | set output "\002GAMECUBE Europe (UK)\002" | |
3242 | } | |
3243 | if {[string match -nocase "aus" $region] == 1} { | |
3244 | set html [fetch_html "/region-4" 20] | |
3245 | set output "\002GAMECUBE Australia (AUS)\002" | |
3246 | } | |
3247 | } | |
3248 | ||
3249 | if {[string match -nocase "ps2" $system] == 1} { | |
3250 | if {[string match -nocase "usa" $region] == 1} { | |
3251 | set html [fetch_html "/region-1" 21] | |
3252 | set output "\002PS2 North America (USA)\002" | |
3253 | } | |
3254 | if {[string match -nocase "jap" $region] == 1} { | |
3255 | set html [fetch_html "/region-2" 21] | |
3256 | set output "\002PS2 Asia (JAPAN)\002" | |
3257 | } | |
3258 | if {[string match -nocase "eur" $region] == 1} { | |
3259 | set html [fetch_html "/region-3" 21] | |
3260 | set output "\002PS2 Europe (UK)\002" | |
3261 | } | |
3262 | if {[string match -nocase "aus" $region] == 1} { | |
3263 | set html [fetch_html "/region-4" 21] | |
3264 | set output "\002PS2 Australia (AUS)\002" | |
3265 | } | |
3266 | } | |
3267 | ||
3268 | if {[string match -nocase "pc" $system] == 1} { | |
3269 | if {[string match -nocase "usa" $region] == 1} { | |
3270 | set html [fetch_html "/region-1" 22] | |
3271 | set output "\002PC North America (USA)\002" | |
3272 | } | |
3273 | if {[string match -nocase "jap" $region] == 1} { | |
3274 | set html [fetch_html "/region-2" 22] | |
3275 | set output "\002PC Asia (JAPAN)\002" | |
3276 | } | |
3277 | if {[string match -nocase "eur" $region] == 1} { | |
3278 | set html [fetch_html "/region-3" 22] | |
3279 | set output "\002PC Europe (UK)\002" | |
3280 | } | |
3281 | if {[string match -nocase "aus" $region] == 1} { | |
3282 | set html [fetch_html "/region-4" 22] | |
3283 | set output "\002PC Australia (AUS)\002" | |
3284 | } | |
3285 | } | |
3286 | ||
3287 | if {[string match -nocase "ps3" $system] == 1} { | |
3288 | if {[string match -nocase "usa" $region] == 1} { | |
3289 | set html [fetch_html "/region-1" 23] | |
3290 | set output "\002PS3 North America (USA)\002" | |
3291 | } | |
3292 | if {[string match -nocase "jap" $region] == 1} { | |
3293 | set html [fetch_html "/region-2" 23] | |
3294 | set output "\002PS3 Asia (JAPAN)\002" | |
3295 | } | |
3296 | if {[string match -nocase "eur" $region] == 1} { | |
3297 | set html [fetch_html "/region-3" 23] | |
3298 | set output "\002PS3 Europe (UK)\002" | |
3299 | } | |
3300 | if {[string match -nocase "aus" $region] == 1} { | |
3301 | set html [fetch_html "/region-4" 23] | |
3302 | set output "\002PS3 Australia (AUS)\002" | |
3303 | } | |
3304 | } | |
3305 | ||
3306 | if {[string match -nocase "wii" $system] == 1} { | |
3307 | if {[string match -nocase "usa" $region] == 1} { | |
3308 | set html [fetch_html "/region-1" 28] | |
3309 | set output "\002Wii North America (USA)\002" | |
3310 | } | |
3311 | if {[string match -nocase "jap" $region] == 1} { | |
3312 | set html [fetch_html "/region-2" 28] | |
3313 | set output "\002Wii Asia (JAPAN)\002" | |
3314 | } | |
3315 | if {[string match -nocase "eur" $region] == 1} { | |
3316 | set html [fetch_html "/region-3" 28] | |
3317 | set output "\002Wii Europe (UK)\002" | |
3318 | } | |
3319 | if {[string match -nocase "aus" $region] == 1} { | |
3320 | set html [fetch_html "/region-4" 28] | |
3321 | set output "\002Wii Australia (AUS)\002" | |
3322 | } | |
3323 | } | |
3324 | ||
3325 | if {[string match -nocase "dc" $system] == 1} { | |
3326 | if {[string match -nocase "jap" $region] == 1} { | |
3327 | set html [fetch_html "/region-2" 29] | |
3328 | set output "\002Dreamcast Asia (JAPAN)\002" | |
3329 | } | |
3330 | } | |
3331 | ||
3332 | if {[string match -nocase "mac" $system] == 1} { | |
3333 | if {[string match -nocase "usa" $region] == 1} { | |
3334 | set html [fetch_html "/region-1" 59] | |
3335 | set output "\002MAC America (USA)\002" | |
3336 | } | |
3337 | if {[string match -nocase "jap" $region] == 1} { | |
3338 | set html [fetch_html "/region-2" 59] | |
3339 | set output "\002MAC Asia (JAPAN)\002" | |
3340 | } | |
3341 | if {[string match -nocase "eur" $region] == 1} { | |
3342 | set html [fetch_html "/region-3" 59] | |
3343 | set output "\002MAC Europe (UK)\002" | |
3344 | } | |
3345 | if {[string match -nocase "aus" $region] == 1} { | |
3346 | set html [fetch_html "/region-4" 59] | |
3347 | set output "\002MAC Australia (AUS)\002" | |
3348 | } | |
3349 | } | |
3350 | ||
3351 | if {[string length $output]} { | |
3352 | set output "$::incith::google::total_modes$output$::incith::google::total_demodes" | |
3353 | } | |
3354 | # remove the bold if it isn't desired. | |
3355 | if {$incith::google::bold_descriptions == 0} { | |
3356 | regsub -all -- "\002" $output {} output | |
3357 | } | |
3358 | ||
3359 | # parse for results and loop until desired amount of results | |
3360 | # is attempted to be reached if possible. | |
3361 | while {$results < $incith::google::gamefaq_results && $output != ""} { | |
3362 | ||
3363 | # grab date and game title and clear future html of it for looping | |
3364 | regexp -nocase {<tr.*?td>(.*?)<.+?td>.*?<td><a.+?href.+?title.+?"(.+?)">.+?<.+?a><.+?td>} $html {} date game | |
3365 | regsub {<tr.*?td>(.+?)<.+?a><.+?td>} $html "" html | |
3366 | ||
3367 | # add the search result | |
3368 | # if there is a date, add date in bold and game to $output | |
3369 | if {[string len $date] > 3} { | |
3370 | if {$incith::google::bold_descriptions == 0} { | |
3371 | append output "${incith::google::seperator}$::incith::google::desc_modes${date} ${game}$::incith::google::desc_demodes" | |
3372 | } else { | |
3373 | append output "${incith::google::seperator}$::incith::google::desc_modes\002${date}\002 ${game}$::incith::google::desc_demodes" | |
3374 | } | |
3375 | # otherwise just add name of game | |
3376 | } elseif {[string len $game] > 1} { | |
3377 | append output "${incith::google::split_char}$::incith::google::desc_modes${game}$::incith::google::desc_demodes" | |
3378 | #append output ",${game}" | |
3379 | } | |
3380 | ||
3381 | # increase the results, clear the variables for the next loop just in case | |
3382 | incr results | |
3383 | ; set date "" ; set game "" | |
3384 | } | |
3385 | ||
3386 | # if we have nothing to send, we have no results :( | |
3387 | if {$output == ""} { | |
3388 | set output "${::incith::google::desc_modes}Sorry, found no results! \[system = 3ds/nds/gc/wii/ps2/psp/ps3/xbox/x360/pc/mac/iphone; region = usa/jap/eur/aus\] usage: !gamefaqs system in region$::incith::google::desc_demodes" | |
3389 | } | |
3390 | return $output | |
3391 | } | |
3392 | ||
3393 | # BLOGSEARCH | |
3394 | # fetches the news from blogsearch.google. | |
3395 | # -madwoota supplied (uses news.google engine), speechless updated | |
3396 | # | |
3397 | proc blog {input} { | |
3398 | ; set results 0 ; set output "" ; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" | |
3399 | ||
3400 | # fetch the html | |
3401 | set html [fetch_html $input 24] | |
3402 | ||
3403 | # user input causing errors? | |
3404 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
3405 | regsub {(.+?)\|} $html {} html | |
3406 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
3407 | } | |
3408 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
3409 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
3410 | } | |
3411 | # strip out 'did you mean?' first | |
3412 | # what do we call 'no search results in any language?' | |
3413 | regexp -- {<p></p></div></div><div id=f>(.+?)<br><br>} $html - no_search | |
3414 | if {$no_search != ""} { | |
3415 | regsub -- {</a>} $no_search "? " no_search | |
3416 | regsub -all -- {<(.+?)>} $no_search { } no_search | |
3417 | while {[string match "* *" $no_search]} { | |
3418 | regsub -all -- { } $no_search " " no_search | |
3419 | } | |
3420 | set no_search [string trim $no_search] | |
3421 | } | |
3422 | ||
3423 | # give results an output header with result tally. | |
3424 | regexp -- {</td><td align=right class=rsb>(.+?)\s\002(.+?)\(\002} $html - titem match | |
3425 | if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} { | |
3426 | set match "Google" | |
3427 | set titem "" | |
3428 | } | |
3429 | regsub -all -- {<(.+?)>} $match {} match | |
3430 | # format output according to variables. | |
3431 | if {$incith::google::total_results != 0 && $match > 0} { | |
3432 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
3433 | if {$incith::google::bold_descriptions == 0} { | |
3434 | regsub -all -- "\002" $output {} output | |
3435 | } | |
3436 | } | |
3437 | ||
3438 | # parse the html | |
3439 | while {$results < $incith::google::news_results} { | |
3440 | # somewhat extenuated regexp due to allowing that there *might* be | |
3441 | # an image next to the story | |
3442 | regexp -- {</p><a href="(.+?)".+?id=.+?">(.+?)</a>.+?<td class=j>(.+?)<br>} $html {} link desc time | |
3443 | regsub -- {</p><a href=(.+?)</a>} $html {} html | |
3444 | ||
3445 | # if there's no desc, return or stop looping, depending | |
3446 | if {[info exists desc] == 0} { | |
3447 | if {$results == 0} { | |
3448 | set reply $no_search | |
3449 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
3450 | } else { | |
3451 | break | |
3452 | } | |
3453 | } | |
3454 | # clean up desc | |
3455 | if {[info exists desc] == 1 && $incith::google::description_length > 0} { | |
3456 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
3457 | set desc "[descdecode [string trim $desc]] ([descdecode [string trim $time]])" | |
3458 | } | |
3459 | # prevent duplicate results is mostly useless here, but will at least | |
3460 | # ensure that we don't get the exact same article. | |
3461 | if {[string match "*$link*" $output] == 1} { | |
3462 | break | |
3463 | } | |
3464 | ||
3465 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
3466 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
3467 | ||
3468 | # add the search result | |
3469 | if {$incith::google::link_only == 1} { | |
3470 | append output "${link}${incith::google::seperator}" | |
3471 | } else { | |
3472 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
3473 | } | |
3474 | ||
3475 | # increase the results, clear the variables for the next loop just in case | |
3476 | unset link; unset desc | |
3477 | incr results | |
3478 | } | |
3479 | ||
3480 | # make sure we have something to send | |
3481 | if {$match == ""} { | |
3482 | set reply $no_search | |
3483 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
3484 | } | |
3485 | return $output | |
3486 | } | |
3487 | ||
3488 | # SCHOLAR SEARCH | |
3489 | # fetches the news from scholar.google. | |
3490 | # -madwoota supplied (uses news.google engine), speechless updated | |
3491 | # | |
3492 | proc scholar {input} { | |
3493 | ; set results 0 ; set output "" ; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen "" | |
3494 | ||
3495 | # this isn't global, so we need to keep ctry (country) here | |
3496 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy | |
3497 | if {$titen == ""} { | |
3498 | set titen "${incith::google::google_country}" | |
3499 | } | |
3500 | ||
3501 | # fetch the html | |
3502 | set html [fetch_html $input 10] | |
3503 | ||
3504 | # user input causing errors? | |
3505 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
3506 | regsub {(.+?)\|} $html {} html | |
3507 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
3508 | } | |
3509 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
3510 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
3511 | } | |
3512 | # strip out 'did you mean?' first | |
3513 | # what do we call 'no search results in any language?' | |
3514 | if {![regexp -- {</script><p>(.+?)\.<br>} $html - no_search]} { | |
3515 | regexp -- {</script><br><br>(.+?)<br><br>} $html - no_search | |
3516 | } | |
3517 | if {$no_search != ""} { | |
3518 | regsub -- {</a>} $no_search "? " no_search | |
3519 | regsub -all -- {<(.*?)>} $no_search { } no_search | |
3520 | while {[string match "* *" $no_search]} { | |
3521 | regsub -all -- { } $no_search " " no_search | |
3522 | } | |
3523 | set no_search [string trim $no_search] | |
3524 | } | |
3525 | ||
3526 | # give results an output header with result tally. | |
3527 | regexp -- {align=right nowrap>(.+?)\s\002(.+?)\(\002} $html - titem match | |
3528 | if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} { | |
3529 | set match "Google" | |
3530 | set titem "" | |
3531 | } | |
3532 | regsub -all -- {<(.+?)>} $match {} match | |
3533 | # format output according to variables. | |
3534 | if {$incith::google::total_results != 0 && $match > 0} { | |
3535 | set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}" | |
3536 | if {$incith::google::bold_descriptions == 0} { | |
3537 | regsub -all -- "\002" $output {} output | |
3538 | } | |
3539 | } | |
3540 | ||
3541 | # parse the html | |
3542 | while {$results < $incith::google::news_results} { | |
3543 | # somewhat extenuated regexp due to allowing that there *might* be | |
3544 | # an image next to the story | |
3545 | if {[regexp -- {<p class=g><h3 class="r">(.+?) } $html - ps]} { | |
3546 | regsub -- {<p class=g><h3 class="r">(.+?) } $html {} html | |
3547 | if {![regexp -- {<a href="(.+?)" onmousedown} $ps - link]} { set link "none" } { regsub {<a href="(.+?)" onmousedown.*?>} $ps "" ps } | |
3548 | if {[regexp -- {(.+?)</h3>.*?<br>(.*?)<br>} $ps - desc time]} { regsub {</a>} $desc "" desc } | |
3549 | } | |
3550 | ||
3551 | # if there's no desc, return or stop looping, depending | |
3552 | if {[info exists desc] == 0} { | |
3553 | if {$results == 0} { | |
3554 | set reply $no_search | |
3555 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
3556 | } else { | |
3557 | break | |
3558 | } | |
3559 | } | |
3560 | # clean up desc | |
3561 | if {[info exists desc] == 1 && $incith::google::description_length > 0} { | |
3562 | set desc [string range $desc 0 [expr $incith::google::description_length - 1]] | |
3563 | set desc "[string trim $desc] ([string trim $time])" | |
3564 | } | |
3565 | # prevent duplicate results is mostly useless here, but will at least | |
3566 | # ensure that we don't get the exact same article. | |
3567 | if {[string match "*$link*" $output] == 1} { | |
3568 | break | |
3569 | } | |
3570 | ||
3571 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
3572 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
3573 | ||
3574 | # add the search result | |
3575 | if {$incith::google::link_only == 1} { | |
3576 | append output "${link}${incith::google::seperator}" | |
3577 | } else { | |
3578 | if {![string equal $link "none"]} { | |
3579 | if {![string match "http*" $link]} { set link "http://scholar.google.${titen}/$link" } | |
3580 | append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}" | |
3581 | } else { | |
3582 | append output "[descdecode $desc]${incith::google::seperator}" | |
3583 | } | |
3584 | } | |
3585 | ||
3586 | # increase the results, clear the variables for the next loop just in case | |
3587 | unset link; unset desc | |
3588 | incr results | |
3589 | } | |
3590 | ||
3591 | # make sure we have something to send | |
3592 | if {$match == ""} { | |
3593 | set reply $no_search | |
3594 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
3595 | } | |
3596 | return $output | |
3597 | } | |
3598 | ||
3599 | ||
3600 | # WIKI | |
3601 | # fetches wiki info from *.wikipedia.org | |
3602 | # -speechless supplied | |
3603 | # | |
3604 | proc wiki {input} { | |
3605 | global incithcharset | |
3606 | ; set output "" ; set ded "" ; set match "" ; set redir "" ; set country "" ; set dec "" | |
3607 | ; set query "" ; set titem "" ; set ebcPR "" ; set results "" ; set tresult "" ; set red 0 | |
3608 | ; set subtag "" ; set region "" ; set regional "" | |
3609 | ||
3610 | # make it so people can search their country | |
3611 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input | |
3612 | if {$country == ""} { | |
3613 | set country "${incith::google::wiki_country}" | |
3614 | } | |
3615 | regexp -nocase -- {(.*)\@(.*)} $country - country region | |
3616 | ||
3617 | # this is my input encoding hack, this will convert input before it goes | |
3618 | # out to be queried. | |
3619 | if {$incith::google::encoding_conversion_input > 0 && $region != ""} { | |
3620 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${region}:*"]] :] 1] | |
3621 | } elseif {$incith::google::encoding_conversion_input > 0 && $country != ""} { | |
3622 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1] | |
3623 | } else { set encoding_found "" } | |
3624 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
3625 | set input [encoding convertfrom $encoding_found $input] | |
3626 | } | |
3627 | regsub -all -- {_} $input { } input | |
3628 | regexp -- {^(.+?)\#(.+?)$} $input - input results | |
3629 | regsub -all -- {_} $results { } results | |
3630 | set input [urlencode $input 0 "utf-8"] | |
3631 | set results [string map {.20 _} [urlencode [string trim $results] 1 "utf-8"]] | |
3632 | ||
3633 | # 1st load of webpage - this is the only part which has error control | |
3634 | # this is where we load the search page to find an exact match or most relevant. | |
3635 | # we will also be able to detect bad user input in the form of socket errors. | |
3636 | ||
3637 | # beware, changing the useragent will result in differently formatted html from Google. | |
3638 | set query "http://${country}.wikipedia.org/wiki/index.php?title=Special%3ASearch&search=${input}&fulltext=Search" | |
3639 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
3640 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
3641 | # stole this bit from rosc2112 on egghelp forums | |
3642 | # borrowed is a better term, all procs eventually need this error handler. | |
3643 | catch {set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 5]]} error | |
3644 | ||
3645 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
3646 | return "${::incith::google::error_modes}Socket Error accessing '${country}.wikipedia.org' .. Does it exist?${::incith::google::error_demodes}" | |
3647 | } | |
3648 | if { [::http::status $http] == "timeout" } { | |
3649 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
3650 | } | |
3651 | ||
3652 | # CHECK CHECK | |
3653 | upvar #0 $http state | |
3654 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
3655 | set html [ungzip [::http::data $http] $state(meta)] | |
3656 | set redir [::http::ncode $http] | |
3657 | # REDIRECT | |
3658 | if {[string match "*${redir}*" "302|301" ]} { | |
3659 | foreach {name value} $state(meta) { | |
3660 | if {[regexp -nocase ^location$ $name]} { | |
3661 | catch {set http [::http::geturl "$value" -query "" -headers $::incith_hdr -timeout [expr 1000 * 10]]} error | |
3662 | if { $::incith::google::debug > 0 } { putserv "privmsg $::incith::google::debugnick :\002redirected:\002 $query -> $value" } | |
3663 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
3664 | return "${::incith::google::error_modes}Socket Error accessing '${country}.wikipedia.org' .. Does it exist?${::incith::google::error_demodes}" | |
3665 | } | |
3666 | if { [::http::status $http] == "timeout" } { | |
3667 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
3668 | } | |
3669 | upvar #0 $http state | |
3670 | set html [ungzip [::http::data $http] $state(meta)] | |
3671 | set query $value | |
3672 | } | |
3673 | } | |
3674 | } | |
3675 | ::http::cleanup $http | |
3676 | ||
3677 | # generic pre-parsing | |
3678 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
3679 | regsub -all -nocase {<font.+?>} $html "" html | |
3680 | regsub -all -nocase {</font>} $html "" html | |
3681 | regsub -all -nocase {<input.+?>} $html "" html | |
3682 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
3683 | regsub -all "\t" $html " " html | |
3684 | regsub -all "\n" $html " " html | |
3685 | regsub -all "\r" $html " " html | |
3686 | regsub -all "\v" $html " " html | |
3687 | regsub -all "</li>" $html ". " html | |
3688 | regsub -all ";;>" $html "" html | |
3689 | regsub {<div class="floating_object".*?>.*?</div>} $html "" html | |
3690 | ||
3691 | if {$html == ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 No html to parse.$::incith::google::error_demodes" } | |
3692 | ||
3693 | # see if our direct result is available and if so, lets take it | |
3694 | if {![regexp -- {<div id="contentSub"><p>.*?<a href="(.+?)".*?title} $html - match]} { | |
3695 | if {![regexp -- {<div class=.searchresults.><p>*?<a href="(.+?)".*?title} $html - match]} { | |
3696 | regexp -- {<div class=.searchresults.><p class="mw-search.*?>.*?<a href="(.+?)".*?title} $html - match | |
3697 | } | |
3698 | } | |
3699 | putserv "privmsg speechles :match $match" | |
3700 | if {[string match -nocase "*action=edit*" $match]} { set match "" } | |
3701 | # otherwise we only care about top result | |
3702 | if {$match == ""} { | |
3703 | if {![regexp -- {<li><a href="((?!http).+?)"} $html - match]} { | |
3704 | if {![regexp -- {<li style.*?><a href="(.+?)"} $html - match]} { | |
3705 | if {![regexp -- {<div class='searchresults'>.*?<a href="(.*?)".*?class="mw-redirect">} $html - match]} { | |
3706 | if {[regexp -- {<li><div class='mw-search-result-heading'>(.*?)</div>} $html - slice]} { | |
3707 | if {![regexp -- {<span class='searchalttitle'>.*?<a href="(.*?)"} $slice - match]} { | |
3708 | regexp -- {<a href="(.*?)"} $slice - match | |
3709 | } | |
3710 | } | |
3711 | } | |
3712 | } | |
3713 | } | |
3714 | } | |
3715 | #if {[string match "http://*" $match]} { set match "" } | |
3716 | if {[string match -nocase "*/wiki*" $country]} { | |
3717 | regsub -- {/wiki} $country {} country | |
3718 | } | |
3719 | # DEBUG DEBUG | |
3720 | set junk [open "ig-debug.txt" w] | |
3721 | puts $junk $html | |
3722 | close $junk | |
3723 | ||
3724 | # at this point we can tell if there was any match, so let's not even bother | |
3725 | # going further if there wasn't a match, this pulls the 'no search etc' found. | |
3726 | # this can be in any language. | |
3727 | if {$match == ""} { | |
3728 | # these are for 'no search results' or similar message | |
3729 | # these can be in any language. | |
3730 | if {[regexp -- {<div class='searchresults'>(.+?)</p>} $html - match]} { | |
3731 | regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match | |
3732 | regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match | |
3733 | regsub -all {<div id.*?>} $match "" match | |
3734 | regsub -- {</a></div>} $match "?" match | |
3735 | regsub -all {</div>} $match "" match | |
3736 | regsub -all {\[Index\]} $match "" match | |
3737 | regsub -all {<span.*?/span>} $match "" match | |
3738 | regsub -all {<script type.*?</script>} $match "" match | |
3739 | regsub -all { \(<.*?>\)} $match ". " match | |
3740 | if {[string match "*<!--*" $match]} { | |
3741 | regexp -- {<li class="normal">.*?</p><p>(.*?)</p>} $html - match | |
3742 | } | |
3743 | } else { | |
3744 | if {[regexp -- {<div id='search results'><p class="mw-search.*?>(.*?)</p>} $html - match]} { | |
3745 | regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match | |
3746 | } | |
3747 | } | |
3748 | ||
3749 | if {$match == ""} { | |
3750 | if {[regexp -nocase -- {<div class='searchresults'>(.*?)<div class="printfooter">} $html - match]} { | |
3751 | regsub -all {<p>} $match " " match | |
3752 | regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match | |
3753 | regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match | |
3754 | regsub -all {<div id.*?>} $match "" match | |
3755 | regsub -- {</a></div>} $match "?" match | |
3756 | regsub -all {</div>} $match "" match | |
3757 | regsub -all {\[Index\]} $match "" match | |
3758 | regsub -all {<span.*?/span>} $match "" match | |
3759 | regsub -all {<script type.*?</script>} $match "" match | |
3760 | regsub -all { \(<.*?>\)} $match ". " match | |
3761 | } | |
3762 | } | |
3763 | # this is our last error catch, this can grab the | |
3764 | # 'wikimedia cannot search at this time' message | |
3765 | # this can be in any language. | |
3766 | if {[string len $match] < 3} { regexp -- {<center><b>(.+?)</b>} $html - match } | |
3767 | if {$match == ""} { | |
3768 | regsub -all -- { } $results {_} results | |
3769 | if {$results != ""} { set results "#${results}" } | |
3770 | return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${results}$::incith::google::error_demodes" | |
3771 | } | |
3772 | # might be tags since we allowed any language here we cut them out | |
3773 | regsub -all -- {<(.+?)>} $match {} match | |
3774 | if {$region == ""} { | |
3775 | return "$::incith::google::desc_modes[utf8encodefix $country [descdecode ${match}]]$::incith::google::desc_demodes" | |
3776 | } else { | |
3777 | return "$::incith::google::desc_modes[utf8encodefix $region [descdecode ${match}]]$::incith::google::desc_demodes" | |
3778 | } | |
3779 | } | |
3780 | ||
3781 | # we assume here we found another page to traverse in our search. | |
3782 | if {$region != ""} { | |
3783 | regsub -- {/wiki/} $match "/$region/" match | |
3784 | } | |
3785 | if {![string match http://* $match]} { set query "http://${country}.wikipedia.org${match}" } { set query $match } | |
3786 | ||
3787 | # 2nd load of webpage - this has no error checking what-so-ever | |
3788 | # here is where we pluck the link to the exact match, or the most relevant 'top' link. | |
3789 | # or in the case of redirects, to other pages, we will handle that here as well. | |
3790 | ||
3791 | # beware, changing the useragent will result in differently formatted html from Google. | |
3792 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
3793 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
3794 | set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 5]] | |
3795 | upvar #0 $http state | |
3796 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
3797 | # this is the output encoding hack. | |
3798 | if {$incith::google::encoding_conversion_output > 0} { | |
3799 | if {$region != ""} { | |
3800 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1] | |
3801 | } else { | |
3802 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
3803 | } | |
3804 | } | |
3805 | ||
3806 | set html [ungzip [::http::data $http] $state(meta)] | |
3807 | if {$incith::google::debug > 0} { | |
3808 | putserv "privmsg $incith::google::debugnick :\002url:\002 $query \002charset:\002 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset] \002\037encode_string:\037\002 $encoding_found" | |
3809 | } | |
3810 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
3811 | set ::incithcharset $encoding_found | |
3812 | set html [incithencode $html] | |
3813 | } | |
3814 | ::http::cleanup $http | |
3815 | #correct the html, remove shitty tags | |
3816 | # generic pre-parsing | |
3817 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
3818 | regsub -all -nocase {<font.+?>} $html "" html | |
3819 | regsub -all -nocase {</font>} $html "" html | |
3820 | regsub -all -nocase {<input.+?>} $html "" html | |
3821 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
3822 | regsub -all "\t" $html " " html | |
3823 | regsub -all "\n" $html " " html | |
3824 | regsub -all "\r" $html " " html | |
3825 | regsub -all "\v" $html " " html | |
3826 | regsub -all "</li>" $html ". " html | |
3827 | regsub -all ";;>" $html "" html | |
3828 | ||
3829 | if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} { | |
3830 | regsub -all -nocase {(?:<b>|</b>)} $html "\002" html | |
3831 | } | |
3832 | set match "" | |
3833 | ||
3834 | # are we redirected to another page? if so, let's go there | |
3835 | regexp -- {alt="#REDIRECT ".+?<a href="(.+?)" title="} $html - match | |
3836 | if {$match != ""} { | |
3837 | incr red 1 | |
3838 | set query "http://${country}.wikipedia.org${match}" | |
3839 | ||
3840 | # 3rd load of webpage - this has no error checking what-so-ever | |
3841 | # here is our final webpage, this is hopefully what the user was looking for. | |
3842 | ||
3843 | # beware, changing the useragent will result in differently formatted html from Google. | |
3844 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
3845 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
3846 | set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 10]] | |
3847 | upvar #0 $http state | |
3848 | ||
3849 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
3850 | # this is the output encoding hack. | |
3851 | if {$incith::google::encoding_conversion_output > 0} { | |
3852 | if {$region != ""} { | |
3853 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1] | |
3854 | } else { | |
3855 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
3856 | } | |
3857 | } else { set ::incithcharset "" } | |
3858 | ||
3859 | set html [ungzip [::http::data $http] $state(meta)] | |
3860 | if {$incith::google::debug > 0} { | |
3861 | putserv "privmsg $incith::google::debugnick :\002url:\002 $query \002charset:\002 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset] \002\037encode_string:\037\002 $encoding_found" | |
3862 | } | |
3863 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
3864 | set ::incithcharset $encoding_found | |
3865 | set html [incithencode $html] | |
3866 | } | |
3867 | ::http::cleanup $http | |
3868 | #correct the html, remove shitty tags | |
3869 | # generic pre-parsing | |
3870 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
3871 | regsub -all -nocase {<font.+?>} $html "" html | |
3872 | regsub -all -nocase {</font>} $html "" html | |
3873 | regsub -all -nocase {<input.+?>} $html "" html | |
3874 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
3875 | regsub -all "\t" $html " " html | |
3876 | regsub -all "\n" $html " " html | |
3877 | regsub -all "\r" $html " " html | |
3878 | regsub -all "\v" $html " " html | |
3879 | regsub -all "</li>" $html ". " html | |
3880 | regsub -all ";;>" $html "" html | |
3881 | ||
3882 | if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} { | |
3883 | regsub -all -nocase {(?:<b>|</b>)} $html "\002" html | |
3884 | } | |
3885 | } | |
3886 | ||
3887 | set match "" | |
3888 | # give results an output header with result tally. | |
3889 | if {[regexp -- {<title>(.+?)</title>} $html - match]} { regexp -- {(.+?)\s(?:-|-)\s} $match - match } | |
3890 | # see if page has a redirect to fragment | |
3891 | regexp -- {redirectToFragment\("\#(.*?)"\)} $html - tresult | |
3892 | if {[string match "*#*" $query]} { regexp -- {^(.*?)#(.*?)$} $query - query tresult } | |
3893 | if {![string match "*<a name=*" $html]} { set walt 1 } | |
3894 | # this is my kludge to allow listing table of contents, to make | |
3895 | # sub-tag lookups easier to see on irc. | |
3896 | if {[string length $results]} { | |
3897 | set tresult "" | |
3898 | set subtag [string tolower $results] | |
3899 | # if the table of contents exists on the page, lets use real world words | |
3900 | # instead of ugly subtags... | |
3901 | if {[string match "*<table id=\"toc*" $html]} { | |
3902 | set ded "\002ToC\002\: " ; set ebcPR "" ; set results "" | |
3903 | # set results [regexp -inline -all -- {<li class="toclevel.*?<span class="toctext">(.*?)</span>} $html] | |
3904 | set results [regexp -inline -all -- {<li class="toclevel.*?href="#(.*?)"} $html] | |
3905 | foreach {junk anchor} $results { lappend anchors $anchor } | |
3906 | #if {![info exists anchors]} { set anchors "toc" } | |
3907 | if {[string tolower $subtag] == "toc"} { | |
3908 | foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] } | |
3909 | append ded [join $new "; "] | |
3910 | set toc 1 | |
3911 | } else { | |
3912 | set ded "" | |
3913 | } | |
3914 | } else { | |
3915 | # table of contents doesnt exist for the page, so we are manually | |
3916 | # going to pull them for the user ourselves. | |
3917 | set ded "\002\(ToC)\002: " ; set ebcPR "" | |
3918 | if {![info exists walt]} { | |
3919 | set results [regexp -inline -all -- {<a name=".*?id="(.+?)"} $html] | |
3920 | } else { | |
3921 | set results [regexp -inline -all -- {<span class="mw-headline".*?id="(.*?)"} $html] | |
3922 | } | |
3923 | foreach {junk anchor} $results { lappend anchors $anchor } | |
3924 | #if {![info exists anchors]} { set anchors "toc" } | |
3925 | if {[string tolower $subtag] == "toc"} { | |
3926 | foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] } | |
3927 | append ded [join $new "; "] | |
3928 | set toc 1 | |
3929 | } else { | |
3930 | set ded "" | |
3931 | } | |
3932 | } | |
3933 | } | |
3934 | ||
3935 | # this is in case an internal redirectToFragment(# ) was found | |
3936 | if {$tresult != ""} { | |
3937 | set subtag $tresult | |
3938 | incr red 1 | |
3939 | if {![info exists walt]} { | |
3940 | set redir "<a name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)" | |
3941 | } else { | |
3942 | if {[string index $tresult 0] == "#"} { set tresult [string range $tresult 1 end] ; set subtag $tresult } | |
3943 | set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)" | |
3944 | } | |
3945 | regexp -nocase "$redir" $html - ded | |
3946 | regsub -all -- {\[<(.*?)>\]} $ded {} ded | |
3947 | regsub -all -- {\[[[:digit:]]+\]} $ded {} ded | |
3948 | regsub -all -- {<th style=.*?</th>} $ded {} ded | |
3949 | regsub -all -- {<table.+?</table>} $ded {} ded | |
3950 | if {$ded == ""} { | |
3951 | return "$::incith::google::error_modes\002Wikipedia Error:\002 redirectToFragment(#${tresult}) not found in body of html @ ${query} . This Wiki Entry is flawed and should be reported for redirect errors.$::incith::google::error_demodes" | |
3952 | } | |
3953 | } | |
3954 | ||
3955 | # This is for our manual #sub-tag search.. | |
3956 | if {![string equal [string tolower $subtag] "toc"] && [string length $subtag] && ![string length $tresult]} { | |
3957 | set subtag [string map {" " "_"} $subtag] | |
3958 | # direct match | |
3959 | if {[info exists anchors]} { | |
3960 | foreach entry $anchors { | |
3961 | if {[string match -nocase $entry $subtag]} { | |
3962 | set stf "true" | |
3963 | incr red 1 | |
3964 | set subtag [string map {" " "_"} $entry] | |
3965 | break | |
3966 | } | |
3967 | } | |
3968 | if {![info exists stf]} { | |
3969 | # starts the anchor | |
3970 | foreach entry $anchors { | |
3971 | if {[string match -nocase "$subtag*" $entry]} { | |
3972 | set stf "true" | |
3973 | incr red 1 | |
3974 | set subtag [string map {" " "_"} $entry] | |
3975 | break | |
3976 | } | |
3977 | } | |
3978 | } | |
3979 | if {![info exists stf]} { | |
3980 | # anywhere in the anchor | |
3981 | foreach entry $anchors { | |
3982 | if {[string match -nocase "*$subtag*" $entry]} { | |
3983 | set stf "true" | |
3984 | incr red 1 | |
3985 | set subtag [string map {" " "_"} $entry] | |
3986 | break | |
3987 | } | |
3988 | } | |
3989 | } | |
3990 | } | |
3991 | if {![info exists stf]} { | |
3992 | return "$::incith::google::error_modes\002Wikipedia Error:\002 Manual #anchor (${subtag}) not found in body of html @ ${query} .$::incith::google::error_demodes" | |
3993 | } | |
3994 | if {![info exists walt]} { | |
3995 | set redir "<a name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)" | |
3996 | } else { | |
3997 | set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)" | |
3998 | } | |
3999 | regexp -nocase "${redir}" $html - ded | |
4000 | regsub -all -- {\[<(.*?)>\]} $ded {} ded | |
4001 | regsub -all -- {\[[[:digit:]]+\]} $ded {} ded | |
4002 | regsub -all -- {<th style=.*?</th>} $ded {} ded | |
4003 | regsub -all -- {<table.+?</table>} $ded {} ded | |
4004 | if {$ded == ""} { | |
4005 | return "$::incith::google::error_modes\002Wikipedia Error:\002 Unknown problem with (${subtag}) found @ ${query} .$::incith::google::error_demodes" | |
4006 | } | |
4007 | } | |
4008 | ||
4009 | # we couldn't chop these earlier because we needed them | |
4010 | # to easily pull our #sub-tag finder above, need to remove | |
4011 | # them here before we go further, because it might upset our checks. | |
4012 | regsub -all -nocase {<span.*?>} $html "" html | |
4013 | regsub -all -nocase {</span>} $html "" html | |
4014 | ||
4015 | # if we have no pre-cut html, let's start the cutting process. | |
4016 | if {$ded == ""} { | |
4017 | regsub -all {<div id="siteNotice">.*?</p></div>} $html {} html | |
4018 | regsub -all {<script type=.*?</script>} $html {} html | |
4019 | regsub -all {<th style=.*?</th>} $html {} html | |
4020 | regsub -all {//<.*?//]]>} $html {} html | |
4021 | ### - trying to clear out those damned wikipedia tables -- | |
4022 | regsub -all -- {<table.+?</table>} $html {} html | |
4023 | regexp -- {<p>(.+?)<h} $html - ded | |
4024 | if {[string match "*</table>*" $ded]} { | |
4025 | regsub -all -- {.+?</table>} $ded {} ded | |
4026 | } elseif {[string match "*<table*" $ded]} { | |
4027 | regsub -all -- {<table.*>.+?} $ded {} ded | |
4028 | } | |
4029 | } | |
4030 | ||
4031 | # if wiki page is non-standard, then this will attempt | |
4032 | # to get at least something from the webpage to display. | |
4033 | if {$ded == ""} { | |
4034 | if {![regexp -- {<p>(.+?)</p>} $html - ded]} { | |
4035 | regexp -- {<p>(.+?)<div class="printfooter">} $html - ded | |
4036 | } | |
4037 | } | |
4038 | #clean up messy parsing. | |
4039 | regsub -all -- {<br>|<br/>} $ded {. } desc | |
4040 | regsub -all -- {\[<(.*?)>\]} $desc {} desc | |
4041 | regsub -all -- {<(.+?)>} $desc {} desc | |
4042 | while {[string match "* *" $desc]} { | |
4043 | regsub -all -- { } $desc " " desc | |
4044 | } | |
4045 | regsub -all -- {\[[[:digit:]]+\]} $desc {} desc | |
4046 | regsub -all -- { , } $desc ", " desc | |
4047 | regsub -all -- { \.} $desc "\." desc | |
4048 | set match [string trim $match] | |
4049 | # if we have a very short description this will grab more. | |
4050 | if {$match != ""} { | |
4051 | if {[string len $desc] < 3} { | |
4052 | regexp -- {<p>.+?<p>(.+?)<h} $html - ded | |
4053 | regsub -all -- {<(.+?)>} $ded { } desc | |
4054 | } | |
4055 | } | |
4056 | # if we still have a tiny description, grab more yet. | |
4057 | if {$match != ""} { | |
4058 | if {[string len $desc] < 3} { | |
4059 | regexp -- {<p>(.+?)<p} $html - ded | |
4060 | regsub -all -- {<(.+?)>} $ded { } desc | |
4061 | } | |
4062 | } | |
4063 | ||
4064 | # clean up messy parsing. | |
4065 | # here we try to sanitize the description | |
4066 | # i'm hoping this works with any language, *crosses fingers* | |
4067 | set desc [string trim $desc] | |
4068 | regsub -all -- {<br>} $desc {. } desc | |
4069 | regsub -all -- {\[<(.*?)>\]} $desc {} desc | |
4070 | regsub -all -- {<(.+?)>} $desc {} desc | |
4071 | while {[string match "* *" $desc]} { | |
4072 | regsub -all -- { } $desc " " desc | |
4073 | } | |
4074 | regsub -all -- {\[[[:digit:]]+\]} $desc {} desc | |
4075 | regsub -all -- { , } $desc ", " desc | |
4076 | regsub -all -- { \.} $desc "\." desc | |
4077 | # regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc | |
4078 | # set our variables so formatting settings work | |
4079 | if {$subtag != ""} { | |
4080 | #regsub -- {" id="top".*?$} $subtag "" subtag | |
4081 | set subtag "#${subtag}" | |
4082 | } | |
4083 | set link $query | |
4084 | if {![info exists toc]} { set desc "[descdecode [string range $desc 0 [expr 360 * $incith::google::wiki_lines]]]" } | |
4085 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
4086 | if {[info exists link]} { set link "$incith::google::link_modes[string trim "$link$subtag"]$incith::google::link_demodes" } | |
4087 | if {[info exists match]} { set match "$incith::google::total_modes[string trim $match]$incith::google::total_demodes" } | |
4088 | # after stripping excessive tags if our description is | |
4089 | # reduced to nothing, let's lie and say it was too much to parse :) | |
4090 | if {$match != "" && $desc == ""} { | |
4091 | regexp -- {<h[0-9].*?>.*?h[0-9]>.*?<ul>(.*?)</ul>} $html - desc | |
4092 | set desc [string trim $desc] | |
4093 | regsub -all -- {<br>} $desc {. } desc | |
4094 | regsub -all -- {\[<(.*?)>\]} $desc {} desc | |
4095 | regsub -all -- {<(.+?)>} $desc {} desc | |
4096 | while {[string match "* *" $desc]} { | |
4097 | regsub -all -- { } $desc " " desc | |
4098 | } | |
4099 | regsub -all -- {\[[[:digit:]]+\]} $desc {} desc | |
4100 | regsub -all -- { , } $desc ", " desc | |
4101 | regsub -all -- { \.} $desc "\." desc | |
4102 | set desc "${::incith::google::desc_modes}$desc${::incith::google::desc_demodes}" | |
4103 | } | |
4104 | # if we have no description, then let's decide what to do. | |
4105 | if {$desc == ""} { | |
4106 | regexp -- {<p>(.+?)</p>} $html - match | |
4107 | if {$match != ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${subtag}$::incith::google::error_demodes" } | |
4108 | if {$match == ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 Sorry, no search results found.$::incith::google::error_demodes" } | |
4109 | break | |
4110 | } | |
4111 | # regular output displayed. | |
4112 | if {$match != ""} { | |
4113 | if {$red > 0} { | |
4114 | set output "\002[descdecode ${match}]\002${incith::google::seperator}${desc}$::incith::google::break${link} $::incith::google::total_modes\[${red} Redirect\(s\)\]$incith::google::total_demodes" | |
4115 | } else { | |
4116 | set output "\002[descdecode ${match}]\002${incith::google::seperator}${desc}$::incith::google::break${link}" | |
4117 | } | |
4118 | } else { | |
4119 | if {$red > 0} { | |
4120 | set output "${desc}$::incith::google::break${link} $::incith::google::total_modes\[${red} Redirect\(s\)\]$::incith::google::total_demodes" | |
4121 | } else { | |
4122 | set output "${desc}$::incith::google::break${link}" | |
4123 | } | |
4124 | } | |
4125 | return $output | |
4126 | } | |
4127 | ||
4128 | ||
4129 | # WIKIMEDIA | |
4130 | # fetches wiki info from sites other than wikipedia.org | |
4131 | # -speechless supplied | |
4132 | # | |
4133 | proc wikimedia {input} { | |
4134 | global incithcharset | |
4135 | ; set output "" ; set ded "" ; set match "" ; set redir "" ; set country "" ; set dec "" | |
4136 | ; set query "" ; set titem "" ; set ebcPR "" ; set results "" ; set tresult "" ; set red 0 | |
4137 | ; set subtag "" ; set no_search "" ; set force 0 ; set fr 0 ; set natch "" ; set region "" | |
4138 | ; set regional "" | |
4139 | ||
4140 | # make it so people can search their wiki in proper encoding.... | |
4141 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input | |
4142 | if {$country == ""} { | |
4143 | set country "${incith::google::wikimedia_site}" | |
4144 | } | |
4145 | regexp -nocase -- {(.*)\@(.*)} $country - country region | |
4146 | # allow full search if desired | |
4147 | if {[string match "+" [string range $region 0 0]]} { | |
4148 | set region [string range $region 1 end] | |
4149 | set regional $region | |
4150 | } | |
4151 | ||
4152 | # this is my input encoding hack, this will convert input before it goes | |
4153 | # out to be queried. | |
4154 | if {$incith::google::encoding_conversion_input > 0 && $region != ""} { | |
4155 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${region}:*"]] :] 1] | |
4156 | } elseif {$incith::google::encoding_conversion_input > 0 && $country != ""} { | |
4157 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1] | |
4158 | } else { set encoding_found "" } | |
4159 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
4160 | set input [encoding convertfrom $encoding_found $input] | |
4161 | } | |
4162 | ||
4163 | regsub -all -- {_} $input { } input | |
4164 | regexp -- {^(.+?)\#(.+?)$} $input - input results | |
4165 | regsub -all -- { } $results { } results | |
4166 | set input [urlencode $input 0 "utf-8"] | |
4167 | set results [string map {.20 _} [urlencode [string trim $results] 1 "utf-8"]] | |
4168 | ||
4169 | # force is for those times you want to MAKE | |
4170 | # it directly go to a location, you use force | |
4171 | # by making first letter of your search term a . | |
4172 | set force [regexp -nocase -- {^\.(.+?)$} $input - input] | |
4173 | if {$force == 1} { | |
4174 | #set query "http://${country}/index.php?search=${input}&go=Go" | |
4175 | set query "http://${country}/index.php/${input}" | |
4176 | #set match "/index.php?search=${input}&go=Go" | |
4177 | #set match "/index.php/${input}" | |
4178 | } else { | |
4179 | set query "http://${country}/index.php?title=Special%3ASearch&search=${input}&fulltext=Search" | |
4180 | } | |
4181 | # pre-load page to get damn redirects out of the way | |
4182 | # this is stupid i agree, but let's not think about it. | |
4183 | ||
4184 | # beware, changing the useragent will result in differently formatted html from Google. | |
4185 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
4186 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
4187 | # stole this bit from rosc2112 on egghelp forums | |
4188 | # borrowed is a better term, all procs eventually need this error handler. | |
4189 | catch {set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 5]]} error | |
4190 | ||
4191 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
4192 | return "${::incith::google::error_modes}Socket Error accessing '${query}' .. Does it exist?${::incith::google::error_demodes}" | |
4193 | } | |
4194 | if { [::http::status $http] == "timeout" } { | |
4195 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
4196 | } | |
4197 | ||
4198 | # CHECK CHECK | |
4199 | upvar #0 $http state | |
4200 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
4201 | set html [ungzip [::http::data $http] $state(meta)] | |
4202 | # REDIRECT | |
4203 | if {[string match "*${redir}*" "302|301" ]} { | |
4204 | foreach {name value} $state(meta) { | |
4205 | if {[regexp -nocase ^location$ $name]} { | |
4206 | catch {set http [::http::geturl "$v" -query "" -headers $::incith_hdr -timeout [expr 1000 * 10]]} error | |
4207 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
4208 | return "${::incith::google::error_modes}Socket Error accessing '${query}' .. Does it exist?${::incith::google::error_demodes}" | |
4209 | } | |
4210 | if { [::http::status $http] == "timeout" } { | |
4211 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
4212 | } | |
4213 | upvar #0 $http state | |
4214 | set html [ungzip [::http::data $http] $state(meta)] | |
4215 | set query $value | |
4216 | incr red | |
4217 | } | |
4218 | } | |
4219 | } | |
4220 | ::http::cleanup $http | |
4221 | ||
4222 | # are we redirected to another page so soon? | |
4223 | # usually this is the case, if our original search page wants | |
4224 | # to search using another method, so let's accomodate it... | |
4225 | regexp -nocase -- {document has moved.+?<a href="(.+?)">} $html - match | |
4226 | regexp -nocase -- {Did you mean to type.+?<a href="(.+?)">} $html - match | |
4227 | ||
4228 | # if we are redirected, then we can modify our url | |
4229 | # to include the redirect as our new destination site. | |
4230 | if {$match != ""} { | |
4231 | incr red 1 ; set fr 1 | |
4232 | set query $match | |
4233 | regsub -all "&" $query {\&} query | |
4234 | regexp -- {http\:\/\/(.+?)/index.php} $match - country | |
4235 | } | |
4236 | ||
4237 | # 1st load of webpage - this is the only part which has error control | |
4238 | # this is where we load the search page to find an exact match or most relevant. | |
4239 | # we will also be able to detect bad user input in the form of socket errors. | |
4240 | ||
4241 | # beware, changing the useragent will result in differently formatted html from Google. | |
4242 | if {$fr == 1} { | |
4243 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
4244 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
4245 | set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]] | |
4246 | upvar #0 $http state | |
4247 | set html [ungzip [::http::data $http] $state(meta)] | |
4248 | ::http::cleanup $http | |
4249 | } | |
4250 | ||
4251 | # generic pre-parsing | |
4252 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
4253 | regsub -all -nocase {<font.+?>} $html "" html | |
4254 | regsub -all -nocase {</font>} $html "" html | |
4255 | regsub -all -nocase {<span.*?>} $html "" html | |
4256 | regsub -all -nocase {</span>} $html "" html | |
4257 | regsub -all -nocase {<input.+?>} $html "" html | |
4258 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
4259 | regsub -all "\t" $html " " html | |
4260 | regsub -all "\n" $html " " html | |
4261 | regsub -all "\r" $html " " html | |
4262 | regsub -all "\v" $html " " html | |
4263 | regsub -all "</li>" $html ". " html | |
4264 | regsub -all ";;>" $html "" html | |
4265 | regsub {<div class="floating_object".*?>.*?</div>} $html "" html | |
4266 | ||
4267 | if {$html == ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 No html to parse.$::incith::google::error_demodes" } | |
4268 | ||
4269 | # this is my kludge, enjoy it | |
4270 | if {$force == 0} { | |
4271 | # see if our direct result is available and if so, lets take it | |
4272 | if {![regexp -- {<div id="contentSub"><p>.*?<a href="((?!#).+?)".*?title} $html - match]} { | |
4273 | regexp -nocase -- {<div class='searchresults'>.*?<a href="(.*?)".*?(class=|title=|style=)} $html - match | |
4274 | } | |
4275 | if {[string match -nocase "*action=edit*" $match]} { set match "" } | |
4276 | # otherwise we only care about top result | |
4277 | # this is the _only_ way to parse mediawiki, sorry. | |
4278 | if {$match == ""} { | |
4279 | regexp -- {<li><a href="(.*?)"} $html - match | |
4280 | if {$match == ""} { | |
4281 | if {![regexp -- {<li><div class='mw-search.*?'><a href="(.*?)"} $html - match]} { | |
4282 | regexp -- {<li style.*?><a href="(.+?)"} $html - match | |
4283 | } | |
4284 | } | |
4285 | } | |
4286 | # this will strip double domain entries from our country if it exists | |
4287 | # on our anchor. | |
4288 | if {$incith::google::wiki_domain_detect != 0} { | |
4289 | if {[string match -nocase [lindex [split $country "/"] end] [lindex [split $match "/"] 1]]} { | |
4290 | set country [join [lrange [split $country "/"] 0 end-1] "/"] | |
4291 | } | |
4292 | } elseif {[string match -nocase "*/wiki*" $country]} { | |
4293 | regsub -- {/wiki} $country {} country | |
4294 | } | |
4295 | ||
4296 | ||
4297 | # at this point we can tell if there was any match, so let's not even bother | |
4298 | # going further if there wasn't a match, this pulls the 'no search etc' found. | |
4299 | # this can be in any language. | |
4300 | if {$match == ""} { | |
4301 | # these are for 'no search results' or similar message | |
4302 | # these can be in any language. | |
4303 | # if {[regexp -- {</form>.*?<p>(.+?)(<p><b>|</p><hr)} $html - match]} { regsub -all -- {<(.+?)>} $match {} match } | |
4304 | if {$match == ""} { | |
4305 | if {[regexp -- {<div class='searchresults'>(.+?)</p>} $html - match]} { | |
4306 | regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match | |
4307 | } else { | |
4308 | if {[regexp -- {<div id="contentSub">(.+?)<form id=} $html - match]} { | |
4309 | regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match | |
4310 | regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match | |
4311 | regsub -- {<div id.*?>} $match "" match | |
4312 | regsub -- {</a></div>} $match "?" match | |
4313 | regsub -- {</div>} $match "" match | |
4314 | regsub -- {\[Index\]} $match "" match | |
4315 | regsub -- {<span.*?/span>} $match "" match | |
4316 | regsub -- { \(<.*?>\)} $match ". " match | |
4317 | if {[string match "*<!--*" $match]} { | |
4318 | regexp -- {<li class="normal">.*?</p><p>(.*?)</p>} $html - match | |
4319 | } | |
4320 | } | |
4321 | } | |
4322 | } | |
4323 | # this is our last error catch, this can grab the | |
4324 | # 'wikimedia cannot search at this time' message | |
4325 | # this can be in any language. | |
4326 | if {[string len $match] < 3} { regexp -- {<center><b>(.+?)</b>} $html - match } | |
4327 | if {$match == ""} { | |
4328 | regsub -all -- { } $results {_} results | |
4329 | if {$results != ""} { set results "#${results}" } | |
4330 | return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${results}$::incith::google::error_demodes" | |
4331 | } | |
4332 | # might be tags since we allowed any language here we cut them out | |
4333 | regsub -all -- {<(.+?)>} $match "" match | |
4334 | if {$region == ""} { | |
4335 | return "$::incith::google::desc_modes[utf8encodefix $country [descdecode ${match}]]$::incith::google::desc_demodes" | |
4336 | } else { | |
4337 | return "$::incith::google::desc_modes[utf8encodefix $region [descdecode ${match}]]$::incith::google::desc_demodes" | |
4338 | } | |
4339 | } | |
4340 | ||
4341 | # this lets us easily change our internal sub redirected wiki link. | |
4342 | #if {$regional != ""} { | |
4343 | # regsub -- {/wiki/} $match "/$region/" match | |
4344 | #} | |
4345 | ||
4346 | # we assume here we found another page to traverse in our search. | |
4347 | if {![string match "*http*" $match]} { set query "http://${country}${match}" } { set query $match } | |
4348 | ||
4349 | # 2nd load of webpage - this has no error checking what-so-ever | |
4350 | # here is where we pluck the link to the exact match, or the most relevant 'top' link. | |
4351 | # or in the case of redirects, to other pages, we will handle that here as well. | |
4352 | ||
4353 | # beware, changing the useragent will result in differently formatted html from Google. | |
4354 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
4355 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
4356 | set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]] | |
4357 | upvar #0 $http state ; set ncode [http::ncode $http] ; set metas $state(meta) ; set value "" | |
4358 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
4359 | # this is the output encoding hack. | |
4360 | if {$incith::google::encoding_conversion_output > 0} { | |
4361 | if {$region != ""} { | |
4362 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1] | |
4363 | } else { | |
4364 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
4365 | } | |
4366 | } | |
4367 | ||
4368 | set html [ungzip [::http::data $http] $state(meta)] | |
4369 | ||
4370 | if {$incith::google::debug > 0} { | |
4371 | putserv "privmsg $incith::google::debugnick :\002url:\002 $query \002charset:\002 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset] \002\037encode_string:\037\002 $encoding_found" | |
4372 | } | |
4373 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
4374 | set ::incithcharset $encoding_found | |
4375 | set html [incithencode $html] | |
4376 | } | |
4377 | ::http::cleanup $http | |
4378 | #correct the html, remove shitty tags | |
4379 | # generic pre-parsing | |
4380 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
4381 | regsub -all -nocase {<font.+?>} $html "" html | |
4382 | regsub -all -nocase {</font>} $html "" html | |
4383 | regsub -all -nocase {<input.+?>} $html "" html | |
4384 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
4385 | regsub -all "\t" $html " " html | |
4386 | regsub -all "\n" $html " " html | |
4387 | regsub -all "\r" $html " " html | |
4388 | regsub -all "\v" $html " " html | |
4389 | regsub -all "</li>" $html ". " html | |
4390 | regsub -all ";;>" $html "" html | |
4391 | if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} { | |
4392 | regsub -all -nocase {(?:<b>|</b>)} $html "\002" html | |
4393 | } | |
4394 | set match "" | |
4395 | ||
4396 | # this is where my kludge ends ;) | |
4397 | # this is if there is no text on a special page. | |
4398 | } else { | |
4399 | if {[regexp -nocase -- {<div class="noarticletext">(.+?)</div>} $html - no_search]} { | |
4400 | regsub -all -- {<(.+?)>} $no_search {} no_search | |
4401 | while {[string match "* *" $no_search]} { | |
4402 | regsub -all -- { } $no_search " " no_search | |
4403 | } | |
4404 | return "$::incith::google::desc_modes$no_search$::incith::google::desc_demodes" | |
4405 | } | |
4406 | } | |
4407 | ||
4408 | if {[string match 30* $ncode]} { | |
4409 | foreach {name value} $metas { | |
4410 | if {[regexp -nocase ^location$ $name]} { | |
4411 | set go $value | |
4412 | } | |
4413 | } | |
4414 | } | |
4415 | # are we redirected to another page? if so, let's go there | |
4416 | if {[regexp -- {alt="#REDIRECT ".+?<a href="(.+?)" title="} $html - match] || [info exists go]} { | |
4417 | if {$match != ""} { | |
4418 | incr red 1 | |
4419 | set query "http://${country}${match}" | |
4420 | } else { set query $go } | |
4421 | ||
4422 | # 3rd load of webpage - this has no error checking what-so-ever | |
4423 | # here is our final webpage, this is hopefully what the user was looking for. | |
4424 | ||
4425 | # beware, changing the useragent will result in differently formatted html from Google. | |
4426 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
4427 | set http [::http::config -useragent $ua -urlencoding "utf-8"] | |
4428 | set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]] | |
4429 | upvar #0 $http state | |
4430 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
4431 | # this is the output encoding hack. | |
4432 | if {$incith::google::encoding_conversion_output > 0} { | |
4433 | if {$region != ""} { | |
4434 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1] | |
4435 | } else { | |
4436 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
4437 | } | |
4438 | } | |
4439 | ||
4440 | set html [ungzip [::http::data $http] $state(meta)] | |
4441 | ||
4442 | if {$incith::google::debug > 0} { | |
4443 | putserv "privmsg $incith::google::debugnick :\002url:\002 $query \002charset:\002 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset] \002\037encode_string:\037\002 $encoding_found" | |
4444 | } | |
4445 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
4446 | set ::incithcharset $encoding_found | |
4447 | set html [incithencode $html] | |
4448 | } | |
4449 | ::http::cleanup $http | |
4450 | #correct the html, remove shitty tags | |
4451 | # generic pre-parsing | |
4452 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
4453 | regsub -all -nocase {<font.+?>} $html "" html | |
4454 | regsub -all -nocase {</font>} $html "" html | |
4455 | regsub -all -nocase {<input.+?>} $html "" html | |
4456 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
4457 | regsub -all "\t" $html " " html | |
4458 | regsub -all "\n" $html " " html | |
4459 | regsub -all "\r" $html " " html | |
4460 | regsub -all "\v" $html " " html | |
4461 | regsub -all "</li>" $html ". " html | |
4462 | regsub -all ";;>" $html "" html | |
4463 | if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} { | |
4464 | regsub -all -nocase {(?:<b>|</b>)} $html "\002" html | |
4465 | } | |
4466 | } | |
4467 | ||
4468 | set match "" | |
4469 | # give results an output header with result tally. | |
4470 | regexp -- {<title>(.+?)\s\-\s.+?</title>} $html - match | |
4471 | # see if page has a redirect to fragment | |
4472 | if {![string length $results]} { regexp -- {redirectToFragment\("(\#.+?)"\)} $html - tresult } | |
4473 | if {![string match "*<a name=*" $html]} { set walt 1 } | |
4474 | # this is my kludge to allow listing table of contents, to make | |
4475 | # sub-tag lookups easier to see on irc. | |
4476 | if {[string length $results] || [string length $tresult]} { | |
4477 | if {[string length $results]} { set tresult "" } | |
4478 | set subtag [string tolower $results] | |
4479 | # if the table of contents exists on the page, lets use real world words | |
4480 | # instead of ugly subtags... | |
4481 | if {[string match "*<table id=\"toc*" $html]} { | |
4482 | set ded "\002ToC\002\: " ; set ebcPR "" ; set results "" | |
4483 | # set results [regexp -inline -all -- {<li class="toclevel.*?<span class="toc.*?">(.*?)</span>} $html] | |
4484 | set results [regexp -inline -all -- {<li class="toclevel.*?href="#(.*?)"} $html] | |
4485 | set anchors [list "toc"] | |
4486 | foreach {junk anchor} $results { lappend anchors $anchor } | |
4487 | if {[string tolower $subtag] == "toc"} { | |
4488 | foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] } | |
4489 | append ded [join $new "; "] | |
4490 | set toc 1 ; set loop 1 | |
4491 | } else { | |
4492 | set ded "" | |
4493 | } | |
4494 | } else { | |
4495 | # table of contents doesnt exist for the page, so we are manually | |
4496 | # going to pull them for the user ourselves. | |
4497 | set ded "\002\(ToC)\002: " ; set ebcPR "" | |
4498 | if {![info exists walt]} { | |
4499 | set results [regexp -inline -all -- {<a name=".*?id="(.+?)"} $html] | |
4500 | } else { | |
4501 | set results [regexp -inline -all -- {<span class="mw-headline".*?id="(.*?)"} $html] | |
4502 | } | |
4503 | set anchors [list "toc"] | |
4504 | foreach {junk anchor} $results { lappend anchors $anchor } | |
4505 | #if {![info exists anchors]} { set anchors "toc" } | |
4506 | if {[string tolower $subtag] == "toc"} { | |
4507 | foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] } | |
4508 | append ded [join $new "; "] | |
4509 | set toc 1 ; set loop 1 | |
4510 | } else { | |
4511 | set ded "" | |
4512 | } | |
4513 | } | |
4514 | } | |
4515 | ||
4516 | # this is in case an internal redirectToFragment(# ) was found | |
4517 | if {$tresult != ""} { | |
4518 | #set subtag $tresult | |
4519 | incr red 1 | |
4520 | if {![info exists walt]} { | |
4521 | set redir "name=\"${tresult}\".*?>(.+?)(<a name|</table>|\<\!\-)" | |
4522 | } else { | |
4523 | set tresult [string range $tresult 1 end] | |
4524 | set redir "<span class=\"mw-headline\" id=\"${tresult}.*?>(.+?)(<span|</table>|\<\!\-)" | |
4525 | } | |
4526 | regexp -nocase "$redir" $html - ded | |
4527 | regsub -all -- {\[<(.*?)>\]} $ded {} ded | |
4528 | regsub -all -- {\[[[:digit:]]+\]} $ded {} ded | |
4529 | regsub -all -- {<table.+?</table>} $ded {} ded | |
4530 | if {$ded == ""} { | |
4531 | return "$::incith::google::error_modes\002Wikimedia Error:\002 redirectToFragment(#${tresult}) not found in body of html @ ${query} . This Wiki Entry is flawed and should be reported for redirect errors.$::incith::google::error_demodes" | |
4532 | } | |
4533 | } | |
4534 | ||
4535 | # This is for our manual #sub-tag search.. | |
4536 | if {![string equal [string tolower $subtag] "toc"] && [string length $subtag]} { | |
4537 | set subtag [string map {" " "_"} $subtag] | |
4538 | # direct match | |
4539 | if {[info exists anchors]} { | |
4540 | foreach entry $anchors { | |
4541 | if {[string match -nocase $entry $subtag]} { | |
4542 | set stf "true" | |
4543 | incr red 1 | |
4544 | set subtag [string map {" " "_"} $entry] | |
4545 | break | |
4546 | } | |
4547 | } | |
4548 | if {![info exists stf]} { | |
4549 | # starts the anchor | |
4550 | foreach entry $anchors { | |
4551 | if {[string match -nocase "$subtag*" $entry]} { | |
4552 | set stf "true" | |
4553 | incr red 1 | |
4554 | set subtag [string map {" " "_"} $entry] | |
4555 | break | |
4556 | } | |
4557 | } | |
4558 | } | |
4559 | if {![info exists stf]} { | |
4560 | # anywhere in the anchor | |
4561 | foreach entry $anchors { | |
4562 | if {[string match -nocase "*$subtag*" $entry]} { | |
4563 | set stf "true" | |
4564 | incr red 1 | |
4565 | set subtag [string map {" " "_"} $entry] | |
4566 | break | |
4567 | } | |
4568 | } | |
4569 | } | |
4570 | } | |
4571 | if {![info exists stf]} { | |
4572 | return "$::incith::google::error_modes\002Wikimedia Error:\002 Manual #anchor (${subtag}) not found in body of html @ ${query} .$::incith::google::error_demodes" | |
4573 | } | |
4574 | if {![info exists walt]} { | |
4575 | set redir "name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)" | |
4576 | } else { | |
4577 | set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)" | |
4578 | } | |
4579 | regexp -nocase "${redir}" $html - ded | |
4580 | regsub -all -- {\[<(.*?)>\]} $ded {} ded | |
4581 | regsub -all -- {\[[[:digit:]]+\]} $ded {} ded | |
4582 | regsub -all -- {<th style=.*?</th>} $ded {} ded | |
4583 | regsub -all -- {<table.+?</table>} $ded {} ded | |
4584 | if {$ded == ""} { | |
4585 | return "$::incith::google::error_modes\002Wikimedia Error:\002 Unknown problem with (${subtag}) found @ ${query} .$::incith::google::error_demodes" | |
4586 | } | |
4587 | } | |
4588 | ||
4589 | # we couldn't chop these earlier because we needed them | |
4590 | # to easily pull our #sub-tag finder above, need to remove | |
4591 | # them here before we go further, because it might upset our checks. | |
4592 | regsub -all -nocase {<span.*?>} $html "" html | |
4593 | regsub -all -nocase {</span>} $html "" html | |
4594 | ||
4595 | # if we have no pre-cut html, let's start the cutting process. | |
4596 | if {$ded == ""} { | |
4597 | regexp -- {<h1.*?>.*?<p>(.+?)<h} $html - ded | |
4598 | ### - trying to clear out those damned wikipedia tables -- | |
4599 | regsub -all -- {<table.+?</table>} $ded {} ded | |
4600 | if {[string match "*</table>*" $ded]} { | |
4601 | regsub -all -- {.+?</table>} $ded {} ded | |
4602 | } elseif {[string match "*<table*" $ded]} { | |
4603 | regsub -all -- {<table.*>.+?} $ded {} ded | |
4604 | } | |
4605 | } | |
4606 | ||
4607 | # if wiki page is non-standard, then this will attempt | |
4608 | # to get at least something from the webpage to display. | |
4609 | if {$ded == ""} { | |
4610 | regexp -- {<p>(.+?)<div class="printfooter">} $html - ded | |
4611 | } | |
4612 | #clean up messy parsing. | |
4613 | regsub -all -- {<br>|<br/>} $ded {. } desc | |
4614 | #regsub -all -- {">:alpha:\]} $desc {} desc | |
4615 | regsub -all -- {\[<(.*?)>\]} $desc {} desc | |
4616 | regsub -all -- {<(.+?)>} $desc {} desc | |
4617 | while {[string match "* *" $desc]} { | |
4618 | regsub -all -- { } $desc " " desc | |
4619 | } | |
4620 | regsub -all -- {\[[[:digit:]]+\]} $desc {} desc | |
4621 | regsub -all -- { , } $desc ", " desc | |
4622 | regsub -all -- { \.} $desc "\." desc | |
4623 | regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc | |
4624 | set match [string trim $match] | |
4625 | # if we have a very short description this will grab more. | |
4626 | if {[string len $desc] < 3} { | |
4627 | if {[regexp -- {<p>.+?<p>(.+?)<h} $html - desc]} { set desc [cleans $desc] } | |
4628 | } | |
4629 | if {[string len $desc] < 3} { | |
4630 | if {[regexp -- {<p>(.+?)<p} $html - desc]} { set desc [cleans $desc] } | |
4631 | } | |
4632 | #if {[string length $tresult]} { set subtag $tresult } | |
4633 | # set our variables so formatting settings work | |
4634 | if {$subtag != ""} { | |
4635 | regsub -- {" id="top".*?$} $subtag "" subtag | |
4636 | set subtag "#${subtag}" | |
4637 | } | |
4638 | set link $query | |
4639 | if {![info exists loop]} { set desc "[string range $desc 0 [expr 360 * $incith::google::wiki_lines]]" } | |
4640 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim [descdecode $desc]]$incith::google::desc_demodes" } | |
4641 | if {[info exists match]} { set match "$incith::google::total_modes[string trim $match]$incith::google::total_demodes" } | |
4642 | if {[info exists link]} { set link "$incith::google::link_modes[string trim "$link$subtag"]$incith::google::link_demodes" } | |
4643 | # after stripping excessive tags if our description is | |
4644 | # reduced to nothing, let's lie and say it was too much to parse :) | |
4645 | ||
4646 | # if we have no description, then let's decide what to do. | |
4647 | if {$desc == ""} { | |
4648 | regexp -- {<p>(.+?)</p>} $html - match | |
4649 | if {$match != ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${subtag}$::incith::google::error_demodes" } | |
4650 | if {$match == ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 Sorry, no search results found.$::incith::google::error_demodes" } | |
4651 | break | |
4652 | } | |
4653 | ||
4654 | # regular output displayed. | |
4655 | if {$match != ""} { | |
4656 | if {$red > 0} { | |
4657 | set output "\002[descdecode ${match}]\002${incith::google::seperator}[descdecode ${desc}]$incith::google::break${link} $incith::google::total_modes\[${red} Redirect\(s\)\]$::incith::google::total_demodes" | |
4658 | } else { | |
4659 | set output "\002[descdecode ${match}]\002${incith::google::seperator}[descdecode ${desc}]$::incith::google::break${link}" | |
4660 | } | |
4661 | } else { | |
4662 | if {$red > 0} { | |
4663 | set output "${desc}$::incith::google::break${link} $::incith::google::total_modes\[${red} Redirect\(s\)\]$::incith::google::total_demodes" | |
4664 | } else { | |
4665 | set output "${desc}$::incith::google::break${link}" | |
4666 | } | |
4667 | } | |
4668 | return $output | |
4669 | } | |
4670 | ||
4671 | # wikipedia/wikimedia support | |
4672 | # CLEANS | |
4673 | # | |
4674 | proc cleans {input} { | |
4675 | # clean up messy parsing. | |
4676 | # here we try to sanitize the description | |
4677 | # i'm hoping this works with any language, *crosses fingers* | |
4678 | set desc [string trim $input] | |
4679 | regsub -all -- {<br>} $desc {. } desc | |
4680 | regsub -all -- {\[<(.*?)>\]} $desc {} desc | |
4681 | regsub -all -- {<(.+?)>} $desc {} desc | |
4682 | while {[string match "* *" $desc]} { | |
4683 | regsub -all -- { } $desc " " desc | |
4684 | } | |
4685 | regsub -all -- {\[[[:digit:]]+\]} $desc {} desc | |
4686 | regsub -all -- { , } $desc ", " desc | |
4687 | regsub -all -- { \.} $desc "\." desc | |
4688 | regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc | |
4689 | return $desc | |
4690 | } | |
4691 | ||
4692 | # EBAY | |
4693 | # fetches search results from ebay for auctions closest to completion. | |
4694 | # -speechless supplied | |
4695 | # | |
4696 | proc ebay {input} { | |
4697 | # lots of variables, keeping them clean is important. | |
4698 | ; set results 0 ; set output "" ; set titem "" ; set tresult "" ; set ebcSP "" | |
4699 | ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR "" ; set ebcTim "" ; set ebcShpNew "" | |
4700 | ; set ebcCheck "" ; set no_search "" ; set auctions "" ; set ebcBid2 "" ; set ebcStr "" | |
4701 | ||
4702 | # this isn't global, so we need to keep ctry (country) here | |
4703 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy | |
4704 | if {$titem == ""} { | |
4705 | set titem "${incith::google::ebay_country}" | |
4706 | } | |
4707 | ||
4708 | # fetch the html | |
4709 | set html [fetch_html $input 25] | |
4710 | if {$html == ""} { | |
4711 | return "$::incith::google::error_modes\002Ebay Error: No html to parse.$::incith::google::error_demodes" | |
4712 | } | |
4713 | ||
4714 | # user input causing errors? | |
4715 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
4716 | regsub {(.+?)\|} $html {} html | |
4717 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
4718 | } | |
4719 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
4720 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
4721 | } | |
4722 | ||
4723 | # set up an ebay results header for results to be appended to as $output | |
4724 | if {![regexp -- {class="sectiontitle">([0-9 Â .,]+)\002.*?<h2 class="standard ens} $html - tresult]} { | |
4725 | if {![regexp -- {<div class="count">([0-9 Â .,]+) } $html - tresult]} { | |
4726 | if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - tresult]} { | |
4727 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s(.*?)\s} $html - tresult auctions]} { | |
4728 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s(.*?)\s} $html - tresult auctions]} { | |
4729 | regexp -nocase {<div id="v.*?" class="fpcc">.*?\s(.+?)\s.*?\:\s*(.+?)\s} $html - auctions tresult | |
4730 | set tresult "[join [scan $tresult "%d%d"] ""]" | |
4731 | } | |
4732 | } | |
4733 | } | |
4734 | } | |
4735 | } | |
4736 | # no_results line in any language. | |
4737 | if {[regexp -- {<div class="msg msg-alert">(.+?)</div>} $html - no_search]} { | |
4738 | if {[regexp -- {div class="msg msg-alert.+?</div>.+?"msg msg-alert">(.+?)</div>} $html - more]} { | |
4739 | append no_search " $more" | |
4740 | } | |
4741 | regsub -all {<(.+?)>} $no_search "" no_search | |
4742 | } else { | |
4743 | if {![regexp -- {class="sectiontitle">(.+?)</h2><h2 class="standard ens"> } $html - no_search]} { | |
4744 | if {![regexp -- {<div class="count">(.+?)(?:</script>|</div>)} $html - no_search]} { | |
4745 | if {![regexp -- {<div class="toplne"><div class="msg">(.+?)</div>} $html - no_search]} { | |
4746 | regexp -- {<div class="cnt">(.*?)</div>} $html - no_search | |
4747 | } | |
4748 | } | |
4749 | } | |
4750 | } | |
4751 | ||
4752 | # santize our no_search results found error message | |
4753 | # may need to use it very shortly if we have no results | |
4754 | if {$no_search != ""} { | |
4755 | #if {[regexp -- {<div class="suggestions".+?<ul><li><div>(.+?)</li>} $html - ebcStr]} { | |
4756 | # regsub -all -- {<(.+?)>} $ebcStr {} ebcStr | |
4757 | # set ebcStr "${ebcStr}. " | |
4758 | #} | |
4759 | #regexp {(^.+?)document.write} $no_search - no_search | |
4760 | #regsub -all -- {<(.+?)>} $no_search {} no_search | |
4761 | #set no_search "${ebcStr}[string trim $no_search]" | |
4762 | } else { | |
4763 | if {$tresult == 0 && $no_search == ""} { | |
4764 | set no_search "eBay error." | |
4765 | } | |
4766 | } | |
4767 | ||
4768 | # bids in any language | |
4769 | if {![regexp -- {<td class="ebcBid">(.+?)</td>} $html {} ebcSP]} {set ebcsp ""} | |
4770 | ||
4771 | # format output according to variables. | |
4772 | if {$incith::google::total_results != 0} { | |
4773 | regexp -- {<option value="1" selected="selected">(.+?)</option>} $html - auctions | |
4774 | set output "$::incith::google::total_modes\002[string trim ${tresult}]\002 [string trim $auctions]$::incith::google::total_demodes${incith::google::seperator}" | |
4775 | if {$incith::google::bold_descriptions == 0} { | |
4776 | regsub -all -- "\002" $output {} output | |
4777 | } | |
4778 | } | |
4779 | ||
4780 | # parse the html | |
4781 | while {$results < $incith::google::ebay_results} { | |
4782 | # these CANNOT be tied together, some results appear in different | |
4783 | # order, so always leave these spread out in a mess... | |
4784 | if {![regexp -nocase {<td class="dtl"><div class="ttl">(.*?)</a></td>} $html - line]} { | |
4785 | if {![regexp -nocase {<table class="lview nol">.*?class="details.*?">(.+?)</table>} $html - line]} { | |
4786 | if {![regexp -nocase {<table class="nol">.*?class="details.*?">(.+?)</table>} $html - line]} { | |
4787 | if {![regexp -nocase {<h3 class="ens fontnormal">(.+?)class="ebRight"} $html - line]} { | |
4788 | if {![regexp -nocase {<td class="details">(.*?)</a></td>} $html - line]} { | |
4789 | set line "" | |
4790 | } else { regsub -nocase {<td class="details">.*?</a></td>} $html {} html } | |
4791 | } else { regsub {<h3 class="ens fontnormal">.+?class="ebRight"} $html {} html } | |
4792 | } else { regsub {<table class="nol">.+?</table>} $html {} html } | |
4793 | } else { regsub {<table class="lview nol">.+?</table>} $html {} html } | |
4794 | } else { regsub -nocase {<td class="dtl"><div class="ttl">.*?</a></td>} $html {} html } | |
4795 | # name & url | |
4796 | if {![regexp -nocase {href=".*?ebay.*?/.*?/(.*?)\?pt.*?>(.*?)</a>} $line - ebcU ebcI]} { | |
4797 | if {![regexp -nocase {<a href=".+?QQitem(.+?)QQ.+?">.+?<a href=".*?">(.+?)</a>} $line - ebcU ebcI]} { | |
4798 | regexp -nocase {<a href="http://cgi.ebay.*?/.*?/(.*?)\?cmd=.*?>(.*?)</a>} $line - ebcU ebcI | |
4799 | } | |
4800 | } | |
4801 | # bid | |
4802 | if {[regexp -nocase {class="bids.*?">(.+?)</td>} $line - ebcBid]} { | |
4803 | if {[regexp {<div.*?>(.+?)</div><img src=".*?title="(.+?)"} $ebcBid - ebcBid ebcBid2]} { | |
4804 | set ebcBid "${ebcBid}/${ebcBid2}" | |
4805 | } | |
4806 | if {[string match *<img* $ebcBid]} { regexp {<img src=".*?title="(.+?)"} $ebcBid - ebcBid } | |
4807 | } else { | |
4808 | regexp -nocase {class="ebcBid">(.*?)</td} $line - ebcBid | |
4809 | # trying to parse out the phrase "buy-it-now" in any language | |
4810 | # this isn't elegant at all, we are chopping 'massive' html tags out | |
4811 | # it works effectively, but isn't quick at all. We also have to account | |
4812 | # for multiple bid/buy-it-now possibilities.... | |
4813 | regexp -- {(^[0-9\-]{1,})<} $ebcBid {} ebcBid2 | |
4814 | if {![regexp -- {title="(.+?)"} $ebcBid {} ebcBid]} { | |
4815 | if {![regexp -- {alt="(.+?)(?:\":\:|-)} $ebcBid {} ebcBid]} { | |
4816 | regsub -all -- {<(.+?)>} $ebcBid "" ebcBid | |
4817 | if {$ebcBid == "-"} { set ebcBid "0" } | |
4818 | if {$ebcBid != ""} { | |
4819 | regsub -all -- {<(.+?)>} $ebcSP "" ebcSP | |
4820 | append ebcBid " ${ebcSP}" | |
4821 | } | |
4822 | if {$ebcBid == ""} { set ebcBid "??" } | |
4823 | } | |
4824 | } | |
4825 | # if our buy-it-now has a bid too, prepend bid to it. | |
4826 | if {![string match "*${ebcBid2}*" $ebcBid]} { | |
4827 | if {$ebcBid2 == "-"} { set ebcBid2 "0" } | |
4828 | regsub -all -- {<(.+?)>} $ebcSP "" ebcSP | |
4829 | set ebcBid "${ebcBid2} ${ebcSP}/[string trim $ebcBid]" | |
4830 | } | |
4831 | } | |
4832 | regsub -nocase {</div><div class=.*?>} $ebcBid "/" ebcBid | |
4833 | regsub -all {<.*?>} $ebcBid "" ebcBid | |
4834 | # prices | |
4835 | if {[regexp -nocase {<td class="prc.*?">(.*?)</td} $line - ebcPR]} { | |
4836 | regsub -- {</div><div>} $ebcPR "/" ebcPR | |
4837 | regexp -- {^(.+)</div>(.*?)$} $ebcPR - ebcPR ebcShpNew | |
4838 | regsub -all {<.*?>} $ebcPR "" ebcPR | |
4839 | } | |
4840 | ||
4841 | # shipping | |
4842 | if {![string length $ebcShpNew]} { | |
4843 | if {[regexp -nocase {td class=".*?(?:ship|fshp).*?">(.+?)</td>} $line - ebcShpNew]} { | |
4844 | if {[string match "<" [string index $ebcShpNew 0]]} { set ebcShpNew "Calculate" } | |
4845 | } else { | |
4846 | regexp -nocase {class="ebcShpNew">(.+?)<} $line - ebcShpNew | |
4847 | if {[info exists ebcShpNew]} { | |
4848 | regexp -- {;;">(.+?)} $ebcShpNew {} ebcCheck | |
4849 | if {$ebcCheck == ""} { | |
4850 | regexp -- {$(.+?)<} $ebcShpNew {} ebcShpNew | |
4851 | if {$ebcShpNew == ""} { | |
4852 | set ebcTim "store" | |
4853 | regexp -nocase {class="ebcStr">.+?http://stores.ebay.com/.+?">(.+?)</a>} $html - ebcStr | |
4854 | } | |
4855 | } else { | |
4856 | if {![regexp -- {(.*?)<div class="tfsp">(.*?)</div>} $ebcPR - ebcPR ebcShpNew]} { | |
4857 | set ebcShpNew "Calculate" | |
4858 | } | |
4859 | } | |
4860 | } | |
4861 | # remove pesky trailing spaces | |
4862 | regsub -all -- {<(.+?)>} $ebcShpNew {} ebcShpNew | |
4863 | regsub -all "Â " $ebcShpNew "" ebcShpNew | |
4864 | } | |
4865 | } | |
4866 | # time left | |
4867 | if {![regexp -nocase {td class="time.*?rt">(.+?)</td>} $line - ebcTim]} { | |
4868 | if {![regexp -nocase {class="ebcTim">(.+?)<} $line - ebcTim]} { | |
4869 | regexp -nocase {class="hidlb">(.+?)<} $line - ebcTim | |
4870 | } | |
4871 | } | |
4872 | if {[info exists ebcTim]} { | |
4873 | regsub -all -- {<.*?>} [string map {\002 ""} $ebcTim] {} ebcTim | |
4874 | if {[string match *:* $ebcTim]} { set ebcTim [join [lrange [split $ebcTim :] 1 end]] } | |
4875 | } | |
4876 | # keep ebay Item from becoming too lengthy | |
4877 | if {[info exists ebcI]} { | |
4878 | #ebay has these odd tags, removing them cleans up results. | |
4879 | regsub -all -nocase "<wbr>" $ebcI "" ebcI | |
4880 | set ebcI [string range $ebcI 0 [expr $incith::google::description_length - 1]] | |
4881 | set ebcI [string trim $ebcI] | |
4882 | } | |
4883 | ||
4884 | # check results are more than 0, return or stop looping, depending | |
4885 | if {$tresult < 1 } { | |
4886 | if {$results == 0} { | |
4887 | set reply $no_search | |
4888 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
4889 | } else { | |
4890 | break | |
4891 | } | |
4892 | } | |
4893 | ||
4894 | # make the link valid because we were only given a partial href result, not a full url | |
4895 | set link "http://cgi.ebay.${titem}/_W0QQItemZ[lindex [split ${ebcU} "/"] end]" | |
4896 | ||
4897 | # fix up our variables so the output looks purdy. | |
4898 | if {$ebcPR == ""} { set ebcPR "--" } | |
4899 | if {$ebcTim == ""} { | |
4900 | set ebcTim "--" | |
4901 | } elseif {$ebcTim == "store"} { | |
4902 | set desc "\037${ebcStr}\037 ${ebcI}, ${ebcPR}(${ebcShpNew}), ${ebcBid}" | |
4903 | } elseif {$ebcI != ""} { | |
4904 | set desc "${ebcI}, ${ebcPR}(${ebcShpNew}), ${ebcBid}, ${ebcTim}" | |
4905 | } else { | |
4906 | set link "" ; set desc "" | |
4907 | } | |
4908 | ||
4909 | # add the search result | |
4910 | if {$link != ""} { | |
4911 | if {[info exists desc] == 1 && $ebcI != ""} { | |
4912 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
4913 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
4914 | if {$incith::google::link_only == 1} { | |
4915 | append output "${link}${incith::google::seperator}" | |
4916 | } else { | |
4917 | append output [descdecode "${desc}$::incith::google::break${link}${incith::google::seperator}"] | |
4918 | } | |
4919 | } | |
4920 | } | |
4921 | ||
4922 | # increase the results, clear the variables for the next loop just in case | |
4923 | unset link ; set ebcCheck "" ; set ebcU "" ; set ebcBid2 "" | |
4924 | set ebcI "" ; set ebcPR "" ; set ebcShpNew "" | |
4925 | incr results | |
4926 | } | |
4927 | ||
4928 | # make sure we have something to send | |
4929 | if {$tresult < 1} { | |
4930 | set reply $no_search | |
4931 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
4932 | } | |
4933 | return $output | |
4934 | } | |
4935 | ||
4936 | ||
4937 | # EBAYFIGHT | |
4938 | # ebay fight ! | |
4939 | # | |
4940 | proc ebayfight {input} { | |
4941 | set output ""; set winner 0 ; set match1 0; set match2 0 | |
4942 | ||
4943 | regexp -nocase -- {^(.+?) vs (.+?)$} $input - word1 word2 | |
4944 | ||
4945 | # fetch the first result | |
4946 | set html [fetch_html $word1 25] | |
4947 | if {![regexp -- {class="sectiontitle">([0-9 Â .,]+)\002.*?<h2 class="standard ens} $html - match1]} { | |
4948 | if {![regexp -- {<div class="count">([0-9 Â .,]+) } $html - match1]} { | |
4949 | if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - match1]} { | |
4950 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s} $html - match1]} { | |
4951 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s} $html - match1]} { | |
4952 | regexp -nocase {<div id="v.*?" class="fpcc">.*?\s.+?\s.*?\:\s*(.+?)\s} $html - auctions match1 | |
4953 | set match1 "[join [scan $match1 "%d%d"] ""]" | |
4954 | } | |
4955 | } | |
4956 | } | |
4957 | } | |
4958 | } | |
4959 | ||
4960 | # fetch the second result | |
4961 | set html [fetch_html $word2 25] | |
4962 | regexp -- {<div id="v.*?" class="fpcc">(.+?)\s} $html - match2 | |
4963 | if {![regexp -- {class="sectiontitle">([0-9 Â .,]+)\002.*?<h2 class="standard ens} $html - match2]} { | |
4964 | if {![regexp -- {<div class="count">([0-9 Â .,]+) } $html - match2]} { | |
4965 | if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - match2]} { | |
4966 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s} $html - match2]} { | |
4967 | if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s} $html - match2]} { | |
4968 | regexp -nocase {<div id="v.*?" class="fpcc">.*?\s.+?\s.*?\:\s*(.+?)\s} $html - auctions match2 | |
4969 | set match2 "[join [scan $match2 "%d%d"] ""]" | |
4970 | } | |
4971 | } | |
4972 | } | |
4973 | } | |
4974 | } | |
4975 | ||
4976 | # clean up our matches, so it looks all tidy and neat. | |
4977 | regsub -all "\002" $match1 " " match1 | |
4978 | regsub -all "\002" $match2 " " match2 | |
4979 | ||
4980 | if {![info exists match1]} { | |
4981 | set match1 "0" | |
4982 | set match1expr "0" | |
4983 | } else { | |
4984 | regsub -all {,} $match1 {} match1expr | |
4985 | } | |
4986 | ||
4987 | if {![info exists match2]} { | |
4988 | set match2 "0" | |
4989 | set match2expr "0" | |
4990 | } else { | |
4991 | regsub -all {,} $match2 {} match2expr | |
4992 | } | |
4993 | ||
4994 | if {[expr $match2expr < $match1expr]} { | |
4995 | set winner 1 | |
4996 | } else { | |
4997 | set winner 2 | |
4998 | } | |
4999 | ||
5000 | if {[expr $match2expr == $match1expr]} { | |
5001 | set winner 1 | |
5002 | set troll1 { | |
5003 | Pissing Shitting SpillingPez DrippingCum Trolling | |
5004 | } | |
5005 | set troll2 { | |
5006 | YourFace YourSister YourMama | |
5007 | } | |
5008 | set match1 "[lindex $troll1 [rand [llength $troll1]]]" | |
5009 | set match2 "[lindex $troll2 [rand [llength $troll2]]]" | |
5010 | } | |
5011 | ||
5012 | if {$incith::google::bold_descriptions > 0 && $incith::google::desc_modes == ""} { | |
5013 | set word1 "\002$word1\002"; set word2 "\002$word2\002" | |
5014 | set match1 "\002 $match1\002"; set match2 "\002 $match2\002" | |
5015 | } elseif {$incith::google::desc_modes != ""} { | |
5016 | set word1 "$incith::google::desc_modes$word1$incith::google::desc_demodes"; set word2 "$incith::google::desc_modes$word2$incith::google::desc_demodes" | |
5017 | set match1 " $incith::google::desc_modes$match1$incith::google::desc_demodes"; set match2 " $incith::google::desc_modes$match2$incith::google::desc_demodes" | |
5018 | } else { | |
5019 | set match1 " $match1"; set match2 " $match2" | |
5020 | } | |
5021 | ||
5022 | regsub -all " " $match1 "" match1 | |
5023 | regsub -all " " $match2 "" match2 | |
5024 | ||
5025 | if {$winner == 1} { | |
5026 | set output "${::incith::google::total_modes}By results on ebay:$::incith::google::total_demodes$incith::google::desc_modes $word1 beats $word2 by $match1 to $match2!$::incith::google::desc_demodes" | |
5027 | } elseif {$winner == 2} { | |
5028 | set output "${::incith::google::total_modes}By results on ebay:$::incith::google::total_demodes$incith::google::desc_modes $word2 beats $word1 by $match2 to $match1!$::incith::google::desc_demodes" | |
5029 | } else { | |
5030 | set output "${::incith::google::total_modes}Could not determine the winner." | |
5031 | } | |
5032 | ||
5033 | # make sure we have something to send | |
5034 | if {[info exists output] == 0} { | |
5035 | set reply "Sorry, no search results were found." | |
5036 | if {[info exists did_you_mean] == 1} { | |
5037 | append reply " Did you mean: ${did_you_mean}?" | |
5038 | } | |
5039 | return "$incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5040 | } | |
5041 | return $output | |
5042 | } | |
5043 | ||
5044 | # Popular | |
5045 | # fetches games results from gamerankings. | |
5046 | # -speechless supplied | |
5047 | # | |
5048 | proc popular {input} { | |
5049 | ||
5050 | # lots of variables, keeping them clean is important. | |
5051 | # borrowed mostly from my ebay proc above. | |
5052 | ; set results 0 ; set output "" ; set tresult "" | |
5053 | ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR "" | |
5054 | ; set ebcCheck "" ; set html "" | |
5055 | ||
5056 | # redundant and messy, yes i know.. but it works, k | |
5057 | # parses the query and reads html according to system desired. | |
5058 | ||
5059 | if {[string match -nocase "gc" $input] == 1} { | |
5060 | set html [fetch_html "0" 30] | |
5061 | set output "\002GameRankings BEST GameCube\002" | |
5062 | } | |
5063 | if {[string match -nocase "pc" $input] == 1} { | |
5064 | set html [fetch_html "0" 31] | |
5065 | set output "\002GameRankings BEST PC\002" | |
5066 | } | |
5067 | if {[string match -nocase "ps2" $input] == 1} { | |
5068 | set html [fetch_html "0" 32] | |
5069 | set output "\002GameRankings BEST PlayStation2\002" | |
5070 | } | |
5071 | if {[string match -nocase "ps3" $input] == 1} { | |
5072 | set html [fetch_html "0" 33] | |
5073 | set output "\002GameRankings BEST PlayStation3\002" | |
5074 | } | |
5075 | if {[string match -nocase "wii" $input] == 1} { | |
5076 | set html [fetch_html "0" 34] | |
5077 | set output "\002GameRankings BEST Wii\002" | |
5078 | } | |
5079 | if {[string match -nocase "xbox" $input] == 1} { | |
5080 | set html [fetch_html "0" 35] | |
5081 | set output "\002GameRankings BEST Xbox\002" | |
5082 | } | |
5083 | if {[string match -nocase "x360" $input] == 1} { | |
5084 | set html [fetch_html "0" 36] | |
5085 | set output "\002GameRankings BEST Xbox360\002" | |
5086 | } | |
5087 | if {[string match -nocase "ds" $input] == 1} { | |
5088 | set html [fetch_html "0" 37] | |
5089 | set output "\002GameRankings BEST NDS\002" | |
5090 | } | |
5091 | if {[string match -nocase "gba" $input] == 1} { | |
5092 | set html [fetch_html "0" 38] | |
5093 | set output "\002GameRankings BEST GBA\002" | |
5094 | } | |
5095 | if {[string match -nocase "psp" $input] == 1} { | |
5096 | set html [fetch_html "0" 39] | |
5097 | set output "\002GameRankings BEST PSP\002" | |
5098 | } | |
5099 | if {[string match -nocase "mobile" $input] == 1} { | |
5100 | set html [fetch_html "0" 40] | |
5101 | set output "\002GameRankings BEST Mobile\002" | |
5102 | } | |
5103 | if {[string match -nocase "ngage" $input] == 1} { | |
5104 | set html [fetch_html "0" 41] | |
5105 | set output "\002GameRankings BEST N-Gage\002" | |
5106 | } | |
5107 | if {[string match -nocase "3do" $input] == 1} { | |
5108 | set html [fetch_html "0" 42] | |
5109 | set output "\002GameRankings BEST 3DO\002" | |
5110 | } | |
5111 | if {[string match -nocase "dc" $input] == 1} { | |
5112 | set html [fetch_html "0" 43] | |
5113 | set output "\002GameRankings BEST Dreamcast\002" | |
5114 | } | |
5115 | if {[string match -nocase "gen" $input] == 1} { | |
5116 | set html [fetch_html "0" 44] | |
5117 | set output "\002GameRankings BEST Genesis\002" | |
5118 | } | |
5119 | if {[string match -nocase "jag" $input] == 1} { | |
5120 | set html [fetch_html "0" 45] | |
5121 | set output "\002GameRankings BEST Jaguar\002" | |
5122 | } | |
5123 | if {[string match -nocase "n64" $input] == 1} { | |
5124 | set html [fetch_html "0" 46] | |
5125 | set output "\002GameRankings BEST N64\002" | |
5126 | } | |
5127 | if {[string match -nocase "neo" $input] == 1} { | |
5128 | set html [fetch_html "0" 47] | |
5129 | set output "\002GameRankings BEST Neo-Geo\002" | |
5130 | } | |
5131 | if {[string match -nocase "ps1" $input] == 1} { | |
5132 | set html [fetch_html "0" 48] | |
5133 | set output "\002GameRankings BEST Playstation\002" | |
5134 | } | |
5135 | if {[string match -nocase "sat" $input] == 1} { | |
5136 | set html [fetch_html "0" 49] | |
5137 | set output "\002GameRankings BEST Saturn\002" | |
5138 | } | |
5139 | if {[string match -nocase "snes" $input] == 1} { | |
5140 | set html [fetch_html "0" 50] | |
5141 | set output "\002GameRankings BEST Snes\002" | |
5142 | } | |
5143 | if {[string match -nocase "segacd" $input] == 1} { | |
5144 | set html [fetch_html "0" 52] | |
5145 | set output "\002GameRankings BEST Sega-CD\002" | |
5146 | } | |
5147 | if {[string match -nocase "gameboy" $input] == 1} { | |
5148 | set html [fetch_html "0" 53] | |
5149 | set output "\002GameRankings BEST GameBoy\002" | |
5150 | } | |
5151 | if {[string match -nocase "gbc" $input] == 1} { | |
5152 | set html [fetch_html "0" 54] | |
5153 | set output "\002GameRankings BEST GameBoy Color\002" | |
5154 | } | |
5155 | if {[string match -nocase "all" $input] == 1} { | |
5156 | set html [fetch_html "0" 55] | |
5157 | set output "\002GameRankings BEST -ALL-\002" | |
5158 | } | |
5159 | if {[string match -nocase "3ds" $input] == 1} { | |
5160 | set html [fetch_html "0" 57] | |
5161 | set output "\002GameRankings BEST 3DS\002" | |
5162 | } | |
5163 | if {[string match -nocase "mac" $input] == 1} { | |
5164 | set html [fetch_html "1" 58] | |
5165 | set output "\002GameRankings WORST MAC\002" | |
5166 | } | |
5167 | ||
5168 | if {[string match -nocase "*http://www.gamespot.com/gamerankings/offline.html*" $html]} { | |
5169 | append output "${incith::google::seperator}${::incith::google::error_modes}We're sorry, we are temporarily offline. We'll be back as soon as possible." | |
5170 | return $output | |
5171 | } | |
5172 | if {[string match -nocase "*Temporarily Unavailable*" $html]} { | |
5173 | append output "${incith::google::seperator}${::incith::google::error_modes}GameRankings is Temporarily Unavailable." | |
5174 | return $output | |
5175 | } | |
5176 | if {$output == ""} { | |
5177 | return "${::incith::google::desc_modes}Sorry, that system is not supported! \[system = gc/pc/mac/ps2/ps3/wii/xbox/x360/3ds/ds/gba/psp/mobile/ngage/3d0/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: $::lastbind system" | |
5178 | } else { set output "$::incith::google::total_modes$output$::incith::google::total_demodes" } | |
5179 | ||
5180 | regsub -all "(?:\t|\n|\r|\v)" $html "" html | |
5181 | ||
5182 | # remove the bold if it isn't desired. | |
5183 | if {$incith::google::bold_descriptions == 0} { | |
5184 | regsub -all -- "\002" $output {} output | |
5185 | } | |
5186 | ||
5187 | # parse for results and loop until desired amount of results | |
5188 | # is attempted to be reached if possible. | |
5189 | while {$results < $incith::google::popular_results && $output != ""} { | |
5190 | # grab date and game title and clear future html of it for looping | |
5191 | if {[regexp -- {<col class="game" />.*?<tr.+?<td>.*?<td>(.*?)</td>.*?<a href=.+?">(.+?)</a>.*?<br />(.+?)</td><td>(.+?)<} $html - sys game pub date]} { | |
5192 | regsub -- {><tr.*?<td>.*?</td></tr} $html "" html | |
5193 | regsub -- {<nobr>} $date "" date | |
5194 | } | |
5195 | ||
5196 | # if there's no desc, return or stop looping, depending | |
5197 | if {![info exists game]} { | |
5198 | if {$results == 0} { | |
5199 | set reply "Sorry, no search results were found." | |
5200 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5201 | } else { | |
5202 | break | |
5203 | } | |
5204 | } | |
5205 | ||
5206 | # add the search result | |
5207 | # add game to output if there is one | |
5208 | if {[info exists game]} { | |
5209 | if {[string match -nocase "all" $input] == 1} { | |
5210 | append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 ($sys) by $pub (${date})$::incith::google::desc_demodes" | |
5211 | } else { | |
5212 | append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 by $pub (${date})$::incith::google::desc_demodes" | |
5213 | } | |
5214 | unset game; unset date | |
5215 | } | |
5216 | # increase the results, clear the variables for the next loop just in case | |
5217 | incr results | |
5218 | } | |
5219 | # if we have nothing to send, we have no results :( | |
5220 | if {$output == ""} { | |
5221 | set output "${::incith::google::desc_modes}Sorry, found no results! \[system = gc/pc/ps2/ps3/wii/xbox/x360/ds/gba/psp/mobile/ngage/3do/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: !popular system" | |
5222 | } | |
5223 | return $output | |
5224 | } | |
5225 | ||
5226 | # Recent Games | |
5227 | # fetches games results from Gamerankings. | |
5228 | # -speechless supplied | |
5229 | # | |
5230 | proc recent {input} { | |
5231 | ||
5232 | # lots of variables, keeping them clean is important. | |
5233 | # borrowed mostly from my ebay proc above. | |
5234 | ; set results 0 ; set output "" ; set tresult "" | |
5235 | ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR "" | |
5236 | ; set ebcCheck "" ; set html "" | |
5237 | ||
5238 | # redundant and messy, yes i know.. but it works, k | |
5239 | # parses the query and reads html according to system desired. | |
5240 | ||
5241 | if {[string match -nocase "gc" $input] == 1} { | |
5242 | set html [fetch_html "1" 30] | |
5243 | set output "\002GameRankings WORST GameCube\002" | |
5244 | } | |
5245 | if {[string match -nocase "pc" $input] == 1} { | |
5246 | set html [fetch_html "1" 31] | |
5247 | set output "\002GameRankings WORST PC\002" | |
5248 | } | |
5249 | if {[string match -nocase "ps2" $input] == 1} { | |
5250 | set html [fetch_html "1" 32] | |
5251 | set output "\002GameRankings WORST PlayStation2\002" | |
5252 | } | |
5253 | if {[string match -nocase "ps3" $input] == 1} { | |
5254 | set html [fetch_html "1" 33] | |
5255 | set output "\002GameRankings WORST PlayStation3\002" | |
5256 | } | |
5257 | if {[string match -nocase "wii" $input] == 1} { | |
5258 | set html [fetch_html "1" 34] | |
5259 | set output "\002GameRankings WORST Wii\002" | |
5260 | } | |
5261 | if {[string match -nocase "xbox" $input] == 1} { | |
5262 | set html [fetch_html "1" 35] | |
5263 | set output "\002GameRankings WORST Xbox\002" | |
5264 | } | |
5265 | if {[string match -nocase "x360" $input] == 1} { | |
5266 | set html [fetch_html "1" 36] | |
5267 | set output "\002GameRankings WORST Xbox360\002" | |
5268 | } | |
5269 | if {[string match -nocase "ds" $input] == 1} { | |
5270 | set html [fetch_html "1" 37] | |
5271 | set output "\002GameRankings WORST NDS\002" | |
5272 | } | |
5273 | if {[string match -nocase "gba" $input] == 1} { | |
5274 | set html [fetch_html "1" 38] | |
5275 | set output "\002GameRankings WORST GBA\002" | |
5276 | } | |
5277 | if {[string match -nocase "psp" $input] == 1} { | |
5278 | set html [fetch_html "1" 39] | |
5279 | set output "\002GameRankings WORST PSP\002" | |
5280 | } | |
5281 | if {[string match -nocase "mobile" $input] == 1} { | |
5282 | set html [fetch_html "1" 40] | |
5283 | set output "\002GameRankings WORST Mobile\002" | |
5284 | } | |
5285 | if {[string match -nocase "ngage" $input] == 1} { | |
5286 | set html [fetch_html "1" 41] | |
5287 | set output "\002GameRankings WORST N-Gage\002" | |
5288 | } | |
5289 | if {[string match -nocase "3do" $input] == 1} { | |
5290 | set html [fetch_html "1" 42] | |
5291 | set output "\002GameRankings WORST 3D0\002" | |
5292 | } | |
5293 | if {[string match -nocase "dc" $input] == 1} { | |
5294 | set html [fetch_html "1" 43] | |
5295 | set output "\002GameRankings WORST Dreamcast\002" | |
5296 | } | |
5297 | if {[string match -nocase "gen" $input] == 1} { | |
5298 | set html [fetch_html "1" 44] | |
5299 | set output "\002GameRankings WORST Genesis\002" | |
5300 | } | |
5301 | if {[string match -nocase "jag" $input] == 1} { | |
5302 | set html [fetch_html "1" 45] | |
5303 | set output "\002GameRankings WORST Jaguar\002" | |
5304 | } | |
5305 | if {[string match -nocase "n64" $input] == 1} { | |
5306 | set html [fetch_html "1" 46] | |
5307 | set output "\002GameRankings WORST N64\002" | |
5308 | } | |
5309 | if {[string match -nocase "neo" $input] == 1} { | |
5310 | set html [fetch_html "1" 47] | |
5311 | set output "\002GameRankings WORST Neo-Geo\002" | |
5312 | } | |
5313 | if {[string match -nocase "ps1" $input] == 1} { | |
5314 | set html [fetch_html "1" 48] | |
5315 | set output "\002GameRankings WORST Playstation\002" | |
5316 | } | |
5317 | if {[string match -nocase "sat" $input] == 1} { | |
5318 | set html [fetch_html "1" 49] | |
5319 | set output "\002GameRankings WORST Saturn\002" | |
5320 | } | |
5321 | if {[string match -nocase "snes" $input] == 1} { | |
5322 | set html [fetch_html "1" 50] | |
5323 | set output "\002GameRankings WORST Snes\002" | |
5324 | } | |
5325 | if {[string match -nocase "segacd" $input] == 1} { | |
5326 | set html [fetch_html "1" 52] | |
5327 | set output "\002GameRankings WORST Sega-CD\002" | |
5328 | } | |
5329 | if {[string match -nocase "gameboy" $input] == 1} { | |
5330 | set html [fetch_html "1" 53] | |
5331 | set output "\002GameRankings WORST GameBoy\002" | |
5332 | } | |
5333 | if {[string match -nocase "gbc" $input] == 1} { | |
5334 | set html [fetch_html "1" 54] | |
5335 | set output "\002GameRankings WORST GameBoy Color\002" | |
5336 | } | |
5337 | if {[string match -nocase "all" $input] == 1} { | |
5338 | set html [fetch_html "1" 55] | |
5339 | set output "\002GameRankings WORST -ALL-\002" | |
5340 | } | |
5341 | if {[string match -nocase "3ds" $input] == 1} { | |
5342 | set html [fetch_html "1" 57] | |
5343 | set output "\002GameRankings WORST 3DS\002" | |
5344 | } | |
5345 | if {[string match -nocase "mac" $input] == 1} { | |
5346 | set html [fetch_html "1" 58] | |
5347 | set output "\002GameRankings WORST MAC\002" | |
5348 | } | |
5349 | ||
5350 | if {[string match -nocase "*http://www.gamespot.com/gamerankings/offline.html*" $html]} { | |
5351 | append output "${incith::google::seperator}${::incith::google::error_modes}We're sorry, we are temporarily offline. We'll be back as soon as possible." | |
5352 | return $output | |
5353 | } | |
5354 | if {[string match -nocase "*Temporarily Unavailable*" $html]} { | |
5355 | append output "${incith::google::seperator}${::incith::google::error_modes}GameRankings is Temporarily Unavailable." | |
5356 | return $output | |
5357 | } | |
5358 | if {$output == ""} { | |
5359 | return "${::incith::google::desc_modes}Sorry, that system is not supported! \[system = gc/pc/mac/ps2/ps3/wii/xbox/x360/3ds/ds/gba/psp/mobile/ngage/3do/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: $::lastbind system" | |
5360 | } else { set output "$::incith::google::total_modes$output$::incith::google::total_demodes" } | |
5361 | ||
5362 | regsub -all "(?:\t|\n|\r|\v)" $html "" html | |
5363 | ||
5364 | # remove the bold if it isn't desired. | |
5365 | if {$incith::google::bold_descriptions == 0} { | |
5366 | regsub -all -- "\002" $output {} output | |
5367 | } | |
5368 | ||
5369 | # parse for results and loop until desired amount of results | |
5370 | # is attempted to be reached if possible. | |
5371 | while {$results < $incith::google::popular_results && $output != ""} { | |
5372 | ||
5373 | # grab date and game title and clear future html of it for looping | |
5374 | if {[regexp -- {<col class="game" />.*?<tr.+?<td>.*?<td>(.*?)</td>.*?<a href=.+?">(.+?)</a>.*?<br />(.+?)</td><td>(.+?)<} $html - sys game pub date]} { | |
5375 | regsub -- {><tr.*?<td>.*?</td></tr} $html "" html | |
5376 | regsub -- {<nobr>} $date "" date | |
5377 | } | |
5378 | ||
5379 | # if there's no desc, return or stop looping, depending | |
5380 | if {![info exists game]} { | |
5381 | if {$results == 0} { | |
5382 | set reply "Sorry, no search results were found." | |
5383 | return "$::incith::google::desc_modes$reply$::incith::google::desc_modes" | |
5384 | } else { | |
5385 | break | |
5386 | } | |
5387 | } | |
5388 | ||
5389 | # add the search result | |
5390 | # add game to output if there is one | |
5391 | if {[info exists game]} { | |
5392 | if {[string match -nocase "all" $input] == 1} { | |
5393 | append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 ($sys) by $pub (${date})$::incith::google::desc_demodes" | |
5394 | } else { | |
5395 | append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 by $pub (${date})$::incith::google::desc_demodes" | |
5396 | } | |
5397 | unset game; unset date | |
5398 | } | |
5399 | # increase the results, clear the variables for the next loop just in case | |
5400 | incr results | |
5401 | } | |
5402 | # if we have nothing to send, we have no results :( | |
5403 | if {$output == ""} { | |
5404 | set output "${::incith::google::desc_modes}Sorry, found no results! \[system = gc/pc/ps2/ps3/wii/xbox/x360/ds/gba/psp/mobile/ngage/3d0/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: !top system" | |
5405 | } | |
5406 | return "$output" | |
5407 | } | |
5408 | ||
5409 | # Google Trends | |
5410 | # fetches top search terms from google | |
5411 | # -speechless supplied | |
5412 | # | |
5413 | proc trends {input} { | |
5414 | ||
5415 | # lots of variables, keeping them clean is important. | |
5416 | ; set results 0 ; set output "" ; set tresult "" ; set no_results "" ; set no_search "" | |
5417 | ||
5418 | set html [fetch_html $input 13] | |
5419 | ||
5420 | # user input causing errors? | |
5421 | if {[string match -nocase "*socketerrorabort*" $html]} { | |
5422 | regsub {(.+?)\|} $html {} html | |
5423 | return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}" | |
5424 | } | |
5425 | if {[string match -nocase "*timeouterrorabort*" $html]} { | |
5426 | return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}" | |
5427 | } | |
5428 | ||
5429 | # give location results we are displaying. | |
5430 | regexp -- {<table width=100% cellpadding=2 cellspacing=0 bgcolor=#E5ECF9><tr><td>(.+?)</td>} $html - tresult | |
5431 | if {$tresult != ""} { set output "$::incith::google::total_modes${tresult}$::incith::google::total_demodes${incith::google::seperator}" } | |
5432 | ||
5433 | # get what we call the no_search for any language. | |
5434 | if {[string match "*system_down.html*" $html]} { | |
5435 | set no_search "$::incith::google::error_modes\002Trends Error:\002 System appears to be down, try again later.$::incith::google::error_demodes" | |
5436 | } else { | |
5437 | if {[regexp -- {<br><br>(.+?)</p>} $html - no_search]} { | |
5438 | regsub -- {<p>} $no_search { } no_search | |
5439 | } else { | |
5440 | if {![regexp -- {<ul><li>(.+?)</ul>} $html - no_search]} { | |
5441 | regexp -- {</table><p>(.+?)</p>} $html - no_search | |
5442 | } | |
5443 | } | |
5444 | } | |
5445 | ||
5446 | # remove the bold if it isn't desired. | |
5447 | if {$incith::google::bold_descriptions == 0} { | |
5448 | regsub -all -- "\002" $output {} output | |
5449 | } | |
5450 | ||
5451 | # parse for results and loop until desired amount of results | |
5452 | # is attempted to be reached if possible. | |
5453 | while {$results < $incith::google::trends_results} { | |
5454 | set link "$::incith::google::total_modes\002[expr $results + 1]\002$::incith::google::total_demodes" | |
5455 | # grab our trend and cut it out | |
5456 | regexp -- {<td class=num>.+?<a href=.+?>(.+?)</a>} $html {} desc | |
5457 | regsub -- {<td class=num>.+?<a href=.+?>(.+?)</a>} $html "" html | |
5458 | if {[info exists desc]} { | |
5459 | append link " $incith::google::desc_modes$desc$::incith::google::desc_demodes" | |
5460 | } else { | |
5461 | if {$results == 0} { | |
5462 | set reply "${no_search}" | |
5463 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5464 | } else { | |
5465 | break | |
5466 | } | |
5467 | } | |
5468 | ||
5469 | # add the search result | |
5470 | # add game to output if there is one | |
5471 | if {[info exists desc]} { | |
5472 | append output "${link}${incith::google::split_char}" | |
5473 | } | |
5474 | # increase the results, clear the variables for the next loop just in case | |
5475 | unset desc; unset link | |
5476 | incr results | |
5477 | } | |
5478 | # if we have nothing to send, we have no results :( | |
5479 | if {$output == ""} { | |
5480 | set output "$::incith::google::desc_modes${no_search}$::incith::google::desc_demodes" | |
5481 | } | |
5482 | return [string trim $output $incith::google::split_char] | |
5483 | } | |
5484 | ||
5485 | # Gamespot Game Review | |
5486 | # fetches review results from gamespot searches. | |
5487 | # -speechless supplied | |
5488 | # | |
5489 | proc rev {input} { | |
5490 | global incithcookie | |
5491 | # lots of variables, keeping them clean is important.. | |
5492 | ; set results "" ; set output "" ; set tresult ""; set inputb "" | |
5493 | ; set ebcU "" ; set ebcI "" ; set ebcPR "" ; set review "" | |
5494 | ; set us "?" ; set them "?" ; set you "?" ; set stats "" ; set vid "" | |
5495 | ||
5496 | regexp -nocase -- {^(.+?) @ (.+?)$} $input - input inputb | |
5497 | ||
5498 | # fetch the html | |
5499 | set html [fetch_html $input 12] | |
5500 | regsub -all {\\n} $html "" html | |
5501 | if {[string match "*NO RESULTS RETURNED*" $html]} { | |
5502 | set reply "${::incith::google::desc_modes}Sorry, no search results were found." | |
5503 | return $reply | |
5504 | } | |
5505 | ||
5506 | if {$inputb != ""} { | |
5507 | while {$results == ""} { | |
5508 | # this could break any second, its cumbersome and long..i know, but for now it works. | |
5509 | regexp -- {<div class=\\"result_title\\">.*?<a href=\\"(.+?)\?tag=result.*?\\">(.+?)<\\/a>} $html - ebcU ebcI | |
5510 | set ebcU [string map {"\\" ""} $ebcU] | |
5511 | if {[string match -nocase "*\(${inputb}\)*" $ebcI] == 1} { set results "true" } | |
5512 | if {$ebcU == $ebcPR} { | |
5513 | regsub -all { } $input {%20} input | |
5514 | return "${::incith::google::desc_modes}Sorry, game does not appear for that console when searching first page results. See for yourself @ http://www.gamespot.com/pages/search/index.php?qs=${input}#game" | |
5515 | } | |
5516 | regsub -- {<div class=\\"result_title\\">.*?<a href=\\".+?\\">.+?<\\/a>} $html "" html | |
5517 | set ebcPR $ebcU | |
5518 | } | |
5519 | } | |
5520 | ||
5521 | # get url snippet where game review can be pulled | |
5522 | if {$inputb == ""} { | |
5523 | if {[regexp -- {<div class=\\"result_title\\">.*?<a href=\\"(.+?)\?tag=result.*?\\">(.+?)<\\/a>} $html - ebcU ebcI]} { | |
5524 | set ebcU [string map {"\\" ""} $ebcU] | |
5525 | } | |
5526 | } | |
5527 | # if no snippet there is nothing more to do | |
5528 | if {$ebcU == "" } { return "${::incith::google::desc_modes}Sorry, no search results were found." } | |
5529 | # grab game review | |
5530 | set query "${ebcU}" | |
5531 | set ebcU ""; set ebcI ""; set ebcPR "" | |
5532 | regexp -- {(.+?)&q=} $query {} query | |
5533 | regexp -- {(.+?)\?q=} $query {} query | |
5534 | if {![string match "*http*" $query]} { | |
5535 | set query "http://www.gamespot.com${query}" | |
5536 | } | |
5537 | ||
5538 | # beware, changing the useragent will result in differently formatted html from Google. | |
5539 | set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
5540 | set http [::http::config -useragent $ua] | |
5541 | set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 10]] | |
5542 | if {$::incith::google::debug > 0 } { | |
5543 | putserv "privmsg $incith::google::debugnick :\002url \([::http::ncode $http]\):\002 $query" | |
5544 | } | |
5545 | upvar #0 $http state | |
5546 | set html [ungzip [::http::data $http] $state(meta)] | |
5547 | ::http::cleanup $http | |
5548 | # strip the html down | |
5549 | regsub -all "\t" $html "" html | |
5550 | regsub -all "\n" $html "" html | |
5551 | regsub -all "\r" $html "" html | |
5552 | regsub -all "\v" $html "" html | |
5553 | regsub -all "<script.*?>.*?</script>" $html "" html | |
5554 | # DEBUG DEBUG | |
5555 | set junk [open "ig-debug.txt" w] | |
5556 | puts $junk $html | |
5557 | close $junk | |
5558 | ||
5559 | if {![regexp -- {<div class="module_title_wrap">(.*?)</div></div>} $html - name]} { | |
5560 | regexp -- {<title>(.+?) \- } $html {} name | |
5561 | # sometimes our game and system cut isn't pretty this cleans it up | |
5562 | regexp -- {(.+?)<.+?title} $name - name | |
5563 | set name [string trim $name] | |
5564 | } else { | |
5565 | regsub -- {</h1>} $name " " name | |
5566 | regsub -all -- {<.*?>} $name "" name | |
5567 | } | |
5568 | ||
5569 | if {[regexp -- {\&tag=scoresummary%3Bgs-score">(.+?)<} $html - us]} { | |
5570 | regsub -- {<.*?>} $us "" us | |
5571 | } | |
5572 | if {[regexp -- {\&tag=scoresummary%3Bcritic-score">(.+?)<} $html - them]} { | |
5573 | regsub -- {<.*?>} $them "" them | |
5574 | } | |
5575 | regexp -- {\?tag=scoresummary%3Buser-score">(.+?)<} $html - you | |
5576 | if {[regexp -- {<ul class="stats">(.+?)<div class="actions">} $html - stats]} { | |
5577 | regsub {<div class="label">Top 5 User Tags\:.+?</ol>} $stats "" stats | |
5578 | regsub {<div class="desc">.+?</ul>} $stats "" stats | |
5579 | regsub {<li class="stat universe">.+?</ul>} $stats "" stats | |
5580 | regsub -all {<.+?>} $stats "" stats | |
5581 | while {[string match "* *" $stats]} { | |
5582 | regsub -all -- { } $stats " " stats | |
5583 | } | |
5584 | regsub {More Info Game Stats} $stats "» «" stats | |
5585 | regsub {Tracking\:.+?Wish It»} $stats "» «" stats | |
5586 | regsub -all {»} $stats "» «" stats | |
5587 | regsub -all {/\s»} $stats "»" stats | |
5588 | regsub -all {«\s/} $stats "«" stats | |
5589 | } | |
5590 | if {[regexp {<p class="review deck".*?>(.+?)</p>} $html - review]} { | |
5591 | regsub -all -- {<.*?>} $review "" review | |
5592 | set review " « $review »" | |
5593 | } elseif {[regexp {<p class="product deck".*?>(.+?)</p>} $html - review]} { | |
5594 | regsub -all -- {<.*?>} $review "" review | |
5595 | set review " « $review »" | |
5596 | } | |
5597 | if {[regexp -- {<ul class="videos">.+?<a href="(.+?)".*?">(.+?)</a>} $html - vurl vid]} { | |
5598 | if {[regexp -nocase -- {a href=""} $vid]} { | |
5599 | if {[regexp -- {<div class="module videos">.*?<div class="head">.*?href="(.*?)">(.*?)</a>} $html - vurl vid]} { | |
5600 | set vurl "http://www.gamespot.com$vurl" | |
5601 | } | |
5602 | } else { | |
5603 | regexp -- {^(.+?)?tag=;} $vurl - vurl | |
5604 | } | |
5605 | if {[string match "/" [string index $vurl 0]]} { set vurl "http://www.gamespot.com$vurl" } | |
5606 | set vid "$incith::google::desc_modes ... \002Video:\002 $vid$::incith::google::desc_demodes$::incith::google::break$::incith::google::link_modes$vurl$::incith::google::link_demodes" | |
5607 | } | |
5608 | set desc "[descdecode "${name} \(us\002$us\002 them\002$them\002 you\002$you\002\) «$stats»$review"]" | |
5609 | # make sure we have something to send | |
5610 | set output "$::incith::google::desc_modes${desc}$::incith::google::desc_demodes$::incith::google::break$::incith::google::link_modes${query}$::incith::google::link_demodes$vid" | |
5611 | return $output | |
5612 | } | |
5613 | ||
5614 | # IGN | |
5615 | # fetches games results from ign searches. | |
5616 | # -speechless supplied | |
5617 | # | |
5618 | proc ign {input} { | |
5619 | ||
5620 | # lots of variables, keeping them clean is important. | |
5621 | # borrowed mostly from my ebay proc above. | |
5622 | ; set results 0 ; set output "" ; set tresult "" | |
5623 | ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR "" | |
5624 | ; set ebcCheck "" ; set match "" | |
5625 | ||
5626 | # fetch the html | |
5627 | set html [fetch_html $input 26] | |
5628 | ||
5629 | if {$html == ""} { return "${::incith::google::error_modes}IGN search page appears to be blank... No results maybe?!" } | |
5630 | ||
5631 | # give results an output header with result tally. | |
5632 | # regexp -- {All Products \(([,0-9]{1,})\)<br/>} $html - match | |
5633 | set match "iGN" | |
5634 | ||
5635 | # format output according to variables. | |
5636 | if {$match != ""} { | |
5637 | set output "$::incith::google::total_modes\002${match}\002 results$::incith::google::total_demodes${incith::google::seperator}" | |
5638 | if {$incith::google::bold_descriptions == 0} { | |
5639 | regsub -all -- "\002" $output {} output | |
5640 | } | |
5641 | } else { | |
5642 | regexp -- {<p.*?class="searchResultTitle">(.+?)</p>} $html - match | |
5643 | set output "${match}$::incith::google::seperator" | |
5644 | } | |
5645 | ||
5646 | if {[regexp -- {<p class="searchResultTitle".+?<strong>(.+?)<br} $html - no_search]} { | |
5647 | return $no_search | |
5648 | } | |
5649 | ||
5650 | # parse the html | |
5651 | while {$results < $incith::google::ign_results} { | |
5652 | # this could break any second, its cumbersome and long..i know, but for now it works. | |
5653 | regexp -- {<h3 class="game-title"><a href="(.*?)">(.*?)</h3>} $html - ebcU ebcI | |
5654 | if {![regexp -- {class="publisherLink">(.*?)</a>(.*?)</p>} $html - ebcBid desc]} { | |
5655 | regexp -- {<div id="articleType"><strong>(.+?)</strong>} $html - ebcBid | |
5656 | set desc "" | |
5657 | } else { | |
5658 | set desc [string trim $desc "- "] | |
5659 | regsub -all -- {\s+} $desc " " desc | |
5660 | if {[string length $desc]} { | |
5661 | set desc " - $desc" | |
5662 | } | |
5663 | } | |
5664 | regsub -- {<h3 class="game-title">(.+?)</div>} $html "" html | |
5665 | ||
5666 | # check results are more than 0, return or stop looping, depending | |
5667 | if {![string length $ebcU]} { | |
5668 | if {$results == 0} { | |
5669 | regexp -nocase -- {<p class="searchFail">(.*?)</p>} $html - reply | |
5670 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5671 | } else { | |
5672 | break | |
5673 | } | |
5674 | } | |
5675 | ||
5676 | # this needs to be done for user formatting of links and descriptions. | |
5677 | set link "${ebcU}" | |
5678 | ||
5679 | # prevent duplicate results is mostly useless here, but will at least | |
5680 | # ensure that we don't get the exact same article. | |
5681 | if {[string match "*$link*" $output] == 1} { | |
5682 | break | |
5683 | } | |
5684 | ||
5685 | # ign clutters with excess spacing to make parsing hard | |
5686 | # this is a quick and dirty way to get through the mud. | |
5687 | ||
5688 | #clean up messy parsing. | |
5689 | regsub -all {<script type=.+?script>} $ebcBid {} ebcBid | |
5690 | regsub -all -- {<(.+?)>} $ebcBid {} ebcBid | |
5691 | while {[string match "* *" $ebcBid]} { | |
5692 | regsub -all -- { } $ebcBid " " ebcBid | |
5693 | } | |
5694 | set ebcBid [string trim $ebcBid] | |
5695 | regexp -- {^(.*?)</a>(.*?)$} $ebcI - ebcI plat | |
5696 | regexp -- {<span class="platform default">(.*?)</span>} $ebcI - plat | |
5697 | regexp -- {^(.*?)</a>} $ebcI - ebcI | |
5698 | regsub -all -- {\s+} $plat { } plat | |
5699 | # set formatting. | |
5700 | set desc "${ebcI} ([string totitle $plat] by ${ebcBid})$desc" | |
5701 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
5702 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
5703 | ||
5704 | # add the search result | |
5705 | if {$incith::google::link_only == 1} { | |
5706 | append output "${link}${incith::google::seperator}" | |
5707 | } else { | |
5708 | append output "[descdecode ${desc}]$::incith::google::break${link}${incith::google::seperator}" | |
5709 | } | |
5710 | ||
5711 | # increase the results, clear the variables for the next loop just in case | |
5712 | unset link ; set ebcCheck "" | |
5713 | incr results | |
5714 | } | |
5715 | ||
5716 | # make sure we have something to send | |
5717 | if {[info exists output] == 0} { | |
5718 | set reply "Sorry, no search results were found." | |
5719 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5720 | } | |
5721 | return $output | |
5722 | } | |
5723 | ||
5724 | # GameSpot | |
5725 | # fetches games results from gamespot searches. | |
5726 | # -speechless supplied | |
5727 | # | |
5728 | proc gamespot {input} { | |
5729 | ||
5730 | # lots of variables, keeping them clean is important. | |
5731 | # borrowed mostly from my ebay proc above. | |
5732 | ; set results 0 ; set output "" ; set tresult "" | |
5733 | ; set type "" ; set name "" | |
5734 | ; set details "" ; set deck "" | |
5735 | ||
5736 | # fetch the html | |
5737 | set html [fetch_html $input 12] | |
5738 | regsub -all {\\n} $html "" html | |
5739 | ||
5740 | # set up gamespot results header so results can be appended to it. | |
5741 | regexp -- {,"num_results"\:"(.+?)"} $html {} tresult | |
5742 | set tresult [string trim $tresult] | |
5743 | # format output according to variables. | |
5744 | if {$incith::google::total_results != 0} { | |
5745 | set output "$::incith::google::total_modes\002[string trim ${tresult}]\002 games$::incith::google::total_demodes${incith::google::seperator}" | |
5746 | if {$incith::google::bold_descriptions == 0} { | |
5747 | regsub -all -- "\002" $output {} output | |
5748 | } | |
5749 | } | |
5750 | ||
5751 | # parse the html | |
5752 | while {$results < $incith::google::gamespot_results} { | |
5753 | # this could break any second, its cumbersome and long..i know, but for now it works. | |
5754 | if {[regexp -- {<div class=\\"result_title\\">(.*?)<a href=\\"(.+?)\\">(.*?)<\\/a>.*?<div class=\\"details\\">(.*?)<\\/div>.+?<div class=\\"deck\\">(.*?)<\\/div>} $html - type link name details deck]} { | |
5755 | regexp -- {^(.+?)\?tag=result} $link - link | |
5756 | if {[string length $deck] > 0} {set deck " - [string trim $deck]"} | |
5757 | regsub -- {<div class=\\"result_title\\">.+?<div class=\\"deck\\">.+?<\\/div>} $html "" html | |
5758 | set details [string map {" | " "/"} $details] | |
5759 | set link [string map {"\\" ""} $link] | |
5760 | set desc "\002[string trim $type] [string trim $name]\002 \([string trim $details]\)$deck" | |
5761 | } | |
5762 | # check results are more than 0, return or stop looping, depending | |
5763 | if {![info exists link]} { | |
5764 | if {$results == 0} { | |
5765 | set reply "Sorry, no search results were found." | |
5766 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5767 | } else { | |
5768 | break | |
5769 | } | |
5770 | } | |
5771 | regsub -all {<.+?>} $desc "" desc | |
5772 | # prevent duplicate results is mostly useless here, but will at least | |
5773 | # ensure that we don't get the exact same article. | |
5774 | if {[string match "*$link*" $output] == 1} { | |
5775 | break | |
5776 | } | |
5777 | ||
5778 | if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" } | |
5779 | if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" } | |
5780 | ||
5781 | # add the search result | |
5782 | if {$incith::google::link_only == 1} { | |
5783 | append output "${link}${incith::google::seperator}" | |
5784 | } else { | |
5785 | append output "${desc}$::incith::google::break${link}${incith::google::seperator}" | |
5786 | } | |
5787 | ||
5788 | # increase the results, clear the variables for the next loop just in case | |
5789 | unset link ; set name "" ; set deck "" ; set type "" ; set details "" | |
5790 | incr results | |
5791 | } | |
5792 | ||
5793 | # make sure we have something to send | |
5794 | if {[info exists output] == 0} { | |
5795 | set reply "Sorry, no search results were found." | |
5796 | return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes" | |
5797 | } | |
5798 | return $output | |
5799 | } | |
5800 | ||
5801 | # TriggerBot | |
5802 | # Displays all the triggers this scripts is capable of | |
5803 | # explaining syntax, and also will let user know if trigger | |
5804 | # is disabled or how many results are available. | |
5805 | # -speechless supplied | |
5806 | # | |
5807 | ||
5808 | proc helpbot {nick input} { | |
5809 | set temp "" ; set output "" ; set num 0 ; set all 0 | |
5810 | set item "" ; set found "" | |
5811 | if {[string tolower $input] == [lindex [split $incith::google::helplist " "] 0]} { set all 1 ; set found "all" } | |
5812 | if {$all == 0} { | |
5813 | foreach item [split $incith::google::helplist] { | |
5814 | if {[string tolower $input] == $item} { set found $item } | |
5815 | } | |
5816 | if {$found == ""} { | |
5817 | foreach item [split $incith::google::helplist " "] { | |
5818 | append temp "${item}," | |
5819 | } | |
5820 | set temp [string trimright $temp ","] | |
5821 | return "${incith::google::helpmsg1} ${temp}" | |
5822 | } | |
5823 | } | |
5824 | puthelp "NOTICE $nick :--> Bot triggers available:" | |
5825 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 1]} { | |
5826 | foreach trig [split $incith::google::google_binds " "] { | |
5827 | append temp "${incith::google::command_char}${trig}," | |
5828 | } | |
5829 | set temp [string trimright $temp ","] | |
5830 | if {$incith::google::search_results > 0} { | |
5831 | set item "${incith::google::helpmsg3}${incith::google::search_results}${incith::google::helpmsg4}" | |
5832 | } else { | |
5833 | set item "${incith::google::helpmsg2}" | |
5834 | } | |
5835 | puthelp "NOTICE $nick :${temp} ${incith::google::help1} ${item}" | |
5836 | } | |
5837 | set temp "" | |
5838 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 2]} { | |
5839 | foreach trig [split $incith::google::image_binds " "] { | |
5840 | append temp "${incith::google::command_char}${trig}," | |
5841 | } | |
5842 | set temp [string trimright $temp ","] | |
5843 | if {$incith::google::image_results > 0} { | |
5844 | set item "${incith::google::helpmsg3}${incith::google::image_results}${incith::google::helpmsg4}" | |
5845 | } else { | |
5846 | set item "${incith::google::helpmsg2}" | |
5847 | } | |
5848 | puthelp "NOTICE $nick :${temp} ${incith::google::help2} ${item}" | |
5849 | } | |
5850 | set temp "" | |
5851 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 3]} { | |
5852 | foreach trig [split $incith::google::group_binds " "] { | |
5853 | append temp "${incith::google::command_char}${trig}," | |
5854 | } | |
5855 | set temp [string trimright $temp ","] | |
5856 | if {$incith::google::group_results > 0} { | |
5857 | set item "${incith::google::helpmsg3}${incith::google::group_results}${incith::google::helpmsg4}" | |
5858 | } else { | |
5859 | set item "${incith::google::helpmsg2}" | |
5860 | } | |
5861 | puthelp "NOTICE $nick :${temp} ${incith::google::help3} ${item}" | |
5862 | } | |
5863 | set temp "" | |
5864 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 4]} { | |
5865 | foreach trig [split $incith::google::news_binds " "] { | |
5866 | append temp "${incith::google::command_char}${trig}," | |
5867 | } | |
5868 | set temp [string trimright $temp ","] | |
5869 | if {$incith::google::news_results > 0} { | |
5870 | set item "${incith::google::helpmsg3}${incith::google::news_results}${incith::google::helpmsg4}" | |
5871 | } else { | |
5872 | set item "${incith::google::helpmsg2}" | |
5873 | } | |
5874 | puthelp "NOTICE $nick :${temp} ${incith::google::help4} ${item}" | |
5875 | } | |
5876 | set temp "" | |
5877 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 5]} { | |
5878 | foreach trig [split $incith::google::local_binds " "] { | |
5879 | append temp "${incith::google::command_char}${trig}," | |
5880 | } | |
5881 | set temp [string trimright $temp ","] | |
5882 | if {$incith::google::local_results > 0} { | |
5883 | set item "${incith::google::helpmsg3}${incith::google::local_results}${incith::google::helpmsg4}" | |
5884 | } else { | |
5885 | set item "${incith::google::helpmsg2}" | |
5886 | } | |
5887 | puthelp "NOTICE $nick :${temp} ${incith::google::help5} ${item}" | |
5888 | } | |
5889 | set temp "" | |
5890 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 6]} { | |
5891 | foreach trig [split $incith::google::print_binds " "] { | |
5892 | append temp "${incith::google::command_char}${trig}," | |
5893 | } | |
5894 | set temp [string trimright $temp ","] | |
5895 | if {$incith::google::print_results > 0} { | |
5896 | set item "${incith::google::helpmsg3}${incith::google::print_results}${incith::google::helpmsg4}" | |
5897 | } else { | |
5898 | set item "${incith::google::helpmsg2}" | |
5899 | } | |
5900 | puthelp "NOTICE $nick :${temp} ${incith::google::help6} ${item}" | |
5901 | } | |
5902 | set temp "" | |
5903 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 7]} { | |
5904 | foreach trig [split $incith::google::video_binds " "] { | |
5905 | append temp "${incith::google::command_char}${trig}," | |
5906 | } | |
5907 | set temp [string trimright $temp ","] | |
5908 | if {$incith::google::video_results > 0} { | |
5909 | set item "${incith::google::helpmsg3}${incith::google::video_results}${incith::google::helpmsg4}" | |
5910 | } else { | |
5911 | set item "${incith::google::helpmsg2}" | |
5912 | } | |
5913 | puthelp "NOTICE $nick :${temp} ${incith::google::help7} ${item}" | |
5914 | } | |
5915 | set temp "" | |
5916 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 8]} { | |
5917 | foreach trig [split $incith::google::fight_binds " "] { | |
5918 | append temp "${incith::google::command_char}${trig}," | |
5919 | } | |
5920 | set temp [string trimright $temp ","] | |
5921 | if {$incith::google::google_fight > 0} { | |
5922 | set item "${incith::google::helpmsg3}${incith::google::google_fight}${incith::google::helpmsg4}" | |
5923 | } else { | |
5924 | set item "${incith::google::helpmsg2}" | |
5925 | } | |
5926 | puthelp "NOTICE $nick :${temp} ${incith::google::help8} ${item}" | |
5927 | } | |
5928 | set temp "" | |
5929 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 9]} { | |
5930 | foreach trig [split $incith::google::youtube_binds " "] { | |
5931 | append temp "${incith::google::command_char}${trig}," | |
5932 | } | |
5933 | set temp [string trimright $temp ","] | |
5934 | if {$incith::google::youtube_results > 0} { | |
5935 | set item "${incith::google::helpmsg3}${incith::google::youtube_results}${incith::google::helpmsg4}" | |
5936 | } else { | |
5937 | set item "${incith::google::helpmsg2}" | |
5938 | } | |
5939 | puthelp "NOTICE $nick :${temp} ${incith::google::help9} ${item}" | |
5940 | } | |
5941 | set temp "" | |
5942 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 10]} { | |
5943 | foreach trig [split $incith::google::trans_binds " "] { | |
5944 | append temp "${incith::google::command_char}${trig}," | |
5945 | } | |
5946 | set temp [string trimright $temp ","] | |
5947 | if {$incith::google::trans_results > 0} { | |
5948 | set item "${incith::google::helpmsg3}${incith::google::trans_results}${incith::google::helpmsg4}" | |
5949 | } else { | |
5950 | set item "${incith::google::helpmsg2}" | |
5951 | } | |
5952 | puthelp "NOTICE $nick :${temp} ${incith::google::help10} ${item}" | |
5953 | } | |
5954 | set temp "" | |
5955 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 11]} { | |
5956 | foreach trig [split $incith::google::gamespot_binds " "] { | |
5957 | append temp "${incith::google::command_char}${trig}," | |
5958 | } | |
5959 | set temp [string trimright $temp ","] | |
5960 | if {$incith::google::gamespot_results > 0} { | |
5961 | set item "${incith::google::helpmsg3}${incith::google::gamespot_results}${incith::google::helpmsg4}" | |
5962 | } else { | |
5963 | set item "${incith::google::helpmsg2}" | |
5964 | } | |
5965 | puthelp "NOTICE $nick :${temp} ${incith::google::help11} ${item}" | |
5966 | } | |
5967 | set temp "" | |
5968 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 12]} { | |
5969 | foreach trig [split $incith::google::gamefaq_binds " "] { | |
5970 | append temp "${incith::google::command_char}${trig}," | |
5971 | } | |
5972 | set temp [string trimright $temp ","] | |
5973 | if {$incith::google::gamefaq_results > 0} { | |
5974 | set item "${incith::google::helpmsg3}${incith::google::gamefaq_results}${incith::google::helpmsg4}" | |
5975 | } else { | |
5976 | set item "${incith::google::helpmsg2}" | |
5977 | } | |
5978 | puthelp "NOTICE $nick :${temp} ${incith::google::help12} ${item}" | |
5979 | } | |
5980 | set temp "" | |
5981 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 13]} { | |
5982 | foreach trig [split $incith::google::blog_binds " "] { | |
5983 | append temp "${incith::google::command_char}${trig}," | |
5984 | } | |
5985 | set temp [string trimright $temp ","] | |
5986 | if {$incith::google::blog_results > 0} { | |
5987 | set item "${incith::google::helpmsg3}${incith::google::blog_results}${incith::google::helpmsg4}" | |
5988 | } else { | |
5989 | set item "${incith::google::helpmsg2}" | |
5990 | } | |
5991 | puthelp "NOTICE $nick :${temp} ${incith::google::help13} ${item}" | |
5992 | } | |
5993 | set temp "" | |
5994 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 14]} { | |
5995 | foreach trig [split $incith::google::ebay_binds " "] { | |
5996 | append temp "${incith::google::command_char}${trig}," | |
5997 | } | |
5998 | set temp [string trimright $temp ","] | |
5999 | if {$incith::google::ebay_results > 0} { | |
6000 | set item "${incith::google::helpmsg3}${incith::google::ebay_results}${incith::google::helpmsg4}" | |
6001 | } else { | |
6002 | set item "${incith::google::helpmsg2}" | |
6003 | } | |
6004 | puthelp "NOTICE $nick :${temp} ${incith::google::help14} ${item}" | |
6005 | } | |
6006 | set temp "" | |
6007 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 15]} { | |
6008 | foreach trig [split $incith::google::efight_binds " "] { | |
6009 | append temp "${incith::google::command_char}${trig}," | |
6010 | } | |
6011 | set temp [string trimright $temp ","] | |
6012 | if {$incith::google::google_fight > 0} { | |
6013 | set item "${incith::google::helpmsg3}${incith::google::google_fight}${incith::google::helpmsg4}" | |
6014 | } else { | |
6015 | set item "${incith::google::helpmsg2}" | |
6016 | } | |
6017 | puthelp "NOTICE $nick :${temp} ${incith::google::help15} ${item}" | |
6018 | } | |
6019 | set temp "" | |
6020 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 16]} { | |
6021 | foreach trig [split $incith::google::wiki_binds " "] { | |
6022 | append temp "${incith::google::command_char}${trig}," | |
6023 | } | |
6024 | set temp [string trimright $temp ","] | |
6025 | if {$incith::google::wiki_results > 0} { | |
6026 | set item "${incith::google::helpmsg3}${incith::google::wiki_results}${incith::google::helpmsg4}" | |
6027 | } else { | |
6028 | set item "${incith::google::helpmsg2}" | |
6029 | } | |
6030 | puthelp "NOTICE $nick :${temp} ${incith::google::help16} ${item}" | |
6031 | } | |
6032 | set temp "" | |
6033 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 17]} { | |
6034 | foreach trig [split $incith::google::wikimedia_binds " "] { | |
6035 | append temp "${incith::google::command_char}${trig}," | |
6036 | } | |
6037 | set temp [string trimright $temp ","] | |
6038 | if {$incith::google::wikimedia_results > 0} { | |
6039 | set item "${incith::google::helpmsg3}${incith::google::wikimedia_results}${incith::google::helpmsg4}" | |
6040 | } else { | |
6041 | set item "${incith::google::helpmsg2}" | |
6042 | } | |
6043 | puthelp "NOTICE $nick :${temp} ${incith::google::help17} ${item}" | |
6044 | } | |
6045 | set temp "" | |
6046 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 18]} { | |
6047 | foreach trig [split $incith::google::locate_binds " "] { | |
6048 | append temp "${incith::google::command_char}${trig}," | |
6049 | } | |
6050 | set temp [string trimright $temp ","] | |
6051 | if {$incith::google::locate_results > 0} { | |
6052 | set item "${incith::google::helpmsg3}${incith::google::locate_results}${incith::google::helpmsg4}" | |
6053 | } else { | |
6054 | set item "${incith::google::helpmsg2}" | |
6055 | } | |
6056 | puthelp "NOTICE $nick :${temp} ${incith::google::help18} ${item}" | |
6057 | } | |
6058 | set temp "" | |
6059 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 19]} { | |
6060 | foreach trig [split $incith::google::rev_binds " "] { | |
6061 | append temp "${incith::google::command_char}${trig}," | |
6062 | } | |
6063 | set temp [string trimright $temp ","] | |
6064 | if {$incith::google::rev_results > 0} { | |
6065 | set item "${incith::google::helpmsg3}${incith::google::rev_results}${incith::google::helpmsg4}" | |
6066 | } else { | |
6067 | set item "${incith::google::helpmsg2}" | |
6068 | } | |
6069 | puthelp "NOTICE $nick :${temp} ${incith::google::help19} ${item}" | |
6070 | } | |
6071 | set temp "" | |
6072 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 20]} { | |
6073 | foreach trig [split $incith::google::mininova_binds " "] { | |
6074 | append temp "${incith::google::command_char}${trig}," | |
6075 | } | |
6076 | set temp [string trimright $temp ","] | |
6077 | if {$incith::google::mininova_results > 0} { | |
6078 | set item "${incith::google::helpmsg3}${incith::google::mininova_results}${incith::google::helpmsg4}" | |
6079 | } else { | |
6080 | set item "${incith::google::helpmsg2}" | |
6081 | } | |
6082 | puthelp "NOTICE $nick :${temp} ${incith::google::help20} ${item}" | |
6083 | } | |
6084 | set temp "" | |
6085 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 21]} { | |
6086 | foreach trig [split $incith::google::recent_binds " "] { | |
6087 | append temp "${incith::google::command_char}${trig}," | |
6088 | } | |
6089 | set temp [string trimright $temp ","] | |
6090 | if {$incith::google::recent_results > 0} { | |
6091 | set item "${incith::google::helpmsg3}${incith::google::recent_results}${incith::google::helpmsg4}" | |
6092 | } else { | |
6093 | set item "${incith::google::helpmsg2}" | |
6094 | } | |
6095 | puthelp "NOTICE $nick :${temp} ${incith::google::help21} ${item}" | |
6096 | } | |
6097 | set temp "" | |
6098 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 22]} { | |
6099 | foreach trig [split $incith::google::popular_binds " "] { | |
6100 | append temp "${incith::google::command_char}${trig}," | |
6101 | } | |
6102 | set temp [string trimright $temp ","] | |
6103 | if {$incith::google::popular_results > 0} { | |
6104 | set item "${incith::google::helpmsg3}${incith::google::popular_results}${incith::google::helpmsg4}" | |
6105 | } else { | |
6106 | set item "${incith::google::helpmsg2}" | |
6107 | } | |
6108 | puthelp "NOTICE $nick :${temp} ${incith::google::help22} ${item}" | |
6109 | } | |
6110 | set temp "" | |
6111 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 23]} { | |
6112 | foreach trig [split $incith::google::daily_binds " "] { | |
6113 | append temp "${incith::google::command_char}${trig}," | |
6114 | } | |
6115 | set temp [string trimright $temp ","] | |
6116 | if {$incith::google::daily_results > 0} { | |
6117 | set item "${incith::google::helpmsg3}${incith::google::daily_results}${incith::google::helpmsg4}" | |
6118 | } else { | |
6119 | set item "${incith::google::helpmsg2}" | |
6120 | } | |
6121 | puthelp "NOTICE $nick :${temp} ${incith::google::help23} ${item}" | |
6122 | } | |
6123 | set temp "" | |
6124 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 24]} { | |
6125 | foreach trig [split $incith::google::ign_binds " "] { | |
6126 | append temp "${incith::google::command_char}${trig}," | |
6127 | } | |
6128 | set temp [string trimright $temp ","] | |
6129 | if {$incith::google::ign_results > 0} { | |
6130 | set item "${incith::google::helpmsg3}${incith::google::ign_results}${incith::google::helpmsg4}" | |
6131 | } else { | |
6132 | set item "${incith::google::helpmsg2}" | |
6133 | } | |
6134 | puthelp "NOTICE $nick :${temp} ${incith::google::help24} ${item}" | |
6135 | } | |
6136 | set temp "" | |
6137 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 25]} { | |
6138 | foreach trig [split $incith::google::myspacevids_binds " "] { | |
6139 | append temp "${incith::google::command_char}${trig}," | |
6140 | } | |
6141 | set temp [string trimright $temp ","] | |
6142 | if {$incith::google::myspacevids_results > 0} { | |
6143 | set item "${incith::google::helpmsg3}${incith::google::myspacevids_results}${incith::google::helpmsg4}" | |
6144 | } else { | |
6145 | set item "${incith::google::helpmsg2}" | |
6146 | } | |
6147 | puthelp "NOTICE $nick :${temp} ${incith::google::help25} ${item}" | |
6148 | } | |
6149 | set temp "" | |
6150 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 26]} { | |
6151 | foreach trig [split $incith::google::trends_binds " "] { | |
6152 | append temp "${incith::google::command_char}${trig}," | |
6153 | } | |
6154 | set temp [string trimright $temp ","] | |
6155 | if {$incith::google::trends_results > 0} { | |
6156 | set item "${incith::google::helpmsg3}${incith::google::trends_results}${incith::google::helpmsg4}" | |
6157 | } else { | |
6158 | set item "${incith::google::helpmsg2}" | |
6159 | } | |
6160 | puthelp "NOTICE $nick :${temp} ${incith::google::help26} ${item}" | |
6161 | } | |
6162 | set temp "" | |
6163 | if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 27]} { | |
6164 | foreach trig [split $incith::google::scholar_binds " "] { | |
6165 | append temp "${incith::google::command_char}${trig}," | |
6166 | } | |
6167 | set temp [string trimright $temp ","] | |
6168 | if {$incith::google::scholar_results > 0} { | |
6169 | set item "${incith::google::helpmsg3}${incith::google::image_results}${incith::google::helpmsg4}" | |
6170 | } else { | |
6171 | set item "${incith::google::helpmsg2}" | |
6172 | } | |
6173 | puthelp "NOTICE $nick :${temp} ${incith::google::help27} ${item}" | |
6174 | } | |
6175 | } | |
6176 | ||
6177 | # FETCH_HTML | |
6178 | # fetches html for the various *.google.com sites | |
6179 | # | |
6180 | proc fetch_html {input switch} { | |
6181 | global incithcharset | |
6182 | global incithcookie | |
6183 | set country "" | |
6184 | #--> # Begin urlencoding kludge | |
6185 | if {($switch < 15) || ($switch > 23) && ($switch != 28) && ($switch !=29) && ($switch !=56) && ($switch !=58) && ($switch !=59)} { | |
6186 | set helps $input | |
6187 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input | |
6188 | # this is my input encoding hack, this will convert input before it goes | |
6189 | # out to be queried. | |
6190 | if {$incith::google::encoding_conversion_input > 0 && $country != "" } { | |
6191 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
6192 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { set input [encoding convertfrom $encoding_found $input] } | |
6193 | } else { set encoding_found "" } | |
6194 | set input [urlencode $input 0 "utf-8"] | |
6195 | set country "" ;#reset country and input | |
6196 | } | |
6197 | #<-- # End urlencoding kludge | |
6198 | ||
6199 | ||
6200 | if {$switch == 1} { | |
6201 | # make it so people can search their country | |
6202 | set country "" | |
6203 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6204 | if {$country == ""} { | |
6205 | set country "${incith::google::google_country}" | |
6206 | set flavor "search" | |
6207 | } else { | |
6208 | if {[string match */* $country]} { | |
6209 | if {![string length [set flavor [join [lrange [split $country /] 1 end] /]]]} { | |
6210 | set flavor "search" | |
6211 | } | |
6212 | set country [lindex [split $country /] 0] | |
6213 | } else { set flavor "search" } | |
6214 | } | |
6215 | if {[string equal -nocase "intl" [lindex [split $flavor /] 0]]} { | |
6216 | set lng [lindex [split $flavor /] 1] | |
6217 | set uselang 1 | |
6218 | } | |
6219 | # we don't want 'define:+<search>', so we'll just remove the space if there is one. | |
6220 | regsub -nocase -- {^define:\s*} $input {define:} input | |
6221 | # spell after define so 'spell: define: foo' doesn't turn into a define lookup | |
6222 | if {[string match -nocase "spell%3a*" $input] == 1} { | |
6223 | regsub -nocase -- {^spell%3a\s*} $input {} input | |
6224 | set spell "&spell=1" | |
6225 | } else { | |
6226 | set spell "" | |
6227 | } | |
6228 | if {[info exists uselang]} { | |
6229 | set query "http://www.google.${country}/search?hl=${lng}&q=${input}&safe=${incith::google::safe_search}&lr=lang_${incith::google::language}&ie=utf-8${spell}&nfpr=1" | |
6230 | } else { | |
6231 | set query "http://www.google.${country}/${flavor}?q=${input}&safe=${incith::google::safe_search}&lr=lang_${incith::google::language}&ie=utf-8${spell}&nfpr=1" | |
6232 | } | |
6233 | # IMAGES | |
6234 | } elseif {$switch == 2} { | |
6235 | # make it so people can search their country | |
6236 | set country "" | |
6237 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6238 | if {$country == ""} { | |
6239 | set country "${incith::google::google_country}" | |
6240 | } | |
6241 | set query "http://images.google.${country}/images?q=${input}&safe=${incith::google::safe_search}&btnG=Search+Images&ie=utf-8&sout=1&nfpr=1" | |
6242 | # LOCAL | |
6243 | } elseif {$switch == 3} { | |
6244 | # make it so people can search their country | |
6245 | set country "" | |
6246 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6247 | if {$country == ""} { | |
6248 | set country "${incith::google::google_country}" | |
6249 | set dummy $helps | |
6250 | } | |
6251 | #regexp -nocase -- {^(.+?) near (.+?)$} $dummy - search location | |
6252 | #set query "http://maps.google.${country}/maps?f=q&q=${search}&near=${location}&ie=UTF8&filter=0&oi=lwp_thresh&sa=X&view=text&ct=clnk&cd=1&nfpr=1" | |
6253 | set query "http://maps.google.${country}/maps?f=q&q=${input}&ie=utf-8&filter=0&oi=lwp_thresh&sa=X&view=text&ct=clnk&cd=1&nfpr=1" | |
6254 | } elseif {$switch == 4} { | |
6255 | # make it so people can search their country | |
6256 | set country "" | |
6257 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6258 | if {$country == ""} { | |
6259 | set country "${incith::google::google_country}" | |
6260 | } | |
6261 | set query "http://groups.google.${country}/groups/search?ie=UTF-8&q=${input}&qt_s=Search&safe=${incith::google::safe_search}&ie=utf-8&nfpr=1" | |
6262 | } elseif {$switch == 5} { | |
6263 | # make it so people can search their country | |
6264 | set country "" | |
6265 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6266 | if {$country == ""} { | |
6267 | set country "${incith::google::google_country}" | |
6268 | } | |
6269 | set query "http://news.google.${country}/news?q=${input}&ie=utf-8&nfpr=1" | |
6270 | } elseif {$switch == 6} { | |
6271 | # make it so people can search their country | |
6272 | set country "" | |
6273 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6274 | if {$country == ""} { | |
6275 | set country "${incith::google::google_country}" | |
6276 | } | |
6277 | set query "http://books.google.${country}/books?q=${input}&btnG=Search+Books&ie=utf-8&nfpr=1" | |
6278 | } elseif {$switch == 7} { | |
6279 | # make it so people can search their country | |
6280 | set country "" | |
6281 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6282 | if {$country == ""} { | |
6283 | set country "${incith::google::google_country}" | |
6284 | } | |
6285 | set query "http://www.google.${country}/search?q=${input}&tbs=vid:1&nfpr=1" | |
6286 | #set query "http://video.google.${country}/videosearch?q=${input}&btnG=Search+Video&ie=utf-8" | |
6287 | } elseif {$switch == 8} { | |
6288 | # make it so people can search their country | |
6289 | set country "" | |
6290 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6291 | if {$country == ""} { | |
6292 | set country "${incith::google::google_country}" | |
6293 | } | |
6294 | set query "http://www.google.${country}/search?hl=&q=${input}&safe=off&btnG=Search&lr=lang_all&num=1&ie=utf-8" | |
6295 | } elseif {$switch == 9} { | |
6296 | # make it so people can search their country | |
6297 | set country "" ; set hd "" | |
6298 | if {[regsub -nocase -all -- "[urlencode $::incith::google::youtube_highdef 0]" $input "" input]} { | |
6299 | set hd "&high_definition=1" | |
6300 | } | |
6301 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6302 | if {$country == ""} { | |
6303 | set country "${incith::google::youtube_country}" | |
6304 | } | |
6305 | if {$country == "com"} { | |
6306 | set query "http://www.youtube.com/results?search_query=${input}&hl=en&ie=utf-8$hd" | |
6307 | } else { | |
6308 | set query "http://${country}.youtube.com/results?search_query=${input}&hl=${country}&ie=utf-8$hd" | |
6309 | } | |
6310 | } elseif {$switch == 10} { | |
6311 | # make it so people can search their country | |
6312 | set country "" | |
6313 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6314 | if {$country == ""} { | |
6315 | set country "${incith::google::google_country}" | |
6316 | } | |
6317 | set query "http://scholar.google.${country}/scholar?hl=all&lr=&safe=${incith::google::safe_search}&q=${input}&btnG=Search&ie=utf-8" | |
6318 | } elseif {$switch == 11} { | |
6319 | #set query "http://vidsearch.myspace.com/index.cfm?fuseaction=vids.fullsearch&searchText=${input}&fullSearch=Search%20Videos" | |
6320 | #set query "http://vids.myspace.com/index.cfm?SearchBoxID=SplashHeader&fuseaction=vids.search&q=${input}&t=tvid" | |
6321 | set query "http://searchservice.myspace.com/index.cfm?fuseaction=sitesearch.results&orig=search_Header&origpfc=VidsSplash&type=MySpaceTV&qry=${input}&submit=Search" | |
6322 | } elseif {$switch == 12} { | |
6323 | #set query "http://www.gamespot.com/search.html?qs=${input}&x=0&y=0" | |
6324 | #set query "http://www.gamespot.com/pages/search/index.php?qs=${input}&sub=g" | |
6325 | set query "http://www.gamespot.com/pages/search/search_ajax.php?q=${input}&type=game&offset=0&tags_only=false&sort=rank" | |
6326 | #set query "http://www.gamespot.com/search.html?tag=search%3Bbutton&om_act=convert&om_clk=search&qs=${input}" | |
6327 | #set query "http://www.gamespot.com/pages/search/index.php?qs=${input}#game" | |
6328 | #set query "http://www.gamespot.com/search.html?qs=${input}" | |
6329 | #set query "http://www.gamespot.com/pages/tags/index.php?type=game&tags=${input}" | |
6330 | } elseif {$switch == 13} { | |
6331 | # make it so people can search their country | |
6332 | set country "" | |
6333 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6334 | if {$country == ""} { | |
6335 | set country "${incith::google::google_country}" | |
6336 | } | |
6337 | set query "http://www.google.${country}/trends/hottrends?date=${input}&sa=x&ctab=0&hl=en" | |
6338 | } elseif {$switch == 14} { | |
6339 | # make it so people can search their country | |
6340 | set country "" | |
6341 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6342 | if {$country == ""} { | |
6343 | set country "${incith::google::daily_country}" | |
6344 | } | |
6345 | if {$country == "en"} { | |
6346 | set query "http://www.dailymotion.com/relevance/search/${input}" | |
6347 | } else { | |
6348 | set query "http://www.dailymotion.com/${country}/relevance/search/${input}" | |
6349 | } | |
6350 | } elseif {$switch == 15} { | |
6351 | set query "http://www.gamefaqs.com/ds/releases${input}" | |
6352 | } elseif {$switch == 16} { | |
6353 | set query "http://www.gamefaqs.com/iphone/releases${input}" | |
6354 | } elseif {$switch == 17} { | |
6355 | set query "http://www.gamefaqs.com/psp/releases${input}" | |
6356 | } elseif {$switch == 18} { | |
6357 | set query "http://www.gamefaqs.com/xbox360/releases${input}" | |
6358 | } elseif {$switch == 19} { | |
6359 | set query "http://www.gamefaqs.com/xbox/releases${input}" | |
6360 | } elseif {$switch == 20} { | |
6361 | set query "http://www.gamefaqs.com/gamecube/releases${input}" | |
6362 | } elseif {$switch == 21} { | |
6363 | set query "http://www.gamefaqs.com/ps2/releases${input}" | |
6364 | } elseif {$switch == 22} { | |
6365 | set query "http://www.gamefaqs.com/pc/releases${input}" | |
6366 | } elseif {$switch == 23} { | |
6367 | set query "http://www.gamefaqs.com/ps3/releases${input}" | |
6368 | } elseif {$switch == 24} { | |
6369 | # make it so people can search their country | |
6370 | set country "" | |
6371 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6372 | if {$country == ""} { | |
6373 | set country "${incith::google::google_country}" | |
6374 | } | |
6375 | regsub -all -- {-} $input "%2d" input | |
6376 | set query "http://blogsearch.google.${country}/blogsearch?q=${input}&lr=&sa=N&tab=gn&ie=utf-8" | |
6377 | } elseif {$switch == 25} { | |
6378 | # make it so people can search their country | |
6379 | set country "" ; set shop "" | |
6380 | regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy | |
6381 | if {$country == ""} { | |
6382 | if {![regexp -nocase -- {^\@(.+?)\s(.+?)$} $helps - shop input]} { | |
6383 | set country $::incith::google::ebay_country | |
6384 | } | |
6385 | } | |
6386 | regsub -all -- {-} $input "%2d" input | |
6387 | regsub -all -- { } $input "-" input | |
6388 | ||
6389 | #set query "http://search.ebay.com/search/search.dll?sofocus=unknown&sbrftog=1&from=R10&_trksid=m37&satitle=${input}&sacat=-1%26catref%3DC6&sargn=-1%26saslc%3D2&sadis=200&fpos=95482&sabfmts=1&saobfmts=insif&ftrt=1&ftrv=1&saprclo=&saprchi=&fsop=1%26fsoo%3D1&coaction=compare&copagenum=1&coentrypage=search" | |
6390 | #set query "http://search.ebay.${country}/${input}" | |
6391 | #set query "http://shop.ebay.${country}/items/_W0QQ_nkwZ${input}QQ_armrsZ1QQ_fromZQQ_mdoZ" | |
6392 | #set query "http://shop.ebay.${country}/${input}" | |
6393 | #set query "http://shop.ebay.${country}/items/_W0QQ_nkwZ${input}QQ_armrsZ1QQ_fromZQQ_mdoZ" | |
6394 | if {![string length $shop]} { | |
6395 | set query "http://shop.ebay.${country}/i.html?_nkw=${input}&_armrs=1&_from=&_ipg=&_dmd=1" | |
6396 | } else { | |
6397 | set query "http://$shop.shop.ebay.com/?_nkw=${input}&_armrs=1&_from=&_ipg=&_dmd=1" | |
6398 | } | |
6399 | #set query "http://search.ebay.${country}/${input}_W0QQpqryZ${input}" | |
6400 | } elseif {$switch == 26} { | |
6401 | set query "http://search.ign.com/products?sort=relevance&query=${input}&so=exact&objtName=all&origin=&startat=0&nc=false&ns=false" | |
6402 | #set query "http://search.ign.com/products?query=${input}" | |
6403 | } elseif {$switch == 27} { | |
6404 | # place holder for wikipedia | |
6405 | # eventually it will get put back into fetch_html | |
6406 | } elseif {$switch == 28} { | |
6407 | set query "http://www.gamefaqs.com/wii/releases${input}" | |
6408 | } elseif {$switch == 29} { | |
6409 | set query "http://www.gamefaqs.com/dreamcast/releases${input}" | |
6410 | } elseif {$switch == 30} { | |
6411 | set query "http://www.gamerankings.com/browse.html?site=gamecube&cat=0&year=2&numrev=0&sort=${input}&search=" | |
6412 | } elseif {$switch == 31} { | |
6413 | set query "http://www.gamerankings.com/browse.html?site=pc&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6414 | } elseif {$switch == 32} { | |
6415 | set query "http://www.gamerankings.com/browse.html?site=ps2&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6416 | } elseif {$switch == 33} { | |
6417 | set query "http://www.gamerankings.com/browse.html?site=ps3&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6418 | } elseif {$switch == 34} { | |
6419 | set query "http://www.gamerankings.com/browse.html?site=wii&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6420 | } elseif {$switch == 35} { | |
6421 | set query "http://www.gamerankings.com/browse.html?site=xbox&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6422 | } elseif {$switch == 36} { | |
6423 | set query "http://www.gamerankings.com/browse.html?site=xbox360&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6424 | } elseif {$switch == 37} { | |
6425 | set query "http://www.gamerankings.com/browse.html?site=ds&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6426 | } elseif {$switch == 38} { | |
6427 | set query "http://www.gamerankings.com/browse.html?site=gba&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6428 | } elseif {$switch == 39} { | |
6429 | set query "http://www.gamerankings.com/browse.html?site=psp&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6430 | } elseif {$switch == 40} { | |
6431 | set query "http://www.gamerankings.com/browse.html?site=mobile&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6432 | } elseif {$switch == 41} { | |
6433 | set query "http://www.gamerankings.com/browse.html?site=ngage&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6434 | } elseif {$switch == 42} { | |
6435 | set query "http://www.gamerankings.com/browse.html?site=3do&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6436 | } elseif {$switch == 43} { | |
6437 | set query "http://www.gamerankings.com/browse.html?site=dreamcast&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6438 | } elseif {$switch == 44} { | |
6439 | set query "http://www.gamerankings.com/browse.html?site=genesis&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6440 | } elseif {$switch == 45} { | |
6441 | set query "http://www.gamerankings.com/browse.html?site=jaguar&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6442 | } elseif {$switch == 46} { | |
6443 | set query "http://www.gamerankings.com/browse.html?site=n64&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6444 | } elseif {$switch == 47} { | |
6445 | set query "http://www.gamerankings.com/browse.html?site=neo&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6446 | } elseif {$switch == 48} { | |
6447 | set query "http://www.gamerankings.com/browse.html?site=ps&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6448 | } elseif {$switch == 49} { | |
6449 | set query "http://www.gamerankings.com/browse.html?site=saturn&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6450 | } elseif {$switch == 50} { | |
6451 | set query "http://www.gamerankings.com/browse.html?site=snes&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6452 | } elseif {$switch == 51} { | |
6453 | set query "http://www.mininova.org/search/${input}/seeds" | |
6454 | } elseif {$switch == 52} { | |
6455 | set query "http://www.gamerankings.com/browse.html?site=segacd&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6456 | } elseif {$switch == 53} { | |
6457 | set query "http://www.gamerankings.com/browse.html?site=gameboy&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6458 | } elseif {$switch == 54} { | |
6459 | set query "http://www.gamerankings.com/browse.html?site=gbc&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6460 | } elseif {$switch == 55} { | |
6461 | set query "http://www.gamerankings.com/browse.html?site=&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6462 | } elseif {$switch == 56} { | |
6463 | set query "http://www.gamefaqs.com/3ds/releases${input}" | |
6464 | } elseif {$switch == 57} { | |
6465 | set query "http://www.gamerankings.com/browse.html?site=3ds&cat=0&year=0&numrev=3&sort=${input}&search=" | |
6466 | } elseif {$switch == 58} { | |
6467 | set query "http://www.gamerankings.com/browse.html?site=mac&cat=0&year=0&numrev=2&sort=${input}&search=" | |
6468 | } elseif {$switch == 59} { | |
6469 | set query "http://www.gamefaqs.com/mac/releases${input}" | |
6470 | } | |
6471 | ||
6472 | # didnt have this before, this is needed for google parsers to correctly | |
6473 | # encode the 'do not include' tag, aka the hyphen.. hehe | |
6474 | if {$switch < 9} { | |
6475 | regsub -nocase -- {-} $input "%2d" input | |
6476 | } | |
6477 | regsub -all -- {\+} $query {%2B} query | |
6478 | regsub -all -- {\"} $query {%22} query | |
6479 | if {$switch != 25} { | |
6480 | regsub -all -- { } $query {+} query | |
6481 | } | |
6482 | ||
6483 | if {$switch == 12} { | |
6484 | # grab the ajax data | |
6485 | set http [::http::geturl $query -headers "X-Requested-With XMLHttpRequest X-Request JSON Referer $query $::incith_hdr" -timeout [expr 1000 * 10]] | |
6486 | upvar #0 $http state | |
6487 | set html [ungzip [string map {"\\n" "" "\\" ""} [::http::data $http]] $state(meta)] | |
6488 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
6489 | set redir [::http::ncode $http] | |
6490 | set cookies [list] | |
6491 | } else { | |
6492 | # beware, changing the useragent will result in differently formatted html from Google. | |
6493 | set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3" | |
6494 | #set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" | |
6495 | # enable proxy | |
6496 | if {![string length $::incith::google::proxy_host]} { | |
6497 | set http [::http::config -useragent $ua] | |
6498 | } else { | |
6499 | set http [::http::config -useragent $ua -proxyhost $::incith::google::proxy_host -proxyport $::incith::google::proxy_port] | |
6500 | } | |
6501 | # stole this bit from rosc2112 on egghelp forums | |
6502 | # borrowed is a better term, all procs eventually need this error handler. | |
6503 | ||
6504 | catch {set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 12]]} error | |
6505 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
6506 | return "socketerrorabort|${query}" | |
6507 | } | |
6508 | if { [::http::status $http] == "timeout" } { | |
6509 | return "timeouterrorabort" | |
6510 | } | |
6511 | upvar #0 $http state | |
6512 | set html [ungzip [::http::data $http] $state(meta)] | |
6513 | set redir [::http::ncode $http] | |
6514 | # CHECK CHECK | |
6515 | upvar #0 $http state | |
6516 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
6517 | # Are there cookies? | |
6518 | set cookies [list] | |
6519 | foreach {name value} $state(meta) { | |
6520 | # do we have cookies? | |
6521 | if {[string equal -nocase $name "Set-Cookie"]} { | |
6522 | # yes, add them to cookie list | |
6523 | lappend webCookies [lindex [split $value {;}] 0] | |
6524 | } | |
6525 | } | |
6526 | if {[info exists webCookies] && [llength $webCookies]} { | |
6527 | set cookies "[string trim [join $webCookies {;}] {;}]" | |
6528 | } else { | |
6529 | set cookies "" | |
6530 | } | |
6531 | # REDIRECT | |
6532 | while {[string match "*${redir}*" "303|302|301" ]} { | |
6533 | foreach {name value} $state(meta) { | |
6534 | if {[regexp -nocase ^location$ $name]} { | |
6535 | if {![string match "http*" $value]} { | |
6536 | if {![string match "/" [string index $value 0]]} { | |
6537 | set value "[join [lrange [split $query "/"] 0 2] "/"]/$value" | |
6538 | } else { | |
6539 | set value "[join [lrange [split $query "/"] 0 2] "/"]$value" | |
6540 | } | |
6541 | } | |
6542 | if {[string length $cookies]} { | |
6543 | set http [::http::geturl "[string map {" " "%20"} $value]" -headers "$::incith_hdr Referer $query Cookie $cookies" -timeout [expr 1000 * 10]] | |
6544 | } else { | |
6545 | set http [::http::geturl "[string map {" " "%20"} $value]" -headers "$::incith_hdr Referer $query" -timeout [expr 1000 * 10]] | |
6546 | } | |
6547 | if { $::incith::google::debug > 0 } { putserv "privmsg $::incith::google::debugnick :\002redirected \($redir\):\002 $query -> $value :: \002Cookie:\002 [join $cookies]" } | |
6548 | if {[string match -nocase "*couldn't open socket*" $error]} { | |
6549 | return "socketerrorabort|${value}" | |
6550 | } | |
6551 | if { [::http::status $http] == "timeout" } { | |
6552 | return "timeouterrorabort" | |
6553 | } | |
6554 | upvar #0 $http state | |
6555 | # Are there cookies? | |
6556 | foreach {nam val} $state(meta) { | |
6557 | # do we have cookies? | |
6558 | if {[string equal -nocase $nam "Set-Cookie"]} { | |
6559 | if {![info exists flagme]} { | |
6560 | set flagme 0 | |
6561 | set cookies [list] | |
6562 | } | |
6563 | # yes, add them to cookie list | |
6564 | lappend webCookies [lindex [split $val {;}] 0] | |
6565 | } | |
6566 | } | |
6567 | if {[info exists webCookies] && [llength $webCookies]} { | |
6568 | set cookies "[string trim [join $webCookies {;}] {;}]" | |
6569 | } else { | |
6570 | set cookies "" | |
6571 | } | |
6572 | set redir [::http::ncode $http] | |
6573 | set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)] | |
6574 | set query [string map {" " "%20"} $value] | |
6575 | } | |
6576 | } | |
6577 | } | |
6578 | } | |
6579 | set html [ungzip [::http::data $http] $state(meta)] | |
6580 | ::http::cleanup $http | |
6581 | # ---- step 1 | |
6582 | # Determine which encoding to use | |
6583 | # | |
6584 | set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1] | |
6585 | if {$incith::google::encoding_conversion_output > 0} { | |
6586 | if {$incith::google::automagic > 0} { | |
6587 | if {[string match -nocase "utf-8" $incithcharset] && $incith::google::utf8workaround > 0 && $encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
6588 | set new_encoding $encoding_found | |
6589 | } else { | |
6590 | set new_encoding $incithcharset | |
6591 | } | |
6592 | } else { | |
6593 | if {$encoding_found != "" } { | |
6594 | set new_encoding $encoding_found | |
6595 | } else { | |
6596 | set new_encoding "NONE" | |
6597 | } | |
6598 | } | |
6599 | } else { | |
6600 | set new_encoding "DISABLED" | |
6601 | } | |
6602 | ||
6603 | # ---- step 2 | |
6604 | # Report the conclusion to debugnick | |
6605 | # | |
6606 | if {$incith::google::debug > 0} { | |
6607 | if {[string match -nocase $new_encoding $incithcharset]} { | |
6608 | if {[lsearch -exact [encoding names] $incithcharset] != -1} { | |
6609 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002\037charset:\037\002 $incithcharset \002encode_string:\002 $encoding_found :: \002Cookie:\002 $cookies" | |
6610 | } else { | |
6611 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002\037charset:\037\002 $incithcharset \037<--ERROR: Unknown\037 \002encode_string:\002 $encoding_found :: \002Cookie:\002 $cookies" | |
6612 | } | |
6613 | } elseif {[string match -nocase $new_encoding $encoding_found]} { | |
6614 | if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { | |
6615 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \037\002encode_string:\002\037 $encoding_found :: \002Cookie:\002 $cookies" | |
6616 | } else { | |
6617 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002\037encode_string:\037\002 $encoding_found \037<--ERROR: Unknown\037 :: \002Cookie:\002 $cookies" | |
6618 | } | |
6619 | } elseif {[string match -nocase "DISABLED" $new_encoding]} { | |
6620 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002encode_string:\002 $encoding_found \037DISABLED:\037 Using default charset. :: \002Cookie:\002 $cookies" | |
6621 | } else { | |
6622 | putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002encode_string:\002 $encoding_found \037UNKNOWN ERROR:\037 Using default charset. :: \002Cookie:\002 $cookies" | |
6623 | } | |
6624 | } | |
6625 | ||
6626 | # ---- step 3 | |
6627 | # Apply the encoding | |
6628 | # | |
6629 | if {![string match *$new_encoding* "utf-8"] && ![string equal "DISABLED" $new_encoding]} { | |
6630 | set incithcharset $new_encoding | |
6631 | set html [incithencode $html] | |
6632 | } | |
6633 | ||
6634 | # generic pre-parsing | |
6635 | regsub -all "\n" $html "" html | |
6636 | regsub -all "(?:\x91|\x92|')" $html {'} html | |
6637 | regsub -all "(?:\x93|\x94|")" $html {"} html | |
6638 | regsub -all "&" $html {\&} html | |
6639 | regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html | |
6640 | if {![string match $switch "4"] && ![string match $switch "26"]} { | |
6641 | regsub -all -nocase {<font.+?>} $html "" html | |
6642 | regsub -all -nocase {</font>} $html "" html | |
6643 | regsub -all -nocase {<script type=.*?script>} $html "" html | |
6644 | } | |
6645 | if {![string match *$switch* "|9|7|"]} { | |
6646 | regsub -all -nocase {<span.*?>} $html "" html | |
6647 | regsub -all -nocase {</span>} $html "" html | |
6648 | } | |
6649 | regsub -all -nocase {<input.+?>} $html "" html | |
6650 | regsub -all -nocase {(?:<i>|</i>)} $html "" html | |
6651 | regsub -all "×" $html {*} html | |
6652 | regsub -all " " $html { } html | |
6653 | regsub -all -nocase "×" $html "x" html | |
6654 | regsub -all -nocase "<" $html "<" html | |
6655 | regsub -all -nocase ">" $html ">" html | |
6656 | regsub -all {\x000f} $html "" html | |
6657 | # ' | |
6658 | # regexps that should remain seperate go here | |
6659 | # google specific regexps | |
6660 | if {$switch == 1} { | |
6661 | # regexp the rest of the html for a much easier result to parse | |
6662 | regsub -all -nocase {<b>\[PDF\]</b>\s*} $html "" html | |
6663 | regsub {<p class=g style="margin-top:0">(.+?)</p>} $html "" html | |
6664 | } elseif {$switch == 2} { | |
6665 | # these %2520 codes, I have no idea. But they're supposed to be %20's | |
6666 | regsub -all {%2520} $html {%20} html | |
6667 | } elseif {$switch == 3} { | |
6668 | regsub -all -nocase { - <nobr>Unverified listing</nobr>} $html "" html | |
6669 | regsub -all -- { } $html { } html | |
6670 | } elseif {$switch == 4} { | |
6671 | } elseif {$switch == 5} { | |
6672 | } elseif {$switch == 6} { | |
6673 | } elseif {$switch == 7} { | |
6674 | } elseif {$switch == 8} { | |
6675 | } elseif {$switch == 9} { | |
6676 | regsub -all "\t" $html "" html | |
6677 | regsub -all "\n" $html "" html | |
6678 | regsub -all "\r" $html "" html | |
6679 | regsub -all "\v" $html "" html | |
6680 | } elseif {$switch == 10} { | |
6681 | regsub -all -nocase { - <nobr>Unverified listing</nobr>} $html "" html | |
6682 | regsub -all -- { } $html { } html | |
6683 | } elseif {$switch == 25} { | |
6684 | regsub -all {<script.*?>.+?</script>} $html "" html | |
6685 | regsub -all "\t" $html "" html | |
6686 | regsub -all "\n" $html "" html | |
6687 | regsub -all "\r" $html "" html | |
6688 | regsub -all "\v" $html "" html | |
6689 | regsub -all "<wbr/>" $html "" html | |
6690 | } elseif {$switch > 11 && $switch < 31 || $switch == 56 || $switch == 58 || $switch == 59} { | |
6691 | regsub -all "\t" $html "" html | |
6692 | regsub -all "\n" $html "" html | |
6693 | regsub -all "\r" $html "" html | |
6694 | regsub -all "\v" $html "" html | |
6695 | regsub -all "'" $html "'" html | |
6696 | } elseif {$switch == 51} { | |
6697 | regsub -all "<strong>|</strong>" $html "\002" html | |
6698 | } | |
6699 | ||
6700 | # no point having it so many times | |
6701 | if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} { | |
6702 | regsub -all -nocase {(?:<b>|</b>|<em>|</em>|<strong>|</strong>)} $html "\002" html | |
6703 | } else { | |
6704 | regsub -all -nocase {(<b>|</b>|<em>|</em>|<strong>|</strong>)} $html "" html | |
6705 | } | |
6706 | # DEBUG DEBUG | |
6707 | set junk [open "ig-debug.txt" w] | |
6708 | puts $junk $html | |
6709 | close $junk | |
6710 | return $html | |
6711 | } | |
6712 | ||
6713 | # PUBLIC_MESSAGE | |
6714 | # decides what to do with binds that get triggered | |
6715 | # | |
6716 | proc public_message {nick uhand hand chan input} { | |
6717 | if {[lsearch -exact [channel info $chan] +google] != -1} { | |
6718 | if {$incith::google::chan_user_level == 3} { | |
6719 | if {[isop $nick $chan] == 0} { | |
6720 | return | |
6721 | } | |
6722 | } elseif {$incith::google::chan_user_level == 2} { | |
6723 | if {[ishalfop $nick $chan] == 0 && [isop $nick $chan] == 0} { | |
6724 | return | |
6725 | } | |
6726 | } elseif {$incith::google::chan_user_level == 1} { | |
6727 | if {[isvoice $nick $chan] == 0 && [ishalfop $nick $chan] == 0 && [isop $nick $chan] == 0} { | |
6728 | return | |
6729 | } | |
6730 | } | |
6731 | send_output "$input" "$chan" "$nick" "$uhand" | |
6732 | } | |
6733 | } | |
6734 | ||
6735 | # PRIVATE_MESSAGE | |
6736 | # decides what to do with binds that get triggered | |
6737 | # | |
6738 | proc private_message {nick uhand hand input} { | |
6739 | if {$incith::google::private_messages >= 1} { | |
6740 | send_output $input $nick $nick $uhand | |
6741 | } | |
6742 | } | |
6743 | ||
6744 | # SEND_OUTPUT | |
6745 | # no point having two copies of this in public/private_message{} | |
6746 | # | |
6747 | proc send_output {input where nick uhand} { | |
6748 | ||
6749 | # this is my input encoding hack, this will convert input before it goes | |
6750 | # out to be queried. | |
6751 | if {$incith::google::encoding_conversion_input > 0} { | |
6752 | if {[encoding system] != "identity" && [lsearch [encoding names] "utf-8"]} { | |
6753 | set command_char [encoding convertfrom "utf-8" ${incith::google::command_char}] | |
6754 | set input [encoding convertfrom "utf-8" $input] | |
6755 | } elseif {[encoding system] == "identity"} { | |
6756 | set command_char [encoding convertfrom identity ${incith::google::command_char}] | |
6757 | set input [encoding convertfrom identity $input] | |
6758 | } else { | |
6759 | set command_char ${incith::google::command_char} | |
6760 | } | |
6761 | } else { | |
6762 | set command_char ${incith::google::command_char} | |
6763 | } | |
6764 | ||
6765 | #Specifically retrieve only ONE (ascii) character, then check that matches the command_char first | |
6766 | set trigger_char [string index $input 0] | |
6767 | if {[encoding system] == "identity"} { | |
6768 | set trigger_char [encoding convertfrom identity $trigger_char] | |
6769 | } | |
6770 | ||
6771 | #Sanity check 1 - If no match, stop right here. No need to match every (first word) of | |
6772 | # every line of channel data against every bind if the command_char doesnt even match. | |
6773 | if {$trigger_char != $command_char} { | |
6774 | return | |
6775 | } | |
6776 | ||
6777 | set trigger [string range [lindex [split $input] 0] 1 end] | |
6778 | #Sanity check 2 - Stop if theres nothing to search for (quiet) | |
6779 | if {$incith::google::aversion_vocabulary > 0} { | |
6780 | set search [vocabaversion [string trim [string range $input [string wordend $input 1] end]]] | |
6781 | } else { | |
6782 | set search [string trim [string range $input [string wordend $input 1] end]] | |
6783 | } | |
6784 | if {$search == ""} { return } | |
6785 | ||
6786 | if {$incith::google::force_private == 1} { set where $nick } | |
6787 | # check for !google | |
6788 | if {$incith::google::search_results > 0} { | |
6789 | foreach bind [split $incith::google::google_binds " "] { | |
6790 | if {[string match -nocase $bind $trigger] == 1} { | |
6791 | # channel filter check | |
6792 | foreach c [split $incith::google::filtered " "] { | |
6793 | if {[string match -nocase $where $c] == 1} { | |
6794 | return | |
6795 | } | |
6796 | } | |
6797 | # flood protection check | |
6798 | if {[flood $nick $uhand]} { | |
6799 | return | |
6800 | } | |
6801 | # call google | |
6802 | foreach line [incith::google::parse_output [google $search]] { | |
6803 | put_output $where "$incith::google::search_prepend$line" | |
6804 | } | |
6805 | break | |
6806 | } | |
6807 | } | |
6808 | } | |
6809 | # check for !images | |
6810 | if {$incith::google::image_results > 0} { | |
6811 | foreach bind [split $incith::google::image_binds " "] { | |
6812 | if {[string match -nocase $bind $trigger] == 1} { | |
6813 | # flood protection check | |
6814 | if {[flood $nick $uhand]} { | |
6815 | return | |
6816 | } | |
6817 | # call images | |
6818 | foreach line [incith::google::parse_output [images $search]] { | |
6819 | put_output $where "$incith::google::image_prepend$line" | |
6820 | } | |
6821 | break | |
6822 | } | |
6823 | } | |
6824 | } | |
6825 | # check for !local | |
6826 | if {$incith::google::local_results > 0} { | |
6827 | foreach bind [split $incith::google::local_binds " "] { | |
6828 | if {[string match -nocase $bind $trigger] == 1} { | |
6829 | # flood protection check | |
6830 | if {[flood $nick $uhand]} { | |
6831 | return | |
6832 | } | |
6833 | # local requires splitting of the search | |
6834 | regexp -nocase -- {^(.+?) near (.+?)$} $search - what location | |
6835 | if {![info exists what] || ![info exists location]} { | |
6836 | put_output $where "Local searches should be the format of 'pizza near footown, bar'" | |
6837 | return | |
6838 | } | |
6839 | foreach line [incith::google::parse_output [local $search]] { | |
6840 | put_output $where "$incith::google::local_prepend$line" | |
6841 | } | |
6842 | break | |
6843 | } | |
6844 | } | |
6845 | } | |
6846 | # check for !groups | |
6847 | if {$incith::google::group_results > 0} { | |
6848 | foreach bind [split $incith::google::group_binds " "] { | |
6849 | if {[string match -nocase $bind $trigger] == 1} { | |
6850 | # flood protection check | |
6851 | if {[flood $nick $uhand]} { | |
6852 | return | |
6853 | } | |
6854 | # call groups | |
6855 | foreach line [incith::google::parse_output [groups $search]] { | |
6856 | put_output $where "$incith::google::group_prepend$line" | |
6857 | } | |
6858 | break | |
6859 | } | |
6860 | } | |
6861 | } | |
6862 | # check for !news | |
6863 | if {$incith::google::news_results > 0} { | |
6864 | foreach bind [split $incith::google::news_binds " "] { | |
6865 | if {[string match -nocase $bind $trigger] == 1} { | |
6866 | # flood protection check | |
6867 | if {[flood $nick $uhand]} { | |
6868 | return | |
6869 | } | |
6870 | # call news | |
6871 | foreach line [incith::google::parse_output [news $search]] { | |
6872 | put_output $where "$incith::google::news_prepend$line" | |
6873 | } | |
6874 | break | |
6875 | } | |
6876 | } | |
6877 | } | |
6878 | # check for !print | |
6879 | if {$incith::google::print_results > 0} { | |
6880 | foreach bind [split $incith::google::print_binds " "] { | |
6881 | if {[string match -nocase $bind $trigger] == 1} { | |
6882 | # flood protection check | |
6883 | if {[flood $nick $uhand]} { | |
6884 | return | |
6885 | } | |
6886 | # call print | |
6887 | foreach line [incith::google::parse_output [print $search]] { | |
6888 | put_output $where "$incith::google::print_prepend$line" | |
6889 | } | |
6890 | break | |
6891 | } | |
6892 | } | |
6893 | } | |
6894 | # check for !video | |
6895 | if {$incith::google::video_results > 0} { | |
6896 | foreach bind [split $incith::google::video_binds " "] { | |
6897 | if {[string match -nocase $bind $trigger] == 1} { | |
6898 | # flood protection check | |
6899 | if {[flood $nick $uhand]} { | |
6900 | return | |
6901 | } | |
6902 | # call video | |
6903 | foreach line [incith::google::parse_output [video $search]] { | |
6904 | put_output $where "$incith::google::video_prepend$line" | |
6905 | } | |
6906 | break | |
6907 | } | |
6908 | } | |
6909 | } | |
6910 | # check for !scholar | |
6911 | if {$incith::google::scholar_results > 0} { | |
6912 | foreach bind [split $incith::google::scholar_binds " "] { | |
6913 | if {[string match -nocase $bind $trigger] == 1} { | |
6914 | # flood protection check | |
6915 | if {[flood $nick $uhand]} { | |
6916 | return | |
6917 | } | |
6918 | # call video | |
6919 | foreach line [incith::google::parse_output [scholar $search]] { | |
6920 | put_output $where "$incith::google::scholar_prepend$line" | |
6921 | } | |
6922 | break | |
6923 | } | |
6924 | } | |
6925 | } | |
6926 | # check for !fight | |
6927 | if {$incith::google::google_fight > 0} { | |
6928 | foreach bind [split $incith::google::fight_binds " "] { | |
6929 | if {[string match -nocase $bind $trigger] == 1} { | |
6930 | # flood protection check | |
6931 | if {[flood $nick $uhand]} { | |
6932 | return | |
6933 | } | |
6934 | # fight requires splitting of the search | |
6935 | regexp -nocase -- {^(.+?) vs (.+?)$} $search - word1 word2 | |
6936 | if {![info exists word1] || ![info exists word2]} { | |
6937 | put_output $where "Google fights should be the format of 'word(s) one vs word(s) two'" | |
6938 | return | |
6939 | } | |
6940 | # call fight | |
6941 | foreach line [incith::google::parse_output [fight $search]] { | |
6942 | put_output $where "$incith::google::fight_prepend$line" | |
6943 | } | |
6944 | break | |
6945 | } | |
6946 | } | |
6947 | } | |
6948 | # check for !ebayfight | |
6949 | if {$incith::google::google_fight > 0} { | |
6950 | foreach bind [split $incith::google::efight_binds " "] { | |
6951 | if {[string match -nocase $bind $trigger] == 1} { | |
6952 | # flood protection check | |
6953 | if {[flood $nick $uhand]} { | |
6954 | return | |
6955 | } | |
6956 | # fight requires splitting of the search | |
6957 | regexp -nocase -- {^(.+?) vs (.+?)$} $search - word1 word2 | |
6958 | if {![info exists word1] || ![info exists word2]} { | |
6959 | put_output $where "Ebay fights should be the format of 'word(s) one vs word(s) two'" | |
6960 | return | |
6961 | } | |
6962 | # call ebayfight | |
6963 | foreach line [incith::google::parse_output [ebayfight $search]] { | |
6964 | put_output $where "$incith::google::ebayfight_prepend$line" | |
6965 | } | |
6966 | break | |
6967 | } | |
6968 | } | |
6969 | } | |
6970 | # check for !youtube | |
6971 | if {$incith::google::youtube_results > 0} { | |
6972 | foreach bind [split $incith::google::youtube_binds " "] { | |
6973 | if {[string match -nocase $bind $trigger] == 1} { | |
6974 | # flood protection check | |
6975 | if {[flood $nick $uhand]} { | |
6976 | return | |
6977 | } | |
6978 | # call youtube | |
6979 | foreach line [incith::google::parse_output [youtube $search]] { | |
6980 | put_output $where "$incith::google::youtube_prepend$line" | |
6981 | } | |
6982 | break | |
6983 | } | |
6984 | } | |
6985 | } | |
6986 | # check for !helpbot | |
6987 | if {$incith::google::helpbot_results > 0} { | |
6988 | foreach bind [split $incith::google::helpbot_binds " "] { | |
6989 | if {[string match -nocase $bind $trigger] == 1} { | |
6990 | # flood protection check | |
6991 | if {[flood $nick $uhand]} { | |
6992 | return | |
6993 | } | |
6994 | # call helpbot | |
6995 | foreach line [incith::google::parse_output [helpbot $nick $search]] { | |
6996 | put_output $where $line | |
6997 | } | |
6998 | break | |
6999 | } | |
7000 | } | |
7001 | } | |
7002 | # check for !myspacevids | |
7003 | if {$incith::google::myspacevids_results > 0} { | |
7004 | foreach bind [split $incith::google::myspacevids_binds " "] { | |
7005 | if {[string match -nocase $bind $trigger] == 1} { | |
7006 | # flood protection check | |
7007 | if {[flood $nick $uhand]} { | |
7008 | return | |
7009 | } | |
7010 | # call myspacevids | |
7011 | foreach line [incith::google::parse_output [myspacevids $search]] { | |
7012 | put_output $where "$incith::google::myspacevids_prepend$line" | |
7013 | } | |
7014 | break | |
7015 | } | |
7016 | } | |
7017 | } | |
7018 | # check for !mininova | |
7019 | if {$incith::google::mininova_results > 0} { | |
7020 | foreach bind [split $incith::google::mininova_binds " "] { | |
7021 | if {[string match -nocase $bind $trigger] == 1} { | |
7022 | # flood protection check | |
7023 | if {[flood $nick $uhand]} { | |
7024 | return | |
7025 | } | |
7026 | # call mininova | |
7027 | foreach line [incith::google::parse_output [mininova $search]] { | |
7028 | put_output $where "$incith::google::mininova_prepend$line" | |
7029 | } | |
7030 | break | |
7031 | } | |
7032 | } | |
7033 | } | |
7034 | # check for !recent | |
7035 | if {$incith::google::recent_results > 0} { | |
7036 | foreach bind [split $incith::google::recent_binds " "] { | |
7037 | if {[string match -nocase $bind $trigger] == 1} { | |
7038 | # flood protection check | |
7039 | if {[flood $nick $uhand]} { | |
7040 | return | |
7041 | } | |
7042 | # call recent game lookup | |
7043 | foreach line [incith::google::parse_output [recent $search]] { | |
7044 | put_output $where "$incith::google::recent_prepend$line" | |
7045 | } | |
7046 | break | |
7047 | } | |
7048 | } | |
7049 | } | |
7050 | # check for !wiki | |
7051 | if {$incith::google::wiki_results > 0} { | |
7052 | foreach bind [split $incith::google::wiki_binds " "] { | |
7053 | if {[string match -nocase $bind $trigger] == 1} { | |
7054 | # flood protection check | |
7055 | if {[flood $nick $uhand]} { | |
7056 | return | |
7057 | } | |
7058 | # call wiki | |
7059 | foreach line [incith::google::parse_output [wiki $search]] { | |
7060 | put_output $where "$incith::google::wiki_prepend$line" | |
7061 | } | |
7062 | break | |
7063 | } | |
7064 | } | |
7065 | } | |
7066 | # check for !wikimedia | |
7067 | if {$incith::google::wikimedia_results > 0} { | |
7068 | foreach bind [split $incith::google::wikimedia_binds " "] { | |
7069 | if {[string match -nocase $bind $trigger] == 1} { | |
7070 | # flood protection check | |
7071 | if {[flood $nick $uhand]} { | |
7072 | return | |
7073 | } | |
7074 | # call wiki | |
7075 | foreach line [incith::google::parse_output [wikimedia $search]] { | |
7076 | put_output $where "$incith::google::wikimedia_prepend$line" | |
7077 | } | |
7078 | break | |
7079 | } | |
7080 | } | |
7081 | } | |
7082 | # check for !review | |
7083 | if {$incith::google::rev_results > 0} { | |
7084 | foreach bind [split $incith::google::rev_binds " "] { | |
7085 | if {[string match -nocase $bind $trigger] == 1} { | |
7086 | # flood protection check | |
7087 | if {[flood $nick $uhand]} { | |
7088 | return | |
7089 | } | |
7090 | # call review | |
7091 | foreach line [incith::google::parse_output [rev $search]] { | |
7092 | put_output $where "$incith::google::rev_prepend$line" | |
7093 | } | |
7094 | break | |
7095 | } | |
7096 | } | |
7097 | } | |
7098 | # check for !ign | |
7099 | if {$incith::google::ign_results > 0} { | |
7100 | foreach bind [split $incith::google::ign_binds " "] { | |
7101 | if {[string match -nocase $bind $trigger] == 1} { | |
7102 | # flood protection check | |
7103 | if {[flood $nick $uhand]} { | |
7104 | return | |
7105 | } | |
7106 | # call ign | |
7107 | foreach line [incith::google::parse_output [ign $search]] { | |
7108 | put_output $where "$incith::google::ign_prepend$line" | |
7109 | } | |
7110 | break | |
7111 | } | |
7112 | } | |
7113 | } | |
7114 | # check for !trends | |
7115 | if {$incith::google::trends_results > 0} { | |
7116 | foreach bind [split $incith::google::trends_binds " "] { | |
7117 | if {[string match -nocase $bind $trigger] == 1} { | |
7118 | # flood protection check | |
7119 | if {[flood $nick $uhand]} { | |
7120 | return | |
7121 | } | |
7122 | # call trends | |
7123 | foreach line [incith::google::parse_output [trends $search]] { | |
7124 | put_output $where "$incith::google::trends_prepend$line" | |
7125 | } | |
7126 | break | |
7127 | } | |
7128 | } | |
7129 | } | |
7130 | # check for !gamespot | |
7131 | if {$incith::google::gamespot_results > 0} { | |
7132 | foreach bind [split $incith::google::gamespot_binds " "] { | |
7133 | if {[string match -nocase $bind $trigger] == 1} { | |
7134 | # flood protection check | |
7135 | if {[flood $nick $uhand]} { | |
7136 | return | |
7137 | } | |
7138 | # call gamespot | |
7139 | foreach line [incith::google::parse_output [gamespot $search]] { | |
7140 | put_output $where "$incith::google::gamespot_prepend$line" | |
7141 | } | |
7142 | break | |
7143 | } | |
7144 | } | |
7145 | } | |
7146 | # check for !trans | |
7147 | if {$incith::google::trans_results > 0} { | |
7148 | foreach bind [split $incith::google::trans_binds " "] { | |
7149 | if {[string match -nocase $bind $trigger] == 1} { | |
7150 | # flood protection check | |
7151 | if {[flood $nick $uhand]} { | |
7152 | return | |
7153 | } | |
7154 | # translation requires splitting of the search | |
7155 | if {![regexp -nocase -- {^(.+?)@(.+?)\s(.+?)$} $search - word1 word2 word3]} { | |
7156 | if {[regexp -nocase -- {^@(.+?)\s(.+?)$} $search - word2 word3]} { | |
7157 | set search [join [lrange [split $search] 1 end]] | |
7158 | } else { | |
7159 | regexp -nocase -- {^(.+?)@\s(.+?)$} $search - word1 word3 | |
7160 | } | |
7161 | } | |
7162 | if {[info exists word2]} { | |
7163 | if {[string equal [string index $word2 0] " "]} { | |
7164 | regexp -nocase -- {^(.+?)@\s(.+?)$} $search - word1 word3 | |
7165 | set word2 $::incith::google::trans | |
7166 | } | |
7167 | } | |
7168 | if {![info exists word1]} { set word1 "auto" } | |
7169 | if {![info exists word2]} { set word2 $::incith::google::trans } | |
7170 | if {![info exists word3]} { set word3 $search } | |
7171 | set search "$word1@$word2 $word3" | |
7172 | # call translate | |
7173 | trans $search $where | |
7174 | } | |
7175 | } | |
7176 | } | |
7177 | # check for !dailymotion | |
7178 | if {$incith::google::daily_results > 0} { | |
7179 | foreach bind [split $incith::google::daily_binds " "] { | |
7180 | if {[string match -nocase $bind $trigger] == 1} { | |
7181 | # flood protection check | |
7182 | if {[flood $nick $uhand]} { | |
7183 | return | |
7184 | } | |
7185 | # call dailymotion | |
7186 | foreach line [incith::google::parse_output [dailymotion $search]] { | |
7187 | put_output $where "$incith::google::dailymotion_prepend$line" | |
7188 | } | |
7189 | break | |
7190 | } | |
7191 | } | |
7192 | } | |
7193 | # check for !gamefaqs | |
7194 | if {$incith::google::gamefaq_results > 0} { | |
7195 | foreach bind [split $incith::google::gamefaq_binds " "] { | |
7196 | if {[string match -nocase $bind $trigger] == 1} { | |
7197 | # flood protection check | |
7198 | if {[flood $nick $uhand]} { | |
7199 | return | |
7200 | } | |
7201 | # gamefaqs requires splitting of the search | |
7202 | regexp -nocase -- {^(.+?) in (.+?)$} $search - system region | |
7203 | if {![info exists system] || ![info exists region]} { | |
7204 | put_output $where "Error! Correct usage: !gamefaqs system in region \[system = nds/gba/gc/wii/ps2/psp/ps3/xbox/x360/pc; region = usa/jap/eur/aus\]" | |
7205 | return | |
7206 | } | |
7207 | # call gamefaqs | |
7208 | foreach line [incith::google::parse_output [gamefaqs $system $region]] { | |
7209 | put_output $where "$incith::google::gamefaqs_prepend$line" | |
7210 | } | |
7211 | break | |
7212 | } | |
7213 | } | |
7214 | } | |
7215 | # check for !locate | |
7216 | if {$incith::google::locate_results > 0} { | |
7217 | foreach bind [split $incith::google::locate_binds " "] { | |
7218 | if {[string match -nocase $bind $trigger] == 1} { | |
7219 | # flood protection check | |
7220 | if {[flood $nick $uhand]} { | |
7221 | return | |
7222 | } | |
7223 | # call locate | |
7224 | if {![string match "*.*" $search]} { | |
7225 | set nsearch [lindex [split [getchanhost $search $where] @] 1] | |
7226 | if {[string length $nsearch]} { set search $nsearch } | |
7227 | } | |
7228 | foreach line [incith::google::parse_output [locate $search]] { | |
7229 | put_output $where "$incith::google::locate_prepend$line" | |
7230 | } | |
7231 | break | |
7232 | } | |
7233 | } | |
7234 | } | |
7235 | # check for !blog | |
7236 | if {$incith::google::blog_results > 0} { | |
7237 | foreach bind [split $incith::google::blog_binds " "] { | |
7238 | if {[string match -nocase $bind $trigger] == 1} { | |
7239 | # flood protection check | |
7240 | if {[flood $nick $uhand]} { | |
7241 | return | |
7242 | } | |
7243 | # call blogsearch.google | |
7244 | foreach line [incith::google::parse_output [blog $search]] { | |
7245 | put_output $where "$incith::google::blog_prepend$line" | |
7246 | } | |
7247 | break | |
7248 | } | |
7249 | } | |
7250 | } | |
7251 | # check for !ebay | |
7252 | if {$incith::google::ebay_results > 0} { | |
7253 | foreach bind [split $incith::google::ebay_binds " "] { | |
7254 | if {[string match -nocase $bind $trigger] == 1} { | |
7255 | # flood protection check | |
7256 | if {[flood $nick $uhand]} { | |
7257 | return | |
7258 | } | |
7259 | # call ebay | |
7260 | foreach line [incith::google::parse_output [ebay $search]] { | |
7261 | put_output $where "$incith::google::ebay_prepend$line" | |
7262 | } | |
7263 | break | |
7264 | } | |
7265 | } | |
7266 | } | |
7267 | # check for !popular | |
7268 | if {$incith::google::popular_results > 0} { | |
7269 | foreach bind [split $incith::google::popular_binds " "] { | |
7270 | if {[string match -nocase $bind $trigger] == 1} { | |
7271 | # flood protection check | |
7272 | if {[flood $nick $uhand]} { | |
7273 | return | |
7274 | } | |
7275 | # call popular | |
7276 | foreach line [incith::google::parse_output [popular $search]] { | |
7277 | put_output $where "$incith::google::popular_prepend$line" | |
7278 | } | |
7279 | break | |
7280 | } | |
7281 | } | |
7282 | } | |
7283 | # check for customized any triggers | |
7284 | if {$incith::google::my_custom > 0} { | |
7285 | foreach bind $incith::google::my_customs { | |
7286 | foreach sbind [split [lindex [split $bind :] 0]] { | |
7287 | if {[string match -nocase $sbind $trigger] == 1} { | |
7288 | # invoke customized trigger with phrase | |
7289 | # no need to flood protect this, if we do | |
7290 | # it may trigger erroneously | |
7291 | set text [join [lrange [split $bind :] 2 end] :] | |
7292 | if {$::incith::google::custom_words > 0} { | |
7293 | set remaps [regexp -inline -all {%%((?:end|[0-9]{1,2}|[0-9]{1,2}-(?:[0-9]{1,2}|end)))%%} $text] | |
7294 | foreach {junk remap} $remaps { | |
7295 | if {[regexp -nocase {^((?:end|[0-9]{1,2}))$} $remap - rnum]} { | |
7296 | if {[string equal -nocase "end" $rnum]} { | |
7297 | set real [llength [split $search]] | |
7298 | } else { | |
7299 | set real [expr {$remap -1}] | |
7300 | } | |
7301 | regsub -all "$junk" $text "[lindex [split $search] $real]" text | |
7302 | } elseif {[regexp -nocase {^([0-9]{1,2})-((?:[0-9]{1,2}|end))$} $remap - rstart rend]} { | |
7303 | if {![string equal -nocase "end" $rend]} { set real [expr {$rend -1}] } else { set real [llength [split $search]] } | |
7304 | regsub -all "$junk" $text "[join [lrange [split $search] [expr {${rstart}-1}] $real]]" text | |
7305 | } | |
7306 | } | |
7307 | } | |
7308 | regsub -all -- {%search%} $text "$search" text | |
7309 | send_output "$::incith::google::command_char[lindex [split $bind :] 1] $text" $where $nick $uhand | |
7310 | } | |
7311 | } | |
7312 | } | |
7313 | } | |
7314 | } | |
7315 | ||
7316 | # PUT_OUTPUT | |
7317 | # actually sends the output to the server | |
7318 | proc put_output {where line} { | |
7319 | if {$incith::google::notice_reply == 1} { | |
7320 | putserv "NOTICE $where :$line" | |
7321 | } else { | |
7322 | putserv "PRIVMSG $where :$line" | |
7323 | } | |
7324 | } | |
7325 | ||
7326 | # PARSE_OUTPUT | |
7327 | # prepares output for sending to a channel/user, calls line_wrap | |
7328 | # | |
7329 | proc parse_output {input} { | |
7330 | set parsed_output [list] ; set parsed_current [list] | |
7331 | if {[string match "*\n*" $incith::google::seperator] == 1} { | |
7332 | set lastline "" | |
7333 | foreach newline [split $input "\n"] { | |
7334 | foreach line [incith::google::line_wrap $newline] { | |
7335 | set fix "" | |
7336 | # bold | |
7337 | if {[expr {[regexp -all {\002} $lastline] & 1 }]} { | |
7338 | append fix "\002" | |
7339 | } | |
7340 | # underline | |
7341 | if {[expr {[regexp -all {\037} $lastline] & 1 }]} { | |
7342 | append fix "\037" | |
7343 | } | |
7344 | # color | |
7345 | if {[expr {[regexp -all {\003} $lastline] & 1 }]} { | |
7346 | if {[set i [string last "\003" $lastline]] != -1} { | |
7347 | set lc [string range $lastline [expr {$i + 1}] [expr {$i + 5}]] | |
7348 | if {![regexp {^[0-9]+\,[0-9+]$} $lc]} { | |
7349 | if {[regexp {^[0-9]+$} [string range $lc 0 1]]} { | |
7350 | append fix "\003[string range $lc 0 1]" | |
7351 | } | |
7352 | } else { | |
7353 | append fix "\003$lc" | |
7354 | } | |
7355 | } | |
7356 | } | |
7357 | # add fix+line to output | |
7358 | if {[string length [string map {" " ""} [stripcodes bcruag $line]]]} { | |
7359 | lappend parsed_output "$fix$line" | |
7360 | } | |
7361 | set lastline "$fix$line" | |
7362 | } | |
7363 | } | |
7364 | } else { | |
7365 | set input [string trimright $input $incith::google::seperator] | |
7366 | set lastline "" | |
7367 | foreach line [incith::google::line_wrap $input] { | |
7368 | # initialize fix each iteration | |
7369 | set fix "" | |
7370 | # add bold | |
7371 | if {[expr {[regexp -all {\002} $lastline] & 1 }]} { | |
7372 | append fix "\002" | |
7373 | } | |
7374 | # add underline | |
7375 | if {[expr {[regexp -all {\037} $lastline] & 1 }]} { | |
7376 | append fix "\037" | |
7377 | } | |
7378 | # add color | |
7379 | if {[expr {[regexp -all {\003} $lastline] & 1 }]} { | |
7380 | if {[set i [string last "\003" $lastline]] != -1} { | |
7381 | set lc [string range $lastline [expr {$i + 1}] [expr {$i + 5}]] | |
7382 | if {![regexp {^[0-9]{1,2}\,[0-9]{1,2}$} $lc]} { | |
7383 | if {[regexp {^[0-9]{1,2}} [string range $lc 0 1]]} { | |
7384 | append fix "\003[string range $lc 0 1]" | |
7385 | } | |
7386 | } else { | |
7387 | append fix "\003$lc" | |
7388 | } | |
7389 | } | |
7390 | } | |
7391 | # add fix+line to output | |
7392 | if {[string length [string map {" " ""} [stripcodes bcruag $line]]]} { | |
7393 | lappend parsed_output "$fix$line" | |
7394 | } | |
7395 | set lastline "$fix$line" | |
7396 | } | |
7397 | } | |
7398 | return $parsed_output | |
7399 | } | |
7400 | ||
7401 | # LINE_WRAP | |
7402 | # takes a long line in, and chops it before the specified length | |
7403 | # http://forum.egghelp.org/viewtopic.php?t=6690 | |
7404 | # | |
7405 | proc line_wrap {str {splitChr { }}} { | |
7406 | set out [set cur {}] | |
7407 | set i 0 | |
7408 | set len $incith::google::split_length | |
7409 | #regsub -all "\002" $str "<ZQ" str | |
7410 | #regsub -all "\037" $str "<ZX" str | |
7411 | #regsub -all "\003" $str "<ZJ" str | |
7412 | foreach word [split [set str][set str ""] $splitChr] { | |
7413 | if {[incr i [string len $word]] > $len} { | |
7414 | #regsub -all "<ZQ" $cur "\002" cur | |
7415 | #regsub -all "<ZX" $cur "\037" cur | |
7416 | #regsub -all "<ZJ" $cur "\003" cur | |
7417 | lappend out [join $cur $splitChr] | |
7418 | set cur [list $word] | |
7419 | set i [string len $word] | |
7420 | } else { | |
7421 | lappend cur $word | |
7422 | } | |
7423 | incr i | |
7424 | } | |
7425 | #regsub -all "<ZQ" $cur "\002" cur | |
7426 | #regsub -all "<ZX" $cur "\037" cur | |
7427 | #regsub -all "<ZJ" $cur "\003" cur | |
7428 | lappend out [join $cur $splitChr] | |
7429 | } | |
7430 | ||
7431 | # FLOOD_INIT | |
7432 | # modified from bseen | |
7433 | # | |
7434 | variable flood_data | |
7435 | variable flood_array | |
7436 | proc flood_init {} { | |
7437 | if {$incith::google::ignore < 1} { | |
7438 | return 0 | |
7439 | } | |
7440 | if {![string match *:* $incith::google::flood]} { | |
7441 | putlog "$incith::google::version: variable flood not set correctly." | |
7442 | return 1 | |
7443 | } | |
7444 | set incith::google::flood_data(flood_num) [lindex [split $incith::google::flood :] 0] | |
7445 | set incith::google::flood_data(flood_time) [lindex [split $incith::google::flood :] 1] | |
7446 | set i [expr $incith::google::flood_data(flood_num) - 1] | |
7447 | while {$i >= 0} { | |
7448 | set incith::google::flood_array($i) 0 | |
7449 | incr i -1 | |
7450 | } | |
7451 | } | |
7452 | ; flood_init | |
7453 | ||
7454 | # FLOOD | |
7455 | # updates and returns a users flood status | |
7456 | # | |
7457 | proc flood {nick uhand} { | |
7458 | if {$incith::google::ignore < 1} { | |
7459 | return 0 | |
7460 | } | |
7461 | if {$incith::google::flood_data(flood_num) == 0} { | |
7462 | return 0 | |
7463 | } | |
7464 | set i [expr ${incith::google::flood_data(flood_num)} - 1] | |
7465 | while {$i >= 1} { | |
7466 | set incith::google::flood_array($i) $incith::google::flood_array([expr $i - 1]) | |
7467 | incr i -1 | |
7468 | } | |
7469 | set incith::google::flood_array(0) [unixtime] | |
7470 | if {[expr [unixtime] - $incith::google::flood_array([expr ${incith::google::flood_data(flood_num)} - 1])] <= ${incith::google::flood_data(flood_time)}} { | |
7471 | putlog "$incith::google::version: flood detected from ${nick}." | |
7472 | putserv "notice $nick :$incith::google::version: flood detected, placing you on ignore for $::incith::google::ignore minute(s)! :P" | |
7473 | newignore [join [maskhost *!*[string trimleft $uhand ~]]] $incith::google::version flooding $incith::google::ignore | |
7474 | return 1 | |
7475 | } else { | |
7476 | return 0 | |
7477 | } | |
7478 | } | |
7479 | ||
7480 | ||
7481 | # AUTOMAGIC CHARSET ENCODING SUPPORT | |
7482 | # on the fly encoding support | |
7483 | # | |
7484 | proc incithdecode {text} { | |
7485 | global incithcharset | |
7486 | if {[lsearch -exact [encoding names] $incithcharset] != -1} { | |
7487 | set text [encoding convertfrom $incithcharset $text] | |
7488 | } | |
7489 | return $text | |
7490 | } | |
7491 | ||
7492 | proc incithencode {text} { | |
7493 | global incithcharset | |
7494 | if {[lsearch -exact [encoding names] $incithcharset] != -1} { | |
7495 | set text [encoding convertto $incithcharset $text] | |
7496 | } | |
7497 | return $text | |
7498 | } | |
7499 | ||
7500 | # utf-8 sucks for displaying any language using extended ascii, this helps alleviate that. | |
7501 | # correct utf-8 problems before they even appear. | |
7502 | proc utf8encodefix {country input} { | |
7503 | if {[lsearch -exact [encoding names] [set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1]]]} { | |
7504 | if {![string match "" $encoding_found]} { set input [encoding convertto $encoding_found $input] } | |
7505 | } | |
7506 | return $input | |
7507 | } | |
7508 | ||
7509 | # Wikipedia/Wikimedia subtag-decoder... | |
7510 | # decodes those silly subtags | |
7511 | # | |
7512 | proc subtagDecode {text} { | |
7513 | set url "" | |
7514 | regsub -all {\.([0-9a-fA-F][0-9a-fA-F])} $text {[format %c 0x\1]} text | |
7515 | set text [subst $text] | |
7516 | regsub -all "\r\n" $text "\n" text | |
7517 | foreach byte [split [encoding convertto "utf-8" $text] ""] { | |
7518 | scan $byte %c i | |
7519 | if { $i < 33 } { | |
7520 | append url [format %%%02X $i] | |
7521 | } else { | |
7522 | append url $byte | |
7523 | } | |
7524 | } | |
7525 | return [string map {% .} $url] | |
7526 | } | |
7527 | ||
7528 | # Vocabulary Aversion | |
7529 | # This converts swear words into appropriate words for IRC | |
7530 | # this is rather rudementary, is probably a better way to do this but meh.. | |
7531 | # | |
7532 | proc vocabaversion {text} { | |
7533 | set newtext "" | |
7534 | foreach element [split $text] { | |
7535 | set violation 0 | |
7536 | foreach vocabulary $incith::google::aversion { | |
7537 | set swear [lindex [split $vocabulary :] 0] | |
7538 | set avert [join [lrange [split $vocabulary :] 1 end]] | |
7539 | if {[string match -nocase "$swear" $element] && $avert != ""} { | |
7540 | append newtext "$avert " | |
7541 | set violation 1 | |
7542 | break | |
7543 | } | |
7544 | } | |
7545 | if {$violation == 0} { append newtext "$element " } | |
7546 | } | |
7547 | return [string trim $newtext] | |
7548 | } | |
7549 | ||
7550 | # Description Decode | |
7551 | # convert html codes into characters - credit perplexa (urban dictionary) | |
7552 | # | |
7553 | proc descdecode {text} { | |
7554 | # code below is neccessary to prevent numerous html markups | |
7555 | # from appearing in the output (ie, ", ᘧ, etc) | |
7556 | # stolen (borrowed is a better term) from perplexa's urban | |
7557 | # dictionary script.. | |
7558 | if {[string match *&* $text]} { | |
7559 | global incithcharset | |
7560 | set escapes { | |
7561 | \xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4 | |
7562 | ¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9 | |
7563 | ª \xaa « \xab ¬ \xac ­ \xad ® \xae | |
7564 | ¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3 | |
7565 | ´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8 | |
7566 | ¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd | |
7567 | ¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2 | |
7568 | Ã \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7 | |
7569 | È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc | |
7570 | Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1 | |
7571 | Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6 | |
7572 | × \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb | |
7573 | Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0 | |
7574 | á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5 | |
7575 | æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea | |
7576 | ë \xeb ì \xec í \xed î \xee ï \xef | |
7577 | ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4 | |
7578 | õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9 | |
7579 | ú \xfa û \xfb ü \xfc ý \xfd þ \xfe | |
7580 | ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394 | |
7581 | Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399 | |
7582 | Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E | |
7583 | Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4 | |
7584 | Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9 | |
7585 | α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5 | |
7586 | ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA | |
7587 | λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF | |
7588 | π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4 | |
7589 | υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9 | |
7590 | ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022 | |
7591 | … \u2026 ′ \u2032 ″ \u2033 ‾ \u203E | |
7592 | ⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C | |
7593 | ™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191 | |
7594 | → \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5 | |
7595 | ⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4 | |
7596 | ∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205 | |
7597 | ∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F | |
7598 | ∑ \u2211 − \u2212 ∗ \u2217 √ \u221A | |
7599 | ∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228 | |
7600 | ∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C | |
7601 | ≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264 | |
7602 | ≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286 | |
7603 | ⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5 | |
7604 | ⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A | |
7605 | ⌋ \u230B ⟨ \u2329 ⟩ \u232A ◊ \u25CA | |
7606 | ♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666 | |
7607 | " \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153 | |
7608 | Š \u160 š \u161 Ÿ \u178 ˆ \u2C6 | |
7609 | ˜ \u2DC   \u2002   \u2003   \u2009 | |
7610 | ‌ \u200C ‍ \u200D ‎ \u200E ‏ \u200F – \u2013 | |
7611 | — \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A | |
7612 | “ \u201C ” \u201D „ \u201E † \u2020 | |
7613 | ‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A | |
7614 | € \u20AC ' \u0027 ‎ "" ‏ "" ‬ "" ‭ "" | |
7615 | ‮ "" — \u2014 | |
7616 | } | |
7617 | set text [string map $escapes $text] | |
7618 | # enable transcoding html elements? | |
7619 | if {$::incith::google::dirty_decode > 0} { | |
7620 | if {![string equal $incithcharset [encoding system]]} { set text [encoding convertfrom $incithcharset $text] } | |
7621 | set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $text] | |
7622 | regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text | |
7623 | regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text | |
7624 | regsub -all -- {\\x([[:xdigit:]]{1,2})} $text {[format %c [scan "\1" %x]]} text | |
7625 | set text [subst "$text"] | |
7626 | if {![string equal $incithcharset [encoding system]]} { set text [encoding convertto $incithcharset $text] } | |
7627 | } | |
7628 | } | |
7629 | # correct possible bleedover of bold or underline | |
7630 | set fix "" ; | |
7631 | if {[expr {[regexp -all {\002} $text] & 1 }]} { | |
7632 | append fix "\002" | |
7633 | } | |
7634 | if {[expr {[regexp -all {\037} $text] & 1 }]} { | |
7635 | append fix "\037" | |
7636 | } | |
7637 | set text "$text$fix" | |
7638 | return $text | |
7639 | ||
7640 | } | |
7641 | ||
7642 | # URL Decode | |
7643 | # Decodes all of the %00 strings in a url and returns it | |
7644 | # | |
7645 | proc urldecode {text} { | |
7646 | set url "" | |
7647 | # tcl filter required because we are using SUBST command below | |
7648 | # this will escape any sequence which could potentially trigger | |
7649 | # the interpreter.. | |
7650 | regsub -all -- \\\\ $text \\\\\\\\ text | |
7651 | regsub -all -- \\\[ $text \\\\\[ text | |
7652 | regsub -all -- \\\] $text \\\\\] text | |
7653 | regsub -all -- \\\} $text \\\\\} text | |
7654 | regsub -all -- \\\{ $text \\\\\{ text | |
7655 | regsub -all -- \\\" $text \\\\\" text | |
7656 | regsub -all -- \\\$ $text \\\\\$ text | |
7657 | # end tcl filter | |
7658 | regsub -all {\%([0-9a-fA-F][0-9a-fA-F])} $text {[format %c 0x\1]} text | |
7659 | set text [subst $text] | |
7660 | foreach byte [split $text ""] { | |
7661 | scan $byte %c i | |
7662 | if { $i < 33 || $i > 127 } { | |
7663 | append url [format %%%02X $i] | |
7664 | } else { | |
7665 | append url $byte | |
7666 | } | |
7667 | } | |
7668 | return $url | |
7669 | } | |
7670 | # Un Gzip | |
7671 | # Unzips those silly g-zipped wikis | |
7672 | # | |
7673 | proc ungzip {html metas} { | |
7674 | if {$::incith::google::use_gzip > 0} { | |
7675 | if {![info exists ::incith_nozlib]} { | |
7676 | foreach {name value} $metas { | |
7677 | if {[regexp -nocase ^Content-Encoding$ $name]} { | |
7678 | if {[string equal -nocase "gzip" $value]} { | |
7679 | if {![info exists ::incith_trf]} { | |
7680 | if {[catch {set html [zlib inflate [string range $html 10 [expr { [string length $html] - 8 } ]]]} error]} { return $html } | |
7681 | } else { | |
7682 | set html [zip -mode decompress -nowrap 1 [string range $html 10 [expr { [string length $html] - 8 } ]]] | |
7683 | } | |
7684 | break | |
7685 | } | |
7686 | } | |
7687 | } | |
7688 | } | |
7689 | } | |
7690 | return $html | |
7691 | } | |
7692 | ||
7693 | # URL Encode | |
7694 | # Encodes anything not a-zA-Z0-9 into %00 strings... | |
7695 | # | |
7696 | proc urlencode {text type {enc ""}} { | |
7697 | if {[string length $enc]} { | |
7698 | set text [encoding convertto $enc $text] | |
7699 | } | |
7700 | set url "" | |
7701 | foreach byte [split $text ""] { | |
7702 | scan $byte %c i | |
7703 | if {$i < 65 || $i > 122} { | |
7704 | append url [format %%%02X $i] | |
7705 | } else { | |
7706 | append url $byte | |
7707 | } | |
7708 | } | |
7709 | if {$type == 1} { | |
7710 | return [string map {%25 . %3A : %2D - %2F / %2E . %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 %80 _ % .} $url] | |
7711 | } else { | |
7712 | return [string map {%2D - %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $url] | |
7713 | } | |
7714 | } | |
7715 | } | |
7716 | } | |
7717 | ||
7718 | putlog " - UNOFFICIAL $incith::google::version loaded." | |
7719 | ||
7720 | # EOF |