Want more features on Pastebin? Sign Up, it's FREE!
Guest

incith-google.tcl v2.0.0c (weather fix)

By: a guest on Sep 13th, 2011  |  syntax: TCL  |  size: 363.03 KB  |  views: 790  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.     # GOOGLE
  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 -- {&deg;} $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|&quot;|\")" $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 {&#8206;} $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 -- "&lrm;" $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&ndash;\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.     # PRINT
  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 "&#039;" $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 "&amp;" $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.