Guest User

incith-google.tcl v2.0.0c

a guest
Sep 13th, 2011
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 363.35 KB | None | 0 0
  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. # [email protected]                                              #
  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 "*icons/onebox/weather*" $html] == 1} {
  1487.          regexp -- {<h3 class=r.*?>(.+?)</h3>.*?<div style="font.*?>(.*?)</div><div.*?>(.*?)<.+?>(.*?)<.+?>(.*?)<} $html - w1 w2 w3 w4 w5
  1488.           regexp -- {<div align=center style="padding:5px.*?">(.+?)<br>.+?src="/images/weather/.*?gif" alt="(.*?)".*?<nobr>(.+?)</nobr>.+?<div align=center style="padding:.*?\:left">(.+?)<br>.+?src="/images/weather/.*?gif" alt="(.*?)".*?<nobr>(.+?)</nobr>.+?<div align=center style="padding:.*?\:left">(.+?)<br>.+?src="/images/weather/.*?gif" alt="(.*?)".*?<nobr>(.+?)</nobr>} $html - f1 f2 f3 f4 f5 f6 f7 f8 f9
  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.           # clean up our conditions
  1500.           set f2 [string totitle [string map {"_" " "} $f2]]
  1501.           set f5 [string totitle [string map {"_" " "} $f5]]
  1502.           set f8 [string totitle [string map {"_" " "} $f8]]
  1503.           # cut spaces out of temperatures
  1504.           set f3 [string map {" " ""} $f3]
  1505.           set f6 [string map {" " ""} $f6]
  1506.           set f9 [string map {" " ""} $f9]
  1507.           set desc "$w1\: $w2$w3$w4$w5; $f1: $f2 \($f3\); $f4: $f5 \($f6\); $f7: $f8 \($f9\)"
  1508.           regsub -all -- {&deg;} $desc {°} desc
  1509.           set link ""
  1510.           regsub -all -- {weather} $input {} input
  1511.           if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" }
  1512.         # time:
  1513.         } elseif {[string match "*src=\"http://www.google.com/chart*chc=localtime*" $html] == 1} {
  1514.           regexp -nocase -- {src="http://www.google.com/chart\?chs=.*?chc=localtime.*?><td valign=[a-z]+>(.+?)</table>} $html - desc
  1515.          regsub -- {<br>} $desc ". " desc
  1516.          regsub -all {<.*?>} $desc "" desc
  1517.          regsub -- {chc=localtime} $html {} html
  1518.          if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" }
  1519.          set link ""
  1520.        # public_data:
  1521.        } elseif {[string match "*/publicdata</div></div>*" $html]} {
  1522.          regexp -nocase -- {valign=top><h3 class=r><a href=.*?>(.*?)</a>.*?<tr><td style.*?><a href="(.*?)".*?<td valign=top.*?>(.*?)<br>} $html - tit link des
  1523.          regsub -all {<.*?>} $des "" des
  1524.          regsub -- {/publicdata</div></div>} $html "" html
  1525.          set desc "$tit: $des"
  1526.          if {[info exists link] == 1 && $link != ""} {
  1527.            if {[string match "*\&sa\=X*" $link]} {
  1528.              regexp -- {(^.+?)&sa\=} [urldecode $link] - link
  1529.            }
  1530.            if {[string match "\/url\?q=*" $link]} {
  1531.              regexp -- {\/url\?q=(.*?)$} $link - link
  1532.            }
  1533.            regexp -- {(.+?)\&ei=} $link - link
  1534.          }
  1535.          if {$::incith::google::short_answers > 0 } {
  1536.            return "${::incith::google::desc_modes}[descdecode ${desc}]${::incith::google::desc_demodes}"
  1537.          }
  1538.        # define:
  1539.        } elseif {[string match "*<ul type=*" $html]} {
  1540.          #[string match "*define:*" $input] == 1
  1541.          set output ""
  1542.          regexp -- {<ul type=.+?<li>(.+?)(?=\s*<li>|<br>).*<a href.*(http.+?)">} $html - desc link
  1543.           regsub -- {<u1 type=.+?><li>(.+?)(?=\s*<li>|<br>)} $html {} html
  1544.           regsub -all -- {\+} $input {%2B} define_input
  1545.           regsub -all -- { } $define_input {+} define_input
  1546.           if {[info exists link] == 1 && $link != ""} {
  1547.             regexp -- {(.+?)\&sig=} $link - link
  1548.             regexp -- {(.+?)\&usg=} $link - link
  1549.             regexp -- {(.+?)\&ei=} $link - link
  1550.             regexp -- {(.+?)\&sa=} $link - link
  1551.             set link "[urldecode $link]"
  1552.             regsub -all " " $link "%20" link
  1553.             append link " ( http://www.google.${titen}/search?q=${define_input} )"
  1554.           } else {
  1555.             if {![regexp -- {</div><div class=med style=".*?"><p>(.+?)\.<br><br>} $html - no_def]} {
  1556.               if {![regexp -- {<div class=med style=".*?"><br>(.+?)<br><br>} $html - no_def]} {
  1557.                 if {![regexp -- {<!--z--><p>(.*?)<br>} $html - no_def]} {
  1558.                   set no_def "Houston, we have a problem. Aborting lift-off!"
  1559.                 }
  1560.               }
  1561.             }
  1562.             regsub -- {</a>} $no_def "." no_def
  1563.             regsub -all -- {<(.+?)>} $no_def "" no_def
  1564.             return "${::incith::google::desc_modes}${no_def}${::incith::google::desc_demodes}"
  1565.           }
  1566.         } elseif {[string match "*oi=define*" $html]} {
  1567.           if {[string match "*oi=spell*" $html]} {
  1568.             regexp -- {</div><div class=med style=.*?><p>(.*?)<p>(.*?)<p>} $html - desc link
  1569.             regsub -- {</a>} $desc "?" desc
  1570.             regsub -all -- {<.*?>} $desc "" desc
  1571.             regsub -all -- {<.*?>} $link "" link
  1572.             return "${::incith::google::desc_modes}${desc} ${link}${::incith::google::desc_demodes}"
  1573.           }
  1574.           regexp -- {<div class=med style=.*?><p>(.*?)<br>.*?<a href=.*?>(.*?)</a>} $html - desc link
  1575.           regsub -- {<div class=med style=.*?><p>.*?<br>.*?<a href=.*?>.*?</a>} $html "" html
  1576.           regsub -all -- {<(.+?)>} [string map {"<li>" " "} $desc] "" desc
  1577.           if {![string match "http*" $link]} { set link "http://$link" }
  1578.           regsub -all -- {\+} $input {%2B} define_input
  1579.           regsub -all -- { } $define_input {+} define_input
  1580.           set link "${link} ( http://www.google.${titen}/search?q=${define_input} )"
  1581.           return "${::incith::google::desc_modes}${desc}${incith::google::break}${link}${::incith::google::desc_demodes}"
  1582.         # finance / stock quotes
  1583.         } elseif {[string match "*<a href=\"/url\?q=http://finance.google.com/finance%3Fclient%3D*" $html] == 1} {
  1584.           # this has to be one of the worst regexps ever written !
  1585.           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
  1586.           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
  1587.           if {[info exists tick] == 1 && [info exists name] == 1 && [info exists price] == 1} {
  1588.             set desc "$tick: $name = $$price"
  1589.             set link "http://finance.google.com/finance?q=$tick"
  1590.         regsub -all -- "\002" $link {} link
  1591.             if {[info exists mktcap] == 1} { append desc " Mkt Cap: $mktcap" }
  1592.             unset tick ; unset name ; unset price ; unset mktcap
  1593.           }
  1594.           if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" }
  1595.         # patents
  1596.         } elseif {[string match "*/images/magnifier.gif*" $html] ==1} {
  1597.           regexp -- {<td valign=top><a href="(http://patft.uspto.gov/.+?)".+?">(.+?)</a>} $html - link desc
  1598.          regsub -- {/images/magnifier.gif} $html {} html
  1599.        # calculator
  1600.        } elseif {[string match "*<img src=/images/calc_img*" $html] || [string match "*<img src=\"/images/icons/onebox/calculator*" $html]} {
  1601.           set calc 1
  1602.           # remove bold codes from the html, not necessary here.
  1603.           regexp -nocase -- {/calc.*?<h2 class=.*?>(.+?)</h2>} $html - desc
  1604.           regsub -all -- {<(.+?)>} $desc "" desc
  1605.           if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" }
  1606.           set link ""
  1607.         # conversion
  1608.         } elseif {[string match "*oi=currency_onebox*" $html] == 1} {
  1609.           set calc 1
  1610.           regexp -nocase -- {<h3 class=r>(.*?)<} $html - desc
  1611.           regsub -nocase -- {oi=currency_onebox} $html {} html
  1612.           if {$::incith::google::short_answers > 0 } { return "$::incith::google::desc_modes[descdecode $desc]" }
  1613.           set link ""
  1614.         # whois
  1615.         } elseif {[string match "*\002Whois\002 record for*" $html] == 1} {
  1616.           if {[regexp -- {<h3 class=r.*?<a href="(.*?)".*?>(.*?)</a>.*?<tr><td>(.*?)<tr>} $html - link desc descwho]} {
  1617.             regsub -- {<h3 class=r.*?<a href=".+?".*?>.+?</a>.*?<tr>.*?<tr>} $html "" html
  1618.             append desc " \(${descwho}\)"
  1619.           }
  1620.           if {[info exists link] == 1 && $link != ""} {
  1621.             if {[string match "*\&sa\=X*" $link]} {
  1622.               regexp -- {(^.+?)&} $link - link
  1623.             }
  1624.             if {[string match "\/url\?q=*" $link]} {
  1625.               regexp -- {\/url\?q=(.*?)$} $link - link
  1626.             }
  1627.           }
  1628.           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}" }
  1629. ### END ONEBOX ###
  1630.  
  1631.         # spell: # special query - not onebox
  1632.         } elseif {$spell == 1} {
  1633.           if {[regexp {<div id=res class=med><p>(.*?)</a>} $html - titem]} {
  1634.             regsub -all {<.*?>} $titem "" titem
  1635.             set desc "$incith::google::total_modes${titem}$incith::google::total_demodes$incith::google::desc_modes${did_you_mean}$incith::google::desc_demodes"
  1636.           } else {
  1637.             if {$match != "Google"} {
  1638.               return "${::incith::google::total_modes}\002${match}\002 ${titem}"
  1639.             } else {
  1640.               return "$incith::google::total_modes$did_you_mean$incith::google::total_demodes$incith::google::desc_modes$no_search"
  1641.             }
  1642.           }
  1643.           if {[string len $desc] < 2} {
  1644.             set desc "$incith::google::desc_modes$no_search$incith::google::desc_demodes"
  1645.           }
  1646.           set link ""
  1647.         # regular search
  1648.         } else {
  1649.           if {![regexp -- {class=g(?!b).*?<a href="(.+?)".*?>((?!<).+?)</a>} $html - link desc]} {
  1650.             if {[regexp -- {class=r.*?<a href="(.+?)".*?>((?!<).+?)</a>} $html - link desc ]} {
  1651.               regsub -- {class=r.*?<a href=".+?".*?>(?!<).+?</a>} $html "" html
  1652.             }
  1653.           } else {
  1654.             regsub -- {class=g(?!b).*?<a href=".+?".*?>.+?</a>} $html "" html
  1655.           }
  1656.  
  1657.           if {[info exists link] == 1} {
  1658.             if {[string match "*\&sa\=X*" $link]} {
  1659.               regexp -- {(^.+?)&} $link - link
  1660.             }
  1661.           }
  1662.           if {[info exists link] == 1} {
  1663.             if {[string match "*http*" $link] == 0} {
  1664.               set link ""
  1665.             } elseif {[string match *.pdf $link] == 1} {
  1666.               set desc "\[PDF\] $desc"
  1667.             }
  1668.           }
  1669.           if {($::incith::google::skip_self > 0) && ([info exists link])} {
  1670.             if {[string match "*.google.*" $link]} {
  1671.               unset link ; unset desc ; set spell 0 ; set calc 0 ; set break 0
  1672.               continue
  1673.             }
  1674.           }
  1675.           # trim the description
  1676.           if {[info exists desc] == 1 && $incith::google::description_length > 0} {
  1677.             set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  1678.           }
  1679.         }
  1680.  
  1681.         # make sure we have something to send
  1682.         if {[info exists desc] == 0} {
  1683.           if {$match == "Google"} {
  1684.             if {[string match "*<img src=/images/calc_img*" $titem] == 1} {
  1685.               regexp -nocase -- {calc_img.+?nowrap>(.+?)</} $titem - desc
  1686.               regexp -- {^(.+?)</td></tr>} $desc - desc
  1687.               set reply "${desc}"
  1688.             } else {
  1689.               set reply "${no_search}"
  1690.             }
  1691.             return "$incith::google::desc_modes$reply"
  1692.           }
  1693.           return $output
  1694.         }
  1695.  
  1696.         if {[info exists link] == 1} {
  1697.           if {[string match "*http*" $link] == 0} {
  1698.             set link ""
  1699.           }
  1700.         }
  1701.         set desc [string trim $desc]
  1702.         regsub -all "%20" $desc " " desc
  1703.         regsub -all "<br>" $desc " " desc
  1704.  
  1705.         # add the search result
  1706.         if {$calc == 0 && $spell == 0 && $populate == 0} {
  1707.           if {[info exists link] && $link != ""} {
  1708.             if {![string match "*define:*" $input]} {
  1709.               set link [urldecode $link]
  1710.               regsub -all " " $link "%20" link
  1711.             }
  1712.             # added because of recent google changes, needed to clean-up *.google.* links
  1713.             if {[string match "*url\?*" $link]} {
  1714.               regexp -- {url\?q=(.+?)$} $link - link
  1715.               regexp -- {(.+?)\&sig=} $link - link
  1716.               regexp -- {(.+?)\&usg=} $link - link
  1717.               regexp -- {\?url=(.+?)$} $link - link
  1718.             }
  1719.             # top result may be news, at the moment it is too close to regular
  1720.             # search results to cull this out.. so in the meantime, this hack
  1721.             # will at least remove the 10,000 google tags at the end of the url
  1722.             # to keep it from spanning 2 lines of results.
  1723.             if {[string match "http://news.google*" $link]} {
  1724.                regexp -- {^(.+?)&hl=} $link - link
  1725.             }
  1726.             regsub -all "(?:\x93|\x94|&quot;|\")" $link {} link
  1727.             if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  1728.             if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  1729.             if {$incith::google::link_only == 1} {
  1730.               append output "${link}${incith::google::seperator}"
  1731.             } else {
  1732.               append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  1733.             }
  1734.           } else {
  1735.             append output "[descdecode $desc]${incith::google::seperator}"
  1736.           }
  1737.         } else {
  1738.           set output "[descdecode $desc]"
  1739.         }
  1740.  
  1741.         # I've hard-coded it to only fetch one result for define lookups, and
  1742.         #   spell shouldn't ever have to loop.
  1743.         if {[string match "define:*" $input] == 1 || $spell == 1 || $calc == 1 || $break == 1 } {
  1744.           break
  1745.         }
  1746.  
  1747.         # increase the results, clear the variables for the next loop
  1748.         unset link ; unset desc ; set spell 0 ; set calc 0 ; set break 0
  1749.         incr results
  1750.       }
  1751.  
  1752.       # make sure we have something to send
  1753.       if {$output == "" && ![string match "*:*" $input] && ![string match "*<img src=/images/calc_img*" $html] } {
  1754.         set reply "${no_search}"
  1755.         return "$::incith::google::desc_modes$reply"
  1756.       }
  1757.       return $output
  1758.     }
  1759.  
  1760.     # IMAGES
  1761.     # fetches a list of links to images from images.google.
  1762.     #
  1763.     proc images {input} {
  1764.       ; set results 0 ; set output ""; set match "" ; set titem "" ; set no_search "" ; set did_you_mean ""
  1765.  
  1766.       # fetch the html
  1767.       set html [fetch_html $input 2]
  1768.  
  1769.       # user input causing errors?
  1770.     if {[string match -nocase "*socketerrorabort*" $html]} {
  1771.             regsub {(.+?)\|} $html {} html
  1772.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  1773.     }
  1774.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  1775.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  1776.     }
  1777.  
  1778.       # strip out 'did you mean?' first
  1779.       # what do we call 'no search results in any language?'
  1780.       if {![regexp -- {--></script><div>(.+?)<br><br>} $html - no_search]} {
  1781.         if {![regexp -- {</a></div><div><p>(.+?)<br><br>} $html - no_search]} {
  1782.           regexp -- {<table border=0 cellpadding=0 cellspacing=0><tr><td class=j><br>(.+?)<br><br>} $html - no_search
  1783.         }
  1784.       }
  1785.       if {$no_search != ""} {
  1786.         regsub -- {</a>} $no_search "? " no_search
  1787.         regsub -all -- {<(.+?)>} $no_search { } no_search
  1788.         while {[string match "*  *" $no_search]} {
  1789.           regsub -all -- {  } $no_search " " no_search
  1790.         }
  1791.         set no_search [string trim $no_search]
  1792.       }
  1793.  
  1794.       # give results an output header with result tally.
  1795.       regexp -- {align=right nowrap id=.*?>(.+?)\s\002(.+?)\(} $html - titem match
  1796.       if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} {
  1797.          set match "Google"
  1798.          set titem ""
  1799.       }
  1800.       regsub -all -- {<(.+?)>} $match {} match
  1801.       # format output according to variables.
  1802.       if {$incith::google::total_results != 0 && $match > 0} {
  1803.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  1804.         if {$incith::google::bold_descriptions == 0} {
  1805.           regsub -all -- "\002" $output {} output
  1806.         }
  1807.       }
  1808.  
  1809.       # parse the html
  1810.       while {$results < $incith::google::image_results} {
  1811.         if {[regexp -- {\["/imgres\?imgurl\\x3d(.*?)\\x26imgrefurl\\x3d.*?\\x26h\\x3d(.*?)\\x26w\\x3d(.*?)\\x26sz\\x3d(.*?)\\x26.*?",.*?,.*?,.*?,.*?,.*?,"(.*?)","(.*?)"} $html - link h w size desc d2]} {
  1812.           regsub -- {\["/imgres\?imgurl\\x3d(.+?)\\x26imgrefurl\\x3d.*?\\x26h\\x3d.*?\\x26w\\x3d.*?\\x26sz\\x3d.*?\\x26} $html {} html
  1813.          # google now makes it very hard to parse titles out, this solves the dilemma.
  1814.          if {[string is integer -strict $desc]} { set desc $d2 }
  1815.          #set desc [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $desc]
  1816.          regsub -all -- {\\x([[:xdigit:]]{1,2})} $desc {[format %c [scan "\1" %x]]} desc
  1817.          set desc [descdecode [subst $desc]]
  1818.          regsub -all -- {(?:<b>|</b>)} $desc "\002" desc
  1819.        }
  1820.        # if there's no link, return or stop looping, depending
  1821.        if {[info exists link] == 0} {
  1822.          if {$results == 0} {
  1823.            set reply $no_search
  1824.            return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  1825.          } else {
  1826.            break
  1827.          }
  1828.        }
  1829.  
  1830.        # prevent duplicate results is mostly useless here, but will at least
  1831.        #   ensure that we don't get the exact same picture.
  1832.        if {[string match "*$link*" $output] == 1} {
  1833.          break
  1834.        }
  1835.        append desc " ($h x $w - ${size}k)"
  1836.        if {$incith::google::desc_modes != ""} { set desc "$incith::google::desc_modes${desc}$incith::google::desc_demodes" }
  1837.        if {$incith::google::link_modes != ""} { set link "$incith::google::link_modes${link}$incith::google::link_demodes" }
  1838.  
  1839.        # add the search result
  1840.        append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  1841.  
  1842.        # increase the results, clear the variables for the next loop just in case
  1843.        unset link
  1844.        incr results
  1845.      }
  1846.  
  1847.      # make sure we have something to send
  1848.      if {$match == ""} {
  1849.        set reply "${no_search}"
  1850.        return "$::incith:google::desc_modes$reply$::incith::google::desc_demodes"
  1851.      }
  1852.      return $output
  1853.    }
  1854.  
  1855.    # LOCAL
  1856.    # fetches a list of address & phone numbers from local.google.
  1857.    # -speechless updated
  1858.    proc local {input} {
  1859.      ; set results 0 ; set output ""; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen ""
  1860.  
  1861.      # fetch the html
  1862.      set html [fetch_html $input 3]
  1863.      regsub -all {&#8206;} $html "" html
  1864.  
  1865.      # this isn't global, so we need to keep ctry (country) here
  1866.      regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen input
  1867.      if {$titen == ""} {
  1868.        set titen "${incith::google::google_country}"
  1869.      }
  1870.  
  1871.      # user input causing errors?
  1872.     if {[string match -nocase "*socketerrorabort*" $html]} {
  1873.            regsub {(.+?)\|} $html {} html
  1874.            return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  1875.     }
  1876.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  1877.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  1878.     }
  1879.  
  1880.      # strip out 'did you mean?' first
  1881.      # what do we call 'no search results in any language?'
  1882.      if {![regexp -- {<div class=spacer></div></div></div><br><p>(.+?)</p>} $html - no_search]} {
  1883.        if {[regexp -- {<table cellpadding=0 cellspacing=0><tr valign=top><td>(.+?)<br><br>} $html - no_search]} {
  1884.          set no_search [string map {"<br>" "; "} $no_search]
  1885.          regsub -all -- {<.*?>} $no_search "" no_search
  1886.          set no_search [string trim $no_search "; "]
  1887.        } elseif {[regexp -- {<div class="suggest noprint">(.*?)</a>} $html - no_search]} {
  1888.          regsub -all -- {<.*?>} $no_search "" no_search
  1889.        } elseif {[regexp -- {<div id=refsec class="suggest noprint">(.*?)<div class=ref>(.*?)<div id=bottomads} $html - did extra]} {
  1890.          foreach {- m} [regexp -all -inline {<a href=.*?>(.*?)</a>} $extra] { lappend matches $m }
  1891.          set no_search "$did [join $matches "; "]"
  1892.        }
  1893.      }
  1894.      if {[regexp -- {<div class="noprint res">.*?<p>(.*?)</p>} $html - more]} {
  1895.        append no_search "$more"
  1896.      }
  1897.  
  1898.      # give results an output header with result tally.
  1899.      if {![regexp -- {<form name="qmod".*?<br/>(.+?)\s\002(.+?)</form>} $html - titem match]} {
  1900.        if {![regexp -- {<form name="qmod".*?>(.+?)\s\002(.+?)</form>} $html - titem match]} {
  1901.          if {![regexp -- {<div id=contentpanel>.*?<form name=qmod>(.+?)\s\002(.+?)</form>} $html - match titem]} {
  1902.            if {[regexp -- {<div class="noprint">(.*?)</div>} $html - match]} {
  1903.              regsub -all -- {<.*?>} $match "" match
  1904.              set match [split [string trim $match]] ; set titem [lindex $match end] ; set match [lindex $match end-1]
  1905.              if {![string length [string trim $match]]} { set match "Google" ; set titem "" }
  1906.            } else {
  1907.              set match "Google"
  1908.              set titem ""
  1909.            }
  1910.          }
  1911.        }
  1912.      }
  1913.      regsub -all -- {<(.+?)>} $match {} match
  1914.      # format output according to variables.
  1915.      if {$incith::google::total_results != 0} {
  1916.        set output "${::incith::google::total_modes}[string trim ${match}] [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  1917.        if {$incith::google::bold_descriptions == 0} {
  1918.          regsub -all -- "\002" $output {} output
  1919.        }
  1920.      }
  1921.      # parse the html
  1922.      while {$results < $incith::google::local_results} {
  1923.        if {[regexp -nocase {class="name lname.*?<a.*?>(.*?)</a>.*?href=".*?cid=(.*?)\&q.*?</a></nobr>.*?</div> <div>(.*?)<div>} $html - loc url add1 desc]} {
  1924.          regsub -nocase {class="name lname.*?<a.*?>.*?</a>.*?href=".*?cid=.*?\&q.*?</a></nobr>.*?</div> <div>.*?<div>} $html "" html
  1925.        } elseif {[regexp -nocase {<div class=lname>.*?href=(.*?) .*?">(.*?)</a></div></div><div class=atxt dir=ltr>(.*?)</div>(.*?)<} $html - url loc add1 desc]} {
  1926.           regsub {<div class=lname>.*?href=(.*?) .*?">(.*?)</a></div></div><div class=atxt dir=ltr>(.*?)</div>} $html "" html
  1927.        }
  1928.        #regsub -nocase {<div class="name.*?href=.*?>.*?</a>.*?<div><div>.*?</div>.*?<div align=left>.*?</div>.*?<a class=f href=(.*?)>} $html "" html
  1929.         if {[info exists url]} {
  1930.           if {![string match -nocase "*maps.google*" $url]} {
  1931.             regexp -- {^/local.*?q=(.*?)(?:$| )} $url - url
  1932.             regsub -- {^/maps} $url "http://maps.google.$titen/maps" url
  1933.             regexp -- {^(.*?)&dq=} $url - url
  1934.           }
  1935.           regexp -- {^(.*?) } $url - url
  1936.         }
  1937.         # if there's no link, return or stop looping, depending
  1938.         if {![info exists loc]} {
  1939.           if {$results == 0} {
  1940.             set reply $no_search
  1941.             return "$incith::google::desc_modes$reply$::incith::google::desc_demodes"
  1942.           } else {
  1943.             return $output
  1944.             break
  1945.           }
  1946.         }
  1947.         regsub -all -- "<.*?nobr>" $add1 {} add1
  1948.         regsub -all -- "&lrm;" $add1 {} add1
  1949.         if {$incith::google::desc_modes != ""} { set loc "$incith::google::desc_modes${loc}$incith::google::desc_demodes" }
  1950.         if {$incith::google::link_modes != ""} { set link "$incith::google::link_modes${add1}$incith::google::link_demodes" } { set link $add1 }
  1951.        
  1952.         # add the search result
  1953.         if {$incith::google::link_only == 1} {
  1954.           append output "${link} ${incith::google::seperator}"
  1955.         } else {
  1956.           append output "[descdecode ${loc}]$::incith::google::break${link}${incith::google::seperator}"
  1957.         }
  1958.  
  1959.         # increase the results, clear the variables for the next loop just in case
  1960.         unset loc ; unset link ; unset desc
  1961.         incr results
  1962.       }
  1963.       return $output
  1964.     }
  1965.  
  1966.     # GROUPS
  1967.     # fetches a list of threads from groups.google.
  1968.     # -speechless updated
  1969.  
  1970.     proc groups {input} {
  1971.       ; set results 0 ; set output "" ; set match "" ; set no_search "" ; set titem "" ; set titen ""
  1972.  
  1973.       # this isn't global, so we need to keep ctry (country) here
  1974.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy
  1975.       if {$titen == ""} {
  1976.         set titen "${incith::google::google_country}"
  1977.       }
  1978.  
  1979.       # fetch the html
  1980.       set html [fetch_html $input 4]
  1981.  
  1982.       # user input causing errors?
  1983.     if {[string match -nocase "*socketerrorabort*" $html]} {
  1984.             regsub {(.+?)\|} $html {} html
  1985.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  1986.     }
  1987.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  1988.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  1989.     }
  1990.  
  1991.       # strip out 'did you mean?' first
  1992.       # what do we call 'no search results in any language?'
  1993.       regexp -- {<div id=res><p>(.+?)</div><div>} $html - no_search
  1994.       if {$no_search != ""} {
  1995.         regsub -- {</a>} $no_search "? " no_search
  1996.         regsub -all -- {<(.+?)>} $no_search { } no_search
  1997.         while {[string match "*  *" $no_search]} {
  1998.           regsub -all -- {  } $no_search " " no_search
  1999.         }
  2000.         set no_search [string trim $no_search]
  2001.       }
  2002.  
  2003.       # give results an output header with result tally.
  2004.       regexp -- {</td><td align="right".*?>(.+?)\s\002(.+?)(\[|<)} $html - titem match
  2005.       if {![regexp -- {1\002\s-\s.+?\002.+?\002(.+?)\002} $match - match]} {
  2006.          set match "Google"
  2007.          set titem ""
  2008.       }
  2009.       regsub -all -- {<(.+?)>} $match {} match
  2010.       # format output according to variables.
  2011.       if {$incith::google::total_results != 0 && $match > 0} {
  2012.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  2013.         if {$incith::google::bold_descriptions == 0} {
  2014.           regsub -all -- "\002" $output {} output
  2015.         }
  2016.       }
  2017.  
  2018.       # parse the html
  2019.       while {$results < $incith::google::group_results} {
  2020.         # this grabs a google group if one exists
  2021.         # this grabs a usenet group if one exists
  2022.         if {[regexp -- {<div class="gdrr"><a\s+href="(.+?)".*?>(.+?)</a>.+?</td></tr></table>} $html {} thread desc]} {
  2023.           regsub -- {<div class="gdrr">(.+?)</td></tr></table>} $html "" html
  2024.           if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} {
  2025.             regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread
  2026.             set thread [urldecode $thread]
  2027.             if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} {
  2028.               regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread
  2029.               set thread [urldecode $thread]
  2030.             }
  2031.           }
  2032.         } elseif {[regexp -- {<div class="g".*?href="(.+?)".*?>(.+?)</a>} $html - thread desc]} {
  2033.           regsub -- {div class="g".*?href=".+?".*?>(.+?)</td></tr>} $html "" html
  2034.           if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} {
  2035.             regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread
  2036.             set thread [urldecode $thread]
  2037.             if {[regexp -- {url\?(?:url|q)=(.+?)\&} $thread - thread]} {
  2038.               regexp -- {^(.+?)&(?:sa|ie|ei)=} $thread - thread
  2039.               set thread [urldecode $thread]
  2040.             }
  2041.           }
  2042.         }
  2043.  
  2044.         # if there's no desc, return or stop looping, depending
  2045.         if {[info exists desc] == 0} {
  2046.           if {$results == 0} {
  2047.             set reply $no_search
  2048.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2049.           } else {
  2050.             break
  2051.           }
  2052.         }
  2053.  
  2054.         if {[info exists desc] == 1 && $incith::google::description_length > 0} {
  2055.           set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  2056.           set desc [string trim $desc]
  2057.         }
  2058.  
  2059.         # make the link valid because we only got a partial href result, not a full url
  2060.         set link $thread
  2061.  
  2062.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2063.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2064.  
  2065.         # add the search result
  2066.         if {$incith::google::link_only == 1} {
  2067.           append output "${link}${incith::google::seperator}"
  2068.         } else {
  2069.           append output "[descdecode $desc] $::incith::google::break${link}${incith::google::seperator}"
  2070.         }
  2071.  
  2072.         # increase the results, clear the variables for the next loop just in case
  2073.         unset link; unset desc
  2074.         incr results
  2075.       }
  2076.  
  2077.       # make sure we have something to send
  2078.       if {$match == ""} {
  2079.         set reply $no_search
  2080.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2081.       }
  2082.       return $output
  2083.     }
  2084.  
  2085.     # NEWS
  2086.     # fetches the news from news.google.
  2087.     # -madwoota supplied, speechless updated
  2088.     #
  2089.     proc news {input} {
  2090.       ; set results 0 ; set output ""; set match ""
  2091.       ; set no_search "" ; set titem ""
  2092.  
  2093.       # fetch the html
  2094.       set html [fetch_html $input 5]
  2095.  
  2096.       # user input causing errors?
  2097.     if {[string match -nocase "*socketerrorabort*" $html]} {
  2098.             regsub {(.+?)\|} $html {} html
  2099.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  2100.     }
  2101.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  2102.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  2103.     }
  2104.       # strip out 'did you mean?' first
  2105.       # what do we call 'no search results in any language?'
  2106.       if {![regexp -- {<div class="spelling-correction">(.+?)</p><p>} $html - no_search]} {
  2107.         regexp -- {<div class="no-results">(.+?)</p>} $html - no_search
  2108.       }
  2109.       if {$no_search != ""} {
  2110.         regsub -- {</a>} $no_search "? " no_search
  2111.         regsub -all -- {<(.+?)>} $no_search { } no_search
  2112.         while {[string match "*  *" $no_search]} {
  2113.           regsub -all -- {  } $no_search " " no_search
  2114.         }
  2115.         set no_search [string trim $no_search]
  2116.       }
  2117.  
  2118.       # give results an output header with result tally.
  2119.       regexp -- {<div class="results-stats">(.+?)\s\002(.+?)\(\002} $html - titem match
  2120.       if {![regexp -- {1\002\s&ndash;\s\002.+?\002.+?\002(.+?)\002} $match - match]} {
  2121.          set match "Google"
  2122.          set titem ""
  2123.       }
  2124.       regsub -all -- {<(.+?)>} $match {} match
  2125.       # format output according to variables.
  2126.       if {$incith::google::total_results != 0 && $match > 0} {
  2127.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  2128.         if {$incith::google::bold_descriptions == 0} {
  2129.           regsub -all -- "\002" $output {} output
  2130.         }
  2131.       }
  2132.  
  2133.       # We have to do a single regsub first to get down to the rough area in the html we need because
  2134.       # its just *not* very elegant attempting doing this in a single regexp. (Read: unreliable)
  2135.       #regsub -- {<html>(.+?)</div>} $html {} html
  2136.  
  2137.       # parse the html
  2138.       while {$results < $incith::google::news_results} {
  2139.         # somewhat extenuated regexp due to allowing that there *might* be
  2140.         # an image next to the story
  2141.       # <h2 class="title">.*?<a class.*?>.*?<a.*?href="(.+?)".*?>(.+?)</a>.+?<div class="sub-title">(.+?)</div>
  2142.         if {[regexp -- {<h2 class="title">.*?<a target.*?href="(.+?)".*?>(.+?)</a>.+?<div class="sub-title">(.+?)</div>} $html {} link desc time]} {
  2143.           regsub -all -- {<.*?>} $time "" time
  2144.         }
  2145.         regsub -- {<h2 class="title">.*?<a.*?href=".+?".*?>.+?</a>.+?<div class="sub-title">.+?</div>} $html {} html
  2146.  
  2147.         # if there's no desc, return or stop looping, depending
  2148.         if {[info exists desc] == 0} {
  2149.           if {$results == 0} {
  2150.             set reply $no_search
  2151.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2152.           } else {
  2153.             break
  2154.           }
  2155.         }
  2156.        
  2157.         if {[info exists desc] == 1 && $incith::google::description_length > 0} {
  2158.           set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  2159.           set desc [descdecode [string trim $desc]]
  2160.         }
  2161.  
  2162.         # prevent duplicate results is mostly useless here, but will at least
  2163.         #   ensure that we don't get the exact same article.
  2164.         if {[string match "*$link*" $output] == 1} {
  2165.           break
  2166.         }
  2167.        
  2168.         if {[info exists desc]} { set desc "$incith::google::desc_modes$desc$incith::google::desc_demodes" }
  2169.         if {[info exists time]} { set time "$incith::google::desc_modes[descdecode [string trim $time]]$incith::google::desc_demodes" }
  2170.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2171.         # add the search result
  2172.         if {$incith::google::link_only == 1} {
  2173.           append output "${link}${incith::google::seperator}"
  2174.         } else {
  2175.           append output "$desc \($time\)$::incith::google::break${link}${incith::google::seperator}"
  2176.         }
  2177.  
  2178.         # increase the results, clear the variables for the next loop just in case
  2179.         unset link; unset desc
  2180.         incr results
  2181.       }
  2182.  
  2183.       # make sure we have something to send
  2184.       if {$match == ""} {
  2185.         set reply $no_search
  2186.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2187.       }
  2188.       return $output
  2189.     }
  2190.  
  2191.     # PRINT
  2192.     # fetches book titles from books.google.
  2193.     # -madwoota supplied, -broken-
  2194.     # -speechless updated, fixed no longer using print.google
  2195.     #
  2196.     proc print {input} {
  2197.       ; set results 0 ; set output "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen ""
  2198.       ; set match ""
  2199.  
  2200.       # this isn't global, so we need to keep ctry (country) here
  2201.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy
  2202.       if {$titen == ""} {
  2203.         set titen "${incith::google::google_country}"
  2204.       }
  2205.  
  2206.       # fetch the html
  2207.       set html [fetch_html $input 6]
  2208.  
  2209.       # user input causing errors?
  2210.     if {[string match -nocase "*socketerrorabort*" $html]} {
  2211.             regsub {(.+?)\|} $html {} html
  2212.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  2213.     }
  2214.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  2215.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  2216.     }
  2217.  
  2218.       # strip out 'did you mean?' first
  2219.       # what do we call 'no search results in any language?'
  2220.       regexp -- {<td id="main_content">(.*?)</p>} $html - no_search
  2221.  
  2222.       # if we have a no search results message, let's format it for displaying possibly.
  2223.       if {$no_search != ""} {
  2224.         #regsub -all -- {\002\002} $no_search "\002" no_search
  2225.         regsub -- {</a></div>} $no_search "? " no_search
  2226.         regsub -all -- {<(.+?)>} $no_search { } no_search
  2227.         while {[string match "*  *" $no_search]} {
  2228.           regsub -all -- {  } $no_search " " no_search
  2229.         }
  2230.         set no_search [string trim $no_search]
  2231.       }
  2232.  
  2233.       # give results an output header with result tally.
  2234.       regexp -- {<td align=right>(.+?)\s\002(.+?)\(\002} $html - titem match
  2235.       if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} {
  2236.          set match "Google"
  2237.          set titem ""
  2238.       }
  2239.  
  2240.       regsub -all -- {<(.+?)>} $match {} match
  2241.       # format output according to variables.
  2242.       if {$incith::google::total_results != 0 && $match > 0} {
  2243.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  2244.         if {$incith::google::bold_descriptions == 0} {
  2245.           regsub -all -- "\002" $output {} output
  2246.         }
  2247.       }
  2248.  
  2249.       while {$results < $incith::google::print_results} {
  2250.         if {[regexp -- {<div class=resbdy><h2 class="resbdy">(.*?)</table>} $html - snippet]} {
  2251.           if {![regexp -- {<a.*?href=".+?id=(.+?)&pg=(.*?)&.*?".*?>(.+?)</a></h2>(.+?)<br} $snippet - id page desc author]} {
  2252.             regexp -- {<a.*?href=".+?id=(.+?)&.*?".*?>(.+?)</a></h2>(.+?)<br} $snippet - id desc author
  2253.           }
  2254.           regsub -- {<div class=resbdy><h2 class="resbdy"><a.*?href=(.+?)</table>} $html "" html
  2255.         }
  2256.  
  2257.         # if there's no desc, return or stop looping, depending
  2258.         if {![info exists desc]} {
  2259.           if {$results == 0} {
  2260.             set reply $no_search
  2261.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2262.           } else {
  2263.             break
  2264.           }
  2265.         }
  2266.  
  2267.         # this cleans up perhaps bad html cuts
  2268.         if {[info exists desc]} {
  2269.           regsub -all -- {<(.+?)>} $desc "" desc
  2270.           set desc [string trim $desc]
  2271.         }
  2272.  
  2273.         if {[info exists desc]} {
  2274.           regsub -all -- {<(.+?)>} $author "" author
  2275.           set author [string trim $author]
  2276.         }
  2277.  
  2278.         # make link by appending book id
  2279.         if {[info exists page]} { set page "&pg=$page" } { set page "" }
  2280.         set link "http://books.google.${titen}?id=${id}${page}"
  2281.    
  2282.         # prevent duplicate results is mostly useless here, but will at least
  2283.         # ensure that we don't get the exact same article.
  2284.         #if {[string match "*$link*" $output] == 1} {
  2285.         # break
  2286.         #}
  2287.         append desc " (${author})"
  2288.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2289.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2290.  
  2291.         # add the search result
  2292.         if {$incith::google::link_only == 1} {
  2293.           append output "${link}${incith::google::seperator}"
  2294.         } else {
  2295.           append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  2296.         }
  2297.  
  2298.         # increase the results, clear the variables for the next loop just in case
  2299.         unset link ; unset desc ; unset page
  2300.         incr results
  2301.       }
  2302.  
  2303.       # make sure we have something to send
  2304.       if {![info exists output]} {
  2305.         set reply $no_search
  2306.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2307.       }
  2308.       return $output
  2309.     }
  2310.  
  2311.     # GeoBytes
  2312.     # Fetches IP Location information
  2313.     # -speechless supplied
  2314.     #
  2315.     proc locate {input} {
  2316.       ; set results 0 ; set output ""
  2317.       ; set city "" ; set region "" ; set country ""
  2318.       ; set certainty "" ; set timezone "" ; set population ""
  2319.       ; set currency "" ; set proxy "" ; set curr "" ;
  2320.  
  2321.       # fetch the html
  2322.       set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  2323.       set http [::http::config -useragent $ua]
  2324.       set url "http://www.geobytes.com/IpLocator.htm?GetLocation"
  2325.       set query [::http::formatQuery ipaddress $input]
  2326.       set http [::http::geturl $url -query $query -headers $::incith_hdr -timeout [expr 1000 * 10]]
  2327.       upvar #0 $http state
  2328.       set html [ungzip [::http::data $http] $state(meta)]
  2329.       ::http::cleanup $http
  2330.  
  2331.       # is site broken? if it is, say so
  2332.       if {![string match "*<html>*" $html]} {
  2333.         return "$::incith::google::error_modes\002 GeoBytes Error:\002 Unable to access site. www.geobytes.com seems to be down.$::incith::google::error_demodes"
  2334.       }
  2335.  
  2336.       #strip html tags
  2337.       regsub -all "\t" $html "" html
  2338.       regsub -all "\n" $html "" html
  2339.       regsub -all "\r" $html "" html
  2340.       regsub -all "\v" $html "" html
  2341.       regsub -all "&#039;" $html "'" html
  2342.  
  2343.       #parse html
  2344.       regexp -- {input.+?name="ro-no_bots_pls13".+?value="(.+?)".+?size} $html {} country
  2345.       regexp -- {input.+?name="ro-no_bots_pls15".+?value="(.+?)".+?size} $html {} region
  2346.       regexp -- {input.+?name="ro-no_bots_pls17".+?value="(.+?)".+?size} $html {} city
  2347.       regexp -- {input.+?name="ro-no_bots_pls18".+?value="(.+?)".+?size} $html {} certainty
  2348.       regexp -- {input.+?name="ro-no_bots_pls9".+?value="(.+?)".+?size} $html {} timezone
  2349.       regexp -- {input.+?name="ro-no_bots_pls3".+?value="(.+?)".+?size} $html {} population
  2350.       regexp -- {input.+?name="ro-no_bots_pls1".+?value="(.+?)".+?size} $html {} currency
  2351.       #currency sometimes has a trailing space, let's fix that with a dirty hack.
  2352.       set currency [string trim $currency]
  2353.       regexp -- {input.+?name="ro-no_bots_pls11".+?value="(.+?)".+?size} $html {} proxy
  2354.       regexp -- {input.+?name="ro-no_bots_pls".+?value="(.+?)".+?size} $html {} curr
  2355.  
  2356.       #in case we get blocked, say we did
  2357.       if {[string match "*temporarily blocked*" $html] == 1} {
  2358.        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"
  2359.       }
  2360.  
  2361.       #if we can't read a country, assume there was nothing to lookup.
  2362.       if {$country == "" && $output == ""} {
  2363.         set output "$::incith::google::error_modes\002GeoBytes Error:\002 (${input}) Undefined IP. Nothing to LookUp.$::incith::google::error_demodes"
  2364.       } elseif {$output == ""} {
  2365.         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"
  2366.       }
  2367.       if {$incith::google::bold_descriptions != 1 && [string match "\002" $incith::google::desc_modes] != 1} {
  2368.          regsub -all -- "\002" $output {} output
  2369.       }
  2370.       return $output
  2371.     }
  2372.  
  2373.     # VIDEO
  2374.     # fetches links to video with search data in it (video.google.com)
  2375.     # -madwoota supplied, speechless updated
  2376.     #
  2377.     proc video {input} {
  2378.       ; set results 0 ; set output ""; set match ""; set ded ""
  2379.       ; set titen "" ; set titem "" ; set no_search "" ; set did_you_mean ""
  2380.  
  2381.       # this isn't global, so we need to keep ctry (country) here
  2382.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy
  2383.       if {$titen == ""} {
  2384.         set titen "${incith::google::google_country}"
  2385.       }
  2386.  
  2387.       # fetch the html
  2388.       set html [fetch_html $input 7]
  2389.  
  2390.       # user input causing errors?
  2391.     if {[string match -nocase "*socketerrorabort*" $html]} {
  2392.             regsub {(.+?)\|} $html {} html
  2393.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  2394.     }
  2395.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  2396.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  2397.     }
  2398.  
  2399.       # strip out 'did you mean?' first
  2400.       # what do we call 'no search results in any language?'
  2401.       if {[regexp -- {<div class=med><p style=.*?>(.*?)<p style} $html - no_search]} {
  2402.         #regsub -all -- {(<strong>|</strong>)} $no_search "\002" no_search
  2403.         #regsub -- {</a>} $no_search "? " no_search
  2404.         #regsub -- {</td>} $no_search ". " no_search
  2405.         regsub -all -- {<(.+?)>} $no_search "" no_search
  2406.         set no_search [string trim $no_search]
  2407.       }
  2408.  
  2409.       # give results an output header with result tally.
  2410.       if {![regexp -- {<div id=resultStats>(.+?)<nobr>} $html - match]} {
  2411.          set match "Google"
  2412.          set titem ""
  2413.       } else {
  2414.         regsub -all -- {<(.+?)>} $match {} match
  2415.         regexp -- {([0-9].*?)$} $match - match
  2416.         set match "\002[join [lrange [split $match] 0 end-1]]\002 [lindex [split $match] end]"
  2417.       }
  2418.       # format output according to variables.
  2419.       if {$incith::google::total_results != 0} {
  2420.         set output "${::incith::google::total_modes}[string trim ${match}]${::incith::google::total_demodes}${incith::google::seperator}"
  2421.         if {$incith::google::bold_descriptions == 0} {
  2422.           regsub -all -- "\002" $output {} output
  2423.         }
  2424.       }
  2425.  
  2426.       # parse the html
  2427.       while {$results < $incith::google::video_results} {
  2428.         # somewhat extenuated regexp due to allowing that there might be an image next to the title
  2429.         regexp -- {<h3 class=r>.*?href="(.*?)".*?>(.*?)</a>.*?<span class=f>(.*?)</span><br>(.*?)<br>} $html {} link desc ded ded2
  2430.         regsub -- {<h3 class=r>.*?href=".*?".*?>.*?</a>.*?<span class=f>.*?</span><br>.*?<br>} $html "" html
  2431.  
  2432.         # if there's no desc, return or stop looping, depending
  2433.         if {[info exists desc] == 0} {
  2434.           if {$results == 0} {
  2435.             set reply $no_search
  2436.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2437.           } else {
  2438.             break
  2439.           }
  2440.         }
  2441.  
  2442.         set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]]
  2443.         # append narration to description for more detail unless its identical
  2444.         # keep description from becoming too lengthy and clean up trailing spaces
  2445.         regsub -all {<div class=description.+?</div>} $ded "" ded
  2446.         regexp {(.+?)\)--} $ded - ded
  2447.         regsub { -} $ded " - " ded
  2448.         regsub {<span class=rl-domain>} $ded " - " ded
  2449.         regsub -all {<(.*?)>} $ded "" ded
  2450.         if {[string length $ded2]} {
  2451.           set ded2 "\([descdecode [string range $ded2 0 [expr $incith::google::description_length - 1]]]\)"
  2452.         }
  2453.         set desc "[descdecode $desc] $ded2\([descdecode [string trim $ded]]\)"
  2454.  
  2455.         # make the link valid because we were only given a partial href result, not a full url
  2456.         if {[string match [string range $link 0 0] "/"]} {
  2457.           regsub -- {&.+?$} $link "" link
  2458.           set link "http://video.google.${titen}${link}"
  2459.         }
  2460.  
  2461.         # prevent duplicate results is mostly useless here, but will at least
  2462.         #   ensure that we don't get the exact same article.
  2463.         if {[string match "*$link*" $output] == 1} {
  2464.          break
  2465.         }
  2466.         # quick and dirty double-space remover
  2467.         while {[string match "*  *" $desc]} {
  2468.           regsub -all -- {  } $desc " " desc
  2469.         }
  2470.         set desc [string trim $desc]
  2471.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2472.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2473.  
  2474.         # add the search result
  2475.         if {$incith::google::link_only == 1} {
  2476.           append output "${link}${incith::google::seperator}"
  2477.         } else {
  2478.           append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  2479.         }
  2480.  
  2481.         # increase the results, clear the variables for the next loop just in case
  2482.         unset link; unset desc
  2483.         incr results
  2484.       }
  2485.  
  2486.       # make sure we have something to send
  2487.       if {$match == ""} {
  2488.         set reply $no_search
  2489.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2490.       }
  2491.       return $output
  2492.     }
  2493.  
  2494.     # FIGHT
  2495.     # google fight !
  2496.     #
  2497.     proc fight {input} {
  2498.       set output ""; set winner 0; set match1 0; set match2 0
  2499.  
  2500.       if {![regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input]} {
  2501.         set country "${incith::google::google_country}"
  2502.       }
  2503.       regexp -nocase -- {^(.+?) vs (.+?)$} $input - word1 word2
  2504.       if {![regexp -nocase -- {^\.(.+?)\s(.+?)$} $word2 - country2 word2]} {
  2505.         set country2 "${incith::google::google_country}"
  2506.       }
  2507.  
  2508.       # fetch the first result
  2509.       set html [fetch_html ".$country $word1" 8]
  2510.       # parse the html
  2511.       if {![regexp -nocase {<div id=prs>.*?</div><p>(.+?)(?:\(\002|\[)} $html - matches1]} {
  2512.         if {![regexp -- {<div id=resultStats> (.*?) (.*?)\(\002} $html - titem matches1]} {
  2513.           if {[regexp -- {<div id=resultStats>(.*?)\(} $html - match]} {
  2514.             set matches1 [lindex [split [string trim $match]] end-1]
  2515.           }
  2516.         }
  2517.       }
  2518.       if {[info exists matches1]} {
  2519.         regsub -- {(?:\002|\s)1\002 - \0021\002} $matches1 "" matches1
  2520.         regsub -- {(?:\002|\s)1\002-\0021\002} $matches1 "" matches1
  2521.         regsub -nocase { of about } $matches1 "" matches1
  2522.         regsub -nocase -all {<a href.*?>} $matches1 "" matches1
  2523.         regsub -nocase -all {</a>} $matches1 "" matches1
  2524.         set match1 $matches1
  2525.         regsub -all -- {[\., ]} $match1 "" match1
  2526.       } else { set matches1 "0" }
  2527.       if {![string is digit $match1]} {
  2528.         regexp -- {\002(.+?)\002.*?\002(.+?)\002} $matches1 - dummy match1
  2529.         if {[string match $match1 $word1]} {
  2530.           regexp -- {\002(.+?)\002} $matches1 - match1
  2531.         }
  2532.       }
  2533.  
  2534.       # fetch the second result
  2535.       set html [fetch_html ".$country2 $word2" 8]
  2536.       # parse the html
  2537.       if {![regexp -nocase {<div id=prs>.*?</div><p>(.+?)(?:\(\002|\[)} $html - matches2]} {
  2538.         if {![regexp -- {<div id=resultStats> (.*?) (.*?)\(\002} $html - titem matches2]} {
  2539.           if {[regexp -- {<div id=resultStats>(.*?)\(} $html - match]} {
  2540.             set matches2 [lindex [split [string trim $match]] end-1]
  2541.           }
  2542.         }
  2543.       }
  2544.       if {[info exists matches2]} {
  2545.         regsub -- {(?:\002|\s)1\002 - \0021\002} $matches2 "" matches2
  2546.         regsub -- {(?:\002|\s)1\002-\0021\002} $matches2 "" matches2
  2547.         regsub -nocase { of about } $matches2 "" matches2
  2548.         regsub -nocase -all {<a href.*?>} $matches2 "" matches2
  2549.         regsub -nocase -all {</a>} $matches2 "" matches2
  2550.         set match2 $matches2
  2551.       } else { set matches2 "0" }
  2552.       if {![string is digit $match2]} {
  2553.         regexp -- {\002(.+?)\002.*?\002(.+?)\002} $matches2 - dummy match2
  2554.         if {[string match $match2 $word2]} {
  2555.           regexp -- {\002(.+?)\002} $matches2 - match2
  2556.         }
  2557.       }
  2558.  
  2559.       if {![string match $country $country2]} { set country "$country and Google.$country2" }
  2560.       if {![info exists match1]} {
  2561.         set match1 "0"
  2562.         set match1expr "0"
  2563.       } else {
  2564.         regsub -all {(?:\.|,| )} $match1 "" match1expr
  2565.       }
  2566.  
  2567.       if {![info exists match2]} {
  2568.         set match2 "0"
  2569.         set match2expr "0"
  2570.       } else {
  2571.         regsub -all {(?:\.|,| )} $match2 "" match2expr
  2572.       }
  2573.  
  2574.       if {[expr $match2expr < $match1expr]} {
  2575.         set winner 1
  2576.       } elseif {[string match $match2expr $match1expr]} {
  2577.         set winner 3
  2578.       } else {
  2579.         set winner 2
  2580.       }
  2581.  
  2582.       if {$incith::google::bold_descriptions > 0 && $incith::google::desc_modes == ""} {
  2583.         set word1 "\002$word1\002"; set word2 "\002$word2\002"
  2584.         set match1 "\002 $matches1\002"; set match2 "\002 $matches2\002"
  2585.       } elseif {$incith::google::desc_modes != ""} {
  2586.         set word1 "\002$word1\002"; set word2 "\002$word2\002"
  2587.         set match1 " $matches1"; set match2 " $matches2"
  2588.       } else {
  2589.         set match1 " $matches1"; set match2 " $matches2"
  2590.       }
  2591.  
  2592.       if {$winner == 1} {
  2593.         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"
  2594.       } elseif {$winner == 2} {
  2595.         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"
  2596.       } else {
  2597.         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"
  2598.       }
  2599.  
  2600.       # make sure we have something to send
  2601.       if {[info exists output] == 0} {
  2602.         set reply "${::incith::google::desc_modes}Sorry, no search results were found. Something is wrong...$::incith::google::desc_demodes"
  2603.         return $reply
  2604.       }
  2605.       return $output
  2606.     }
  2607.  
  2608.     # YOUTUBE
  2609.     # fetches links to video with search data in it (youtube.com)
  2610.     # -speechless supplied
  2611.     #
  2612.     proc youtube {input} {
  2613.      
  2614.       ; set results 0 ; set output "" ; set ded ""; set match "" ; set titem "" ; set titen ""
  2615.       if {[regsub -nocase -all -- "$::incith::google::youtube_highdef" $input "" dummy]} { set hd 1 }
  2616.       # this isn't global, so we need to keep ctry (country) here
  2617.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy
  2618.       if {$titem == ""} {
  2619.         set titem "${incith::google::youtube_country}"
  2620.       }
  2621.  
  2622.       # fetch the html
  2623.       set html [fetch_html $input 9]
  2624.  
  2625.       # user input causing errors?
  2626.     if {[string match -nocase "*socketerrorabort*" $html]} {
  2627.             regsub {(.+?)\|} $html {} html
  2628.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  2629.     }
  2630.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  2631.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  2632.     }
  2633.  
  2634.       # give results an output header with result tally.
  2635.       if {![regexp -- {<div id="search-num-results" class="name">(.*?)</div} $html - match]} {
  2636.         set match "YouTube"
  2637.         set titen "results"
  2638.       } else {
  2639.         regsub -all {\s+} [string trim $match] " " match
  2640.         set match [split $match]
  2641.         set titen [lindex $match end-6]
  2642.         set match [lindex $match end]
  2643.       }
  2644.       # format output according to variables.
  2645.       if {$incith::google::total_results != 0 && $match != ""} {
  2646.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titen]]${::incith::google::total_demodes}${incith::google::seperator}"
  2647.         if {$incith::google::bold_descriptions == 0} {
  2648.           regsub -all -- "\002" $output {} output
  2649.         }
  2650.       }
  2651.       if {[regexp -nocase {<div class="marT10">(.+?)(</div></div>|</div><div>|</a></div>|<\!--)} $html - reply]} {
  2652.         regsub -all -nocase {<div class="marT10">.+?(</div></div>|</div><div>|</a></div>|<\!--)} $html "" html
  2653.         regsub -all {<td>} $reply ". " reply
  2654.         regsub -all -- {<.*?>} $reply "" reply
  2655.       } elseif {[regexp -nocase {id="search-no-results-message">(.*?)</div>} $html - reply]} {
  2656.         regsub -all -- {<.*?>} $reply "" reply
  2657.       } elseif {[regexp -nocase {id="results-main-.*?>.*?<img.*?>(.*?)<br>} $html - reply]} {
  2658.        regsub -all -- {<.*?>} $reply "" reply
  2659.      } else { set reply "" }
  2660.  
  2661.      # parse the html
  2662.      while {$results < $incith::google::youtube_results} {
  2663.        # somewhat extenuated regexp due to allowing that there might be an image next to the title
  2664.        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]} {
  2665.           if {[string match "*</span>*" $desc]} {
  2666.             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
  2667.          }
  2668.          regsub -nocase {<span class="video-time">.*?</span.*?class="video\-view\-count">.*?</span} $html "" html
  2669.        }
  2670.        if {[info exists desc] == 0} {
  2671.          if {$results == 0} {
  2672.            append output "[descdecode [string trim $reply]]${incith::google::seperator}"
  2673.            return "$incith::google::desc_modes[descdecode $reply]$::incith::google::desc_demodes"
  2674.          } else {
  2675.            break
  2676.          }
  2677.        }
  2678.  
  2679.        # keep description from becoming too lengthy and clean up trailing spaces
  2680.        if {[info exists desc]} {
  2681.          set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  2682.          set desc [descdecode [string trim $desc]]
  2683.        }
  2684.  
  2685.        # append length to description for more detail
  2686.        if {[info exists ded] && [info exists desc]} {
  2687.          if {![string equal "<" [string index $ded 0]]} {
  2688.            set ded " ([descdecode [string trim [string range $ded 0 [expr $incith::google::description_length - 1]]]]) "
  2689.          } else { set ded " " }
  2690.          if {[string match " ($desc) " $ded]} { set ded " " }
  2691.          if {[info exists ded4]} {
  2692.            append desc "${ded}(${ded4}; ${ded2}; ${ded3})"
  2693.          } else {
  2694.            append desc "${ded}"
  2695.          }
  2696.        }
  2697.  
  2698.        # make the link valid because we were only given a partial href result, not a full url
  2699.        if {$titem == "com" } {
  2700.          set link "http://youtube.com/watch?v=${cid}&hl=en"
  2701.        } else {
  2702.          set link "http://${titem}.youtube.com/watch?v=${cid}&hl=${titem}"
  2703.        }
  2704.        # fullscreen window link - http://youtube.com/v/${cid}
  2705.  
  2706.        if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2707.        if {[info exists link]} {
  2708.          if {[info exists hd]} {
  2709.            set link [string map {"&hd=1" "&fmt=22"} $link]
  2710.          } elseif {$incith::google::youtube_highquality != 0} {
  2711.            append link "&fmt=18"
  2712.          }
  2713.          set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes"
  2714.        }
  2715.  
  2716.        # add the search result
  2717.        if {$incith::google::link_only == 1} {
  2718.          append output "${link}${incith::google::seperator}"
  2719.        } else {
  2720.          append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  2721.        }
  2722.  
  2723.        # increase the results, clear the variables for the next loop just in case
  2724.        unset link; unset desc ; set ded ""
  2725.        incr results
  2726.      }
  2727.      return $output
  2728.    }
  2729.  
  2730.    # MYSPACEVIDS
  2731.    # fetches links to video with search data in it (videosearch.myspace.com)
  2732.    # -speechless supplied
  2733.    #
  2734.    proc myspacevids {input} {
  2735.  
  2736.      ; set results 0 ; set output "" ; set ded ""; set match "" ; set rating ""
  2737.  
  2738.      # fetch the html
  2739.      set html [fetch_html $input 11]
  2740.  
  2741.      # give results an output header with result tally.
  2742.      regexp -nocase -- {class="resultsInfo">.*?1-.*?\s.*?\s(.*?)\s(.*?)\s} $html - match videos
  2743.  
  2744.      # format output according to variables.
  2745.      if {$incith::google::total_results != 0 && $match != ""} {
  2746.        set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $videos]]${::incith::google::total_demodes}${incith::google::seperator}"
  2747.        if {$incith::google::bold_descriptions == 0} {
  2748.          regsub -all -- "\002" $output {} output
  2749.        }
  2750.      }
  2751.  
  2752.      # parse the html
  2753.      while {$results < $incith::google::myspacevids_results} {
  2754.        # somewhat extenuated regexp due to allowing that there might be an image next to the title
  2755.        regexp -nocase -- {a class="taggedlink.*?href=.*?videoid=(.*?)\&.*?>(.*?)</a>.*?<a class=.*?>(.*?)</a>.*?<ul class="videoData group">(.*?)</ul>} $html - cid desc ded rating
  2756.         regsub -nocase -- {a class="taggedlink.*?href=.*?videoid=.*?\&.*?>.*?</a>.*?<a class=.*?>.*?</a>.*?<ul class="videoData group">.*?</ul>} $html {} html
  2757.        # if there's no desc, return or stop looping, depending
  2758.        if {![info exists desc]} {
  2759.          if {$results == 0} {
  2760.            if {[regexp -- {class="displayingSummary">(.+?)</div>} $html - reply]} {
  2761.              return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2762.            } elseif {[regexp -- {<p id="displaySummary" class="resultsInfo">(.*?)</p>} $html - reply]} {
  2763.              return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2764.            }
  2765.          } else {
  2766.            break
  2767.          }
  2768.        }
  2769.  
  2770.        # duplicate link filter, clumsy indeed.. will remove soon and fix properly
  2771.        if {[string match "*${cid}*" $output] == 1} {
  2772.          break
  2773.        }
  2774.        if {[info exists rating]} {
  2775.           regsub -all {</li>} [string map {"    " "" "\002" ""} $rating] ";" rating
  2776.          regsub -all {<.*?>} $rating "" rating
  2777.          regsub -all {\s+} $rating " " rating
  2778.          regsub -all { ;} $rating ";" rating
  2779.        }
  2780.        if {[info exists ded]} {
  2781.          regsub -all {<.*?>} [string trim $ded] "" ded
  2782.          if {[string length $ded]} { set ded "(by $ded)" }
  2783.        }
  2784.        # keep description from becoming too lengthy and clean up trailing spaces
  2785.        if {[info exists desc]} {
  2786.          set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]]
  2787.          set desc "${desc} ${ded}([string trim ${rating} "; "])"
  2788.        }
  2789.  
  2790.        # make the link valid because we were only given a partial href result, not a full url
  2791.        set link "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=${cid}"
  2792.  
  2793.        if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2794.        if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2795.  
  2796.        # add the search result
  2797.        if {$incith::google::link_only == 1} {
  2798.          append output "${link}${incith::google::seperator}"
  2799.        } else {
  2800.          append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  2801.        }
  2802.  
  2803.        # increase the results, clear the variables for the next loop just in case
  2804.        unset link; unset desc
  2805.        incr results
  2806.      }
  2807.  
  2808.      # make sure we have something to send
  2809.      if {$match == ""} {
  2810.        regexp -- {class="displayingSummary">(.+?)</div>} $html - reply
  2811.        return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  2812.      }
  2813.      if {$incith::google::bold_descriptions != 0} {
  2814.        regsub -all -- "(<mark>|</mark>)" $output "\002" output
  2815.      } else { regsub -all -- "(<mark>|</mark>)" $output "" output }
  2816.      return $output
  2817.    }
  2818.  
  2819.    # trans
  2820.    # google translation -(www.google.com\translate_t?)
  2821.    # -speechless supplied
  2822.    #
  2823.    proc trans {input where} {
  2824.      global incithcharset
  2825.      ; set results 0 ; set output ""; set match "" ; set titem ""
  2826.      if {[regsub -nocase -all -- $incith::google::trans_input_t $input "" input]} { set y 0 }
  2827.      if {[regsub -nocase -all -- $incith::google::trans_output_t $input "" input]} { set z 0 }
  2828.      # split up stuff
  2829.      regexp -nocase -- {^(.+?)@(.+?)\s(.+?)$} $input - link desc titem
  2830.      # fetch the html
  2831.      set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3"
  2832.      if {$::incith::google::trans_input > 0} {
  2833.        set http [::http::config -useragent $ua -urlencoding "utf-8"]
  2834.      } else {
  2835.        set http [::http::config -useragent $ua -urlencoding ""]
  2836.      }
  2837.      set url "http://translate.google.com/translate_t?"
  2838.      if {$::incith::google::trans_input > 0} {
  2839.        if {![info exists y]} {
  2840.          set ie "&ie=utf-8"
  2841.        } else {
  2842.          set ie ""
  2843.        }
  2844.      } else {
  2845.        if {![info exists y]} {
  2846.          set ie ""
  2847.        } else {
  2848.          set ie "&ie=utf-8"
  2849.        }
  2850.      }
  2851.      if {$::incith::google::trans_output > 0} {
  2852.        if {![info exists z]} {
  2853.          set oe "&oe=utf-8"
  2854.        } else {
  2855.          set oe ""
  2856.        }
  2857.      } else {
  2858.        if {![info exists z]} {
  2859.          set oe ""
  2860.        } else {
  2861.          set oe "&oe=utf-8"
  2862.        }
  2863.      }
  2864.      if {![info exists y]} {
  2865.        set query "text=[urlencode $titem 0 "utf-8"]&sl=${link}&tl=${desc}$ie$oe"
  2866.      } else {
  2867.        set query "text=[urlencode $titem 0]&sl=${link}&tl=${desc}$ie$oe"
  2868.      }
  2869.     catch {set http [::http::geturl "$url" -query $query -headers $::incith_hdr -timeout [expr 1000 * 10]]} error
  2870.  
  2871.      # CHECK CHECK
  2872.      upvar #0 $http state
  2873.      set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  2874.      if {$incith::google::debug > 0} {
  2875.        putserv "privmsg $incith::google::debugnick :\002url:\002 $url$query \002\037charset:\002\037 [string map -nocase {"iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $incithcharset]"
  2876.      }
  2877.     if {[string match -nocase "*couldn't open socket*" $error]} {
  2878.         return "${::incith::google::error_modes}Socket Error accessing '${url}' .. Does it exist?${::incith::google::error_demodes}"
  2879.     }
  2880.     if { [::http::status $http] == "timeout" } {
  2881.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  2882.     }
  2883.      set html [ungzip [::http::data $http] $state(meta)]
  2884.      if {[info exists z]} { set html [incithencode $html] }
  2885.      ::http::cleanup $http
  2886.  
  2887.      regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  2888.      regsub -all -nocase {<font.+?>} $html "" html
  2889.      regsub -all -nocase {</font>} $html "" html
  2890.      regsub -all -nocase {<span.*?>} $html "" html
  2891.      regsub -all -nocase {</span>} $html "" html
  2892.      regsub -all -nocase {<input.+?>} $html "" html
  2893.      regsub -all -nocase {(?:<i>|</i>)} $html "" html
  2894.      regsub -all -nocase {<i style.*?>} $html "" html
  2895.      regsub -all "\t" $html " " html
  2896.      regsub -all "\n" $html " " html
  2897.      regsub -all "\r" $html " " html
  2898.      regsub -all "\v" $html " " html
  2899.      regsub -all "</li>" $html ". " html
  2900.      regsub -all ";;>" $html "" html
  2901.      # make sure everything is lowercase.
  2902.      # make sure everything is lowercase.
  2903.      set desc [string tolower $desc]
  2904.      set link [string tolower $link]
  2905.      if {![regexp -- {<h3 id=headingtext.*?>(.+?)</h3>} $html {} detect]} {set detect ""} { regsub -all {<.*?>} $detect "" detect}
  2906.      if {[regexp -- {</h3>.*?</object></div>(.+?)</div>} $html - match]} { regsub -all {<.*?>} $match "" match }
  2907.      if {[string length $match]} {
  2908.        put_output $where "${::incith::google::total_modes}Google\:$::incith::google::total_demodes$::incith::google::desc_modes \(${link}\-\>${desc}\)\ [descdecode $detect]"
  2909.        put_output $where [descdecode [descdecode ${match}]]
  2910.      } else {
  2911.        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"
  2912.      }
  2913.    }
  2914.  
  2915.    # MININOVA TORRENT HUNT
  2916.    # fetches torrent links from mininova. (mininova.com)
  2917.    # -speechless supplied
  2918.    #
  2919.    proc mininova {input} {
  2920.  
  2921.      ; set results 0 ; set output ""; set match "" ; set ebcSP "" ; set match2 ""
  2922.  
  2923.      #regsub -all {-} $input { } input
  2924.      # fetch the html
  2925.      set html [fetch_html $input 51]
  2926.  
  2927.      # give results an output header with result tally.
  2928.      regexp -- {<h1>(?!No).*?\((.+?)\s(.+?)\)} $html - match match2
  2929.      # format output according to variables.
  2930.      if {$incith::google::total_results != 0} {
  2931.        set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $match2]]${::incith::google::total_demodes}${incith::google::seperator}"
  2932.        if {$incith::google::bold_descriptions == 0} {
  2933.          regsub -all -- "\002" $output {} output
  2934.        }
  2935.      }
  2936.      regsub {<tr.*?>(.+?)</tr>} $html "" html
  2937.  
  2938.      # parse the html
  2939.      while {$results < $incith::google::mininova_results && $match != ""} {
  2940.        # this could break any second, its cumbersome and long..i know, but for now it works.
  2941.        regexp -nocase {<tr.*?>(.+?)</tr>} $html - htm
  2942.        regsub {<tr.*?>(.+?)</tr>} $html "" html
  2943.        regexp -nocase {<td>(.+?)</td><td><a href="/cat.+?>(.+?)</a>.+?<a href="/get/(.*?)".+?">.+?<a href="/tor.+?">(.+?)</a>} $htm - ebcU ebcI ebcBid ebcPR
  2944.        regexp -nocase {<td align="right">(.+?)</td><td align="right">(.+?)</td><td align="right">(.+?)</td>} $htm - ebcShpNew ebcTim ebcCheck
  2945.        regexp -nocase {title="Tracker URL: (.+?)"} $htm - ebcSP
  2946.        if {$ebcSP != ""} {
  2947.          set ebcSP "\037${ebcSP}\037 "
  2948.        }
  2949.        # keep torrent name from becoming too lengthy
  2950.        if {[info exists ebcPR]} {
  2951.          set ebcPR [string range $ebcPR 0 [expr $incith::google::description_length - 1]]
  2952.          set ebcPR [string trim $ebcPR]
  2953.        }
  2954.  
  2955.        # check results are more than 0, return or stop looping, depending
  2956.        if {$match < 1 } {
  2957.          if {$results == 0} {
  2958.            regexp -nocase {<h1>(.+?)</h1>} $html - reply
  2959.            if {![regexp -nocase {</h1><p>(.+?)</p>} $html - reply2]} { set reply2 "" } {
  2960.              if {![string match *Didn't* $reply2]} { regsub -all -- {<(.+?)>} $reply2 "" reply2 ; set reply2 ". $reply2" } { set reply2 "" }
  2961.             }
  2962.             regsub -all -- {<(.+?)>} $reply "" reply
  2963.             return "$::incith::google::desc_modes$reply$reply2$::incith::google::desc_demodes"
  2964.           } else {
  2965.             break
  2966.           }
  2967.         }
  2968.  
  2969.         # make the link valid because we were only given a partial href result, not a full url
  2970.         set link "http://mininova.org/get/${ebcBid}"
  2971.  
  2972.         # prevent duplicate results is mostly useless here, but will at least
  2973.         # ensure that we don't get the exact same article.
  2974.         if {[string match "*$link*" $output] == 1} {
  2975.           break
  2976.         }
  2977.  
  2978.         # fix up our variables so the output looks purdy.
  2979.         set desc "${ebcU}/${ebcI} ${ebcSP}\002${ebcPR}\002 (${ebcShpNew}, ${ebcTim}s, ${ebcCheck}p)"
  2980.  
  2981.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  2982.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  2983.  
  2984.         # add the search result
  2985.         if {$incith::google::link_only == 1} {
  2986.           append output "${link}${incith::google::seperator}"
  2987.         } else {
  2988.           append output "$desc$::incith::google::break${link}${incith::google::seperator}"
  2989.         }
  2990.  
  2991.         # increase the results, clear the variables for the next loop just in case
  2992.         unset link ; set ebcCheck "" ; set ebcU "" ; set ebcSP ""
  2993.         incr results
  2994.       }
  2995.  
  2996.       # make sure we have something to send
  2997.       if {$match == ""} {
  2998.         regexp -nocase {<h1>(.+?)</h1>} $html - reply
  2999.         if {![regexp -nocase {</h1><p>(.+?)</p>} $html - reply2]} { set reply2 "" } {
  3000.           if {![string match *Didn't* $reply2]} { regsub -all -- {<(.+?)>} $reply2 "" reply2 ; set reply2 ". $reply2" } { set reply2 "" }
  3001.        }
  3002.        regsub -all -- {<(.+?)>} $reply "" reply
  3003.        return "$::incith::google::desc_modes$reply$reply2$::incith::google::desc_demodes"
  3004.      }
  3005.  
  3006.      regsub -all -- " " $input "+" input
  3007.      append output "www.mininova.org/search/${input}/seeds"
  3008.      #append output "www.mininova.org/search/?search=${input}"
  3009.      return $output
  3010.    }
  3011.  
  3012.    # DAILYMOTION
  3013.    # fetches links to video with search data in it (dailymotion.com)
  3014.    # -speechless supplied
  3015.    #
  3016.    proc dailymotion {input} {
  3017.  
  3018.      ; set results 0 ; set output "" ; set titem ""
  3019.  
  3020.      # this isn't global, so we need to keep ctry (country) here
  3021.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy
  3022.       if {$titem == ""} {
  3023.         set titem "${incith::google::daily_country}"
  3024.       }
  3025.  
  3026.       # fetch the html
  3027.       set html [fetch_html $input 14]
  3028.  
  3029.       # user input causing errors?
  3030.     if {[string match -nocase "*socketerrorabort*" $html]} {
  3031.             regsub {(.+?)\|} $html {} html
  3032.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  3033.     }
  3034.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  3035.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  3036.     }
  3037.  
  3038.       if {[regexp -- {<div class="dmco_text foreground2">(.*?)</div>} $html - nope]} {
  3039.         regsub -all -- {</a>} $nope "." nope
  3040.         regsub -all -- {<br/>} $nope " " nope
  3041.         regsub -all -- {<.*?>} $nope "" nope
  3042.         set reply "${::incith::google::desc_modes}$nope$::incith::google::desc_demodes"
  3043.         return $reply
  3044.       }
  3045.  
  3046.       set output "DailyMotion${incith::google::seperator}"
  3047.       if {$incith::google::bold_descriptions != 0} {
  3048.         set output "$::incith::google::total_modes\002DailyMotion\002$::incith::google::total_demodes${incith::google::seperator}"
  3049.       }
  3050.       # parse the html
  3051.       while {$results < $incith::google::daily_results} {
  3052.         # somewhat extenuated regexp due to allowing that there might be an image next to the title
  3053.         regexp -nocase -- {<div class="dmco_text duration">(.*?)<.*?<a class=.+?href=.*?/video/(.*?)_.*?">(.*?)<.*?<div class="dmpi_video_description foreground.*?>.*?<div>(.*?)<} $html - snatch cid desc vote
  3054.         regsub -nocase -- {<div class="dmco_text duration">.*?<h4 class="dmco_title.*?>.*?<a class=.+?href=.*?/video/.+?_.*?">.*?div class="dmco_date">(.*?)<} $html "" html
  3055.  
  3056.         # if there's no desc, return or stop looping, depending
  3057.         if {[info exists desc] == 0} {
  3058.           if {$results == 0} {
  3059.             set reply "Sorry, no search results were found."
  3060.             return "${::incith::google::desc_modes}$reply$::incith::google::desc_demodes"
  3061.           } else {
  3062.             break
  3063.           }
  3064.         }
  3065.         set desc [string trim [string range $desc 0 [expr $incith::google::description_length - 1]]]
  3066.         set vote [string trim [string range $vote 0 [expr $incith::google::description_length - 1]]]
  3067.         set desc "${desc} (${snatch}) ([string trim $vote])"
  3068.  
  3069.         # make the link valid because we were only given a partial href result, not a full url
  3070.         set link "http://www.dailymotion.com/${titem}/video/${cid}"
  3071.  
  3072.         # prevent duplicate results is mostly useless here, but will at least
  3073.         #   ensure that we don't get the exact same article.
  3074.         if {[string match "*$link*" $output] == 1} {
  3075.          break
  3076.         }
  3077.  
  3078.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  3079.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  3080.  
  3081.         # add the search result
  3082.         if {$incith::google::link_only == 1} {
  3083.           append output "${link}${incith::google::seperator}"
  3084.         } else {
  3085.           append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  3086.         }
  3087.  
  3088.         # increase the results, clear the variables for the next loop just in case
  3089.         unset link; unset desc ; unset cid
  3090.         incr results
  3091.       }
  3092.  
  3093.       # make sure we have something to send
  3094.       if {[info exists output] == 0} {
  3095.         set reply "Sorry, no search results were found."
  3096.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  3097.       }
  3098.       return $output
  3099.     }
  3100.  
  3101.     # GAMEFAQS
  3102.     # fetches upcoming game list variable by system and region (gamefaqs.com)
  3103.     # this is far better than any gamefaqs procedure you've seen before, this is looooong, but very simple
  3104.     # in it's approach. I learned alot coding it.
  3105.     # -speechless supplied
  3106.     #
  3107.     proc gamefaqs {system region} {
  3108.  
  3109.       ; set results 0 ; set output "" ; set html "" ; set match 0 ; set game "" ; set date ""
  3110.  
  3111.       # strip excessive spaces from region and system desired.
  3112.       regsub -all " " $system "" system
  3113.       regsub -all " " $region "" region
  3114.  
  3115.       # this is where most of the work is done
  3116.       # parsing systems and regions to create an output header
  3117.       # and cut the html down to the specified region
  3118.  
  3119.       if {[string match -nocase "nds" $system] == 1} {
  3120.         if {[string match -nocase "usa" $region] == 1} {
  3121.           set html [fetch_html "/region-1" 15]
  3122.           set output "\002NDS North America (USA)\002"
  3123.         }
  3124.         if {[string match -nocase "jap" $region] == 1} {
  3125.           set html [fetch_html "/region-2" 15]
  3126.           set output "\002NDS Asia (JAPAN)\002"        
  3127.         }
  3128.         if {[string match -nocase "eur" $region] == 1} {
  3129.           set html [fetch_html "/region-3" 15]
  3130.           set output "\002NDS Europe (UK)\002"
  3131.         }
  3132.         if {[string match -nocase "aus" $region] == 1} {
  3133.           set html [fetch_html "/region-4" 15]
  3134.           set output "\002NDS Australia (AUS)\002"
  3135.         }
  3136.       }
  3137.  
  3138.       if {[string match -nocase "3ds" $system] == 1} {
  3139.         if {[string match -nocase "usa" $region] == 1} {
  3140.           set html [fetch_html "/region-1" 56]
  3141.           set output "\0023DS North America (USA)\002"
  3142.         }
  3143.         if {[string match -nocase "jap" $region] == 1} {
  3144.           set html [fetch_html "/region-2" 56]
  3145.           set output "\0023DS Asia (JAPAN)\002"        
  3146.         }
  3147.         if {[string match -nocase "eur" $region] == 1} {
  3148.           set html [fetch_html "/region-3" 56]
  3149.           set output "\0023DS Europe (UK)\002"
  3150.         }
  3151.         if {[string match -nocase "aus" $region] == 1} {
  3152.           set html [fetch_html "/region-4" 56]
  3153.           set output "\002NDS Australia (AUS)\002"
  3154.         }
  3155.       }
  3156.  
  3157.       if {[string match -nocase "iphone" $system] == 1} {
  3158.         if {[string match -nocase "usa" $region] == 1} {
  3159.           set html [fetch_html "/region-1" 16]  
  3160.           set output "\002iPhone North America (USA)\002"
  3161.         }
  3162.         if {[string match -nocase "jap" $region] == 1} {
  3163.           set html [fetch_html "/region-2" 16]
  3164.           set output "\002iPhone Asia (JAPAN)\002"
  3165.         }
  3166.         if {[string match -nocase "eur" $region] == 1} {
  3167.           set html [fetch_html "/region-3" 16]
  3168.           set output "\002iPhone Europe (UK)\002"
  3169.         }
  3170.         if {[string match -nocase "aus" $region] == 1} {
  3171.           set html [fetch_html "/region-4" 16]
  3172.           set output "\002iPhone Australia (AUS)\002"
  3173.         }
  3174.       }
  3175.  
  3176.       if {[string match -nocase "psp" $system] == 1} {
  3177.         if {[string match -nocase "usa" $region] == 1} {
  3178.           set html [fetch_html "/region-1" 17]
  3179.           set output "\002PSP North America (USA)\002"
  3180.         }
  3181.         if {[string match -nocase "jap" $region] == 1} {
  3182.           set html [fetch_html "/region-2" 17]
  3183.           set output "\002PSP Asia (JAPAN)\002"
  3184.         }
  3185.         if {[string match -nocase "eur" $region] == 1} {
  3186.           set html [fetch_html "/region-3" 17]
  3187.           set output "\002PSP Europe (UK)\002"
  3188.         }
  3189.         if {[string match -nocase "aus" $region] == 1} {
  3190.           set html [fetch_html "/region-4" 17]
  3191.           set output "\002PSP Australia (AUS)\002"
  3192.         }
  3193.       }
  3194.  
  3195.       if {[string match -nocase "x360" $system] == 1} {
  3196.         if {[string match -nocase "usa" $region] == 1} {
  3197.           set html [fetch_html "/region-1" 18]
  3198.           set output "\002XBOX360 North America (USA)\002"
  3199.         }
  3200.         if {[string match -nocase "jap" $region] == 1} {
  3201.           set html [fetch_html "/region-2" 18]
  3202.           set output "\002XBOX360 Asia (JAPAN)\002"
  3203.         }
  3204.         if {[string match -nocase "eur" $region] == 1} {
  3205.           set html [fetch_html "/region-3" 18]    
  3206.           set output "\002XBOX360 Europe (UK)\002"
  3207.         }
  3208.         if {[string match -nocase "aus" $region] == 1} {
  3209.           set html [fetch_html "/region-4" 18]
  3210.           set output "\002XBOX360 Australia (AUS)\002"
  3211.         }
  3212.       }
  3213.  
  3214.       if {[string match -nocase "xbox" $system] == 1} {
  3215.         if {[string match -nocase "usa" $region] == 1} {
  3216.           set html [fetch_html "/region-1" 19]
  3217.           set output "\002XBOX North America (USA)\002"
  3218.         }
  3219.         if {[string match -nocase "jap" $region] == 1} {
  3220.           set html [fetch_html "/region-2" 19]
  3221.           set output "\002XBOX Asia (JAPAN)\002"
  3222.         }
  3223.         if {[string match -nocase "eur" $region] == 1} {
  3224.           set html [fetch_html "/region-3" 19]  
  3225.           set output "\002XBOX Europe (UK)\002"
  3226.         }
  3227.         if {[string match -nocase "aus" $region] == 1} {
  3228.           set html [fetch_html "/region-4" 19]
  3229.           set output "\002XBOX Australia (AUS)\002"
  3230.         }
  3231.       }
  3232.  
  3233.       if {[string match -nocase "gc" $system] == 1} {
  3234.         if {[string match -nocase "usa" $region] == 1} {
  3235.           set html [fetch_html "/region-1" 20]
  3236.           set output "\002GAMECUBE North America (USA)\002"
  3237.         }
  3238.         if {[string match -nocase "jap" $region] == 1} {
  3239.           set html [fetch_html "/region-2" 20]
  3240.           set output "\002GAMECUBE Asia (JAPAN)\002"
  3241.         }
  3242.         if {[string match -nocase "eur" $region] == 1} {
  3243.           set html [fetch_html "/region-3" 20]
  3244.           set output "\002GAMECUBE Europe (UK)\002"
  3245.         }
  3246.         if {[string match -nocase "aus" $region] == 1} {
  3247.           set html [fetch_html "/region-4" 20]
  3248.           set output "\002GAMECUBE Australia (AUS)\002"
  3249.         }
  3250.       }
  3251.  
  3252.       if {[string match -nocase "ps2" $system] == 1} {
  3253.         if {[string match -nocase "usa" $region] == 1} {
  3254.           set html [fetch_html "/region-1" 21]
  3255.           set output "\002PS2 North America (USA)\002"
  3256.         }
  3257.         if {[string match -nocase "jap" $region] == 1} {
  3258.           set html [fetch_html "/region-2" 21]
  3259.           set output "\002PS2 Asia (JAPAN)\002"
  3260.         }
  3261.         if {[string match -nocase "eur" $region] == 1} {
  3262.           set html [fetch_html "/region-3" 21]
  3263.           set output "\002PS2 Europe (UK)\002"
  3264.         }
  3265.         if {[string match -nocase "aus" $region] == 1} {
  3266.           set html [fetch_html "/region-4" 21]
  3267.           set output "\002PS2 Australia (AUS)\002"
  3268.         }
  3269.       }
  3270.  
  3271.       if {[string match -nocase "pc" $system] == 1} {
  3272.         if {[string match -nocase "usa" $region] == 1} {
  3273.           set html [fetch_html "/region-1" 22]
  3274.           set output "\002PC North America (USA)\002"
  3275.         }
  3276.         if {[string match -nocase "jap" $region] == 1} {
  3277.           set html [fetch_html "/region-2" 22]
  3278.           set output "\002PC Asia (JAPAN)\002"
  3279.         }
  3280.         if {[string match -nocase "eur" $region] == 1} {
  3281.           set html [fetch_html "/region-3" 22]
  3282.           set output "\002PC Europe (UK)\002"
  3283.         }
  3284.         if {[string match -nocase "aus" $region] == 1} {
  3285.           set html [fetch_html "/region-4" 22]
  3286.           set output "\002PC Australia (AUS)\002"
  3287.         }
  3288.       }
  3289.  
  3290.       if {[string match -nocase "ps3" $system] == 1} {
  3291.         if {[string match -nocase "usa" $region] == 1} {
  3292.           set html [fetch_html "/region-1" 23]
  3293.           set output "\002PS3 North America (USA)\002"
  3294.         }
  3295.         if {[string match -nocase "jap" $region] == 1} {
  3296.           set html [fetch_html "/region-2" 23]
  3297.           set output "\002PS3 Asia (JAPAN)\002"
  3298.         }
  3299.         if {[string match -nocase "eur" $region] == 1} {
  3300.           set html [fetch_html "/region-3" 23]
  3301.           set output "\002PS3 Europe (UK)\002"
  3302.         }
  3303.         if {[string match -nocase "aus" $region] == 1} {
  3304.           set html [fetch_html "/region-4" 23]
  3305.           set output "\002PS3 Australia (AUS)\002"
  3306.         }
  3307.       }
  3308.  
  3309.       if {[string match -nocase "wii" $system] == 1} {
  3310.         if {[string match -nocase "usa" $region] == 1} {
  3311.           set html [fetch_html "/region-1" 28]
  3312.           set output "\002Wii North America (USA)\002"
  3313.         }
  3314.         if {[string match -nocase "jap" $region] == 1} {
  3315.           set html [fetch_html "/region-2" 28]
  3316.           set output "\002Wii Asia (JAPAN)\002"
  3317.         }
  3318.         if {[string match -nocase "eur" $region] == 1} {
  3319.           set html [fetch_html "/region-3" 28]
  3320.           set output "\002Wii Europe (UK)\002"
  3321.         }
  3322.         if {[string match -nocase "aus" $region] == 1} {
  3323.           set html [fetch_html "/region-4" 28]
  3324.           set output "\002Wii Australia (AUS)\002"
  3325.         }
  3326.       }
  3327.  
  3328.       if {[string match -nocase "dc" $system] == 1} {
  3329.         if {[string match -nocase "jap" $region] == 1} {
  3330.           set html [fetch_html "/region-2" 29]
  3331.           set output "\002Dreamcast Asia (JAPAN)\002"
  3332.         }
  3333.       }
  3334.  
  3335.       if {[string match -nocase "mac" $system] == 1} {
  3336.         if {[string match -nocase "usa" $region] == 1} {
  3337.           set html [fetch_html "/region-1" 59]
  3338.           set output "\002MAC America (USA)\002"
  3339.         }
  3340.         if {[string match -nocase "jap" $region] == 1} {
  3341.           set html [fetch_html "/region-2" 59]
  3342.           set output "\002MAC Asia (JAPAN)\002"        
  3343.         }
  3344.         if {[string match -nocase "eur" $region] == 1} {
  3345.           set html [fetch_html "/region-3" 59]
  3346.           set output "\002MAC Europe (UK)\002"
  3347.         }
  3348.         if {[string match -nocase "aus" $region] == 1} {
  3349.           set html [fetch_html "/region-4" 59]
  3350.           set output "\002MAC Australia (AUS)\002"
  3351.         }
  3352.       }
  3353.  
  3354.       if {[string length $output]} {
  3355.         set output "$::incith::google::total_modes$output$::incith::google::total_demodes"
  3356.       }
  3357.       # remove the bold if it isn't desired.
  3358.       if {$incith::google::bold_descriptions == 0} {
  3359.         regsub -all -- "\002" $output {} output
  3360.       }
  3361.  
  3362.       # parse for results and loop until desired amount of results
  3363.       # is attempted to be reached if possible.
  3364.       while {$results < $incith::google::gamefaq_results && $output != ""} {
  3365.  
  3366.         # grab date and game title and clear future html of it for looping
  3367.         regexp -nocase {<tr.*?td>(.*?)<.+?td>.*?<td><a.+?href.+?title.+?"(.+?)">.+?<.+?a><.+?td>} $html {} date game
  3368.         regsub {<tr.*?td>(.+?)<.+?a><.+?td>} $html "" html
  3369.  
  3370.         # add the search result
  3371.         # if there is a date, add date in bold and game to $output
  3372.         if {[string len $date] > 3} {
  3373.           if {$incith::google::bold_descriptions == 0} {
  3374.             append output "${incith::google::seperator}$::incith::google::desc_modes${date} ${game}$::incith::google::desc_demodes"
  3375.           } else {
  3376.             append output "${incith::google::seperator}$::incith::google::desc_modes\002${date}\002 ${game}$::incith::google::desc_demodes"
  3377.           }
  3378.         # otherwise just add name of game
  3379.         } elseif {[string len $game] > 1}  {
  3380.           append output "${incith::google::split_char}$::incith::google::desc_modes${game}$::incith::google::desc_demodes"
  3381.           #append output ",${game}"
  3382.         }
  3383.  
  3384.         # increase the results, clear the variables for the next loop just in case
  3385.         incr results
  3386.         ; set date "" ; set game ""    
  3387.       }
  3388.  
  3389.       # if we have nothing to send, we have no results :(
  3390.       if {$output == ""} {
  3391.         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"
  3392.       }
  3393.       return $output
  3394.     }
  3395.  
  3396.     # BLOGSEARCH
  3397.     # fetches the news from blogsearch.google.
  3398.     # -madwoota supplied (uses news.google engine), speechless updated
  3399.     #
  3400.     proc blog {input} {
  3401.       ; set results 0 ; set output "" ; set match "" ; set titem "" ; set no_search "" ; set did_you_mean ""
  3402.  
  3403.       # fetch the html
  3404.       set html [fetch_html $input 24]
  3405.  
  3406.       # user input causing errors?
  3407.     if {[string match -nocase "*socketerrorabort*" $html]} {
  3408.             regsub {(.+?)\|} $html {} html
  3409.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  3410.     }
  3411.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  3412.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  3413.     }
  3414.       # strip out 'did you mean?' first
  3415.       # what do we call 'no search results in any language?'
  3416.       regexp -- {<p></p></div></div><div id=f>(.+?)<br><br>} $html - no_search
  3417.       if {$no_search != ""} {
  3418.         regsub -- {</a>} $no_search "? " no_search
  3419.         regsub -all -- {<(.+?)>} $no_search { } no_search
  3420.         while {[string match "*  *" $no_search]} {
  3421.           regsub -all -- {  } $no_search " " no_search
  3422.         }
  3423.         set no_search [string trim $no_search]
  3424.       }
  3425.  
  3426.       # give results an output header with result tally.
  3427.       regexp -- {</td><td align=right class=rsb>(.+?)\s\002(.+?)\(\002} $html - titem match
  3428.       if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} {
  3429.          set match "Google"
  3430.          set titem ""
  3431.       }
  3432.       regsub -all -- {<(.+?)>} $match {} match
  3433.       # format output according to variables.
  3434.       if {$incith::google::total_results != 0 && $match > 0} {
  3435.         set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  3436.         if {$incith::google::bold_descriptions == 0} {
  3437.           regsub -all -- "\002" $output {} output
  3438.         }
  3439.       }
  3440.  
  3441.       # parse the html
  3442.       while {$results < $incith::google::news_results} {
  3443.         # somewhat extenuated regexp due to allowing that there *might* be
  3444.         # an image next to the story
  3445.         regexp -- {</p><a href="(.+?)".+?id=.+?">(.+?)</a>.+?<td class=j>(.+?)<br>} $html {} link desc time
  3446.        regsub -- {</p><a href=(.+?)</a>} $html {} html
  3447.  
  3448.        # if there's no desc, return or stop looping, depending
  3449.        if {[info exists desc] == 0} {
  3450.          if {$results == 0} {
  3451.            set reply $no_search
  3452.            return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  3453.          } else {
  3454.            break
  3455.          }
  3456.        }
  3457.        # clean up desc
  3458.        if {[info exists desc] == 1 && $incith::google::description_length > 0} {
  3459.          set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  3460.          set desc "[descdecode [string trim $desc]] ([descdecode [string trim $time]])"
  3461.        }
  3462.        # prevent duplicate results is mostly useless here, but will at least
  3463.        # ensure that we don't get the exact same article.
  3464.        if {[string match "*$link*" $output] == 1} {
  3465.          break
  3466.        }
  3467.  
  3468.        if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  3469.        if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  3470.  
  3471.        # add the search result
  3472.        if {$incith::google::link_only == 1} {
  3473.          append output "${link}${incith::google::seperator}"
  3474.        } else {
  3475.          append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  3476.        }
  3477.  
  3478.        # increase the results, clear the variables for the next loop just in case
  3479.        unset link; unset desc
  3480.        incr results
  3481.      }
  3482.  
  3483.      # make sure we have something to send
  3484.      if {$match == ""} {
  3485.        set reply $no_search
  3486.        return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  3487.      }
  3488.      return $output
  3489.    }
  3490.  
  3491.    # SCHOLAR SEARCH
  3492.    # fetches the news from scholar.google.
  3493.    # -madwoota supplied (uses news.google engine), speechless updated
  3494.    #
  3495.    proc scholar {input} {
  3496.      ; set results 0 ; set output "" ; set match "" ; set titem "" ; set no_search "" ; set did_you_mean "" ; set titen ""
  3497.  
  3498.      # this isn't global, so we need to keep ctry (country) here
  3499.      regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titen dummy
  3500.      if {$titen == ""} {
  3501.        set titen "${incith::google::google_country}"
  3502.      }
  3503.  
  3504.      # fetch the html
  3505.      set html [fetch_html $input 10]
  3506.  
  3507.      # user input causing errors?
  3508.     if {[string match -nocase "*socketerrorabort*" $html]} {
  3509.            regsub {(.+?)\|} $html {} html
  3510.            return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  3511.     }
  3512.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  3513.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  3514.     }
  3515.      # strip out 'did you mean?' first
  3516.      # what do we call 'no search results in any language?'
  3517.      if {![regexp -- {</script><p>(.+?)\.<br>} $html - no_search]} {
  3518.        regexp -- {</script><br><br>(.+?)<br><br>} $html - no_search
  3519.      }
  3520.      if {$no_search != ""} {
  3521.        regsub -- {</a>} $no_search "? " no_search
  3522.        regsub -all -- {<(.*?)>} $no_search { } no_search
  3523.        while {[string match "*  *" $no_search]} {
  3524.          regsub -all -- {  } $no_search " " no_search
  3525.        }
  3526.        set no_search [string trim $no_search]
  3527.      }
  3528.  
  3529.      # give results an output header with result tally.
  3530.      regexp -- {align=right nowrap>(.+?)\s\002(.+?)\(\002} $html - titem match
  3531.      if {![regexp -- {1\002\s-\s\002.+?\002.+?\002(.+?)\002} $match - match]} {
  3532.         set match "Google"
  3533.         set titem ""
  3534.      }
  3535.      regsub -all -- {<(.+?)>} $match {} match
  3536.      # format output according to variables.
  3537.      if {$incith::google::total_results != 0 && $match > 0} {
  3538.        set output "${::incith::google::total_modes}\002[string trim ${match}]\002 [descdecode [string trim $titem]]${::incith::google::total_demodes}${incith::google::seperator}"
  3539.        if {$incith::google::bold_descriptions == 0} {
  3540.          regsub -all -- "\002" $output {} output
  3541.        }
  3542.      }
  3543.  
  3544.      # parse the html
  3545.      while {$results < $incith::google::news_results} {
  3546.        # somewhat extenuated regexp due to allowing that there *might* be
  3547.        # an image next to the story
  3548.        if {[regexp -- {<p class=g><h3 class="r">(.+?)   } $html - ps]} {
  3549.          regsub -- {<p class=g><h3 class="r">(.+?)   } $html {} html
  3550.          if {![regexp -- {<a href="(.+?)" onmousedown} $ps - link]} { set link "none" } { regsub {<a href="(.+?)" onmousedown.*?>} $ps "" ps }
  3551.          if {[regexp -- {(.+?)</h3>.*?<br>(.*?)<br>} $ps - desc time]} { regsub {</a>} $desc "" desc }
  3552.        }
  3553.  
  3554.        # if there's no desc, return or stop looping, depending
  3555.        if {[info exists desc] == 0} {
  3556.          if {$results == 0} {
  3557.            set reply $no_search
  3558.            return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  3559.          } else {
  3560.            break
  3561.          }
  3562.        }
  3563.        # clean up desc
  3564.        if {[info exists desc] == 1 && $incith::google::description_length > 0} {
  3565.          set desc [string range $desc 0 [expr $incith::google::description_length - 1]]
  3566.          set desc "[string trim $desc] ([string trim $time])"
  3567.        }
  3568.        # prevent duplicate results is mostly useless here, but will at least
  3569.        # ensure that we don't get the exact same article.
  3570.        if {[string match "*$link*" $output] == 1} {
  3571.          break
  3572.        }
  3573.  
  3574.        if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  3575.        if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  3576.  
  3577.        # add the search result
  3578.        if {$incith::google::link_only == 1} {
  3579.          append output "${link}${incith::google::seperator}"
  3580.        } else {
  3581.          if {![string equal $link "none"]} {
  3582.            if {![string match "http*" $link]} { set link "http://scholar.google.${titen}/$link" }
  3583.            append output "[descdecode $desc]$::incith::google::break${link}${incith::google::seperator}"
  3584.          } else {
  3585.            append output "[descdecode $desc]${incith::google::seperator}"
  3586.          }
  3587.        }
  3588.  
  3589.        # increase the results, clear the variables for the next loop just in case
  3590.        unset link; unset desc
  3591.        incr results
  3592.      }
  3593.  
  3594.      # make sure we have something to send
  3595.      if {$match == ""} {
  3596.        set reply $no_search
  3597.        return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  3598.      }
  3599.      return $output
  3600.    }
  3601.  
  3602.  
  3603.    # WIKI
  3604.    # fetches wiki info from *.wikipedia.org
  3605.    # -speechless supplied
  3606.    #
  3607.    proc wiki {input} {
  3608.      global incithcharset
  3609.      ; set output "" ; set ded "" ; set match "" ; set redir "" ; set country "" ; set dec ""
  3610.      ; set query "" ; set titem "" ; set ebcPR "" ; set results "" ; set tresult "" ; set red 0
  3611.      ; set subtag "" ; set region "" ; set regional ""
  3612.  
  3613.      # make it so people can search their country
  3614.      regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input
  3615.      if {$country == ""} {
  3616.        set country "${incith::google::wiki_country}"
  3617.      }
  3618.      regexp -nocase -- {(.*)\@(.*)} $country - country region
  3619.  
  3620.      # this is my input encoding hack, this will convert input before it goes
  3621.      # out to be queried.
  3622.      if {$incith::google::encoding_conversion_input > 0 && $region != ""} {
  3623.        set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${region}:*"]] :] 1]
  3624.      } elseif {$incith::google::encoding_conversion_input > 0 && $country != ""} {
  3625.        set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1]
  3626.      } else { set encoding_found "" }
  3627.      if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  3628.        set input [encoding convertfrom $encoding_found $input]
  3629.      }
  3630.      regsub -all -- {_} $input { } input
  3631.      regexp -- {^(.+?)\#(.+?)$} $input - input results
  3632.      regsub -all -- {_} $results { } results
  3633.      set input [urlencode $input 0 "utf-8"]
  3634.      set results [string map {.20 _} [urlencode [string trim $results] 1 "utf-8"]]
  3635.  
  3636. # 1st load of webpage - this is the only part which has error control
  3637. # this is where we load the search page to find an exact match or most relevant.
  3638. # we will also be able to detect bad user input in the form of socket errors.
  3639.  
  3640.      # beware, changing the useragent will result in differently formatted html from Google.
  3641.      set query "http://${country}.wikipedia.org/wiki/index.php?title=Special%3ASearch&search=${input}&fulltext=Search"
  3642.      set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  3643.      set http [::http::config -useragent $ua -urlencoding "utf-8"]
  3644.      # stole this bit from rosc2112 on egghelp forums
  3645.      # borrowed is a better term, all procs eventually need this error handler.
  3646.     catch {set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 5]]} error
  3647.  
  3648.     if {[string match -nocase "*couldn't open socket*" $error]} {
  3649.         return "${::incith::google::error_modes}Socket Error accessing '${country}.wikipedia.org' .. Does it exist?${::incith::google::error_demodes}"
  3650.     }
  3651.     if { [::http::status $http] == "timeout" } {
  3652.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  3653.     }
  3654.  
  3655.      # CHECK CHECK
  3656.      upvar #0 $http state
  3657.      set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  3658.      set html [ungzip [::http::data $http] $state(meta)]
  3659.      set redir [::http::ncode $http]
  3660.      # REDIRECT
  3661.      if {[string match "*${redir}*" "302|301" ]} {
  3662.        foreach {name value} $state(meta) {
  3663.         if {[regexp -nocase ^location$ $name]} {
  3664.           catch {set http [::http::geturl "$value" -query "" -headers $::incith_hdr -timeout [expr 1000 * 10]]} error
  3665.            if { $::incith::google::debug > 0 } { putserv "privmsg $::incith::google::debugnick :\002redirected:\002 $query -> $value" }
  3666.           if {[string match -nocase "*couldn't open socket*" $error]} {
  3667.              return "${::incith::google::error_modes}Socket Error accessing '${country}.wikipedia.org' .. Does it exist?${::incith::google::error_demodes}"
  3668.           }
  3669.           if { [::http::status $http] == "timeout" } {
  3670.           return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  3671.           }
  3672.            upvar #0 $http state
  3673.            set html [ungzip [::http::data $http] $state(meta)]
  3674.            set query $value
  3675.         }
  3676.        }
  3677.      }
  3678.      ::http::cleanup $http
  3679.    
  3680.      # generic pre-parsing
  3681.      regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  3682.      regsub -all -nocase {<font.+?>} $html "" html
  3683.      regsub -all -nocase {</font>} $html "" html
  3684.      regsub -all -nocase {<input.+?>} $html "" html
  3685.      regsub -all -nocase {(?:<i>|</i>)} $html "" html
  3686.      regsub -all "\t" $html " " html
  3687.      regsub -all "\n" $html " " html
  3688.      regsub -all "\r" $html " " html
  3689.      regsub -all "\v" $html " " html
  3690.      regsub -all "</li>" $html ". " html
  3691.      regsub -all ";;>" $html "" html
  3692.      regsub {<div class="floating_object".*?>.*?</div>} $html "" html
  3693.  
  3694.      if {$html == ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 No html to parse.$::incith::google::error_demodes" }
  3695.  
  3696.      # see if our direct result is available and if so, lets take it
  3697.      if {![regexp -- {<div id="contentSub"><p>.*?<a href="(.+?)".*?title} $html - match]} {
  3698.        if {![regexp -- {<div class=.searchresults.><p>*?<a href="(.+?)".*?title} $html - match]} {
  3699.          regexp -- {<div class=.searchresults.><p class="mw-search.*?>.*?<a href="(.+?)".*?title} $html - match
  3700.         }
  3701.       }
  3702.       putserv "privmsg speechles :match $match"
  3703.       if {[string match -nocase "*action=edit*" $match]} { set match "" }
  3704.       # otherwise we only care about top result
  3705.       if {$match == ""} {
  3706.         if {![regexp -- {<li><a href="((?!http).+?)"} $html - match]} {
  3707.           if {![regexp -- {<li style.*?><a href="(.+?)"} $html - match]} {
  3708.             if {![regexp -- {<div class='searchresults'>.*?<a href="(.*?)".*?class="mw-redirect">} $html - match]} {
  3709.               if {[regexp -- {<li><div class='mw-search-result-heading'>(.*?)</div>} $html - slice]} {
  3710.             if {![regexp -- {<span class='searchalttitle'>.*?<a href="(.*?)"} $slice - match]} {
  3711.               regexp -- {<a href="(.*?)"} $slice - match
  3712.                 }
  3713.               }
  3714.             }
  3715.           }
  3716.         }
  3717.       }
  3718.       #if {[string match "http://*" $match]} { set match "" }
  3719.       if {[string match -nocase "*/wiki*" $country]} {
  3720.         regsub -- {/wiki} $country {} country
  3721.       }
  3722.       # DEBUG DEBUG                    
  3723.       set junk [open "ig-debug.txt" w]
  3724.       puts $junk $html
  3725.       close $junk
  3726.  
  3727.       # at this point we can tell if there was any match, so let's not even bother
  3728.       # going further if there wasn't a match, this pulls the 'no search etc' found.
  3729.       # this can be in any language.
  3730.       if {$match == ""} {
  3731.         # these are for 'no search results' or similar message
  3732.         # these can be in any language.
  3733.         if {[regexp -- {<div class='searchresults'>(.+?)</p>} $html - match]} {
  3734.           regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match
  3735.           regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match
  3736.          regsub -all {<div id.*?>} $match "" match
  3737.          regsub -- {</a></div>} $match "?" match
  3738.          regsub -all {</div>} $match "" match
  3739.          regsub -all {\[Index\]} $match "" match
  3740.          regsub -all {<span.*?/span>} $match "" match
  3741.          regsub -all {<script type.*?</script>} $match "" match
  3742.          regsub -all { \(<.*?>\)} $match ". " match
  3743.          if {[string match "*<!--*" $match]} {
  3744.            regexp -- {<li class="normal">.*?</p><p>(.*?)</p>} $html - match
  3745.          }
  3746.        } else {
  3747.          if {[regexp -- {<div id='search results'><p class="mw-search.*?>(.*?)</p>} $html - match]} {
  3748.             regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match
  3749.           }
  3750.         }
  3751.  
  3752.         if {$match == ""} {
  3753.           if {[regexp -nocase -- {<div class='searchresults'>(.*?)<div class="printfooter">} $html - match]} {
  3754.             regsub -all {<p>} $match " " match
  3755.             regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match
  3756.             regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match
  3757.            regsub -all {<div id.*?>} $match "" match
  3758.            regsub -- {</a></div>} $match "?" match
  3759.            regsub -all {</div>} $match "" match
  3760.            regsub -all {\[Index\]} $match "" match
  3761.            regsub -all {<span.*?/span>} $match "" match
  3762.            regsub -all {<script type.*?</script>} $match "" match
  3763.            regsub -all { \(<.*?>\)} $match ". " match
  3764.          }
  3765.        }
  3766.        # this is our last error catch, this can grab the
  3767.        # 'wikimedia cannot search at this time' message
  3768.        # this can be in any language.
  3769.        if {[string len $match] < 3} { regexp -- {<center><b>(.+?)</b>} $html - match }
  3770.        if {$match == ""} {
  3771.          regsub -all -- { } $results {_} results
  3772.          if {$results != ""} { set results "#${results}" }
  3773.           return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${results}$::incith::google::error_demodes"
  3774.         }
  3775.         # might be tags since we allowed any language here we cut them out
  3776.         regsub -all -- {<(.+?)>} $match {} match
  3777.         if {$region == ""} {
  3778.           return "$::incith::google::desc_modes[utf8encodefix $country [descdecode ${match}]]$::incith::google::desc_demodes"
  3779.         } else {
  3780.           return "$::incith::google::desc_modes[utf8encodefix $region [descdecode ${match}]]$::incith::google::desc_demodes"
  3781.         }
  3782.       }
  3783.  
  3784.       # we assume here we found another page to traverse in our search.
  3785.       if {$region != ""} {
  3786.         regsub -- {/wiki/} $match "/$region/" match
  3787.       }
  3788.       if {![string match http://* $match]} { set query "http://${country}.wikipedia.org${match}" } { set query $match }
  3789.  
  3790. # 2nd load of webpage - this has no error checking what-so-ever
  3791. # here is where we pluck the link to the exact match, or the most relevant 'top' link.
  3792. # or in the case of redirects, to other pages, we will handle that here as well.
  3793.  
  3794.       # beware, changing the useragent will result in differently formatted html from Google.
  3795.       set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  3796.       set http [::http::config -useragent $ua -urlencoding "utf-8"]
  3797.       set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 5]]
  3798.       upvar #0 $http state
  3799.       set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  3800.       # this is the output encoding hack.
  3801.       if {$incith::google::encoding_conversion_output > 0} {
  3802.         if {$region != ""} {
  3803.           set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1]
  3804.         } else {
  3805.           set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  3806.         }
  3807.       }
  3808.  
  3809.       set html [ungzip [::http::data $http] $state(meta)]
  3810.       if {$incith::google::debug > 0} {
  3811.         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"
  3812.       }
  3813.       if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  3814.         set ::incithcharset $encoding_found
  3815.         set html [incithencode $html]
  3816.       }
  3817.       ::http::cleanup $http
  3818.       #correct the html, remove shitty tags
  3819.       # generic pre-parsing
  3820.       regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  3821.       regsub -all -nocase {<font.+?>} $html "" html
  3822.       regsub -all -nocase {</font>} $html "" html
  3823.       regsub -all -nocase {<input.+?>} $html "" html
  3824.       regsub -all -nocase {(?:<i>|</i>)} $html "" html
  3825.       regsub -all "\t" $html " " html
  3826.       regsub -all "\n" $html " " html
  3827.       regsub -all "\r" $html " " html
  3828.       regsub -all "\v" $html " " html
  3829.       regsub -all "</li>" $html ". " html
  3830.       regsub -all ";;>" $html "" html
  3831.  
  3832.       if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} {
  3833.         regsub -all -nocase {(?:<b>|</b>)} $html "\002" html
  3834.       }
  3835.       set match ""
  3836.  
  3837.       # are we redirected to another page? if so, let's go there
  3838.       regexp -- {alt="#REDIRECT ".+?<a href="(.+?)" title="} $html - match
  3839.      if {$match != ""} {
  3840.        incr red 1
  3841.        set query "http://${country}.wikipedia.org${match}"
  3842.  
  3843. # 3rd load of webpage - this has no error checking what-so-ever
  3844. # here is our final webpage, this is hopefully what the user was looking for.
  3845.  
  3846.        # beware, changing the useragent will result in differently formatted html from Google.
  3847.        set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  3848.        set http [::http::config -useragent $ua -urlencoding "utf-8"]
  3849.        set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 10]]
  3850.        upvar #0 $http state
  3851.  
  3852.        set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  3853.        # this is the output encoding hack.
  3854.        if {$incith::google::encoding_conversion_output > 0} {
  3855.          if {$region != ""} {
  3856.            set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1]
  3857.          } else {
  3858.            set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  3859.          }
  3860.        } else { set ::incithcharset "" }
  3861.  
  3862.        set html [ungzip [::http::data $http] $state(meta)]
  3863.        if {$incith::google::debug > 0} {
  3864.          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"
  3865.        }
  3866.        if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  3867.          set ::incithcharset $encoding_found
  3868.          set html [incithencode $html]
  3869.        }
  3870.        ::http::cleanup $http
  3871.        #correct the html, remove shitty tags
  3872.        # generic pre-parsing
  3873.        regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  3874.        regsub -all -nocase {<font.+?>} $html "" html
  3875.        regsub -all -nocase {</font>} $html "" html
  3876.        regsub -all -nocase {<input.+?>} $html "" html
  3877.        regsub -all -nocase {(?:<i>|</i>)} $html "" html
  3878.        regsub -all "\t" $html " " html
  3879.        regsub -all "\n" $html " " html
  3880.        regsub -all "\r" $html " " html
  3881.        regsub -all "\v" $html " " html
  3882.        regsub -all "</li>" $html ". " html
  3883.        regsub -all ";;>" $html "" html
  3884.  
  3885.        if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} {
  3886.          regsub -all -nocase {(?:<b>|</b>)} $html "\002" html
  3887.        }
  3888.      }
  3889.  
  3890.      set match ""
  3891.      # give results an output header with result tally.
  3892.      if {[regexp -- {<title>(.+?)</title>} $html - match]} { regexp -- {(.+?)\s(?:-|-)\s} $match - match }
  3893.      # see if page has a redirect to fragment
  3894.      regexp -- {redirectToFragment\("\#(.*?)"\)} $html - tresult
  3895.      if {[string match "*#*" $query]} { regexp -- {^(.*?)#(.*?)$} $query - query tresult }
  3896.       if {![string match "*<a name=*" $html]} { set walt 1 }
  3897.       # this is my kludge to allow listing table of contents, to make
  3898.       # sub-tag lookups easier to see on irc.
  3899.       if {[string length $results]} {
  3900.         set tresult ""
  3901.         set subtag [string tolower $results]
  3902.         # if the table of contents exists on the page, lets use real world words
  3903.         # instead of ugly subtags...
  3904.         if {[string match "*<table id=\"toc*" $html]} {
  3905.           set ded "\002ToC\002\: " ; set ebcPR "" ; set results ""
  3906.           # set results [regexp -inline -all -- {<li class="toclevel.*?<span class="toctext">(.*?)</span>} $html]
  3907.           set results [regexp -inline -all -- {<li class="toclevel.*?href="#(.*?)"} $html]
  3908.           foreach {junk anchor} $results { lappend anchors $anchor }
  3909.           #if {![info exists anchors]} { set anchors "toc" }
  3910.           if {[string tolower $subtag] == "toc"} {
  3911.             foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] }
  3912.             append ded [join $new "; "]
  3913.             set toc 1
  3914.           } else {
  3915.             set ded ""
  3916.           }
  3917.         } else {
  3918.           # table of contents doesnt exist for the page, so we are manually
  3919.           # going to pull them for the user ourselves.
  3920.           set ded "\002\(ToC)\002: " ; set ebcPR ""
  3921.           if {![info exists walt]} {
  3922.             set results [regexp -inline -all -- {<a name=".*?id="(.+?)"} $html]
  3923.          } else {
  3924.            set results [regexp -inline -all -- {<span class="mw-headline".*?id="(.*?)"} $html]
  3925.          }
  3926.          foreach {junk anchor} $results { lappend anchors $anchor }
  3927.          #if {![info exists anchors]} { set anchors "toc" }
  3928.          if {[string tolower $subtag] == "toc"} {
  3929.            foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] }
  3930.            append ded [join $new "; "]
  3931.            set toc 1
  3932.          } else {
  3933.            set ded ""
  3934.          }
  3935.        }
  3936.      }
  3937.  
  3938.      # this is in case an internal redirectToFragment(# ) was found
  3939.      if {$tresult != ""} {
  3940.        set subtag $tresult
  3941.        incr red 1
  3942.        if {![info exists walt]} {
  3943.          set redir "<a name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)"
  3944.         } else {
  3945.           if {[string index $tresult 0] == "#"} { set tresult [string range $tresult 1 end] ; set subtag $tresult }
  3946.           set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)"
  3947.         }
  3948.         regexp -nocase "$redir" $html - ded
  3949.         regsub -all -- {\[<(.*?)>\]} $ded {} ded
  3950.         regsub -all -- {\[[[:digit:]]+\]}  $ded {} ded
  3951.         regsub -all -- {<th style=.*?</th>} $ded {} ded
  3952.         regsub -all -- {<table.+?</table>} $ded {} ded
  3953.         if {$ded == ""} {
  3954.             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"
  3955.         }
  3956.       }
  3957.  
  3958.       # This is for our manual #sub-tag search..
  3959.       if {![string equal [string tolower $subtag] "toc"] && [string length $subtag] && ![string length $tresult]} {
  3960.         set subtag [string map {" " "_"} $subtag]
  3961.         # direct match
  3962.         if {[info exists anchors]} {
  3963.         foreach entry $anchors {
  3964.             if {[string match -nocase $entry $subtag]} {
  3965.               set stf "true"
  3966.               incr red 1
  3967.               set subtag [string map {" " "_"} $entry]
  3968.               break
  3969.             }
  3970.           }
  3971.           if {![info exists stf]} {
  3972.             # starts the anchor
  3973.             foreach entry $anchors {
  3974.               if {[string match -nocase "$subtag*" $entry]} {
  3975.                 set stf "true"
  3976.                 incr red 1
  3977.                 set subtag [string map {" " "_"} $entry]
  3978.                 break
  3979.               }
  3980.             }
  3981.           }
  3982.           if {![info exists stf]} {
  3983.             # anywhere in the anchor
  3984.             foreach entry $anchors {
  3985.               if {[string match -nocase "*$subtag*" $entry]} {
  3986.             set stf "true"
  3987.                 incr red 1
  3988.                 set subtag [string map {" " "_"} $entry]
  3989.                 break
  3990.               }
  3991.             }
  3992.           }
  3993.         }
  3994.         if {![info exists stf]} {
  3995.           return "$::incith::google::error_modes\002Wikipedia Error:\002 Manual #anchor (${subtag}) not found in body of html @ ${query} .$::incith::google::error_demodes"
  3996.         }
  3997.         if {![info exists walt]} {
  3998.           set redir "<a name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)"
  3999.         } else {
  4000.           set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)"
  4001.         }
  4002.         regexp -nocase "${redir}" $html - ded
  4003.         regsub -all -- {\[<(.*?)>\]} $ded {} ded
  4004.         regsub -all -- {\[[[:digit:]]+\]}  $ded {} ded
  4005.         regsub -all -- {<th style=.*?</th>} $ded {} ded
  4006.         regsub -all -- {<table.+?</table>} $ded {} ded
  4007.         if {$ded == ""} {
  4008.             return "$::incith::google::error_modes\002Wikipedia Error:\002 Unknown problem with (${subtag}) found @ ${query} .$::incith::google::error_demodes"
  4009.         }
  4010.       }
  4011.  
  4012.       # we couldn't chop these earlier because we needed them
  4013.       # to easily pull our #sub-tag finder above, need to remove
  4014.       # them here before we go further, because it might upset our checks.
  4015.       regsub -all -nocase {<span.*?>} $html "" html
  4016.       regsub -all -nocase {</span>} $html "" html
  4017.  
  4018.       # if we have no pre-cut html, let's start the cutting process.
  4019.       if {$ded == ""} {
  4020.         regsub -all {<div id="siteNotice">.*?</p></div>} $html {} html
  4021.         regsub -all {<script type=.*?</script>} $html {} html
  4022.         regsub -all {<th style=.*?</th>} $html {} html
  4023.         regsub -all {//<.*?//]]>} $html {} html
  4024.         ### - trying to clear out those damned wikipedia tables --
  4025.         regsub -all -- {<table.+?</table>} $html {} html
  4026.         regexp -- {<p>(.+?)<h} $html - ded
  4027.         if {[string match "*</table>*" $ded]} {
  4028.           regsub -all -- {.+?</table>} $ded {} ded
  4029.         } elseif {[string match "*<table*" $ded]} {
  4030.           regsub -all -- {<table.*>.+?} $ded {} ded
  4031.         }
  4032.       }
  4033.    
  4034.       # if wiki page is non-standard, then this will attempt
  4035.       # to get at least something from the webpage to display.
  4036.       if {$ded == ""} {
  4037.         if {![regexp -- {<p>(.+?)</p>} $html - ded]} {
  4038.           regexp -- {<p>(.+?)<div class="printfooter">} $html - ded
  4039.         }
  4040.       }
  4041.       #clean up messy parsing.
  4042.       regsub -all -- {<br>|<br/>} $ded {. } desc
  4043.       regsub -all -- {\[<(.*?)>\]} $desc {} desc
  4044.       regsub -all -- {<(.+?)>} $desc {} desc
  4045.       while {[string match "*  *" $desc]} {
  4046.         regsub -all -- {  } $desc " " desc
  4047.       }
  4048.       regsub -all -- {\[[[:digit:]]+\]}  $desc {} desc
  4049.       regsub -all -- { , } $desc ", " desc
  4050.       regsub -all -- { \.} $desc "\." desc
  4051.       set match [string trim $match]
  4052.       # if we have a very short description this will grab more.
  4053.       if {$match != ""} {
  4054.         if {[string len $desc] < 3} {
  4055.           regexp -- {<p>.+?<p>(.+?)<h} $html - ded
  4056.           regsub -all -- {<(.+?)>} $ded { } desc
  4057.         }
  4058.       }
  4059.       # if we still have a tiny description, grab more yet.
  4060.       if {$match != ""} {
  4061.         if {[string len $desc] < 3} {
  4062.           regexp -- {<p>(.+?)<p} $html - ded
  4063.           regsub -all -- {<(.+?)>} $ded { } desc
  4064.         }
  4065.       }
  4066.  
  4067.       # clean up messy parsing.
  4068.       # here we try to sanitize the description
  4069.       # i'm hoping this works with any language, *crosses fingers*
  4070.       set desc [string trim $desc]
  4071.       regsub -all -- {<br>} $desc {. } desc
  4072.       regsub -all -- {\[<(.*?)>\]} $desc {} desc
  4073.       regsub -all -- {<(.+?)>} $desc {} desc
  4074.       while {[string match "*  *" $desc]} {
  4075.         regsub -all -- {  } $desc " " desc
  4076.       }
  4077.       regsub -all -- {\[[[:digit:]]+\]}  $desc {} desc
  4078.       regsub -all -- { , } $desc ", " desc
  4079.       regsub -all -- { \.} $desc "\." desc
  4080.       # regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc
  4081.       # set our variables so formatting settings work
  4082.       if {$subtag != ""} {
  4083.         #regsub -- {" id="top".*?$} $subtag "" subtag
  4084.         set subtag "#${subtag}"
  4085.       }
  4086.       set link $query
  4087.       if {![info exists toc]} { set desc "[descdecode [string range $desc 0 [expr 360 * $incith::google::wiki_lines]]]" }
  4088.       if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  4089.       if {[info exists link]} { set link "$incith::google::link_modes[string trim "$link$subtag"]$incith::google::link_demodes" }
  4090.       if {[info exists match]} { set match "$incith::google::total_modes[string trim $match]$incith::google::total_demodes" }
  4091.       # after stripping excessive tags if our description is
  4092.       # reduced to nothing, let's lie and say it was too much to parse :)
  4093.       if {$match != "" && $desc == ""} {
  4094.         regexp -- {<h[0-9].*?>.*?h[0-9]>.*?<ul>(.*?)</ul>} $html - desc
  4095.         set desc [string trim $desc]
  4096.         regsub -all -- {<br>} $desc {. } desc
  4097.         regsub -all -- {\[<(.*?)>\]} $desc {} desc
  4098.         regsub -all -- {<(.+?)>} $desc {} desc
  4099.         while {[string match "*  *" $desc]} {
  4100.           regsub -all -- {  } $desc " " desc
  4101.         }
  4102.         regsub -all -- {\[[[:digit:]]+\]}  $desc {} desc
  4103.         regsub -all -- { , } $desc ", " desc
  4104.         regsub -all -- { \.} $desc "\." desc
  4105.         set desc "${::incith::google::desc_modes}$desc${::incith::google::desc_demodes}"
  4106.       }
  4107.       # if we have no description, then let's decide what to do.
  4108.       if {$desc == ""} {
  4109.         regexp -- {<p>(.+?)</p>} $html - match
  4110.         if {$match != ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${subtag}$::incith::google::error_demodes" }
  4111.         if {$match == ""} { return "$::incith::google::error_modes\002Wikipedia Error:\002 Sorry, no search results found.$::incith::google::error_demodes" }
  4112.         break
  4113.       }
  4114.       # regular output displayed.
  4115.       if {$match != ""} {
  4116.         if {$red > 0} {
  4117.           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"
  4118.         } else {
  4119.           set output "\002[descdecode ${match}]\002${incith::google::seperator}${desc}$::incith::google::break${link}"
  4120.         }
  4121.       } else {
  4122.         if {$red > 0} {
  4123.           set output "${desc}$::incith::google::break${link} $::incith::google::total_modes\[${red} Redirect\(s\)\]$::incith::google::total_demodes"
  4124.         } else {
  4125.           set output "${desc}$::incith::google::break${link}"
  4126.         }
  4127.       }
  4128.       return $output
  4129.     }
  4130.  
  4131.  
  4132.     # WIKIMEDIA
  4133.     # fetches wiki info from sites other than wikipedia.org
  4134.     # -speechless supplied
  4135.     #
  4136.     proc wikimedia {input} {
  4137.       global incithcharset
  4138.       ; set output "" ; set ded "" ; set match "" ; set redir "" ; set country "" ; set dec ""
  4139.       ; set query "" ; set titem "" ; set ebcPR "" ; set results "" ; set tresult "" ; set red 0
  4140.       ; set subtag "" ; set no_search "" ; set force 0 ; set fr 0 ; set natch "" ; set region ""
  4141.       ; set regional ""
  4142.  
  4143.       # make it so people can search their wiki in proper encoding....
  4144.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input
  4145.       if {$country == ""} {
  4146.         set country "${incith::google::wikimedia_site}"
  4147.       }
  4148.       regexp -nocase -- {(.*)\@(.*)} $country - country region
  4149.       # allow full search if desired
  4150.       if {[string match "+" [string range $region 0 0]]} {
  4151.         set region [string range $region 1 end]
  4152.         set regional $region
  4153.       }
  4154.  
  4155.       # this is my input encoding hack, this will convert input before it goes
  4156.       # out to be queried.
  4157.       if {$incith::google::encoding_conversion_input > 0 && $region != ""} {
  4158.         set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${region}:*"]] :] 1]
  4159.       } elseif {$incith::google::encoding_conversion_input > 0 && $country != ""} {
  4160.         set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1]
  4161.       } else { set encoding_found "" }
  4162.       if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  4163.         set input [encoding convertfrom $encoding_found $input]
  4164.       }
  4165.  
  4166.       regsub -all -- {_} $input { } input
  4167.       regexp -- {^(.+?)\#(.+?)$} $input - input results
  4168.       regsub -all -- { } $results { } results
  4169.       set input [urlencode $input 0 "utf-8"]
  4170.       set results [string map {.20 _} [urlencode [string trim $results] 1 "utf-8"]]
  4171.  
  4172.       # force is for those times you want to MAKE
  4173.       # it directly go to a location, you use force
  4174.       # by making first letter of your search term a .
  4175.       set force [regexp -nocase -- {^\.(.+?)$} $input - input]
  4176.       if {$force == 1} {
  4177.         #set query "http://${country}/index.php?search=${input}&go=Go"
  4178.         set query "http://${country}/index.php/${input}"
  4179.         #set match "/index.php?search=${input}&go=Go"
  4180.         #set match "/index.php/${input}"
  4181.       } else {
  4182.         set query "http://${country}/index.php?title=Special%3ASearch&search=${input}&fulltext=Search"
  4183.       }
  4184. # pre-load page to get damn redirects out of the way
  4185. # this is stupid i agree, but let's not think about it.
  4186.  
  4187.       # beware, changing the useragent will result in differently formatted html from Google.
  4188.       set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  4189.       set http [::http::config -useragent $ua -urlencoding "utf-8"]
  4190.       # stole this bit from rosc2112 on egghelp forums
  4191.       # borrowed is a better term, all procs eventually need this error handler.
  4192.     catch {set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 5]]} error
  4193.  
  4194.     if {[string match -nocase "*couldn't open socket*" $error]} {
  4195.         return "${::incith::google::error_modes}Socket Error accessing '${query}' .. Does it exist?${::incith::google::error_demodes}"
  4196.     }
  4197.     if { [::http::status $http] == "timeout" } {
  4198.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  4199.     }
  4200.  
  4201.       # CHECK CHECK
  4202.       upvar #0 $http state
  4203.       set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  4204.       set html [ungzip [::http::data $http] $state(meta)]
  4205.       # REDIRECT
  4206.       if {[string match "*${redir}*" "302|301" ]} {
  4207.         foreach {name value} $state(meta) {
  4208.         if {[regexp -nocase ^location$ $name]} {
  4209.           catch {set http [::http::geturl "$v" -query "" -headers $::incith_hdr -timeout [expr 1000 * 10]]} error
  4210.           if {[string match -nocase "*couldn't open socket*" $error]} {
  4211.           return "${::incith::google::error_modes}Socket Error accessing '${query}' .. Does it exist?${::incith::google::error_demodes}"
  4212.           }
  4213.           if { [::http::status $http] == "timeout" } {
  4214.           return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  4215.           }
  4216.             upvar #0 $http state
  4217.             set html [ungzip [::http::data $http] $state(meta)]
  4218.             set query $value
  4219.             incr red
  4220.         }
  4221.         }
  4222.       }
  4223.       ::http::cleanup $http
  4224.  
  4225.       # are we redirected to another page so soon?
  4226.       # usually this is the case, if our original search page wants
  4227.       # to search using another method, so let's accomodate it...
  4228.       regexp -nocase -- {document has moved.+?<a href="(.+?)">} $html - match
  4229.       regexp -nocase -- {Did you mean to type.+?<a href="(.+?)">} $html - match
  4230.  
  4231.       # if we are redirected, then we can modify our url
  4232.       # to include the redirect as our new destination site.
  4233.       if {$match != ""} {
  4234.         incr red 1 ; set fr 1
  4235.         set query $match
  4236.         regsub -all "&amp;" $query {\&} query
  4237.         regexp -- {http\:\/\/(.+?)/index.php} $match - country
  4238.       }
  4239.  
  4240. # 1st load of webpage - this is the only part which has error control
  4241. # this is where we load the search page to find an exact match or most relevant.
  4242. # we will also be able to detect bad user input in the form of socket errors.
  4243.  
  4244.       # beware, changing the useragent will result in differently formatted html from Google.
  4245.       if {$fr == 1} {
  4246.         set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  4247.         set http [::http::config -useragent $ua -urlencoding "utf-8"]
  4248.       set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]]
  4249.         upvar #0 $http state
  4250.         set html [ungzip [::http::data $http] $state(meta)]
  4251.         ::http::cleanup $http
  4252.       }
  4253.  
  4254.       # generic pre-parsing
  4255.       regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  4256.       regsub -all -nocase {<font.+?>} $html "" html
  4257.       regsub -all -nocase {</font>} $html "" html
  4258.       regsub -all -nocase {<span.*?>} $html "" html
  4259.       regsub -all -nocase {</span>} $html "" html
  4260.       regsub -all -nocase {<input.+?>} $html "" html
  4261.       regsub -all -nocase {(?:<i>|</i>)} $html "" html
  4262.       regsub -all "\t" $html " " html
  4263.       regsub -all "\n" $html " " html
  4264.       regsub -all "\r" $html " " html
  4265.       regsub -all "\v" $html " " html
  4266.       regsub -all "</li>" $html ". " html
  4267.       regsub -all ";;>" $html "" html
  4268.       regsub {<div class="floating_object".*?>.*?</div>} $html "" html
  4269.  
  4270.       if {$html == ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 No html to parse.$::incith::google::error_demodes" }
  4271.  
  4272.   # this is my kludge, enjoy it
  4273.   if {$force == 0} {
  4274.       # see if our direct result is available and if so, lets take it
  4275.       if {![regexp -- {<div id="contentSub"><p>.*?<a href="((?!#).+?)".*?title} $html - match]} {
  4276.         regexp -nocase -- {<div class='searchresults'>.*?<a href="(.*?)".*?(class=|title=|style=)} $html - match
  4277.       }
  4278.       if {[string match -nocase "*action=edit*" $match]} { set match "" }
  4279.       # otherwise we only care about top result
  4280.       # this is the _only_ way to parse mediawiki, sorry.
  4281.       if {$match == ""} {
  4282.         regexp -- {<li><a href="(.*?)"} $html - match
  4283.         if {$match == ""} {
  4284.           if {![regexp -- {<li><div class='mw-search.*?'><a href="(.*?)"} $html - match]} {
  4285.             regexp -- {<li style.*?><a href="(.+?)"} $html - match
  4286.           }
  4287.         }
  4288.       }
  4289.       # this will strip double domain entries from our country if it exists
  4290.       # on our anchor.
  4291.       if {$incith::google::wiki_domain_detect != 0} {
  4292.         if {[string match -nocase [lindex [split $country "/"] end] [lindex [split $match "/"] 1]]} {
  4293.           set country [join [lrange [split $country "/"] 0 end-1] "/"]
  4294.         }
  4295.       } elseif {[string match -nocase "*/wiki*" $country]} {
  4296.        regsub -- {/wiki} $country {} country
  4297.       }
  4298.  
  4299.  
  4300.       # at this point we can tell if there was any match, so let's not even bother
  4301.       # going further if there wasn't a match, this pulls the 'no search etc' found.
  4302.       # this can be in any language.
  4303.       if {$match == ""} {
  4304.         # these are for 'no search results' or similar message
  4305.         # these can be in any language.
  4306.         # if {[regexp -- {</form>.*?<p>(.+?)(<p><b>|</p><hr)} $html - match]} { regsub -all -- {<(.+?)>} $match {} match }
  4307.         if {$match == ""} {
  4308.           if {[regexp -- {<div class='searchresults'>(.+?)</p>} $html - match]} {
  4309.             regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match
  4310.           } else {
  4311.             if {[regexp -- {<div id="contentSub">(.+?)<form id=} $html - match]} {
  4312.               regsub -all {(?:<b>|</b>|<em>|</em>)} $match "\002" match
  4313.               regsub -- {<a href="/wiki/Special\:Allpages.*?</a>} $match "." match
  4314.              regsub -- {<div id.*?>} $match "" match
  4315.              regsub -- {</a></div>} $match "?" match
  4316.              regsub -- {</div>} $match "" match
  4317.              regsub -- {\[Index\]} $match "" match
  4318.              regsub -- {<span.*?/span>} $match "" match
  4319.              regsub -- { \(<.*?>\)} $match ". " match
  4320.              if {[string match "*<!--*" $match]} {
  4321.                regexp -- {<li class="normal">.*?</p><p>(.*?)</p>} $html - match
  4322.              }
  4323.            }
  4324.          }
  4325.        }
  4326.        # this is our last error catch, this can grab the
  4327.        # 'wikimedia cannot search at this time' message
  4328.        # this can be in any language.
  4329.        if {[string len $match] < 3} { regexp -- {<center><b>(.+?)</b>} $html - match }
  4330.        if {$match == ""} {
  4331.          regsub -all -- { } $results {_} results
  4332.          if {$results != ""} { set results "#${results}" }
  4333.           return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${results}$::incith::google::error_demodes"
  4334.         }
  4335.         # might be tags since we allowed any language here we cut them out
  4336.         regsub -all -- {<(.+?)>} $match "" match
  4337.         if {$region == ""} {
  4338.           return "$::incith::google::desc_modes[utf8encodefix $country [descdecode ${match}]]$::incith::google::desc_demodes"
  4339.         } else {
  4340.           return "$::incith::google::desc_modes[utf8encodefix $region [descdecode ${match}]]$::incith::google::desc_demodes"
  4341.         }
  4342.       }
  4343.      
  4344.       # this lets us easily change our internal sub redirected wiki link.
  4345.       #if {$regional != ""} {
  4346.       # regsub -- {/wiki/} $match "/$region/" match
  4347.       #}
  4348.  
  4349.       # we assume here we found another page to traverse in our search.
  4350.       if {![string match "*http*" $match]} { set query "http://${country}${match}" } { set query $match }
  4351.  
  4352. # 2nd load of webpage - this has no error checking what-so-ever
  4353. # here is where we pluck the link to the exact match, or the most relevant 'top' link.
  4354. # or in the case of redirects, to other pages, we will handle that here as well.
  4355.  
  4356.       # beware, changing the useragent will result in differently formatted html from Google.
  4357.       set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  4358.       set http [::http::config -useragent $ua -urlencoding "utf-8"]
  4359.       set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]]
  4360.       upvar #0 $http state ; set ncode [http::ncode $http] ; set metas $state(meta) ; set value ""
  4361.       set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  4362.       # this is the output encoding hack.
  4363.       if {$incith::google::encoding_conversion_output > 0} {
  4364.         if {$region != ""} {
  4365.           set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1]
  4366.         } else {
  4367.           set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  4368.         }
  4369.       }
  4370.  
  4371.       set html [ungzip [::http::data $http] $state(meta)]
  4372.  
  4373.       if {$incith::google::debug > 0} {
  4374.         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"
  4375.       }
  4376.       if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  4377.         set ::incithcharset $encoding_found
  4378.         set html [incithencode $html]
  4379.       }
  4380.       ::http::cleanup $http
  4381.       #correct the html, remove shitty tags
  4382.       # generic pre-parsing
  4383.       regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  4384.       regsub -all -nocase {<font.+?>} $html "" html
  4385.       regsub -all -nocase {</font>} $html "" html
  4386.       regsub -all -nocase {<input.+?>} $html "" html
  4387.       regsub -all -nocase {(?:<i>|</i>)} $html "" html
  4388.       regsub -all "\t" $html " " html
  4389.       regsub -all "\n" $html " " html
  4390.       regsub -all "\r" $html " " html
  4391.       regsub -all "\v" $html " " html
  4392.       regsub -all "</li>" $html ". " html
  4393.       regsub -all ";;>" $html "" html
  4394.       if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} {
  4395.         regsub -all -nocase {(?:<b>|</b>)} $html "\002" html
  4396.       }
  4397.       set match ""
  4398.    
  4399.     # this is where my kludge ends ;)
  4400.     # this is if there is no text on a special page.
  4401.     } else {
  4402.      if {[regexp -nocase -- {<div class="noarticletext">(.+?)</div>} $html - no_search]} {
  4403.        regsub -all -- {<(.+?)>} $no_search {} no_search
  4404.        while {[string match "*  *" $no_search]} {
  4405.          regsub -all -- {  } $no_search " " no_search
  4406.        }
  4407.        return "$::incith::google::desc_modes$no_search$::incith::google::desc_demodes"
  4408.      }
  4409.     }
  4410.    
  4411.     if {[string match 30* $ncode]} {
  4412.       foreach {name value} $metas {
  4413.         if {[regexp -nocase ^location$ $name]} {
  4414.           set go $value
  4415.         }
  4416.       }
  4417.     }
  4418.     # are we redirected to another page? if so, let's go there
  4419.     if {[regexp -- {alt="#REDIRECT ".+?<a href="(.+?)" title="} $html - match] || [info exists go]} {
  4420.      if {$match != ""} {
  4421.        incr red 1
  4422.        set query "http://${country}${match}"
  4423.      } else { set query $go }
  4424.  
  4425. # 3rd load of webpage - this has no error checking what-so-ever
  4426. # here is our final webpage, this is hopefully what the user was looking for.
  4427.  
  4428.        # beware, changing the useragent will result in differently formatted html from Google.
  4429.        set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  4430.        set http [::http::config -useragent $ua -urlencoding "utf-8"]
  4431.        set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 15]]
  4432.        upvar #0 $http state
  4433.        set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  4434.        # this is the output encoding hack.
  4435.        if {$incith::google::encoding_conversion_output > 0} {
  4436.          if {$region != ""} {
  4437.            set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$region:*"]] :] 1]
  4438.          } else {
  4439.            set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  4440.          }
  4441.        }
  4442.  
  4443.        set html [ungzip [::http::data $http] $state(meta)]
  4444.  
  4445.        if {$incith::google::debug > 0} {
  4446.          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"
  4447.        }
  4448.        if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  4449.          set ::incithcharset $encoding_found
  4450.          set html [incithencode $html]
  4451.        }
  4452.        ::http::cleanup $http
  4453.        #correct the html, remove shitty tags
  4454.        # generic pre-parsing
  4455.        regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  4456.        regsub -all -nocase {<font.+?>} $html "" html
  4457.        regsub -all -nocase {</font>} $html "" html
  4458.        regsub -all -nocase {<input.+?>} $html "" html
  4459.        regsub -all -nocase {(?:<i>|</i>)} $html "" html
  4460.        regsub -all "\t" $html " " html
  4461.        regsub -all "\n" $html " " html
  4462.        regsub -all "\r" $html " " html
  4463.        regsub -all "\v" $html " " html
  4464.        regsub -all "</li>" $html ". " html
  4465.        regsub -all ";;>" $html "" html
  4466.        if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} {
  4467.          regsub -all -nocase {(?:<b>|</b>)} $html "\002" html
  4468.        }
  4469.      }
  4470.  
  4471.      set match ""
  4472.      # give results an output header with result tally.
  4473.      regexp -- {<title>(.+?)\s\-\s.+?</title>} $html - match
  4474.      # see if page has a redirect to fragment
  4475.      if {![string length $results]} { regexp -- {redirectToFragment\("(\#.+?)"\)} $html - tresult }
  4476.      if {![string match "*<a name=*" $html]} { set walt 1 }
  4477.      # this is my kludge to allow listing table of contents, to make
  4478.      # sub-tag lookups easier to see on irc.
  4479.      if {[string length $results] || [string length $tresult]} {
  4480.        if {[string length $results]} { set tresult "" }
  4481.        set subtag [string tolower $results]
  4482.        # if the table of contents exists on the page, lets use real world words
  4483.        # instead of ugly subtags...
  4484.        if {[string match "*<table id=\"toc*" $html]} {
  4485.           set ded "\002ToC\002\: " ; set ebcPR "" ; set results ""
  4486.           # set results [regexp -inline -all -- {<li class="toclevel.*?<span class="toc.*?">(.*?)</span>} $html]
  4487.           set results [regexp -inline -all -- {<li class="toclevel.*?href="#(.*?)"} $html]
  4488.           set anchors [list "toc"]
  4489.           foreach {junk anchor} $results { lappend anchors $anchor }
  4490.           if {[string tolower $subtag] == "toc"} {
  4491.             foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] }
  4492.             append ded [join $new "; "]
  4493.             set toc 1 ; set loop 1
  4494.           } else {
  4495.             set ded ""
  4496.           }
  4497.         } else {
  4498.           # table of contents doesnt exist for the page, so we are manually
  4499.           # going to pull them for the user ourselves.
  4500.           set ded "\002\(ToC)\002: " ; set ebcPR ""
  4501.           if {![info exists walt]} {
  4502.             set results [regexp -inline -all -- {<a name=".*?id="(.+?)"} $html]
  4503.          } else {
  4504.            set results [regexp -inline -all -- {<span class="mw-headline".*?id="(.*?)"} $html]
  4505.          }
  4506.          set anchors [list "toc"]
  4507.          foreach {junk anchor} $results { lappend anchors $anchor }
  4508.          #if {![info exists anchors]} { set anchors "toc" }
  4509.          if {[string tolower $subtag] == "toc"} {
  4510.            foreach anchor $anchors { lappend new [string map {"_" " "} [subtagDecode $anchor]] }
  4511.            append ded [join $new "; "]
  4512.            set toc 1 ; set loop 1
  4513.          } else {
  4514.            set ded ""
  4515.          }
  4516.        }
  4517.      }
  4518.  
  4519.      # this is in case an internal redirectToFragment(# ) was found
  4520.      if {$tresult != ""} {
  4521.        #set subtag $tresult
  4522.        incr red 1
  4523.        if {![info exists walt]} {
  4524.          set redir "name=\"${tresult}\".*?>(.+?)(<a name|</table>|\<\!\-)"
  4525.         } else {
  4526.           set tresult [string range $tresult 1 end]
  4527.           set redir "<span class=\"mw-headline\" id=\"${tresult}.*?>(.+?)(<span|</table>|\<\!\-)"
  4528.         }
  4529.         regexp -nocase "$redir" $html - ded
  4530.         regsub -all -- {\[<(.*?)>\]} $ded {} ded
  4531.         regsub -all -- {\[[[:digit:]]+\]}  $ded {} ded
  4532.         regsub -all -- {<table.+?</table>} $ded {} ded
  4533.         if {$ded == ""} {
  4534.             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"
  4535.         }
  4536.       }
  4537.  
  4538.       # This is for our manual #sub-tag search..
  4539.       if {![string equal [string tolower $subtag] "toc"] && [string length $subtag]} {
  4540.         set subtag [string map {" " "_"} $subtag]
  4541.         # direct match
  4542.         if {[info exists anchors]} {
  4543.         foreach entry $anchors {
  4544.             if {[string match -nocase $entry $subtag]} {
  4545.               set stf "true"
  4546.               incr red 1
  4547.               set subtag [string map {" " "_"} $entry]
  4548.               break
  4549.             }
  4550.           }
  4551.           if {![info exists stf]} {
  4552.             # starts the anchor
  4553.             foreach entry $anchors {
  4554.               if {[string match -nocase "$subtag*" $entry]} {
  4555.                 set stf "true"
  4556.                 incr red 1
  4557.                 set subtag [string map {" " "_"} $entry]
  4558.                 break
  4559.               }
  4560.             }
  4561.           }
  4562.           if {![info exists stf]} {
  4563.             # anywhere in the anchor
  4564.             foreach entry $anchors {
  4565.               if {[string match -nocase "*$subtag*" $entry]} {
  4566.             set stf "true"
  4567.                 incr red 1
  4568.                 set subtag [string map {" " "_"} $entry]
  4569.                 break
  4570.               }
  4571.             }
  4572.           }
  4573.         }
  4574.         if {![info exists stf]} {
  4575.           return "$::incith::google::error_modes\002Wikimedia Error:\002 Manual #anchor (${subtag}) not found in body of html @ ${query} .$::incith::google::error_demodes"
  4576.         }
  4577.         if {![info exists walt]} {
  4578.           set redir "name=\"${subtag}\".*?>(.*?)(?:<a name|<div class=\"printfooter)"
  4579.         } else {
  4580.           set redir "<span class=\"mw-headline\" id=\"${subtag}\".*?>(.*?)(?:<span class=\"mw-headline|<div class=\"printfooter)"
  4581.         }
  4582.         regexp -nocase "${redir}" $html - ded
  4583.         regsub -all -- {\[<(.*?)>\]} $ded {} ded
  4584.         regsub -all -- {\[[[:digit:]]+\]}  $ded {} ded
  4585.         regsub -all -- {<th style=.*?</th>} $ded {} ded
  4586.         regsub -all -- {<table.+?</table>} $ded {} ded
  4587.         if {$ded == ""} {
  4588.             return "$::incith::google::error_modes\002Wikimedia Error:\002 Unknown problem with (${subtag}) found @ ${query} .$::incith::google::error_demodes"
  4589.         }
  4590.       }
  4591.  
  4592.       # we couldn't chop these earlier because we needed them
  4593.       # to easily pull our #sub-tag finder above, need to remove
  4594.       # them here before we go further, because it might upset our checks.
  4595.       regsub -all -nocase {<span.*?>} $html "" html
  4596.       regsub -all -nocase {</span>} $html "" html
  4597.  
  4598.       # if we have no pre-cut html, let's start the cutting process.
  4599.       if {$ded == ""} {  
  4600.         regexp -- {<h1.*?>.*?<p>(.+?)<h} $html - ded
  4601.         ### - trying to clear out those damned wikipedia tables --
  4602.         regsub -all -- {<table.+?</table>} $ded {} ded
  4603.         if {[string match "*</table>*" $ded]} {
  4604.           regsub -all -- {.+?</table>} $ded {} ded
  4605.         } elseif {[string match "*<table*" $ded]} {
  4606.           regsub -all -- {<table.*>.+?} $ded {} ded
  4607.         }
  4608.       }
  4609.    
  4610.       # if wiki page is non-standard, then this will attempt
  4611.       # to get at least something from the webpage to display.
  4612.       if {$ded == ""} {
  4613.         regexp -- {<p>(.+?)<div class="printfooter">} $html - ded
  4614.       }
  4615.       #clean up messy parsing.
  4616.       regsub -all -- {<br>|<br/>} $ded {. } desc
  4617.       #regsub -all -- {">:alpha:\]} $desc {} desc
  4618.       regsub -all -- {\[<(.*?)>\]} $desc {} desc
  4619.       regsub -all -- {<(.+?)>} $desc {} desc
  4620.       while {[string match "*  *" $desc]} {
  4621.         regsub -all -- {  } $desc " " desc
  4622.       }
  4623.       regsub -all -- {\[[[:digit:]]+\]}  $desc {} desc
  4624.       regsub -all -- { , } $desc ", " desc
  4625.       regsub -all -- { \.} $desc "\." desc
  4626.       regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc
  4627.       set match [string trim $match]
  4628.       # if we have a very short description this will grab more.
  4629.       if {[string len $desc] < 3} {
  4630.         if {[regexp -- {<p>.+?<p>(.+?)<h} $html - desc]} { set desc [cleans $desc] }
  4631.       }
  4632.       if {[string len $desc] < 3} {
  4633.         if {[regexp -- {<p>(.+?)<p} $html - desc]}  { set desc [cleans $desc] }
  4634.       }
  4635.       #if {[string length $tresult]} { set subtag $tresult }
  4636.       # set our variables so formatting settings work
  4637.       if {$subtag != ""} {
  4638.         regsub -- {" id="top".*?$} $subtag "" subtag
  4639.        set subtag "#${subtag}"
  4640.       }
  4641.       set link $query
  4642.       if {![info exists loop]} { set desc "[string range $desc 0 [expr 360 * $incith::google::wiki_lines]]" }
  4643.       if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim [descdecode $desc]]$incith::google::desc_demodes" }
  4644.       if {[info exists match]} { set match "$incith::google::total_modes[string trim $match]$incith::google::total_demodes" }
  4645.       if {[info exists link]} { set link "$incith::google::link_modes[string trim "$link$subtag"]$incith::google::link_demodes" }
  4646.       # after stripping excessive tags if our description is
  4647.       # reduced to nothing, let's lie and say it was too much to parse :)
  4648.  
  4649.       # if we have no description, then let's decide what to do.
  4650.       if {$desc == ""} {
  4651.         regexp -- {<p>(.+?)</p>} $html - match
  4652.         if {$match != ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 Unable to parse for: \002${input}\002 @ ${query}${subtag}$::incith::google::error_demodes" }
  4653.         if {$match == ""} { return "$::incith::google::error_modes\002Wikimedia Error:\002 Sorry, no search results found.$::incith::google::error_demodes" }
  4654.         break
  4655.       }
  4656.  
  4657.       # regular output displayed.
  4658.       if {$match != ""} {
  4659.         if {$red > 0} {
  4660.           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"
  4661.         } else {
  4662.           set output "\002[descdecode ${match}]\002${incith::google::seperator}[descdecode ${desc}]$::incith::google::break${link}"
  4663.         }
  4664.       } else {
  4665.         if {$red > 0} {
  4666.           set output "${desc}$::incith::google::break${link} $::incith::google::total_modes\[${red} Redirect\(s\)\]$::incith::google::total_demodes"
  4667.         } else {
  4668.           set output "${desc}$::incith::google::break${link}"
  4669.         }
  4670.       }
  4671.       return $output
  4672.     }
  4673.  
  4674.     # wikipedia/wikimedia support
  4675.     # CLEANS
  4676.     #
  4677.     proc cleans {input} {
  4678.       # clean up messy parsing.
  4679.       # here we try to sanitize the description
  4680.       # i'm hoping this works with any language, *crosses fingers*
  4681.       set desc [string trim $input]
  4682.       regsub -all -- {<br>} $desc {. } desc
  4683.       regsub -all -- {\[<(.*?)>\]} $desc {} desc
  4684.       regsub -all -- {<(.+?)>} $desc {} desc
  4685.       while {[string match "*  *" $desc]} {
  4686.         regsub -all -- {  } $desc " " desc
  4687.       }
  4688.       regsub -all -- {\[[[:digit:]]+\]}  $desc {} desc
  4689.       regsub -all -- { , } $desc ", " desc
  4690.       regsub -all -- { \.} $desc "\." desc
  4691.       regsub -all -- {&#(25(\[6-9\])?|2(\[6-9\])?[\d]|(\[3-9\])?[\d]{2}|[\d]{4,5});} $desc "?" desc
  4692.       return $desc
  4693.     }
  4694.  
  4695.     # EBAY
  4696.     # fetches search results from ebay for auctions closest to completion.
  4697.     # -speechless supplied
  4698.     #
  4699.     proc ebay {input} {
  4700.       # lots of variables, keeping them clean is important.
  4701.       ; set results 0 ; set output "" ; set titem "" ; set tresult "" ; set ebcSP ""
  4702.       ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR "" ; set ebcTim "" ; set ebcShpNew ""
  4703.       ; set ebcCheck "" ; set no_search "" ; set auctions "" ; set ebcBid2 "" ; set ebcStr ""
  4704.  
  4705.       # this isn't global, so we need to keep ctry (country) here
  4706.       regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - titem dummy
  4707.       if {$titem == ""} {
  4708.         set titem "${incith::google::ebay_country}"
  4709.       }
  4710.  
  4711.       # fetch the html
  4712.       set html [fetch_html $input 25]
  4713.       if {$html == ""} {
  4714.         return "$::incith::google::error_modes\002Ebay Error: No html to parse.$::incith::google::error_demodes"
  4715.       }
  4716.  
  4717.       # user input causing errors?
  4718.     if {[string match -nocase "*socketerrorabort*" $html]} {
  4719.             regsub {(.+?)\|} $html {} html
  4720.             return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  4721.     }
  4722.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  4723.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  4724.     }
  4725.  
  4726.       # set up an ebay results header for results to be appended to as $output
  4727.       if {![regexp -- {class="sectiontitle">([0-9  .,]+)\002.*?<h2 class="standard ens} $html - tresult]} {
  4728.        if {![regexp -- {<div class="count">([0-9  .,]+) } $html - tresult]} {
  4729.           if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - tresult]} {
  4730.             if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s(.*?)\s} $html - tresult auctions]} {
  4731.               if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s(.*?)\s} $html - tresult auctions]} {
  4732.                 regexp -nocase {<div id="v.*?" class="fpcc">.*?\s(.+?)\s.*?\:\s*(.+?)\s} $html - auctions tresult
  4733.                 set tresult "[join [scan  $tresult "%d%d"] ""]"
  4734.               }
  4735.             }
  4736.           }
  4737.        }
  4738.      }
  4739.      # no_results line in any language.
  4740.      if {[regexp -- {<div class="msg msg-alert">(.+?)</div>} $html - no_search]} {
  4741.        if {[regexp -- {div class="msg msg-alert.+?</div>.+?"msg msg-alert">(.+?)</div>} $html - more]} {
  4742.           append no_search " $more"
  4743.         }
  4744.         regsub -all {<(.+?)>} $no_search "" no_search
  4745.       } else {
  4746.         if {![regexp -- {class="sectiontitle">(.+?)</h2><h2 class="standard ens"> } $html - no_search]} {
  4747.           if {![regexp -- {<div class="count">(.+?)(?:</script>|</div>)} $html - no_search]} {
  4748.             if {![regexp -- {<div class="toplne"><div class="msg">(.+?)</div>} $html - no_search]} {
  4749.               regexp -- {<div class="cnt">(.*?)</div>} $html - no_search
  4750.             }
  4751.           }
  4752.         }
  4753.       }
  4754.  
  4755.       # santize our no_search results found error message
  4756.       # may need to use it very shortly if we have no results
  4757.       if {$no_search != ""} {
  4758.         #if {[regexp -- {<div class="suggestions".+?<ul><li><div>(.+?)</li>} $html - ebcStr]} {
  4759.         #  regsub -all -- {<(.+?)>} $ebcStr {} ebcStr
  4760.         #  set ebcStr "${ebcStr}. "
  4761.         #}
  4762.         #regexp {(^.+?)document.write} $no_search - no_search
  4763.         #regsub -all -- {<(.+?)>} $no_search {} no_search
  4764.         #set no_search "${ebcStr}[string trim $no_search]"
  4765.       } else {
  4766.         if {$tresult == 0 && $no_search == ""} {
  4767.           set no_search "eBay error."
  4768.         }
  4769.       }
  4770.  
  4771.       # bids in any language
  4772.       if {![regexp -- {<td class="ebcBid">(.+?)</td>} $html {} ebcSP]} {set ebcsp ""}
  4773.  
  4774.       # format output according to variables.
  4775.       if {$incith::google::total_results != 0} {
  4776.         regexp -- {<option value="1" selected="selected">(.+?)</option>} $html - auctions
  4777.         set output "$::incith::google::total_modes\002[string trim ${tresult}]\002 [string trim $auctions]$::incith::google::total_demodes${incith::google::seperator}"
  4778.         if {$incith::google::bold_descriptions == 0} {
  4779.           regsub -all -- "\002" $output {} output
  4780.         }
  4781.       }
  4782.  
  4783.       # parse the html
  4784.       while {$results < $incith::google::ebay_results} {
  4785.         # these CANNOT be tied together, some results appear in different
  4786.         # order, so always leave these spread out in a mess...
  4787.         if {![regexp -nocase {<td class="dtl"><div class="ttl">(.*?)</a></td>} $html - line]} {
  4788.           if {![regexp -nocase {<table class="lview nol">.*?class="details.*?">(.+?)</table>} $html - line]} {
  4789.             if {![regexp -nocase {<table class="nol">.*?class="details.*?">(.+?)</table>} $html - line]} {
  4790.               if {![regexp -nocase {<h3 class="ens fontnormal">(.+?)class="ebRight"} $html - line]} {
  4791.                 if {![regexp -nocase {<td class="details">(.*?)</a></td>} $html - line]} {
  4792.                   set line ""
  4793.                 } else { regsub -nocase {<td class="details">.*?</a></td>} $html {} html }
  4794.               } else { regsub {<h3 class="ens fontnormal">.+?class="ebRight"} $html {} html }
  4795.             } else { regsub {<table class="nol">.+?</table>} $html {} html }
  4796.           } else { regsub {<table class="lview nol">.+?</table>} $html {} html }
  4797.         } else { regsub -nocase {<td class="dtl"><div class="ttl">.*?</a></td>} $html {} html }
  4798.         # name & url
  4799.         if {![regexp -nocase {href=".*?ebay.*?/.*?/(.*?)\?pt.*?>(.*?)</a>} $line - ebcU ebcI]} {
  4800.          if {![regexp -nocase {<a href=".+?QQitem(.+?)QQ.+?">.+?<a href=".*?">(.+?)</a>} $line - ebcU ebcI]} {
  4801.         regexp -nocase {<a href="http://cgi.ebay.*?/.*?/(.*?)\?cmd=.*?>(.*?)</a>} $line - ebcU ebcI
  4802.           }
  4803.         }
  4804.         # bid
  4805.         if {[regexp -nocase {class="bids.*?">(.+?)</td>} $line - ebcBid]} {
  4806.           if {[regexp {<div.*?>(.+?)</div><img src=".*?title="(.+?)"} $ebcBid - ebcBid ebcBid2]} {
  4807.            set ebcBid "${ebcBid}/${ebcBid2}"
  4808.          }
  4809.          if {[string match *<img* $ebcBid]} { regexp {<img src=".*?title="(.+?)"} $ebcBid - ebcBid }
  4810.         } else {
  4811.           regexp -nocase {class="ebcBid">(.*?)</td} $line - ebcBid
  4812.           # trying to parse out the phrase "buy-it-now" in any language
  4813.           # this isn't elegant at all, we are chopping 'massive' html tags out
  4814.           # it works effectively, but isn't quick at all. We also have to account
  4815.           # for multiple bid/buy-it-now possibilities....
  4816.           regexp -- {(^[0-9\-]{1,})<} $ebcBid {} ebcBid2
  4817.           if {![regexp -- {title="(.+?)"} $ebcBid {} ebcBid]} {
  4818.             if {![regexp -- {alt="(.+?)(?:\":\:|-)} $ebcBid {} ebcBid]} {
  4819.              regsub -all -- {<(.+?)>} $ebcBid "" ebcBid
  4820.              if {$ebcBid == "-"} { set ebcBid "0" }
  4821.              if {$ebcBid != ""} {
  4822.                regsub -all -- {<(.+?)>} $ebcSP "" ebcSP
  4823.                append ebcBid " ${ebcSP}"
  4824.              }
  4825.              if {$ebcBid == ""} { set ebcBid "??" }
  4826.            }
  4827.          }
  4828.          # if our buy-it-now has a bid too, prepend bid to it.
  4829.          if {![string match "*${ebcBid2}*" $ebcBid]} {
  4830.             if {$ebcBid2 == "-"} { set ebcBid2 "0" }
  4831.             regsub -all -- {<(.+?)>} $ebcSP "" ebcSP
  4832.             set ebcBid "${ebcBid2} ${ebcSP}/[string trim $ebcBid]"
  4833.          }
  4834.        }
  4835.        regsub -nocase {</div><div class=.*?>} $ebcBid "/" ebcBid
  4836.        regsub -all {<.*?>} $ebcBid "" ebcBid
  4837.        # prices
  4838.        if {[regexp -nocase {<td class="prc.*?">(.*?)</td} $line - ebcPR]} {
  4839.          regsub -- {</div><div>} $ebcPR "/" ebcPR
  4840.          regexp -- {^(.+)</div>(.*?)$} $ebcPR - ebcPR ebcShpNew
  4841.          regsub -all {<.*?>} $ebcPR "" ebcPR
  4842.        }
  4843.        
  4844.        # shipping
  4845.        if {![string length $ebcShpNew]} {
  4846.          if {[regexp -nocase {td class=".*?(?:ship|fshp).*?">(.+?)</td>} $line - ebcShpNew]} {
  4847.            if {[string match "<" [string index $ebcShpNew 0]]} { set ebcShpNew "Calculate" }
  4848.          } else {
  4849.            regexp -nocase {class="ebcShpNew">(.+?)<} $line - ebcShpNew
  4850.            if {[info exists ebcShpNew]} {
  4851.              regexp -- {;;">(.+?)} $ebcShpNew {} ebcCheck
  4852.               if {$ebcCheck == ""} {
  4853.                 regexp -- {$(.+?)<} $ebcShpNew {} ebcShpNew
  4854.                 if {$ebcShpNew == ""} {
  4855.                   set ebcTim "store"
  4856.                   regexp -nocase {class="ebcStr">.+?http://stores.ebay.com/.+?">(.+?)</a>} $html - ebcStr
  4857.                }
  4858.              } else {
  4859.             if {![regexp -- {(.*?)<div class="tfsp">(.*?)</div>} $ebcPR - ebcPR ebcShpNew]} {
  4860.                  set ebcShpNew "Calculate"
  4861.             }
  4862.              }
  4863.            }
  4864.            # remove pesky trailing spaces
  4865.            regsub -all -- {<(.+?)>} $ebcShpNew {} ebcShpNew
  4866.            regsub -all " " $ebcShpNew "" ebcShpNew
  4867.          }
  4868.        }
  4869.        # time left
  4870.        if {![regexp -nocase {td class="time.*?rt">(.+?)</td>} $line - ebcTim]} {
  4871.          if {![regexp -nocase {class="ebcTim">(.+?)<} $line - ebcTim]} {
  4872.            regexp -nocase {class="hidlb">(.+?)<} $line - ebcTim
  4873.          }
  4874.        }
  4875.        if {[info exists ebcTim]} {
  4876.          regsub -all -- {<.*?>} [string map {\002 ""} $ebcTim] {} ebcTim
  4877.          if {[string match *:* $ebcTim]} { set ebcTim [join [lrange [split $ebcTim :] 1 end]] }
  4878.        }
  4879.        # keep ebay Item from becoming too lengthy
  4880.        if {[info exists ebcI]} {
  4881.          #ebay has these odd tags, removing them cleans up results.
  4882.          regsub -all -nocase "<wbr>" $ebcI "" ebcI
  4883.          set ebcI [string range $ebcI 0 [expr $incith::google::description_length - 1]]
  4884.          set ebcI [string trim $ebcI]
  4885.        }
  4886.  
  4887.        # check results are more than 0, return or stop looping, depending
  4888.        if {$tresult < 1 } {
  4889.          if {$results == 0} {
  4890.            set reply $no_search
  4891.            return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  4892.          } else {
  4893.            break
  4894.          }
  4895.        }
  4896.  
  4897.        # make the link valid because we were only given a partial href result, not a full url
  4898.        set link "http://cgi.ebay.${titem}/_W0QQItemZ[lindex [split ${ebcU} "/"] end]"
  4899.  
  4900.        # fix up our variables so the output looks purdy.
  4901.        if {$ebcPR == ""} { set ebcPR "--" }
  4902.        if {$ebcTim == ""} {
  4903.          set ebcTim "--"
  4904.        } elseif {$ebcTim == "store"} {
  4905.          set desc "\037${ebcStr}\037 ${ebcI}, ${ebcPR}(${ebcShpNew}), ${ebcBid}"
  4906.        } elseif {$ebcI != ""} {
  4907.          set desc "${ebcI}, ${ebcPR}(${ebcShpNew}), ${ebcBid}, ${ebcTim}"
  4908.        } else {
  4909.          set link "" ; set desc ""
  4910.        }
  4911.  
  4912.        # add the search result
  4913.        if {$link != ""} {
  4914.          if {[info exists desc] == 1 && $ebcI != ""} {
  4915.          if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  4916.          if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  4917.            if {$incith::google::link_only == 1} {
  4918.              append output "${link}${incith::google::seperator}"
  4919.            } else {
  4920.              append output [descdecode "${desc}$::incith::google::break${link}${incith::google::seperator}"]
  4921.            }
  4922.          }
  4923.        }
  4924.  
  4925.        # increase the results, clear the variables for the next loop just in case
  4926.        unset link ; set ebcCheck "" ; set ebcU "" ; set ebcBid2 ""
  4927.        set ebcI "" ; set ebcPR "" ; set ebcShpNew ""
  4928.        incr results
  4929.      }
  4930.  
  4931.      # make sure we have something to send
  4932.      if {$tresult < 1} {
  4933.        set reply $no_search
  4934.        return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  4935.      }
  4936.      return $output
  4937.    }
  4938.  
  4939.  
  4940.    # EBAYFIGHT
  4941.    # ebay fight !
  4942.    #
  4943.    proc ebayfight {input} {
  4944.      set output ""; set winner 0 ; set match1 0; set match2 0
  4945.      
  4946.      regexp -nocase -- {^(.+?) vs (.+?)$} $input - word1 word2
  4947.  
  4948.      # fetch the first result
  4949.      set html [fetch_html $word1 25]
  4950.      if {![regexp -- {class="sectiontitle">([0-9  .,]+)\002.*?<h2 class="standard ens} $html - match1]} {
  4951.         if {![regexp -- {<div class="count">([0-9  .,]+) } $html - match1]} {
  4952.            if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - match1]} {
  4953.              if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s} $html - match1]} {
  4954.                if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s} $html - match1]} {
  4955.                  regexp -nocase {<div id="v.*?" class="fpcc">.*?\s.+?\s.*?\:\s*(.+?)\s} $html - auctions match1
  4956.                  set match1 "[join [scan  $match1 "%d%d"] ""]"
  4957.                }
  4958.              }
  4959.            }
  4960.         }
  4961.       }
  4962.  
  4963.       # fetch the second result
  4964.       set html [fetch_html $word2 25]
  4965.       regexp -- {<div id="v.*?" class="fpcc">(.+?)\s} $html - match2
  4966.       if {![regexp -- {class="sectiontitle">([0-9  .,]+)\002.*?<h2 class="standard ens} $html - match2]} {
  4967.        if {![regexp -- {<div class="count">([0-9  .,]+) } $html - match2]} {
  4968.           if {![regexp -- {var.*?getCustomAdConfig.*?,"items=(.+?)"} $html - match2]} {
  4969.             if {![regexp -nocase {<div id="v.*?" class="fpcc"><div><h1 class="smuy">(.*?)\s(.*?)\s} $html - match2]} {
  4970.               if {![regexp -nocase {<div id="v.*?" class="fpcc"><div>(.*?)\s(.*?)\s} $html - match2]} {
  4971.                 regexp -nocase {<div id="v.*?" class="fpcc">.*?\s.+?\s.*?\:\s*(.+?)\s} $html - auctions match2
  4972.                 set match2 "[join [scan  $match2 "%d%d"] ""]"
  4973.               }
  4974.             }
  4975.           }
  4976.        }
  4977.      }
  4978.  
  4979.      # clean up our matches, so it looks all tidy and neat.
  4980.      regsub -all "\002" $match1 " " match1
  4981.      regsub -all "\002" $match2 " " match2
  4982.  
  4983.      if {![info exists match1]} {
  4984.        set match1 "0"
  4985.        set match1expr "0"
  4986.      } else {
  4987.        regsub -all {,} $match1 {} match1expr
  4988.      }
  4989.  
  4990.      if {![info exists match2]} {
  4991.        set match2 "0"
  4992.        set match2expr "0"
  4993.      } else {
  4994.        regsub -all {,} $match2 {} match2expr
  4995.      }
  4996.  
  4997.      if {[expr $match2expr < $match1expr]} {
  4998.        set winner 1
  4999.      } else {
  5000.        set winner 2
  5001.      }
  5002.  
  5003.      if {[expr $match2expr == $match1expr]} {
  5004.        set winner 1
  5005.        set troll1 {
  5006.         Pissing Shitting SpillingPez DrippingCum Trolling
  5007.        }
  5008.        set troll2 {
  5009.         YourFace YourSister YourMama
  5010.        }
  5011.        set match1 "[lindex $troll1 [rand [llength $troll1]]]"
  5012.        set match2 "[lindex $troll2 [rand [llength $troll2]]]"
  5013.      }
  5014.  
  5015.      if {$incith::google::bold_descriptions > 0 && $incith::google::desc_modes == ""} {
  5016.        set word1 "\002$word1\002"; set word2 "\002$word2\002"
  5017.        set match1 "\002 $match1\002"; set match2 "\002 $match2\002"
  5018.      } elseif {$incith::google::desc_modes != ""} {
  5019.        set word1 "$incith::google::desc_modes$word1$incith::google::desc_demodes"; set word2 "$incith::google::desc_modes$word2$incith::google::desc_demodes"
  5020.        set match1 " $incith::google::desc_modes$match1$incith::google::desc_demodes"; set match2 " $incith::google::desc_modes$match2$incith::google::desc_demodes"
  5021.      } else {
  5022.        set match1 " $match1"; set match2 " $match2"
  5023.      }
  5024.  
  5025.      regsub -all " " $match1 "" match1
  5026.      regsub -all " " $match2 "" match2
  5027.  
  5028.      if {$winner == 1} {
  5029.        set output "${::incith::google::total_modes}By results on ebay:$::incith::google::total_demodes$incith::google::desc_modes $word1 beats $word2 by $match1 to $match2!$::incith::google::desc_demodes"
  5030.      } elseif {$winner == 2} {
  5031.        set output "${::incith::google::total_modes}By results on ebay:$::incith::google::total_demodes$incith::google::desc_modes $word2 beats $word1 by $match2 to $match1!$::incith::google::desc_demodes"
  5032.      } else {
  5033.        set output "${::incith::google::total_modes}Could not determine the winner."
  5034.      }
  5035.  
  5036.      # make sure we have something to send
  5037.      if {[info exists output] == 0} {
  5038.        set reply "Sorry, no search results were found."
  5039.        if {[info exists did_you_mean] == 1} {
  5040.          append reply " Did you mean: ${did_you_mean}?"
  5041.        }
  5042.        return "$incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5043.      }
  5044.      return $output
  5045.    }
  5046.  
  5047.    # Popular
  5048.    # fetches games results from gamerankings.
  5049.    # -speechless supplied
  5050.    #
  5051.    proc popular {input} {
  5052.  
  5053.      # lots of variables, keeping them clean is important.
  5054.      # borrowed mostly from my ebay proc above.
  5055.      ; set results 0 ; set output "" ; set tresult ""
  5056.      ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR ""
  5057.      ; set ebcCheck "" ; set html ""
  5058.      
  5059.      # redundant and messy, yes i know.. but it works, k
  5060.      # parses the query and reads html according to system desired.
  5061.  
  5062.      if {[string match -nocase "gc" $input] == 1} {
  5063.        set html [fetch_html "0" 30]
  5064.        set output "\002GameRankings BEST GameCube\002"
  5065.      }
  5066.      if {[string match -nocase "pc" $input] == 1} {
  5067.        set html [fetch_html "0" 31]
  5068.        set output "\002GameRankings BEST PC\002"
  5069.      }
  5070.      if {[string match -nocase "ps2" $input] == 1} {
  5071.        set html [fetch_html "0" 32]
  5072.        set output "\002GameRankings BEST PlayStation2\002"
  5073.      }
  5074.      if {[string match -nocase "ps3" $input] == 1} {
  5075.        set html [fetch_html "0" 33]
  5076.        set output "\002GameRankings BEST PlayStation3\002"
  5077.      }
  5078.      if {[string match -nocase "wii" $input] == 1} {
  5079.        set html [fetch_html "0" 34]
  5080.        set output "\002GameRankings BEST Wii\002"
  5081.      }
  5082.      if {[string match -nocase "xbox" $input] == 1} {
  5083.        set html [fetch_html "0" 35]
  5084.        set output "\002GameRankings BEST Xbox\002"
  5085.      }
  5086.      if {[string match -nocase "x360" $input] == 1} {
  5087.        set html [fetch_html "0" 36]
  5088.        set output "\002GameRankings BEST Xbox360\002"
  5089.      }
  5090.      if {[string match -nocase "ds" $input] == 1} {
  5091.        set html [fetch_html "0" 37]
  5092.        set output "\002GameRankings BEST NDS\002"
  5093.      }
  5094.      if {[string match -nocase "gba" $input] == 1} {
  5095.        set html [fetch_html "0" 38]
  5096.        set output "\002GameRankings BEST GBA\002"
  5097.      }
  5098.      if {[string match -nocase "psp" $input] == 1} {
  5099.        set html [fetch_html "0" 39]
  5100.        set output "\002GameRankings BEST PSP\002"
  5101.      }
  5102.      if {[string match -nocase "mobile" $input] == 1} {
  5103.        set html [fetch_html "0" 40]
  5104.        set output "\002GameRankings BEST Mobile\002"
  5105.      }
  5106.      if {[string match -nocase "ngage" $input] == 1} {
  5107.        set html [fetch_html "0" 41]
  5108.        set output "\002GameRankings BEST N-Gage\002"
  5109.      }
  5110.      if {[string match -nocase "3do" $input] == 1} {
  5111.        set html [fetch_html "0" 42]
  5112.        set output "\002GameRankings BEST 3DO\002"
  5113.      }
  5114.      if {[string match -nocase "dc" $input] == 1} {
  5115.        set html [fetch_html "0" 43]
  5116.        set output "\002GameRankings BEST Dreamcast\002"
  5117.      }
  5118.      if {[string match -nocase "gen" $input] == 1} {
  5119.        set html [fetch_html "0" 44]
  5120.        set output "\002GameRankings BEST Genesis\002"
  5121.      }
  5122.      if {[string match -nocase "jag" $input] == 1} {
  5123.        set html [fetch_html "0" 45]
  5124.        set output "\002GameRankings BEST Jaguar\002"
  5125.      }
  5126.      if {[string match -nocase "n64" $input] == 1} {
  5127.        set html [fetch_html "0" 46]
  5128.        set output "\002GameRankings BEST N64\002"
  5129.      }
  5130.      if {[string match -nocase "neo" $input] == 1} {
  5131.        set html [fetch_html "0" 47]
  5132.        set output "\002GameRankings BEST Neo-Geo\002"
  5133.      }
  5134.      if {[string match -nocase "ps1" $input] == 1} {
  5135.        set html [fetch_html "0" 48]
  5136.        set output "\002GameRankings BEST Playstation\002"
  5137.      }
  5138.      if {[string match -nocase "sat" $input] == 1} {
  5139.        set html [fetch_html "0" 49]
  5140.        set output "\002GameRankings BEST Saturn\002"
  5141.      }
  5142.      if {[string match -nocase "snes" $input] == 1} {
  5143.        set html [fetch_html "0" 50]
  5144.        set output "\002GameRankings BEST Snes\002"
  5145.      }
  5146.      if {[string match -nocase "segacd" $input] == 1} {
  5147.        set html [fetch_html "0" 52]
  5148.        set output "\002GameRankings BEST Sega-CD\002"
  5149.      }
  5150.      if {[string match -nocase "gameboy" $input] == 1} {
  5151.        set html [fetch_html "0" 53]
  5152.        set output "\002GameRankings BEST GameBoy\002"
  5153.      }
  5154.      if {[string match -nocase "gbc" $input] == 1} {
  5155.        set html [fetch_html "0" 54]
  5156.        set output "\002GameRankings BEST GameBoy Color\002"
  5157.      }
  5158.      if {[string match -nocase "all" $input] == 1} {
  5159.        set html [fetch_html "0" 55]
  5160.        set output "\002GameRankings BEST -ALL-\002"
  5161.      }
  5162.      if {[string match -nocase "3ds" $input] == 1} {
  5163.        set html [fetch_html "0" 57]
  5164.        set output "\002GameRankings BEST 3DS\002"
  5165.      }
  5166.      if {[string match -nocase "mac" $input] == 1} {
  5167.        set html [fetch_html "1" 58]
  5168.        set output "\002GameRankings WORST MAC\002"
  5169.      }
  5170.  
  5171.      if {[string match -nocase "*http://www.gamespot.com/gamerankings/offline.html*" $html]} {
  5172.        append output "${incith::google::seperator}${::incith::google::error_modes}We're sorry, we are temporarily offline.  We'll be back as soon as possible."
  5173.        return $output
  5174.      }
  5175.      if {[string match -nocase "*Temporarily Unavailable*" $html]} {
  5176.        append output "${incith::google::seperator}${::incith::google::error_modes}GameRankings is Temporarily Unavailable."
  5177.        return $output
  5178.      }
  5179.      if {$output == ""} {
  5180.        return "${::incith::google::desc_modes}Sorry, that system is not supported! \[system = gc/pc/mac/ps2/ps3/wii/xbox/x360/3ds/ds/gba/psp/mobile/ngage/3d0/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: $::lastbind system"
  5181.      } else { set output "$::incith::google::total_modes$output$::incith::google::total_demodes" }
  5182.  
  5183.      regsub -all "(?:\t|\n|\r|\v)" $html "" html
  5184.      
  5185.      # remove the bold if it isn't desired.
  5186.      if {$incith::google::bold_descriptions == 0} {
  5187.        regsub -all -- "\002" $output {} output
  5188.      }
  5189.  
  5190.      # parse for results and loop until desired amount of results
  5191.      # is attempted to be reached if possible.
  5192.      while {$results < $incith::google::popular_results && $output != ""} {
  5193.        # grab date and game title and clear future html of it for looping
  5194.        if {[regexp -- {<col class="game" />.*?<tr.+?<td>.*?<td>(.*?)</td>.*?<a href=.+?">(.+?)</a>.*?<br />(.+?)</td><td>(.+?)<} $html - sys game pub date]} {
  5195.           regsub -- {><tr.*?<td>.*?</td></tr} $html "" html
  5196.           regsub -- {<nobr>} $date "" date
  5197.         }
  5198.  
  5199.         # if there's no desc, return or stop looping, depending
  5200.         if {![info exists game]} {
  5201.           if {$results == 0} {
  5202.             set reply "Sorry, no search results were found."
  5203.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5204.           } else {
  5205.             break
  5206.           }
  5207.         }
  5208.  
  5209.         # add the search result
  5210.         # add game to output if there is one
  5211.         if {[info exists game]} {
  5212.           if {[string match -nocase "all" $input] == 1} {
  5213.             append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 ($sys) by $pub (${date})$::incith::google::desc_demodes"
  5214.           } else {
  5215.             append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 by $pub (${date})$::incith::google::desc_demodes"
  5216.           }
  5217.           unset game; unset date
  5218.         }
  5219.         # increase the results, clear the variables for the next loop just in case
  5220.         incr results
  5221.       }
  5222.       # if we have nothing to send, we have no results :(
  5223.       if {$output == ""} {
  5224.         set output "${::incith::google::desc_modes}Sorry, found no results! \[system = gc/pc/ps2/ps3/wii/xbox/x360/ds/gba/psp/mobile/ngage/3do/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: !popular system"
  5225.       }
  5226.       return $output
  5227.     }
  5228.  
  5229.     # Recent Games
  5230.     # fetches games results from Gamerankings.
  5231.     # -speechless supplied
  5232.     #
  5233.     proc recent {input} {
  5234.  
  5235.       # lots of variables, keeping them clean is important.
  5236.       # borrowed mostly from my ebay proc above.
  5237.       ; set results 0 ; set output "" ; set tresult ""
  5238.       ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR ""
  5239.       ; set ebcCheck "" ; set html ""
  5240.      
  5241.       # redundant and messy, yes i know.. but it works, k
  5242.       # parses the query and reads html according to system desired.
  5243.  
  5244.       if {[string match -nocase "gc" $input] == 1} {
  5245.         set html [fetch_html "1" 30]
  5246.         set output "\002GameRankings WORST GameCube\002"
  5247.       }
  5248.       if {[string match -nocase "pc" $input] == 1} {
  5249.         set html [fetch_html "1" 31]
  5250.         set output "\002GameRankings WORST PC\002"
  5251.       }
  5252.       if {[string match -nocase "ps2" $input] == 1} {
  5253.         set html [fetch_html "1" 32]
  5254.         set output "\002GameRankings WORST PlayStation2\002"
  5255.       }
  5256.       if {[string match -nocase "ps3" $input] == 1} {
  5257.         set html [fetch_html "1" 33]
  5258.         set output "\002GameRankings WORST PlayStation3\002"
  5259.       }
  5260.       if {[string match -nocase "wii" $input] == 1} {
  5261.         set html [fetch_html "1" 34]
  5262.         set output "\002GameRankings WORST Wii\002"
  5263.       }
  5264.       if {[string match -nocase "xbox" $input] == 1} {
  5265.         set html [fetch_html "1" 35]
  5266.         set output "\002GameRankings WORST Xbox\002"
  5267.       }
  5268.       if {[string match -nocase "x360" $input] == 1} {
  5269.         set html [fetch_html "1" 36]
  5270.         set output "\002GameRankings WORST Xbox360\002"
  5271.       }
  5272.       if {[string match -nocase "ds" $input] == 1} {
  5273.         set html [fetch_html "1" 37]
  5274.         set output "\002GameRankings WORST NDS\002"
  5275.       }
  5276.       if {[string match -nocase "gba" $input] == 1} {
  5277.         set html [fetch_html "1" 38]
  5278.         set output "\002GameRankings WORST GBA\002"
  5279.       }
  5280.       if {[string match -nocase "psp" $input] == 1} {
  5281.         set html [fetch_html "1" 39]
  5282.         set output "\002GameRankings WORST PSP\002"
  5283.       }
  5284.       if {[string match -nocase "mobile" $input] == 1} {
  5285.         set html [fetch_html "1" 40]
  5286.         set output "\002GameRankings WORST Mobile\002"
  5287.       }
  5288.       if {[string match -nocase "ngage" $input] == 1} {
  5289.         set html [fetch_html "1" 41]
  5290.         set output "\002GameRankings WORST N-Gage\002"
  5291.       }
  5292.       if {[string match -nocase "3do" $input] == 1} {
  5293.         set html [fetch_html "1" 42]
  5294.         set output "\002GameRankings WORST 3D0\002"
  5295.       }
  5296.       if {[string match -nocase "dc" $input] == 1} {
  5297.         set html [fetch_html "1" 43]
  5298.         set output "\002GameRankings WORST Dreamcast\002"
  5299.       }
  5300.       if {[string match -nocase "gen" $input] == 1} {
  5301.         set html [fetch_html "1" 44]
  5302.         set output "\002GameRankings WORST Genesis\002"
  5303.       }
  5304.       if {[string match -nocase "jag" $input] == 1} {
  5305.         set html [fetch_html "1" 45]
  5306.         set output "\002GameRankings WORST Jaguar\002"
  5307.       }
  5308.       if {[string match -nocase "n64" $input] == 1} {
  5309.         set html [fetch_html "1" 46]
  5310.         set output "\002GameRankings WORST N64\002"
  5311.       }
  5312.       if {[string match -nocase "neo" $input] == 1} {
  5313.         set html [fetch_html "1" 47]
  5314.         set output "\002GameRankings WORST Neo-Geo\002"
  5315.       }
  5316.       if {[string match -nocase "ps1" $input] == 1} {
  5317.         set html [fetch_html "1" 48]
  5318.         set output "\002GameRankings WORST Playstation\002"
  5319.       }
  5320.       if {[string match -nocase "sat" $input] == 1} {
  5321.         set html [fetch_html "1" 49]
  5322.         set output "\002GameRankings WORST Saturn\002"
  5323.       }
  5324.       if {[string match -nocase "snes" $input] == 1} {
  5325.         set html [fetch_html "1" 50]
  5326.         set output "\002GameRankings WORST Snes\002"
  5327.       }
  5328.       if {[string match -nocase "segacd" $input] == 1} {
  5329.         set html [fetch_html "1" 52]
  5330.         set output "\002GameRankings WORST Sega-CD\002"
  5331.       }
  5332.       if {[string match -nocase "gameboy" $input] == 1} {
  5333.         set html [fetch_html "1" 53]
  5334.         set output "\002GameRankings WORST GameBoy\002"
  5335.       }
  5336.       if {[string match -nocase "gbc" $input] == 1} {
  5337.         set html [fetch_html "1" 54]
  5338.         set output "\002GameRankings WORST GameBoy Color\002"
  5339.       }
  5340.       if {[string match -nocase "all" $input] == 1} {
  5341.         set html [fetch_html "1" 55]
  5342.         set output "\002GameRankings WORST -ALL-\002"
  5343.       }
  5344.       if {[string match -nocase "3ds" $input] == 1} {
  5345.         set html [fetch_html "1" 57]
  5346.         set output "\002GameRankings WORST 3DS\002"
  5347.       }
  5348.       if {[string match -nocase "mac" $input] == 1} {
  5349.         set html [fetch_html "1" 58]
  5350.         set output "\002GameRankings WORST MAC\002"
  5351.       }
  5352.  
  5353.       if {[string match -nocase "*http://www.gamespot.com/gamerankings/offline.html*" $html]} {
  5354.         append output "${incith::google::seperator}${::incith::google::error_modes}We're sorry, we are temporarily offline.  We'll be back as soon as possible."
  5355.         return $output
  5356.       }
  5357.       if {[string match -nocase "*Temporarily Unavailable*" $html]} {
  5358.         append output "${incith::google::seperator}${::incith::google::error_modes}GameRankings is Temporarily Unavailable."
  5359.         return $output
  5360.       }
  5361.       if {$output == ""} {
  5362.         return "${::incith::google::desc_modes}Sorry, that system is not supported! \[system = gc/pc/mac/ps2/ps3/wii/xbox/x360/3ds/ds/gba/psp/mobile/ngage/3do/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: $::lastbind system"
  5363.       } else { set output "$::incith::google::total_modes$output$::incith::google::total_demodes" }
  5364.  
  5365.       regsub -all "(?:\t|\n|\r|\v)" $html "" html
  5366.  
  5367.       # remove the bold if it isn't desired.
  5368.       if {$incith::google::bold_descriptions == 0} {
  5369.         regsub -all -- "\002" $output {} output
  5370.       }
  5371.  
  5372.       # parse for results and loop until desired amount of results
  5373.       # is attempted to be reached if possible.
  5374.       while {$results < $incith::google::popular_results && $output != ""} {
  5375.      
  5376.         # grab date and game title and clear future html of it for looping
  5377.         if {[regexp -- {<col class="game" />.*?<tr.+?<td>.*?<td>(.*?)</td>.*?<a href=.+?">(.+?)</a>.*?<br />(.+?)</td><td>(.+?)<} $html - sys game pub date]} {
  5378.          regsub -- {><tr.*?<td>.*?</td></tr} $html "" html
  5379.          regsub -- {<nobr>} $date "" date
  5380.        }
  5381.  
  5382.        # if there's no desc, return or stop looping, depending
  5383.        if {![info exists game]} {
  5384.          if {$results == 0} {
  5385.            set reply "Sorry, no search results were found."
  5386.            return "$::incith::google::desc_modes$reply$::incith::google::desc_modes"
  5387.          } else {
  5388.            break
  5389.          }
  5390.        }
  5391.  
  5392.        # add the search result
  5393.        # add game to output if there is one
  5394.        if {[info exists game]} {
  5395.          if {[string match -nocase "all" $input] == 1} {
  5396.            append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 ($sys) by $pub (${date})$::incith::google::desc_demodes"
  5397.          } else {
  5398.            append output "${incith::google::seperator}$::incith::google::desc_modes\002${game}\002 by $pub (${date})$::incith::google::desc_demodes"
  5399.          }
  5400.          unset game; unset date
  5401.        }
  5402.        # increase the results, clear the variables for the next loop just in case
  5403.        incr results
  5404.      }
  5405.      # if we have nothing to send, we have no results :(
  5406.      if {$output == ""} {
  5407.        set output "${::incith::google::desc_modes}Sorry, found no results! \[system = gc/pc/ps2/ps3/wii/xbox/x360/ds/gba/psp/mobile/ngage/3d0/dc/gen/jag/n64/neo/ps1/sat/snes\] usage: !top system"
  5408.      }
  5409.      return "$output"
  5410.    }
  5411.  
  5412.    # Google Trends
  5413.    # fetches top search terms from google
  5414.    # -speechless supplied
  5415.    #
  5416.    proc trends {input} {
  5417.  
  5418.      # lots of variables, keeping them clean is important.
  5419.      ; set results 0 ; set output "" ; set tresult "" ; set no_results "" ; set no_search ""
  5420.  
  5421.      set html [fetch_html $input 13]
  5422.  
  5423.      # user input causing errors?
  5424.     if {[string match -nocase "*socketerrorabort*" $html]} {
  5425.            regsub {(.+?)\|} $html {} html
  5426.            return "${::incith::google::error_modes}Socket Error accessing '${html}' .. Does it exist?${::incith::google::error_demodes}"
  5427.     }
  5428.     if {[string match -nocase "*timeouterrorabort*" $html]} {
  5429.         return "${::incith::google::error_modes}Connection has timed out...${::incith::google::error_demodes}"
  5430.     }
  5431.  
  5432.      # give location results we are displaying.
  5433.      regexp -- {<table width=100%  cellpadding=2 cellspacing=0 bgcolor=#E5ECF9><tr><td>(.+?)</td>} $html - tresult
  5434.      if {$tresult != ""} { set output "$::incith::google::total_modes${tresult}$::incith::google::total_demodes${incith::google::seperator}" }
  5435.  
  5436.      # get what we call the no_search for any language.
  5437.      if {[string match "*system_down.html*" $html]} {
  5438.        set no_search "$::incith::google::error_modes\002Trends Error:\002 System appears to be down, try again later.$::incith::google::error_demodes"
  5439.      } else {
  5440.         if {[regexp -- {<br><br>(.+?)</p>} $html - no_search]} {
  5441.          regsub -- {<p>} $no_search { } no_search
  5442.        } else {
  5443.          if {![regexp -- {<ul><li>(.+?)</ul>} $html - no_search]} {
  5444.            regexp -- {</table><p>(.+?)</p>} $html - no_search
  5445.          }
  5446.        }
  5447.      }
  5448.  
  5449.      # remove the bold if it isn't desired.
  5450.      if {$incith::google::bold_descriptions == 0} {
  5451.        regsub -all -- "\002" $output {} output
  5452.      }
  5453.  
  5454.      # parse for results and loop until desired amount of results
  5455.      # is attempted to be reached if possible.
  5456.      while {$results < $incith::google::trends_results} {
  5457.        set link "$::incith::google::total_modes\002[expr $results + 1]\002$::incith::google::total_demodes"
  5458.        # grab our trend and cut it out
  5459.        regexp -- {<td class=num>.+?<a href=.+?>(.+?)</a>} $html {} desc
  5460.        regsub -- {<td class=num>.+?<a href=.+?>(.+?)</a>} $html "" html
  5461.        if {[info exists desc]} {
  5462.          append link " $incith::google::desc_modes$desc$::incith::google::desc_demodes"
  5463.        } else {
  5464.          if {$results == 0} {
  5465.            set reply "${no_search}"
  5466.            return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5467.          } else {
  5468.            break
  5469.          }
  5470.        }
  5471.  
  5472.        # add the search result
  5473.        # add game to output if there is one
  5474.        if {[info exists desc]} {
  5475.          append output "${link}${incith::google::split_char}"
  5476.        }
  5477.        # increase the results, clear the variables for the next loop just in case
  5478.        unset desc; unset link
  5479.        incr results
  5480.      }
  5481.      # if we have nothing to send, we have no results :(
  5482.      if {$output == ""} {
  5483.        set output "$::incith::google::desc_modes${no_search}$::incith::google::desc_demodes"
  5484.      }
  5485.      return [string trim $output $incith::google::split_char]
  5486.    }
  5487.  
  5488.    # Gamespot Game Review
  5489.    # fetches review results from gamespot searches.
  5490.    # -speechless supplied
  5491.    #
  5492.    proc rev {input} {
  5493.      global incithcookie
  5494.      # lots of variables, keeping them clean is important..
  5495.      ; set results "" ; set output "" ; set tresult ""; set inputb ""
  5496.      ; set ebcU "" ; set ebcI "" ; set ebcPR "" ; set review ""
  5497.      ; set us "?" ; set them "?" ; set you "?" ; set stats "" ; set vid ""
  5498.  
  5499.      regexp -nocase -- {^(.+?) @ (.+?)$} $input - input inputb
  5500.      
  5501.      # fetch the html
  5502.      set html [fetch_html $input 12]
  5503.      regsub -all {\\n} $html "" html
  5504.      if {[string match "*NO RESULTS RETURNED*" $html]} {
  5505.        set reply "${::incith::google::desc_modes}Sorry, no search results were found."
  5506.        return $reply
  5507.      }
  5508.  
  5509.      if {$inputb != ""} {
  5510.        while {$results == ""} {
  5511.          # this could break any second, its cumbersome and long..i know, but for now it works.
  5512.          regexp -- {<div class=\\"result_title\\">.*?<a href=\\"(.+?)\?tag=result.*?\\">(.+?)<\\/a>} $html - ebcU ebcI
  5513.          set ebcU [string map {"\\" ""} $ebcU]
  5514.          if {[string match -nocase "*\(${inputb}\)*" $ebcI] == 1} { set results "true" }
  5515.          if {$ebcU == $ebcPR} {
  5516.            regsub -all { } $input {%20} input
  5517.            return "${::incith::google::desc_modes}Sorry, game does not appear for that console when searching first page results. See for yourself @ http://www.gamespot.com/pages/search/index.php?qs=${input}#game"
  5518.           }
  5519.           regsub -- {<div class=\\"result_title\\">.*?<a href=\\".+?\\">.+?<\\/a>} $html "" html
  5520.           set ebcPR $ebcU
  5521.         }
  5522.       }
  5523.  
  5524.       # get url snippet where game review can be pulled
  5525.       if {$inputb == ""} {
  5526.         if {[regexp -- {<div class=\\"result_title\\">.*?<a href=\\"(.+?)\?tag=result.*?\\">(.+?)<\\/a>} $html - ebcU ebcI]} {
  5527.           set ebcU [string map {"\\" ""} $ebcU]
  5528.         }
  5529.       }
  5530.       # if no snippet there is nothing more to do
  5531.       if {$ebcU == "" } { return "${::incith::google::desc_modes}Sorry, no search results were found." }
  5532.       # grab game review
  5533.       set query "${ebcU}"
  5534.       set ebcU ""; set ebcI ""; set ebcPR ""
  5535.       regexp -- {(.+?)&q=} $query {} query
  5536.       regexp -- {(.+?)\?q=} $query {} query
  5537.       if {![string match "*http*" $query]} {
  5538.         set query "http://www.gamespot.com${query}"
  5539.       }
  5540.  
  5541.       # beware, changing the useragent will result in differently formatted html from Google.
  5542.       set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  5543.       set http [::http::config -useragent $ua]
  5544.       set http [::http::geturl $query -headers $::incith_hdr -timeout [expr 1000 * 10]]
  5545.       if {$::incith::google::debug > 0 } {
  5546.         putserv "privmsg $incith::google::debugnick :\002url \([::http::ncode $http]\):\002 $query"
  5547.       }
  5548.       upvar #0 $http state
  5549.       set html [ungzip [::http::data $http] $state(meta)]
  5550.       ::http::cleanup $http
  5551.       # strip the html down
  5552.         regsub -all "\t" $html "" html
  5553.         regsub -all "\n" $html "" html
  5554.         regsub -all "\r" $html "" html
  5555.         regsub -all "\v" $html "" html
  5556.         regsub -all "<script.*?>.*?</script>" $html "" html
  5557.       # DEBUG DEBUG                    
  5558.       set junk [open "ig-debug.txt" w]
  5559.       puts $junk $html
  5560.       close $junk
  5561.  
  5562.       if {![regexp -- {<div class="module_title_wrap">(.*?)</div></div>} $html - name]} {
  5563.         regexp -- {<title>(.+?) \- } $html {} name
  5564.         # sometimes our game and system cut isn't pretty this cleans it up
  5565.         regexp -- {(.+?)<.+?title} $name - name
  5566.         set name [string trim $name]
  5567.       } else {
  5568.         regsub -- {</h1>} $name " " name
  5569.         regsub -all -- {<.*?>} $name "" name
  5570.     }
  5571.  
  5572.       if {[regexp -- {\&tag=scoresummary%3Bgs-score">(.+?)<} $html - us]} {
  5573.         regsub -- {<.*?>} $us "" us
  5574.      }
  5575.      if {[regexp -- {\&tag=scoresummary%3Bcritic-score">(.+?)<} $html - them]} {
  5576.         regsub -- {<.*?>} $them "" them
  5577.       }
  5578.       regexp -- {\?tag=scoresummary%3Buser-score">(.+?)<} $html - you
  5579.      if {[regexp -- {<ul class="stats">(.+?)<div class="actions">} $html - stats]} {
  5580.        regsub {<div class="label">Top 5 User Tags\:.+?</ol>} $stats "" stats
  5581.        regsub {<div class="desc">.+?</ul>} $stats "" stats
  5582.        regsub {<li class="stat universe">.+?</ul>} $stats "" stats
  5583.        regsub -all {<.+?>} $stats "" stats
  5584.        while {[string match "*  *" $stats]} {
  5585.          regsub -all -- {  } $stats " " stats
  5586.        }
  5587.        regsub {More Info Game Stats} $stats "» «" stats
  5588.        regsub {Tracking\:.+?Wish It&raquo;} $stats "» «" stats
  5589.        regsub -all {&raquo;} $stats "» «" stats
  5590.        regsub -all {/\s»} $stats "»" stats
  5591.        regsub -all {«\s/} $stats "«" stats
  5592.      }
  5593.      if {[regexp {<p class="review deck".*?>(.+?)</p>} $html - review]} {
  5594.        regsub -all -- {<.*?>} $review "" review
  5595.        set review " « $review »"
  5596.      } elseif {[regexp {<p class="product deck".*?>(.+?)</p>} $html - review]} {
  5597.        regsub -all -- {<.*?>} $review "" review
  5598.        set review " « $review »"
  5599.      }
  5600.      if {[regexp -- {<ul class="videos">.+?<a href="(.+?)".*?">(.+?)</a>} $html - vurl vid]} {
  5601.         if {[regexp -nocase -- {a href=""} $vid]} {
  5602.           if {[regexp -- {<div class="module videos">.*?<div class="head">.*?href="(.*?)">(.*?)</a>} $html - vurl vid]} {
  5603.             set vurl "http://www.gamespot.com$vurl"
  5604.           }
  5605.         } else {
  5606.           regexp -- {^(.+?)?tag=;} $vurl - vurl
  5607.         }
  5608.         if {[string match "/" [string index $vurl 0]]} { set vurl "http://www.gamespot.com$vurl" }
  5609.         set vid "$incith::google::desc_modes ... \002Video:\002 $vid$::incith::google::desc_demodes$::incith::google::break$::incith::google::link_modes$vurl$::incith::google::link_demodes"
  5610.       }
  5611.       set desc "[descdecode "${name} \(us\002$us\002 them\002$them\002 you\002$you\002\) «$stats»$review"]"
  5612.       # make sure we have something to send
  5613.       set output "$::incith::google::desc_modes${desc}$::incith::google::desc_demodes$::incith::google::break$::incith::google::link_modes${query}$::incith::google::link_demodes$vid"
  5614.       return $output
  5615.     }
  5616.  
  5617.     # IGN
  5618.     # fetches games results from ign searches.
  5619.     # -speechless supplied
  5620.     #
  5621.     proc ign {input} {
  5622.  
  5623.       # lots of variables, keeping them clean is important.
  5624.       # borrowed mostly from my ebay proc above.
  5625.       ; set results 0 ; set output "" ; set tresult ""
  5626.       ; set ebcU "" ; set ebcI "" ; set ebcBid "" ; set ebcPR ""
  5627.       ; set ebcCheck "" ; set match ""
  5628.  
  5629.       # fetch the html
  5630.       set html [fetch_html $input 26]
  5631.  
  5632.       if {$html == ""} { return "${::incith::google::error_modes}IGN search page appears to be blank... No results maybe?!" }
  5633.  
  5634.       # give results an output header with result tally.
  5635.       # regexp -- {All Products \(([,0-9]{1,})\)<br/>} $html - match
  5636.       set match "iGN"
  5637.  
  5638.       # format output according to variables.
  5639.       if {$match != ""} {
  5640.         set output "$::incith::google::total_modes\002${match}\002 results$::incith::google::total_demodes${incith::google::seperator}"
  5641.         if {$incith::google::bold_descriptions == 0} {
  5642.           regsub -all -- "\002" $output {} output
  5643.         }
  5644.       } else {
  5645.         regexp -- {<p.*?class="searchResultTitle">(.+?)</p>} $html - match
  5646.         set output "${match}$::incith::google::seperator"
  5647.       }
  5648.  
  5649.       if {[regexp -- {<p class="searchResultTitle".+?<strong>(.+?)<br} $html - no_search]} {
  5650.         return $no_search
  5651.       }
  5652.  
  5653.       # parse the html
  5654.       while {$results < $incith::google::ign_results} {
  5655.         # this could break any second, its cumbersome and long..i know, but for now it works.
  5656.         regexp -- {<h3 class="game-title"><a href="(.*?)">(.*?)</h3>} $html - ebcU ebcI
  5657.         if {![regexp -- {class="publisherLink">(.*?)</a>(.*?)</p>} $html - ebcBid desc]} {
  5658.           regexp -- {<div id="articleType"><strong>(.+?)</strong>} $html - ebcBid
  5659.           set desc ""
  5660.         } else {
  5661.           set desc [string trim $desc "- "]
  5662.           regsub -all -- {\s+} $desc " " desc
  5663.           if {[string length $desc]} {
  5664.             set desc " - $desc"
  5665.           }
  5666.         }
  5667.         regsub -- {<h3 class="game-title">(.+?)</div>} $html "" html
  5668.  
  5669.         # check results are more than 0, return or stop looping, depending
  5670.         if {![string length $ebcU]} {
  5671.           if {$results == 0} {
  5672.             regexp -nocase -- {<p class="searchFail">(.*?)</p>} $html - reply
  5673.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5674.           } else {
  5675.             break
  5676.           }
  5677.         }
  5678.  
  5679.         # this needs to be done for user formatting of links and descriptions.
  5680.         set link "${ebcU}"
  5681.  
  5682.         # prevent duplicate results is mostly useless here, but will at least
  5683.         # ensure that we don't get the exact same article.
  5684.         if {[string match "*$link*" $output] == 1} {
  5685.          break
  5686.         }
  5687.  
  5688.         # ign clutters with excess spacing to make parsing hard
  5689.         # this is a quick and dirty way to get through the mud.
  5690.  
  5691.         #clean up messy parsing.
  5692.         regsub -all {<script type=.+?script>} $ebcBid {} ebcBid
  5693.         regsub -all -- {<(.+?)>} $ebcBid {} ebcBid
  5694.         while {[string match "*  *" $ebcBid]} {
  5695.           regsub -all -- {  } $ebcBid " " ebcBid
  5696.         }
  5697.         set ebcBid [string trim $ebcBid]
  5698.         regexp -- {^(.*?)</a>(.*?)$} $ebcI - ebcI plat
  5699.         regexp -- {<span class="platform default">(.*?)</span>} $ebcI - plat
  5700.         regexp -- {^(.*?)</a>} $ebcI - ebcI
  5701.         regsub -all -- {\s+} $plat { } plat
  5702.         # set formatting.
  5703.         set desc "${ebcI} ([string totitle $plat] by ${ebcBid})$desc"
  5704.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  5705.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  5706.  
  5707.         # add the search result
  5708.         if {$incith::google::link_only == 1} {
  5709.           append output "${link}${incith::google::seperator}"
  5710.         } else {
  5711.           append output "[descdecode ${desc}]$::incith::google::break${link}${incith::google::seperator}"
  5712.         }
  5713.  
  5714.         # increase the results, clear the variables for the next loop just in case
  5715.         unset link ; set ebcCheck ""
  5716.         incr results
  5717.       }
  5718.  
  5719.       # make sure we have something to send
  5720.       if {[info exists output] == 0} {
  5721.         set reply "Sorry, no search results were found."
  5722.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5723.       }
  5724.       return $output
  5725.     }
  5726.  
  5727.     # GameSpot
  5728.     # fetches games results from gamespot searches.
  5729.     # -speechless supplied
  5730.     #
  5731.     proc gamespot {input} {
  5732.      
  5733.       # lots of variables, keeping them clean is important.
  5734.       # borrowed mostly from my ebay proc above.
  5735.       ; set results 0 ; set output "" ; set tresult ""
  5736.       ; set type "" ; set name ""
  5737.       ; set details "" ; set deck ""
  5738.  
  5739.       # fetch the html
  5740.       set html [fetch_html $input 12]
  5741.       regsub -all {\\n} $html "" html
  5742.  
  5743.       # set up gamespot results header so results can be appended to it.
  5744.       regexp -- {,"num_results"\:"(.+?)"} $html {} tresult
  5745.       set tresult [string trim $tresult]
  5746.       # format output according to variables.
  5747.       if {$incith::google::total_results != 0} {
  5748.         set output "$::incith::google::total_modes\002[string trim ${tresult}]\002 games$::incith::google::total_demodes${incith::google::seperator}"
  5749.         if {$incith::google::bold_descriptions == 0} {
  5750.           regsub -all -- "\002" $output {} output
  5751.         }
  5752.       }
  5753.  
  5754.       # parse the html
  5755.       while {$results < $incith::google::gamespot_results} {
  5756.         # this could break any second, its cumbersome and long..i know, but for now it works.
  5757.         if {[regexp -- {<div class=\\"result_title\\">(.*?)<a href=\\"(.+?)\\">(.*?)<\\/a>.*?<div class=\\"details\\">(.*?)<\\/div>.+?<div class=\\"deck\\">(.*?)<\\/div>} $html - type link name details deck]} {
  5758.           regexp -- {^(.+?)\?tag=result} $link - link
  5759.           if {[string length $deck] > 0} {set deck " - [string trim $deck]"}
  5760.           regsub -- {<div class=\\"result_title\\">.+?<div class=\\"deck\\">.+?<\\/div>} $html "" html
  5761.           set details [string map {" | " "/"} $details]
  5762.           set link [string map {"\\" ""} $link]
  5763.           set desc "\002[string trim $type] [string trim $name]\002 \([string trim $details]\)$deck"
  5764.         }
  5765.         # check results are more than 0, return or stop looping, depending
  5766.         if {![info exists link]} {
  5767.           if {$results == 0} {
  5768.             set reply "Sorry, no search results were found."
  5769.             return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5770.           } else {
  5771.             break
  5772.           }
  5773.         }
  5774.         regsub -all {<.+?>} $desc "" desc
  5775.         # prevent duplicate results is mostly useless here, but will at least
  5776.         # ensure that we don't get the exact same article.
  5777.         if {[string match "*$link*" $output] == 1} {
  5778.          break
  5779.         }
  5780.  
  5781.         if {[info exists desc]} { set desc "$incith::google::desc_modes[string trim $desc]$incith::google::desc_demodes" }
  5782.         if {[info exists link]} { set link "$incith::google::link_modes[string trim $link]$incith::google::link_demodes" }
  5783.  
  5784.         # add the search result
  5785.         if {$incith::google::link_only == 1} {
  5786.           append output "${link}${incith::google::seperator}"
  5787.         } else {
  5788.           append output "${desc}$::incith::google::break${link}${incith::google::seperator}"
  5789.         }
  5790.  
  5791.         # increase the results, clear the variables for the next loop just in case
  5792.         unset link ; set name "" ; set deck "" ; set type "" ; set details ""
  5793.         incr results
  5794.       }
  5795.  
  5796.       # make sure we have something to send
  5797.       if {[info exists output] == 0} {
  5798.         set reply "Sorry, no search results were found."
  5799.         return "$::incith::google::desc_modes$reply$::incith::google::desc_demodes"
  5800.       }
  5801.       return $output
  5802.     }
  5803.  
  5804.     # TriggerBot
  5805.     # Displays all the triggers this scripts is capable of
  5806.     # explaining syntax, and also will let user know if trigger
  5807.     # is disabled or how many results are available.
  5808.     # -speechless supplied
  5809.     #
  5810.  
  5811.     proc helpbot {nick input} {
  5812.       set temp "" ; set output "" ; set num 0 ; set all 0
  5813.       set item "" ; set found ""
  5814.       if {[string tolower $input] == [lindex [split $incith::google::helplist " "] 0]} { set all 1 ; set found "all" }
  5815.       if {$all == 0} {
  5816.         foreach item [split $incith::google::helplist] {
  5817.           if {[string tolower $input] == $item} { set found $item }
  5818.         }
  5819.         if {$found == ""} {
  5820.            foreach item [split $incith::google::helplist " "] {
  5821.              append temp "${item},"
  5822.            }
  5823.            set temp [string trimright $temp ","]
  5824.            return "${incith::google::helpmsg1} ${temp}"
  5825.         }
  5826.       }
  5827.       puthelp "NOTICE $nick :--> Bot triggers available:"
  5828.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 1]} {
  5829.         foreach trig [split $incith::google::google_binds " "] {
  5830.           append temp "${incith::google::command_char}${trig},"
  5831.         }
  5832.         set temp [string trimright $temp ","]
  5833.         if {$incith::google::search_results > 0} {
  5834.           set item "${incith::google::helpmsg3}${incith::google::search_results}${incith::google::helpmsg4}"
  5835.         } else {
  5836.           set item "${incith::google::helpmsg2}"
  5837.         }
  5838.         puthelp "NOTICE $nick :${temp} ${incith::google::help1} ${item}"
  5839.       }
  5840.       set temp ""
  5841.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 2]} {
  5842.         foreach trig [split $incith::google::image_binds " "] {
  5843.           append temp "${incith::google::command_char}${trig},"
  5844.         }
  5845.         set temp [string trimright $temp ","]
  5846.         if {$incith::google::image_results > 0} {
  5847.           set item "${incith::google::helpmsg3}${incith::google::image_results}${incith::google::helpmsg4}"
  5848.         } else {
  5849.           set item "${incith::google::helpmsg2}"
  5850.         }
  5851.         puthelp "NOTICE $nick :${temp} ${incith::google::help2} ${item}"
  5852.       }
  5853.       set temp ""
  5854.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 3]} {
  5855.         foreach trig [split $incith::google::group_binds " "] {
  5856.           append temp "${incith::google::command_char}${trig},"
  5857.         }
  5858.         set temp [string trimright $temp ","]
  5859.         if {$incith::google::group_results > 0} {
  5860.           set item "${incith::google::helpmsg3}${incith::google::group_results}${incith::google::helpmsg4}"
  5861.         } else {
  5862.           set item "${incith::google::helpmsg2}"
  5863.         }
  5864.         puthelp "NOTICE $nick :${temp} ${incith::google::help3} ${item}"
  5865.       }
  5866.       set temp ""
  5867.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 4]} {
  5868.         foreach trig [split $incith::google::news_binds " "] {
  5869.           append temp "${incith::google::command_char}${trig},"
  5870.         }
  5871.         set temp [string trimright $temp ","]
  5872.         if {$incith::google::news_results > 0} {
  5873.           set item "${incith::google::helpmsg3}${incith::google::news_results}${incith::google::helpmsg4}"
  5874.         } else {
  5875.           set item "${incith::google::helpmsg2}"
  5876.         }
  5877.         puthelp "NOTICE $nick :${temp} ${incith::google::help4} ${item}"
  5878.       }
  5879.       set temp ""
  5880.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 5]} {
  5881.         foreach trig [split $incith::google::local_binds " "] {
  5882.           append temp "${incith::google::command_char}${trig},"
  5883.         }
  5884.         set temp [string trimright $temp ","]
  5885.         if {$incith::google::local_results > 0} {
  5886.           set item "${incith::google::helpmsg3}${incith::google::local_results}${incith::google::helpmsg4}"
  5887.         } else {
  5888.           set item "${incith::google::helpmsg2}"
  5889.         }
  5890.         puthelp "NOTICE $nick :${temp} ${incith::google::help5} ${item}"
  5891.       }
  5892.       set temp ""
  5893.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 6]} {
  5894.         foreach trig [split $incith::google::print_binds " "] {
  5895.           append temp "${incith::google::command_char}${trig},"
  5896.         }
  5897.         set temp [string trimright $temp ","]
  5898.         if {$incith::google::print_results > 0} {
  5899.           set item "${incith::google::helpmsg3}${incith::google::print_results}${incith::google::helpmsg4}"
  5900.         } else {
  5901.           set item "${incith::google::helpmsg2}"
  5902.         }
  5903.         puthelp "NOTICE $nick :${temp} ${incith::google::help6} ${item}"
  5904.       }
  5905.       set temp ""
  5906.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 7]} {
  5907.         foreach trig [split $incith::google::video_binds " "] {
  5908.           append temp "${incith::google::command_char}${trig},"
  5909.         }
  5910.         set temp [string trimright $temp ","]
  5911.         if {$incith::google::video_results > 0} {
  5912.           set item "${incith::google::helpmsg3}${incith::google::video_results}${incith::google::helpmsg4}"
  5913.         } else {
  5914.           set item "${incith::google::helpmsg2}"
  5915.         }
  5916.         puthelp "NOTICE $nick :${temp} ${incith::google::help7} ${item}"
  5917.       }
  5918.       set temp ""
  5919.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 8]} {
  5920.         foreach trig [split $incith::google::fight_binds " "] {
  5921.           append temp "${incith::google::command_char}${trig},"
  5922.         }
  5923.         set temp [string trimright $temp ","]
  5924.         if {$incith::google::google_fight > 0} {
  5925.           set item "${incith::google::helpmsg3}${incith::google::google_fight}${incith::google::helpmsg4}"
  5926.         } else {
  5927.           set item "${incith::google::helpmsg2}"
  5928.         }
  5929.         puthelp "NOTICE $nick :${temp} ${incith::google::help8} ${item}"
  5930.       }
  5931.       set temp ""
  5932.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 9]} {
  5933.         foreach trig [split $incith::google::youtube_binds " "] {
  5934.           append temp "${incith::google::command_char}${trig},"
  5935.         }
  5936.         set temp [string trimright $temp ","]
  5937.         if {$incith::google::youtube_results > 0} {
  5938.           set item "${incith::google::helpmsg3}${incith::google::youtube_results}${incith::google::helpmsg4}"
  5939.         } else {
  5940.           set item "${incith::google::helpmsg2}"
  5941.         }
  5942.         puthelp "NOTICE $nick :${temp} ${incith::google::help9} ${item}"
  5943.       }
  5944.       set temp ""
  5945.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 10]} {
  5946.         foreach trig [split $incith::google::trans_binds " "] {
  5947.           append temp "${incith::google::command_char}${trig},"
  5948.         }
  5949.         set temp [string trimright $temp ","]
  5950.         if {$incith::google::trans_results > 0} {
  5951.           set item "${incith::google::helpmsg3}${incith::google::trans_results}${incith::google::helpmsg4}"
  5952.         } else {
  5953.           set item "${incith::google::helpmsg2}"
  5954.         }
  5955.         puthelp "NOTICE $nick :${temp} ${incith::google::help10} ${item}"
  5956.       }
  5957.       set temp ""
  5958.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 11]} {
  5959.         foreach trig [split $incith::google::gamespot_binds " "] {
  5960.           append temp "${incith::google::command_char}${trig},"
  5961.         }
  5962.         set temp [string trimright $temp ","]
  5963.         if {$incith::google::gamespot_results > 0} {
  5964.           set item "${incith::google::helpmsg3}${incith::google::gamespot_results}${incith::google::helpmsg4}"
  5965.         } else {
  5966.           set item "${incith::google::helpmsg2}"
  5967.         }
  5968.         puthelp "NOTICE $nick :${temp} ${incith::google::help11} ${item}"
  5969.       }
  5970.       set temp ""
  5971.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 12]} {
  5972.         foreach trig [split $incith::google::gamefaq_binds " "] {
  5973.           append temp "${incith::google::command_char}${trig},"
  5974.         }
  5975.         set temp [string trimright $temp ","]
  5976.         if {$incith::google::gamefaq_results > 0} {
  5977.           set item "${incith::google::helpmsg3}${incith::google::gamefaq_results}${incith::google::helpmsg4}"
  5978.         } else {
  5979.           set item "${incith::google::helpmsg2}"
  5980.         }
  5981.         puthelp "NOTICE $nick :${temp} ${incith::google::help12} ${item}"
  5982.       }
  5983.       set temp ""
  5984.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 13]} {
  5985.         foreach trig [split $incith::google::blog_binds " "] {
  5986.           append temp "${incith::google::command_char}${trig},"
  5987.         }
  5988.         set temp [string trimright $temp ","]
  5989.         if {$incith::google::blog_results > 0} {
  5990.           set item "${incith::google::helpmsg3}${incith::google::blog_results}${incith::google::helpmsg4}"
  5991.         } else {
  5992.           set item "${incith::google::helpmsg2}"
  5993.         }
  5994.         puthelp "NOTICE $nick :${temp} ${incith::google::help13} ${item}"
  5995.       }
  5996.       set temp ""
  5997.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 14]} {
  5998.         foreach trig [split $incith::google::ebay_binds " "] {
  5999.           append temp "${incith::google::command_char}${trig},"
  6000.         }
  6001.         set temp [string trimright $temp ","]
  6002.         if {$incith::google::ebay_results > 0} {
  6003.           set item "${incith::google::helpmsg3}${incith::google::ebay_results}${incith::google::helpmsg4}"
  6004.         } else {
  6005.           set item "${incith::google::helpmsg2}"
  6006.         }
  6007.         puthelp "NOTICE $nick :${temp} ${incith::google::help14} ${item}"
  6008.       }
  6009.       set temp ""
  6010.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 15]} {
  6011.         foreach trig [split $incith::google::efight_binds " "] {
  6012.           append temp "${incith::google::command_char}${trig},"
  6013.         }
  6014.         set temp [string trimright $temp ","]
  6015.         if {$incith::google::google_fight > 0} {
  6016.           set item "${incith::google::helpmsg3}${incith::google::google_fight}${incith::google::helpmsg4}"
  6017.         } else {
  6018.           set item "${incith::google::helpmsg2}"
  6019.         }
  6020.         puthelp "NOTICE $nick :${temp} ${incith::google::help15} ${item}"
  6021.       }
  6022.       set temp ""
  6023.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 16]} {
  6024.         foreach trig [split $incith::google::wiki_binds " "] {
  6025.           append temp "${incith::google::command_char}${trig},"
  6026.         }
  6027.         set temp [string trimright $temp ","]
  6028.         if {$incith::google::wiki_results > 0} {
  6029.           set item "${incith::google::helpmsg3}${incith::google::wiki_results}${incith::google::helpmsg4}"
  6030.         } else {
  6031.           set item "${incith::google::helpmsg2}"
  6032.         }
  6033.         puthelp "NOTICE $nick :${temp} ${incith::google::help16} ${item}"
  6034.       }
  6035.       set temp ""
  6036.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 17]} {
  6037.         foreach trig [split $incith::google::wikimedia_binds " "] {
  6038.           append temp "${incith::google::command_char}${trig},"
  6039.         }
  6040.         set temp [string trimright $temp ","]
  6041.         if {$incith::google::wikimedia_results > 0} {
  6042.           set item "${incith::google::helpmsg3}${incith::google::wikimedia_results}${incith::google::helpmsg4}"
  6043.         } else {
  6044.           set item "${incith::google::helpmsg2}"
  6045.         }
  6046.         puthelp "NOTICE $nick :${temp} ${incith::google::help17} ${item}"
  6047.       }
  6048.       set temp ""
  6049.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 18]} {
  6050.         foreach trig [split $incith::google::locate_binds " "] {
  6051.           append temp "${incith::google::command_char}${trig},"
  6052.         }
  6053.         set temp [string trimright $temp ","]
  6054.         if {$incith::google::locate_results > 0} {
  6055.           set item "${incith::google::helpmsg3}${incith::google::locate_results}${incith::google::helpmsg4}"
  6056.         } else {
  6057.           set item "${incith::google::helpmsg2}"
  6058.         }
  6059.         puthelp "NOTICE $nick :${temp} ${incith::google::help18} ${item}"
  6060.       }
  6061.       set temp ""
  6062.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 19]} {
  6063.         foreach trig [split $incith::google::rev_binds " "] {
  6064.           append temp "${incith::google::command_char}${trig},"
  6065.         }
  6066.         set temp [string trimright $temp ","]
  6067.         if {$incith::google::rev_results > 0} {
  6068.           set item "${incith::google::helpmsg3}${incith::google::rev_results}${incith::google::helpmsg4}"
  6069.         } else {
  6070.           set item "${incith::google::helpmsg2}"
  6071.         }
  6072.         puthelp "NOTICE $nick :${temp} ${incith::google::help19} ${item}"
  6073.       }
  6074.       set temp ""
  6075.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 20]} {
  6076.         foreach trig [split $incith::google::mininova_binds " "] {
  6077.           append temp "${incith::google::command_char}${trig},"
  6078.         }
  6079.         set temp [string trimright $temp ","]
  6080.         if {$incith::google::mininova_results > 0} {
  6081.           set item "${incith::google::helpmsg3}${incith::google::mininova_results}${incith::google::helpmsg4}"
  6082.         } else {
  6083.           set item "${incith::google::helpmsg2}"
  6084.         }
  6085.         puthelp "NOTICE $nick :${temp} ${incith::google::help20} ${item}"
  6086.       }
  6087.       set temp ""
  6088.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 21]} {
  6089.         foreach trig [split $incith::google::recent_binds " "] {
  6090.           append temp "${incith::google::command_char}${trig},"
  6091.         }
  6092.         set temp [string trimright $temp ","]
  6093.         if {$incith::google::recent_results > 0} {
  6094.           set item "${incith::google::helpmsg3}${incith::google::recent_results}${incith::google::helpmsg4}"
  6095.         } else {
  6096.           set item "${incith::google::helpmsg2}"
  6097.         }
  6098.         puthelp "NOTICE $nick :${temp} ${incith::google::help21} ${item}"
  6099.       }
  6100.       set temp ""
  6101.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 22]} {
  6102.         foreach trig [split $incith::google::popular_binds " "] {
  6103.           append temp "${incith::google::command_char}${trig},"
  6104.         }
  6105.         set temp [string trimright $temp ","]
  6106.         if {$incith::google::popular_results > 0} {
  6107.           set item "${incith::google::helpmsg3}${incith::google::popular_results}${incith::google::helpmsg4}"
  6108.         } else {
  6109.           set item "${incith::google::helpmsg2}"
  6110.         }
  6111.         puthelp "NOTICE $nick :${temp} ${incith::google::help22} ${item}"
  6112.       }
  6113.       set temp ""
  6114.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 23]} {
  6115.         foreach trig [split $incith::google::daily_binds " "] {
  6116.           append temp "${incith::google::command_char}${trig},"
  6117.         }
  6118.         set temp [string trimright $temp ","]
  6119.         if {$incith::google::daily_results > 0} {
  6120.           set item "${incith::google::helpmsg3}${incith::google::daily_results}${incith::google::helpmsg4}"
  6121.         } else {
  6122.           set item "${incith::google::helpmsg2}"
  6123.         }
  6124.         puthelp "NOTICE $nick :${temp} ${incith::google::help23} ${item}"
  6125.       }
  6126.       set temp ""
  6127.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 24]} {
  6128.         foreach trig [split $incith::google::ign_binds " "] {
  6129.           append temp "${incith::google::command_char}${trig},"
  6130.         }
  6131.         set temp [string trimright $temp ","]
  6132.         if {$incith::google::ign_results > 0} {
  6133.           set item "${incith::google::helpmsg3}${incith::google::ign_results}${incith::google::helpmsg4}"
  6134.         } else {
  6135.           set item "${incith::google::helpmsg2}"
  6136.         }
  6137.         puthelp "NOTICE $nick :${temp} ${incith::google::help24} ${item}"
  6138.       }
  6139.       set temp ""
  6140.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 25]} {
  6141.         foreach trig [split $incith::google::myspacevids_binds " "] {
  6142.           append temp "${incith::google::command_char}${trig},"
  6143.         }
  6144.         set temp [string trimright $temp ","]
  6145.         if {$incith::google::myspacevids_results > 0} {
  6146.           set item "${incith::google::helpmsg3}${incith::google::myspacevids_results}${incith::google::helpmsg4}"
  6147.         } else {
  6148.           set item "${incith::google::helpmsg2}"
  6149.         }
  6150.         puthelp "NOTICE $nick :${temp} ${incith::google::help25} ${item}"
  6151.       }
  6152.       set temp ""
  6153.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 26]} {
  6154.         foreach trig [split $incith::google::trends_binds " "] {
  6155.           append temp "${incith::google::command_char}${trig},"
  6156.         }
  6157.         set temp [string trimright $temp ","]
  6158.         if {$incith::google::trends_results > 0} {
  6159.           set item "${incith::google::helpmsg3}${incith::google::trends_results}${incith::google::helpmsg4}"
  6160.         } else {
  6161.           set item "${incith::google::helpmsg2}"
  6162.         }
  6163.         puthelp "NOTICE $nick :${temp} ${incith::google::help26} ${item}"
  6164.       }
  6165.       set temp ""
  6166.       if {$found == "all" || $found == [lindex [split $incith::google::helplist " "] 27]} {
  6167.         foreach trig [split $incith::google::scholar_binds " "] {
  6168.           append temp "${incith::google::command_char}${trig},"
  6169.         }
  6170.         set temp [string trimright $temp ","]
  6171.         if {$incith::google::scholar_results > 0} {
  6172.           set item "${incith::google::helpmsg3}${incith::google::image_results}${incith::google::helpmsg4}"
  6173.         } else {
  6174.           set item "${incith::google::helpmsg2}"
  6175.         }
  6176.         puthelp "NOTICE $nick :${temp} ${incith::google::help27} ${item}"
  6177.       }
  6178.     }
  6179.      
  6180.     # FETCH_HTML
  6181.     # fetches html for the various *.google.com sites
  6182.     #
  6183.     proc fetch_html {input switch} {
  6184.     global incithcharset
  6185.     global incithcookie
  6186.     set country ""
  6187. #-->  # Begin urlencoding kludge
  6188.       if {($switch < 15) || ($switch > 23) && ($switch != 28) && ($switch !=29) && ($switch !=56) && ($switch !=58) && ($switch !=59)} {
  6189.         set helps $input
  6190.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $input - country input
  6191.         # this is my input encoding hack, this will convert input before it goes
  6192.         # out to be queried.
  6193.         if {$incith::google::encoding_conversion_input > 0 && $country != "" } {
  6194.           set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  6195.           if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} { set input [encoding convertfrom $encoding_found $input] }
  6196.         } else { set encoding_found "" }
  6197.         set input [urlencode $input 0 "utf-8"]
  6198.         set country "" ;#reset country and input
  6199.       }
  6200. #<--  # End urlencoding kludge
  6201.  
  6202.       # GOOGLE
  6203.       if {$switch == 1} {
  6204.         # make it so people can search their country
  6205.         set country ""
  6206.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6207.         if {$country == ""} {
  6208.           set country "${incith::google::google_country}"
  6209.           set flavor "search"
  6210.         } else {
  6211.           if {[string match */* $country]} {
  6212.             if {![string length [set flavor [join [lrange [split $country /] 1 end] /]]]} {
  6213.               set flavor "search"
  6214.             }
  6215.             set country [lindex [split $country /] 0]
  6216.           } else { set flavor "search" }
  6217.         }
  6218.         if {[string equal -nocase "intl" [lindex [split $flavor /] 0]]} {
  6219.           set lng [lindex [split $flavor /] 1]
  6220.           set uselang 1
  6221.         }
  6222.         # we don't want 'define:+<search>', so we'll just remove the space if there is one.
  6223.         regsub -nocase -- {^define:\s*} $input {define:} input
  6224.         # spell after define so 'spell: define: foo' doesn't turn into a define lookup
  6225.         if {[string match -nocase "spell%3a*" $input] == 1} {
  6226.           regsub -nocase -- {^spell%3a\s*} $input {} input
  6227.           set spell "&spell=1"
  6228.         } else {
  6229.           set spell ""
  6230.         }
  6231.         if {[info exists uselang]} {
  6232.           set query "http://www.google.${country}/search?hl=${lng}&q=${input}&safe=${incith::google::safe_search}&lr=lang_${incith::google::language}&ie=utf-8${spell}&nfpr=1"
  6233.         } else {
  6234.           set query "http://www.google.${country}/${flavor}?q=${input}&safe=${incith::google::safe_search}&lr=lang_${incith::google::language}&ie=utf-8${spell}&nfpr=1"
  6235.         }
  6236.       # IMAGES
  6237.       } elseif {$switch == 2} {
  6238.         # make it so people can search their country
  6239.         set country ""
  6240.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6241.         if {$country == ""} {
  6242.           set country "${incith::google::google_country}"
  6243.         }
  6244.         set query "http://images.google.${country}/images?q=${input}&safe=${incith::google::safe_search}&btnG=Search+Images&ie=utf-8&sout=1&nfpr=1"
  6245.       # LOCAL
  6246.       } elseif {$switch == 3} {
  6247.         # make it so people can search their country
  6248.         set country ""
  6249.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6250.         if {$country == ""} {
  6251.           set country "${incith::google::google_country}"
  6252.           set dummy $helps
  6253.         }
  6254.         #regexp -nocase -- {^(.+?) near (.+?)$} $dummy - search location
  6255.         #set query "http://maps.google.${country}/maps?f=q&q=${search}&near=${location}&ie=UTF8&filter=0&oi=lwp_thresh&sa=X&view=text&ct=clnk&cd=1&nfpr=1"
  6256.         set query "http://maps.google.${country}/maps?f=q&q=${input}&ie=utf-8&filter=0&oi=lwp_thresh&sa=X&view=text&ct=clnk&cd=1&nfpr=1"
  6257.       } elseif {$switch == 4} {
  6258.         # make it so people can search their country
  6259.         set country ""
  6260.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6261.         if {$country == ""} {
  6262.           set country "${incith::google::google_country}"
  6263.         }
  6264.         set query "http://groups.google.${country}/groups/search?ie=UTF-8&q=${input}&qt_s=Search&safe=${incith::google::safe_search}&ie=utf-8&nfpr=1"
  6265.       } elseif {$switch == 5} {
  6266.         # make it so people can search their country
  6267.         set country ""
  6268.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6269.         if {$country == ""} {
  6270.           set country "${incith::google::google_country}"
  6271.         }
  6272.         set query "http://news.google.${country}/news?q=${input}&ie=utf-8&nfpr=1"
  6273.       } elseif {$switch == 6} {
  6274.         # make it so people can search their country
  6275.         set country ""
  6276.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6277.         if {$country == ""} {
  6278.           set country "${incith::google::google_country}"
  6279.         }
  6280.         set query "http://books.google.${country}/books?q=${input}&btnG=Search+Books&ie=utf-8&nfpr=1"
  6281.       } elseif {$switch == 7} {
  6282.         # make it so people can search their country
  6283.         set country ""
  6284.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6285.         if {$country == ""} {
  6286.           set country "${incith::google::google_country}"
  6287.         }
  6288.         set query "http://www.google.${country}/search?q=${input}&tbs=vid:1&nfpr=1"
  6289.         #set query "http://video.google.${country}/videosearch?q=${input}&btnG=Search+Video&ie=utf-8"
  6290.       } elseif {$switch == 8} {
  6291.         # make it so people can search their country
  6292.         set country ""
  6293.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6294.         if {$country == ""} {
  6295.           set country "${incith::google::google_country}"
  6296.         }
  6297.         set query "http://www.google.${country}/search?hl=&q=${input}&safe=off&btnG=Search&lr=lang_all&num=1&ie=utf-8"
  6298.       } elseif {$switch == 9} {
  6299.         # make it so people can search their country
  6300.         set country "" ; set hd ""
  6301.         if {[regsub -nocase -all -- "[urlencode $::incith::google::youtube_highdef 0]" $input "" input]} {
  6302.           set hd "&high_definition=1"
  6303.         }
  6304.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6305.         if {$country == ""} {
  6306.           set country "${incith::google::youtube_country}"
  6307.         }
  6308.         if {$country == "com"} {
  6309.           set query "http://www.youtube.com/results?search_query=${input}&hl=en&ie=utf-8$hd"
  6310.         } else {
  6311.           set query "http://${country}.youtube.com/results?search_query=${input}&hl=${country}&ie=utf-8$hd"
  6312.         }
  6313.       } elseif {$switch == 10} {
  6314.         # make it so people can search their country
  6315.         set country ""
  6316.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6317.         if {$country == ""} {
  6318.           set country "${incith::google::google_country}"
  6319.         }
  6320.         set query "http://scholar.google.${country}/scholar?hl=all&lr=&safe=${incith::google::safe_search}&q=${input}&btnG=Search&ie=utf-8"
  6321.       } elseif {$switch == 11} {
  6322.         #set query "http://vidsearch.myspace.com/index.cfm?fuseaction=vids.fullsearch&searchText=${input}&fullSearch=Search%20Videos"
  6323.         #set query "http://vids.myspace.com/index.cfm?SearchBoxID=SplashHeader&fuseaction=vids.search&q=${input}&t=tvid"
  6324.         set query "http://searchservice.myspace.com/index.cfm?fuseaction=sitesearch.results&orig=search_Header&origpfc=VidsSplash&type=MySpaceTV&qry=${input}&submit=Search"
  6325.       } elseif {$switch == 12} {
  6326.         #set query "http://www.gamespot.com/search.html?qs=${input}&x=0&y=0"
  6327.         #set query "http://www.gamespot.com/pages/search/index.php?qs=${input}&sub=g"
  6328.         set query "http://www.gamespot.com/pages/search/search_ajax.php?q=${input}&type=game&offset=0&tags_only=false&sort=rank"
  6329.         #set query "http://www.gamespot.com/search.html?tag=search%3Bbutton&om_act=convert&om_clk=search&qs=${input}"
  6330.         #set query "http://www.gamespot.com/pages/search/index.php?qs=${input}#game"
  6331.         #set query "http://www.gamespot.com/search.html?qs=${input}"
  6332.         #set query "http://www.gamespot.com/pages/tags/index.php?type=game&tags=${input}"
  6333.       } elseif {$switch == 13} {
  6334.         # make it so people can search their country
  6335.         set country ""
  6336.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6337.         if {$country == ""} {
  6338.           set country "${incith::google::google_country}"
  6339.         }
  6340.         set query "http://www.google.${country}/trends/hottrends?date=${input}&sa=x&ctab=0&hl=en"
  6341.       } elseif {$switch == 14} {
  6342.         # make it so people can search their country
  6343.         set country ""
  6344.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6345.         if {$country == ""} {
  6346.           set country "${incith::google::daily_country}"
  6347.         }
  6348.         if {$country == "en"} {
  6349.           set query "http://www.dailymotion.com/relevance/search/${input}"
  6350.         } else {
  6351.           set query "http://www.dailymotion.com/${country}/relevance/search/${input}"
  6352.         }
  6353.       } elseif {$switch == 15} {
  6354.         set query "http://www.gamefaqs.com/ds/releases${input}"
  6355.       } elseif {$switch == 16} {
  6356.         set query "http://www.gamefaqs.com/iphone/releases${input}"
  6357.       } elseif {$switch == 17} {
  6358.         set query "http://www.gamefaqs.com/psp/releases${input}"
  6359.       } elseif {$switch == 18} {
  6360.         set query "http://www.gamefaqs.com/xbox360/releases${input}"
  6361.       } elseif {$switch == 19} {
  6362.         set query "http://www.gamefaqs.com/xbox/releases${input}"
  6363.       } elseif {$switch == 20} {
  6364.         set query "http://www.gamefaqs.com/gamecube/releases${input}"
  6365.       } elseif {$switch == 21} {
  6366.         set query "http://www.gamefaqs.com/ps2/releases${input}"
  6367.       } elseif {$switch == 22} {
  6368.         set query "http://www.gamefaqs.com/pc/releases${input}"
  6369.       } elseif {$switch == 23} {
  6370.         set query "http://www.gamefaqs.com/ps3/releases${input}"
  6371.       } elseif {$switch == 24} {
  6372.         # make it so people can search their country
  6373.         set country ""
  6374.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6375.         if {$country == ""} {
  6376.           set country "${incith::google::google_country}"
  6377.         }
  6378.         regsub -all -- {-} $input "%2d" input
  6379.         set query "http://blogsearch.google.${country}/blogsearch?q=${input}&lr=&sa=N&tab=gn&ie=utf-8"
  6380.       } elseif {$switch == 25} {
  6381.         # make it so people can search their country
  6382.         set country "" ; set shop ""
  6383.         regexp -nocase -- {^\.(.+?)\s(.+?)$} $helps - country dummy
  6384.         if {$country == ""} {
  6385.           if {![regexp -nocase -- {^\@(.+?)\s(.+?)$} $helps - shop input]} {
  6386.              set country $::incith::google::ebay_country
  6387.           }
  6388.         }
  6389.         regsub -all -- {-} $input "%2d" input
  6390.         regsub -all -- { } $input "-" input
  6391.  
  6392.         #set query "http://search.ebay.com/search/search.dll?sofocus=unknown&sbrftog=1&from=R10&_trksid=m37&satitle=${input}&sacat=-1%26catref%3DC6&sargn=-1%26saslc%3D2&sadis=200&fpos=95482&sabfmts=1&saobfmts=insif&ftrt=1&ftrv=1&saprclo=&saprchi=&fsop=1%26fsoo%3D1&coaction=compare&copagenum=1&coentrypage=search"
  6393.         #set query "http://search.ebay.${country}/${input}"
  6394.         #set query "http://shop.ebay.${country}/items/_W0QQ_nkwZ${input}QQ_armrsZ1QQ_fromZQQ_mdoZ"
  6395.         #set query "http://shop.ebay.${country}/${input}"
  6396.         #set query "http://shop.ebay.${country}/items/_W0QQ_nkwZ${input}QQ_armrsZ1QQ_fromZQQ_mdoZ"
  6397.         if {![string length $shop]} {
  6398.           set query "http://shop.ebay.${country}/i.html?_nkw=${input}&_armrs=1&_from=&_ipg=&_dmd=1"
  6399.         } else {
  6400.           set query "http://$shop.shop.ebay.com/?_nkw=${input}&_armrs=1&_from=&_ipg=&_dmd=1"
  6401.         }
  6402.         #set query "http://search.ebay.${country}/${input}_W0QQpqryZ${input}"
  6403.       } elseif {$switch == 26} {
  6404.         set query "http://search.ign.com/products?sort=relevance&query=${input}&so=exact&objtName=all&origin=&startat=0&nc=false&ns=false"
  6405.         #set query "http://search.ign.com/products?query=${input}"
  6406.       } elseif {$switch == 27} {
  6407.         # place holder for wikipedia
  6408.         # eventually it will get put back into fetch_html
  6409.       } elseif {$switch == 28} {
  6410.         set query "http://www.gamefaqs.com/wii/releases${input}"
  6411.       } elseif {$switch == 29} {
  6412.         set query "http://www.gamefaqs.com/dreamcast/releases${input}"
  6413.       } elseif {$switch == 30} {
  6414.         set query "http://www.gamerankings.com/browse.html?site=gamecube&cat=0&year=2&numrev=0&sort=${input}&search="
  6415.       } elseif {$switch == 31} {
  6416.         set query "http://www.gamerankings.com/browse.html?site=pc&cat=0&year=0&numrev=2&sort=${input}&search="
  6417.       } elseif {$switch == 32} {
  6418.         set query "http://www.gamerankings.com/browse.html?site=ps2&cat=0&year=0&numrev=2&sort=${input}&search="
  6419.       } elseif {$switch == 33} {
  6420.         set query "http://www.gamerankings.com/browse.html?site=ps3&cat=0&year=0&numrev=2&sort=${input}&search="
  6421.       } elseif {$switch == 34} {
  6422.         set query "http://www.gamerankings.com/browse.html?site=wii&cat=0&year=0&numrev=2&sort=${input}&search="
  6423.       } elseif {$switch == 35} {
  6424.         set query "http://www.gamerankings.com/browse.html?site=xbox&cat=0&year=0&numrev=2&sort=${input}&search="
  6425.       } elseif {$switch == 36} {
  6426.         set query "http://www.gamerankings.com/browse.html?site=xbox360&cat=0&year=0&numrev=2&sort=${input}&search="
  6427.       } elseif {$switch == 37} {
  6428.         set query "http://www.gamerankings.com/browse.html?site=ds&cat=0&year=0&numrev=2&sort=${input}&search="
  6429.       } elseif {$switch == 38} {
  6430.         set query "http://www.gamerankings.com/browse.html?site=gba&cat=0&year=0&numrev=2&sort=${input}&search="
  6431.       } elseif {$switch == 39} {
  6432.         set query "http://www.gamerankings.com/browse.html?site=psp&cat=0&year=0&numrev=2&sort=${input}&search="
  6433.       } elseif {$switch == 40} {
  6434.         set query "http://www.gamerankings.com/browse.html?site=mobile&cat=0&year=0&numrev=2&sort=${input}&search="
  6435.       } elseif {$switch == 41} {
  6436.         set query "http://www.gamerankings.com/browse.html?site=ngage&cat=0&year=0&numrev=2&sort=${input}&search="
  6437.       } elseif {$switch == 42} {
  6438.         set query "http://www.gamerankings.com/browse.html?site=3do&cat=0&year=0&numrev=2&sort=${input}&search="
  6439.       } elseif {$switch == 43} {
  6440.         set query "http://www.gamerankings.com/browse.html?site=dreamcast&cat=0&year=0&numrev=2&sort=${input}&search="
  6441.       } elseif {$switch == 44} {
  6442.         set query "http://www.gamerankings.com/browse.html?site=genesis&cat=0&year=0&numrev=2&sort=${input}&search="
  6443.       } elseif {$switch == 45} {
  6444.         set query "http://www.gamerankings.com/browse.html?site=jaguar&cat=0&year=0&numrev=2&sort=${input}&search="
  6445.       } elseif {$switch == 46} {
  6446.         set query "http://www.gamerankings.com/browse.html?site=n64&cat=0&year=0&numrev=2&sort=${input}&search="
  6447.       } elseif {$switch == 47} {
  6448.         set query "http://www.gamerankings.com/browse.html?site=neo&cat=0&year=0&numrev=2&sort=${input}&search="
  6449.       } elseif {$switch == 48} {
  6450.         set query "http://www.gamerankings.com/browse.html?site=ps&cat=0&year=0&numrev=2&sort=${input}&search="
  6451.       } elseif {$switch == 49} {
  6452.         set query "http://www.gamerankings.com/browse.html?site=saturn&cat=0&year=0&numrev=2&sort=${input}&search="
  6453.       } elseif {$switch == 50} {
  6454.         set query "http://www.gamerankings.com/browse.html?site=snes&cat=0&year=0&numrev=2&sort=${input}&search="
  6455.       } elseif {$switch == 51} {
  6456.         set query "http://www.mininova.org/search/${input}/seeds"
  6457.       } elseif {$switch == 52} {
  6458.         set query "http://www.gamerankings.com/browse.html?site=segacd&cat=0&year=0&numrev=2&sort=${input}&search="
  6459.       } elseif {$switch == 53} {
  6460.         set query "http://www.gamerankings.com/browse.html?site=gameboy&cat=0&year=0&numrev=2&sort=${input}&search="
  6461.       } elseif {$switch == 54} {
  6462.         set query "http://www.gamerankings.com/browse.html?site=gbc&cat=0&year=0&numrev=2&sort=${input}&search="
  6463.       } elseif {$switch == 55} {
  6464.         set query "http://www.gamerankings.com/browse.html?site=&cat=0&year=0&numrev=2&sort=${input}&search="
  6465.       } elseif {$switch == 56} {
  6466.         set query "http://www.gamefaqs.com/3ds/releases${input}"
  6467.       } elseif {$switch == 57} {
  6468.         set query "http://www.gamerankings.com/browse.html?site=3ds&cat=0&year=0&numrev=3&sort=${input}&search="
  6469.       } elseif {$switch == 58} {
  6470.         set query "http://www.gamerankings.com/browse.html?site=mac&cat=0&year=0&numrev=2&sort=${input}&search="
  6471.       } elseif {$switch == 59} {
  6472.         set query "http://www.gamefaqs.com/mac/releases${input}"
  6473.       }
  6474.  
  6475.       # didnt have this before, this is needed for google parsers to correctly
  6476.       # encode the 'do not include' tag, aka the hyphen.. hehe
  6477.       if {$switch < 9} {
  6478.         regsub -nocase -- {-} $input "%2d" input
  6479.       }
  6480.       regsub -all -- {\+} $query {%2B} query
  6481.       regsub -all -- {\"} $query {%22} query
  6482.      if {$switch != 25} {
  6483.        regsub -all -- { } $query {+} query
  6484.      }
  6485.      
  6486.      if {$switch == 12} {
  6487.        # grab the ajax data
  6488.        set http [::http::geturl $query -headers "X-Requested-With XMLHttpRequest X-Request JSON Referer $query $::incith_hdr" -timeout [expr 1000 * 10]]
  6489.        upvar #0 $http state
  6490.        set html [ungzip [string map {"\\n" "" "\\" ""} [::http::data $http]] $state(meta)]
  6491.        set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  6492.        set redir [::http::ncode $http]
  6493.        set cookies [list]
  6494.      } else {    
  6495.        # beware, changing the useragent will result in differently formatted html from Google.
  6496.        set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"
  6497.        #set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"
  6498.        # enable proxy
  6499.        if {![string length $::incith::google::proxy_host]} {
  6500.          set http [::http::config -useragent $ua]
  6501.        } else {
  6502.         set http [::http::config -useragent $ua -proxyhost $::incith::google::proxy_host -proxyport $::incith::google::proxy_port]
  6503.        }
  6504.        # stole this bit from rosc2112 on egghelp forums
  6505.        # borrowed is a better term, all procs eventually need this error handler.
  6506.  
  6507.        catch {set http [::http::geturl "$query" -headers $::incith_hdr -timeout [expr 1000 * 12]]} error
  6508.        if {[string match -nocase "*couldn't open socket*" $error]} {
  6509.              return "socketerrorabort|${query}"
  6510.        }
  6511.        if { [::http::status $http] == "timeout" } {
  6512.         return "timeouterrorabort"
  6513.       }
  6514.        upvar #0 $http state
  6515.        set html [ungzip [::http::data $http] $state(meta)]
  6516.        set redir [::http::ncode $http]
  6517.        # CHECK CHECK
  6518.        upvar #0 $http state
  6519.        set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  6520.        # Are there cookies?
  6521.        set cookies [list]
  6522.        foreach {name value} $state(meta) {
  6523.          # do we have cookies?                                                                                                                                                                            
  6524.          if {[string equal -nocase $name "Set-Cookie"]} {
  6525.            # yes, add them to cookie list                                                                                                                                                                          
  6526.            lappend webCookies [lindex [split $value {;}] 0]                                                                                                                                                            
  6527.          }                                                                                                                                                                                                            
  6528.        }
  6529.        if {[info exists webCookies] && [llength $webCookies]} {
  6530.          set cookies "[string trim [join $webCookies {;}] {;}]"
  6531.        } else {
  6532.          set cookies ""
  6533.        }
  6534.        # REDIRECT
  6535.        while {[string match "*${redir}*" "303|302|301" ]} {
  6536.          foreach {name value} $state(meta) {
  6537.            if {[regexp -nocase ^location$ $name]} {
  6538.              if {![string match "http*" $value]} {
  6539.                if {![string match "/" [string index $value 0]]} {
  6540.                  set value "[join [lrange [split $query "/"] 0 2] "/"]/$value"
  6541.                } else {
  6542.                  set value "[join [lrange [split $query "/"] 0 2] "/"]$value"
  6543.                }
  6544.              }
  6545.              if {[string length $cookies]} {
  6546.                set http [::http::geturl "[string map {" " "%20"} $value]" -headers "$::incith_hdr Referer $query Cookie $cookies" -timeout [expr 1000 * 10]]
  6547.              } else {
  6548.                set http [::http::geturl "[string map {" " "%20"} $value]" -headers "$::incith_hdr Referer $query" -timeout [expr 1000 * 10]]
  6549.              }
  6550.              if { $::incith::google::debug > 0 } { putserv "privmsg $::incith::google::debugnick :\002redirected \($redir\):\002 $query -> $value :: \002Cookie:\002 [join $cookies]" }
  6551.              if {[string match -nocase "*couldn't open socket*" $error]} {
  6552.                return "socketerrorabort|${value}"
  6553.              }
  6554.              if { [::http::status $http] == "timeout" } {
  6555.             return "timeouterrorabort"
  6556.              }
  6557.              upvar #0 $http state
  6558.              # Are there cookies?
  6559.              foreach {nam val} $state(meta) {
  6560.                # do we have cookies?                                                                                                                                                                            
  6561.                if {[string equal -nocase $nam "Set-Cookie"]} {
  6562.                  if {![info exists flagme]} {
  6563.                    set flagme 0
  6564.                    set cookies [list]
  6565.                  }
  6566.                  # yes, add them to cookie list                                                                                                                                                                          
  6567.                  lappend webCookies [lindex [split $val {;}] 0]                                                                                                                                                            
  6568.                }                                                                                                                                                                                                            
  6569.              }
  6570.              if {[info exists webCookies] && [llength $webCookies]} {
  6571.                set cookies "[string trim [join $webCookies {;}] {;}]"
  6572.              } else {
  6573.                set cookies ""
  6574.              }
  6575.              set redir [::http::ncode $http]
  6576.              set incithcharset [string map -nocase {"UTF-" "utf-" "iso-" "iso" "windows-" "cp" "shift_jis" "shiftjis"} $state(charset)]
  6577.              set query [string map {" " "%20"} $value]
  6578.            }
  6579.          }
  6580.        }
  6581.      }
  6582.      set html [ungzip [::http::data $http] $state(meta)]
  6583.      ::http::cleanup $http
  6584.      # ---- step 1
  6585.      # Determine which encoding to use
  6586.      #
  6587.      set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "$country:*"]] :] 1]
  6588.      if {$incith::google::encoding_conversion_output > 0} {
  6589.        if {$incith::google::automagic > 0} {
  6590.          if {[string match -nocase "utf-8" $incithcharset] && $incith::google::utf8workaround > 0 && $encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  6591.            set new_encoding $encoding_found
  6592.          } else {
  6593.            set new_encoding $incithcharset
  6594.          }
  6595.        } else {
  6596.          if {$encoding_found != "" } {
  6597.            set new_encoding $encoding_found
  6598.          } else {
  6599.            set new_encoding "NONE"
  6600.          }
  6601.        }
  6602.      } else {
  6603.        set new_encoding "DISABLED"
  6604.      }
  6605.  
  6606.      # ---- step 2
  6607.      # Report the conclusion to debugnick
  6608.      #
  6609.      if {$incith::google::debug > 0} {
  6610.        if {[string match -nocase $new_encoding $incithcharset]} {
  6611.          if {[lsearch -exact [encoding names] $incithcharset] != -1} {
  6612.            putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002\037charset:\037\002 $incithcharset \002encode_string:\002 $encoding_found :: \002Cookie:\002 $cookies"
  6613.          } else {
  6614.            putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002\037charset:\037\002 $incithcharset \037<--ERROR: Unknown\037 \002encode_string:\002 $encoding_found :: \002Cookie:\002 $cookies"
  6615.          }
  6616.        } elseif {[string match -nocase $new_encoding $encoding_found]} {
  6617.          if {$encoding_found != "" && [lsearch -exact [encoding names] $encoding_found] != -1} {
  6618.            putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \037\002encode_string:\002\037 $encoding_found :: \002Cookie:\002 $cookies"
  6619.          } else {
  6620.            putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002\037encode_string:\037\002 $encoding_found \037<--ERROR: Unknown\037 :: \002Cookie:\002 $cookies"
  6621.          }
  6622.        } elseif {[string match -nocase "DISABLED" $new_encoding]} {
  6623.          putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002encode_string:\002 $encoding_found \037DISABLED:\037 Using default charset. :: \002Cookie:\002 $cookies"
  6624.        } else {
  6625.          putserv "privmsg $incith::google::debugnick :\002url \($redir\):\002 $query \002charset:\002 $incithcharset \002encode_string:\002 $encoding_found \037UNKNOWN ERROR:\037 Using default charset. :: \002Cookie:\002 $cookies"
  6626.        }
  6627.      }
  6628.  
  6629.      # ---- step 3
  6630.      # Apply the encoding
  6631.      #
  6632.      if {![string match *$new_encoding* "utf-8"] && ![string equal "DISABLED" $new_encoding]} {
  6633.         set incithcharset $new_encoding
  6634.         set html [incithencode $html]
  6635.      }
  6636.  
  6637.      # generic pre-parsing
  6638.      regsub -all "\n" $html "" html
  6639.      regsub -all "(?:\x91|\x92|&#39;)" $html {'} html
  6640.       regsub -all "(?:\x93|\x94|&quot;)" $html {"} html
  6641.      regsub -all "&amp;" $html {\&} html
  6642.      regsub -all -nocase {<sup>(.+?)</sup>} $html {^\1} html
  6643.      if {![string match $switch "4"] && ![string match $switch "26"]} {
  6644.        regsub -all -nocase {<font.+?>} $html "" html
  6645.        regsub -all -nocase {</font>} $html "" html
  6646.        regsub -all -nocase {<script type=.*?script>} $html "" html
  6647.      }
  6648.      if {![string match *$switch* "|9|7|"]} {
  6649.         regsub -all -nocase {<span.*?>} $html "" html
  6650.         regsub -all -nocase {</span>} $html "" html
  6651.      }
  6652.      regsub -all -nocase {<input.+?>} $html "" html
  6653.      regsub -all -nocase {(?:<i>|</i>)} $html "" html
  6654.      regsub -all "&times;" $html {*} html
  6655.      regsub -all "&nbsp;" $html { } html
  6656.      regsub -all -nocase "&#215;" $html "x" html
  6657.       regsub -all -nocase "&lt;" $html "<" html
  6658.       regsub -all -nocase "&gt;" $html ">" html
  6659.       regsub -all {\x000f} $html "" html
  6660.       # '
  6661.       # regexps that should remain seperate go here
  6662.       # google specific regexps
  6663.       if {$switch == 1} {
  6664.         # regexp the rest of the html for a much easier result to parse
  6665.         regsub -all -nocase {<b>\[PDF\]</b>\s*} $html "" html
  6666.         regsub {<p class=g style="margin-top:0">(.+?)</p>} $html "" html
  6667.       } elseif {$switch == 2} {
  6668.         # these %2520 codes, I have no idea. But they're supposed to be %20's
  6669.         regsub -all {%2520} $html {%20} html
  6670.       } elseif {$switch == 3} {
  6671.         regsub -all -nocase { - <nobr>Unverified listing</nobr>} $html "" html
  6672.         regsub -all -- {&#160;} $html { } html  
  6673.       } elseif {$switch == 4} {
  6674.       } elseif {$switch == 5} {
  6675.       } elseif {$switch == 6} {
  6676.       } elseif {$switch == 7} {
  6677.       } elseif {$switch == 8} {
  6678.       } elseif {$switch == 9} {
  6679.         regsub -all "\t" $html "" html
  6680.         regsub -all "\n" $html "" html
  6681.         regsub -all "\r" $html "" html
  6682.         regsub -all "\v" $html "" html
  6683.       } elseif {$switch == 10} {
  6684.         regsub -all -nocase { - <nobr>Unverified listing</nobr>} $html "" html
  6685.         regsub -all -- {&#160;} $html { } html
  6686.       } elseif {$switch == 25} {
  6687.         regsub -all {<script.*?>.+?</script>} $html "" html
  6688.         regsub -all "\t" $html "" html
  6689.         regsub -all "\n" $html "" html
  6690.         regsub -all "\r" $html "" html
  6691.         regsub -all "\v" $html "" html
  6692.         regsub -all "<wbr/>" $html "" html
  6693.       } elseif {$switch > 11 && $switch < 31 || $switch == 56 || $switch == 58 || $switch == 59} {
  6694.         regsub -all "\t" $html "" html
  6695.         regsub -all "\n" $html "" html
  6696.         regsub -all "\r" $html "" html
  6697.         regsub -all "\v" $html "" html
  6698.         regsub -all "&#039;" $html "'" html
  6699.       } elseif {$switch == 51} {
  6700.         regsub -all "<strong>|</strong>" $html "\002" html
  6701.       }
  6702.  
  6703.       # no point having it so many times
  6704.       if {$incith::google::bold_descriptions > 0 && [string match "\002" $incith::google::desc_modes] != 1} {
  6705.         regsub -all -nocase {(?:<b>|</b>|<em>|</em>|<strong>|</strong>)} $html "\002" html
  6706.       } else {
  6707.         regsub -all -nocase {(<b>|</b>|<em>|</em>|<strong>|</strong>)} $html "" html
  6708.       }
  6709.       # DEBUG DEBUG                    
  6710.       set junk [open "ig-debug.txt" w]
  6711.       puts $junk $html
  6712.       close $junk
  6713.       return $html
  6714.     }
  6715.  
  6716.     # PUBLIC_MESSAGE
  6717.     # decides what to do with binds that get triggered
  6718.     #
  6719.     proc public_message {nick uhand hand chan input} {
  6720.       if {[lsearch -exact [channel info $chan] +google] != -1} {
  6721.         if {$incith::google::chan_user_level == 3} {
  6722.           if {[isop $nick $chan] == 0} {
  6723.             return
  6724.           }
  6725.         } elseif {$incith::google::chan_user_level == 2} {
  6726.           if {[ishalfop $nick $chan] == 0 && [isop $nick $chan] == 0} {
  6727.             return
  6728.           }
  6729.         } elseif {$incith::google::chan_user_level == 1} {
  6730.           if {[isvoice $nick $chan] == 0 && [ishalfop $nick $chan] == 0 && [isop $nick $chan] == 0} {
  6731.             return
  6732.           }
  6733.         }
  6734.         send_output "$input" "$chan" "$nick" "$uhand"
  6735.       }
  6736.     }
  6737.  
  6738.     # PRIVATE_MESSAGE
  6739.     # decides what to do with binds that get triggered
  6740.     #
  6741.     proc private_message {nick uhand hand input} {
  6742.       if {$incith::google::private_messages >= 1} {
  6743.         send_output $input $nick $nick $uhand
  6744.       }
  6745.     }
  6746.  
  6747.     # SEND_OUTPUT
  6748.     # no point having two copies of this in public/private_message{}
  6749.     #
  6750.     proc send_output {input where nick uhand} {
  6751.  
  6752.       # this is my input encoding hack, this will convert input before it goes
  6753.       # out to be queried.
  6754.       if {$incith::google::encoding_conversion_input > 0} {
  6755.         if {[encoding system] != "identity" && [lsearch [encoding names] "utf-8"]} {
  6756.           set command_char [encoding convertfrom "utf-8" ${incith::google::command_char}]
  6757.           set input [encoding convertfrom "utf-8" $input]
  6758.         } elseif {[encoding system] == "identity"} {
  6759.           set command_char [encoding convertfrom identity ${incith::google::command_char}]
  6760.           set input [encoding convertfrom identity $input]
  6761.         } else {
  6762.           set command_char ${incith::google::command_char}
  6763.         }
  6764.       } else {
  6765.         set command_char ${incith::google::command_char}
  6766.       }
  6767.  
  6768.       #Specifically retrieve only ONE (ascii) character, then check that matches the command_char first
  6769.       set trigger_char [string index $input 0]
  6770.       if {[encoding system] == "identity"} {
  6771.         set trigger_char [encoding convertfrom identity $trigger_char]
  6772.       }
  6773.  
  6774.       #Sanity check 1 - If no match, stop right here. No need to match every (first word) of
  6775.       # every line of channel data against every bind if the command_char doesnt even match.
  6776.       if {$trigger_char != $command_char} {
  6777.         return
  6778.       }
  6779.  
  6780.       set trigger [string range [lindex [split $input] 0] 1 end]
  6781.       #Sanity check 2 - Stop if theres nothing to search for (quiet)
  6782.       if {$incith::google::aversion_vocabulary > 0} {
  6783.         set search [vocabaversion [string trim [string range $input [string wordend $input 1] end]]]
  6784.       } else {
  6785.         set search [string trim [string range $input [string wordend $input 1] end]]
  6786.       }
  6787.       if {$search == ""} { return }
  6788.  
  6789.       if {$incith::google::force_private == 1} { set where $nick }
  6790.       # check for !google
  6791.       if {$incith::google::search_results > 0} {
  6792.         foreach bind [split $incith::google::google_binds " "] {
  6793.           if {[string match -nocase $bind $trigger] == 1} {
  6794.             # channel filter check
  6795.             foreach c [split $incith::google::filtered " "] {
  6796.               if {[string match -nocase $where $c] == 1} {
  6797.                 return
  6798.               }
  6799.             }
  6800.             # flood protection check
  6801.             if {[flood $nick $uhand]} {
  6802.               return
  6803.             }
  6804.             # call google
  6805.             foreach line [incith::google::parse_output [google $search]] {
  6806.               put_output $where "$incith::google::search_prepend$line"
  6807.             }
  6808.             break
  6809.           }
  6810.         }
  6811.       }
  6812.       # check for !images
  6813.       if {$incith::google::image_results > 0} {
  6814.         foreach bind [split $incith::google::image_binds " "] {
  6815.           if {[string match -nocase $bind $trigger] == 1} {
  6816.             # flood protection check
  6817.             if {[flood $nick $uhand]} {
  6818.               return
  6819.             }
  6820.             # call images
  6821.             foreach line [incith::google::parse_output [images $search]] {
  6822.               put_output $where "$incith::google::image_prepend$line"
  6823.             }
  6824.             break
  6825.           }
  6826.         }
  6827.       }
  6828.       # check for !local
  6829.       if {$incith::google::local_results > 0} {
  6830.         foreach bind [split $incith::google::local_binds " "] {
  6831.           if {[string match -nocase $bind $trigger] == 1} {
  6832.             # flood protection check
  6833.             if {[flood $nick $uhand]} {
  6834.               return
  6835.             }
  6836.             # local requires splitting of the search
  6837.             regexp -nocase -- {^(.+?) near (.+?)$} $search - what location
  6838.             if {![info exists what] || ![info exists location]} {
  6839.               put_output $where "Local searches should be the format of 'pizza near footown, bar'"
  6840.               return
  6841.             }
  6842.             foreach line [incith::google::parse_output [local $search]] {
  6843.               put_output $where "$incith::google::local_prepend$line"
  6844.             }
  6845.             break
  6846.           }
  6847.         }
  6848.       }
  6849.       # check for !groups
  6850.       if {$incith::google::group_results > 0} {
  6851.         foreach bind [split $incith::google::group_binds " "] {
  6852.           if {[string match -nocase $bind $trigger] == 1} {
  6853.             # flood protection check
  6854.             if {[flood $nick $uhand]} {
  6855.               return
  6856.             }
  6857.             # call groups
  6858.             foreach line [incith::google::parse_output [groups $search]] {
  6859.               put_output $where "$incith::google::group_prepend$line"
  6860.             }
  6861.             break
  6862.           }
  6863.         }
  6864.       }
  6865.       # check for !news
  6866.       if {$incith::google::news_results > 0} {
  6867.         foreach bind [split $incith::google::news_binds " "] {
  6868.           if {[string match -nocase $bind $trigger] == 1} {
  6869.             # flood protection check
  6870.             if {[flood $nick $uhand]} {
  6871.               return
  6872.             }
  6873.             # call news
  6874.             foreach line [incith::google::parse_output [news $search]] {
  6875.               put_output $where "$incith::google::news_prepend$line"
  6876.             }
  6877.             break
  6878.           }
  6879.         }
  6880.       }
  6881.       # check for !print
  6882.       if {$incith::google::print_results > 0} {
  6883.         foreach bind [split $incith::google::print_binds " "] {
  6884.           if {[string match -nocase $bind $trigger] == 1} {
  6885.             # flood protection check
  6886.             if {[flood $nick $uhand]} {
  6887.               return
  6888.             }
  6889.             # call print
  6890.             foreach line [incith::google::parse_output [print $search]] {
  6891.               put_output $where "$incith::google::print_prepend$line"
  6892.             }
  6893.             break
  6894.           }
  6895.         }
  6896.       }
  6897.       # check for !video
  6898.       if {$incith::google::video_results > 0} {
  6899.         foreach bind [split $incith::google::video_binds " "] {
  6900.           if {[string match -nocase $bind $trigger] == 1} {
  6901.             # flood protection check
  6902.             if {[flood $nick $uhand]} {
  6903.               return
  6904.             }
  6905.             # call video
  6906.             foreach line [incith::google::parse_output [video $search]] {
  6907.               put_output $where "$incith::google::video_prepend$line"
  6908.             }
  6909.             break
  6910.           }
  6911.         }
  6912.       }
  6913.       # check for !scholar
  6914.       if {$incith::google::scholar_results > 0} {
  6915.         foreach bind [split $incith::google::scholar_binds " "] {
  6916.           if {[string match -nocase $bind $trigger] == 1} {
  6917.             # flood protection check
  6918.             if {[flood $nick $uhand]} {
  6919.               return
  6920.             }
  6921.             # call video
  6922.             foreach line [incith::google::parse_output [scholar $search]] {
  6923.               put_output $where "$incith::google::scholar_prepend$line"
  6924.             }
  6925.             break
  6926.           }
  6927.         }
  6928.       }
  6929.       # check for !fight
  6930.       if {$incith::google::google_fight > 0} {
  6931.         foreach bind [split $incith::google::fight_binds " "] {
  6932.           if {[string match -nocase $bind $trigger] == 1} {
  6933.             # flood protection check
  6934.             if {[flood $nick $uhand]} {
  6935.               return
  6936.             }
  6937.             # fight requires splitting of the search
  6938.             regexp -nocase -- {^(.+?) vs (.+?)$} $search - word1 word2
  6939.             if {![info exists word1] || ![info exists word2]} {
  6940.               put_output $where "Google fights should be the format of 'word(s) one vs word(s) two'"
  6941.               return
  6942.             }
  6943.             # call fight
  6944.             foreach line [incith::google::parse_output [fight $search]] {
  6945.               put_output $where "$incith::google::fight_prepend$line"
  6946.             }
  6947.             break
  6948.           }
  6949.         }
  6950.       }
  6951.       # check for !ebayfight
  6952.       if {$incith::google::google_fight > 0} {
  6953.         foreach bind [split $incith::google::efight_binds " "] {
  6954.           if {[string match -nocase $bind $trigger] == 1} {
  6955.             # flood protection check
  6956.             if {[flood $nick $uhand]} {
  6957.               return
  6958.             }
  6959.             # fight requires splitting of the search
  6960.             regexp -nocase -- {^(.+?) vs (.+?)$} $search - word1 word2
  6961.             if {![info exists word1] || ![info exists word2]} {
  6962.               put_output $where "Ebay fights should be the format of 'word(s) one vs word(s) two'"
  6963.               return
  6964.             }
  6965.             # call ebayfight
  6966.             foreach line [incith::google::parse_output [ebayfight $search]] {
  6967.               put_output $where "$incith::google::ebayfight_prepend$line"
  6968.             }
  6969.             break
  6970.           }
  6971.         }
  6972.       }
  6973.       # check for !youtube
  6974.       if {$incith::google::youtube_results > 0} {
  6975.         foreach bind [split $incith::google::youtube_binds " "] {
  6976.           if {[string match -nocase $bind $trigger] == 1} {
  6977.             # flood protection check
  6978.             if {[flood $nick $uhand]} {
  6979.               return
  6980.             }
  6981.             # call youtube
  6982.             foreach line [incith::google::parse_output [youtube $search]] {
  6983.               put_output $where "$incith::google::youtube_prepend$line"
  6984.             }
  6985.             break
  6986.           }
  6987.         }
  6988.       }
  6989.       # check for !helpbot
  6990.       if {$incith::google::helpbot_results > 0} {
  6991.         foreach bind [split $incith::google::helpbot_binds " "] {
  6992.           if {[string match -nocase $bind $trigger] == 1} {
  6993.             # flood protection check
  6994.             if {[flood $nick $uhand]} {
  6995.               return
  6996.             }
  6997.             # call helpbot
  6998.             foreach line [incith::google::parse_output [helpbot $nick $search]] {
  6999.               put_output $where $line
  7000.             }
  7001.             break
  7002.           }
  7003.         }
  7004.       }
  7005.       # check for !myspacevids
  7006.       if {$incith::google::myspacevids_results > 0} {
  7007.         foreach bind [split $incith::google::myspacevids_binds " "] {
  7008.           if {[string match -nocase $bind $trigger] == 1} {
  7009.             # flood protection check
  7010.             if {[flood $nick $uhand]} {
  7011.               return
  7012.             }
  7013.             # call myspacevids
  7014.             foreach line [incith::google::parse_output [myspacevids $search]] {
  7015.               put_output $where "$incith::google::myspacevids_prepend$line"
  7016.             }
  7017.             break
  7018.           }
  7019.         }
  7020.       }
  7021.       # check for !mininova
  7022.       if {$incith::google::mininova_results > 0} {
  7023.         foreach bind [split $incith::google::mininova_binds " "] {
  7024.           if {[string match -nocase $bind $trigger] == 1} {
  7025.             # flood protection check
  7026.             if {[flood $nick $uhand]} {
  7027.               return
  7028.             }
  7029.             # call mininova
  7030.             foreach line [incith::google::parse_output [mininova $search]] {
  7031.               put_output $where "$incith::google::mininova_prepend$line"
  7032.             }
  7033.             break
  7034.           }
  7035.         }
  7036.       }
  7037.       # check for !recent
  7038.       if {$incith::google::recent_results > 0} {
  7039.         foreach bind [split $incith::google::recent_binds " "] {
  7040.           if {[string match -nocase $bind $trigger] == 1} {
  7041.             # flood protection check
  7042.             if {[flood $nick $uhand]} {
  7043.               return
  7044.             }
  7045.             # call recent game lookup
  7046.             foreach line [incith::google::parse_output [recent $search]] {
  7047.               put_output $where "$incith::google::recent_prepend$line"
  7048.             }
  7049.             break
  7050.           }
  7051.         }
  7052.       }
  7053.       # check for !wiki
  7054.       if {$incith::google::wiki_results > 0} {
  7055.         foreach bind [split $incith::google::wiki_binds " "] {
  7056.           if {[string match -nocase $bind $trigger] == 1} {
  7057.             # flood protection check
  7058.             if {[flood $nick $uhand]} {
  7059.               return
  7060.             }
  7061.             # call wiki
  7062.             foreach line [incith::google::parse_output [wiki $search]] {
  7063.               put_output $where "$incith::google::wiki_prepend$line"
  7064.             }
  7065.             break
  7066.           }
  7067.         }
  7068.       }
  7069.       # check for !wikimedia
  7070.       if {$incith::google::wikimedia_results > 0} {
  7071.         foreach bind [split $incith::google::wikimedia_binds " "] {
  7072.           if {[string match -nocase $bind $trigger] == 1} {
  7073.             # flood protection check
  7074.             if {[flood $nick $uhand]} {
  7075.               return
  7076.             }
  7077.             # call wiki
  7078.             foreach line [incith::google::parse_output [wikimedia $search]] {
  7079.               put_output $where "$incith::google::wikimedia_prepend$line"
  7080.             }
  7081.             break
  7082.           }
  7083.         }
  7084.       }
  7085.       # check for !review
  7086.       if {$incith::google::rev_results > 0} {
  7087.         foreach bind [split $incith::google::rev_binds " "] {
  7088.           if {[string match -nocase $bind $trigger] == 1} {
  7089.             # flood protection check
  7090.             if {[flood $nick $uhand]} {
  7091.               return
  7092.             }
  7093.             # call review
  7094.             foreach line [incith::google::parse_output [rev $search]] {
  7095.               put_output $where "$incith::google::rev_prepend$line"
  7096.             }
  7097.             break
  7098.           }
  7099.         }
  7100.       }
  7101.       # check for !ign
  7102.       if {$incith::google::ign_results > 0} {
  7103.         foreach bind [split $incith::google::ign_binds " "] {
  7104.           if {[string match -nocase $bind $trigger] == 1} {
  7105.             # flood protection check
  7106.             if {[flood $nick $uhand]} {
  7107.               return
  7108.             }
  7109.             # call ign
  7110.             foreach line [incith::google::parse_output [ign $search]] {
  7111.               put_output $where "$incith::google::ign_prepend$line"
  7112.             }
  7113.             break
  7114.           }
  7115.         }
  7116.       }
  7117.       # check for !trends
  7118.       if {$incith::google::trends_results > 0} {
  7119.         foreach bind [split $incith::google::trends_binds " "] {
  7120.           if {[string match -nocase $bind $trigger] == 1} {
  7121.             # flood protection check
  7122.             if {[flood $nick $uhand]} {
  7123.               return
  7124.             }
  7125.             # call trends
  7126.             foreach line [incith::google::parse_output [trends $search]] {
  7127.               put_output $where "$incith::google::trends_prepend$line"
  7128.             }
  7129.             break
  7130.           }
  7131.         }
  7132.       }
  7133.       # check for !gamespot
  7134.       if {$incith::google::gamespot_results > 0} {
  7135.         foreach bind [split $incith::google::gamespot_binds " "] {
  7136.           if {[string match -nocase $bind $trigger] == 1} {
  7137.             # flood protection check
  7138.             if {[flood $nick $uhand]} {
  7139.               return
  7140.             }
  7141.             # call gamespot
  7142.             foreach line [incith::google::parse_output [gamespot $search]] {
  7143.               put_output $where "$incith::google::gamespot_prepend$line"
  7144.             }
  7145.             break
  7146.           }
  7147.         }
  7148.       }
  7149.       # check for !trans
  7150.       if {$incith::google::trans_results > 0} {
  7151.         foreach bind [split $incith::google::trans_binds " "] {
  7152.           if {[string match -nocase $bind $trigger] == 1} {
  7153.             # flood protection check
  7154.             if {[flood $nick $uhand]} {
  7155.               return
  7156.             }
  7157.             # translation requires splitting of the search
  7158.             if {![regexp -nocase -- {^(.+?)@(.+?)\s(.+?)$} $search - word1 word2 word3]} {
  7159.               if {[regexp -nocase -- {^@(.+?)\s(.+?)$} $search - word2 word3]} {
  7160.                 set search [join [lrange [split $search] 1 end]]
  7161.               } else {
  7162.                 regexp -nocase -- {^(.+?)@\s(.+?)$} $search - word1 word3
  7163.               }
  7164.             }
  7165.             if {[info exists word2]} {
  7166.               if {[string equal [string index $word2 0] " "]} {
  7167.                 regexp -nocase -- {^(.+?)@\s(.+?)$} $search - word1 word3
  7168.                 set word2 $::incith::google::trans
  7169.               }
  7170.             }
  7171.             if {![info exists word1]} { set word1 "auto" }
  7172.             if {![info exists word2]} { set word2 $::incith::google::trans }
  7173.             if {![info exists word3]} { set word3 $search }
  7174.             set search "$word1@$word2 $word3"
  7175.             # call translate
  7176.             trans $search $where
  7177.           }
  7178.         }
  7179.       }
  7180.       # check for !dailymotion
  7181.       if {$incith::google::daily_results > 0} {
  7182.         foreach bind [split $incith::google::daily_binds " "] {
  7183.           if {[string match -nocase $bind $trigger] == 1} {
  7184.             # flood protection check
  7185.             if {[flood $nick $uhand]} {
  7186.               return
  7187.             }
  7188.             # call dailymotion
  7189.             foreach line [incith::google::parse_output [dailymotion $search]] {
  7190.               put_output $where "$incith::google::dailymotion_prepend$line"
  7191.             }
  7192.             break
  7193.           }
  7194.         }
  7195.       }
  7196.       # check for !gamefaqs
  7197.       if {$incith::google::gamefaq_results > 0} {
  7198.         foreach bind [split $incith::google::gamefaq_binds " "] {
  7199.           if {[string match -nocase $bind $trigger] == 1} {
  7200.             # flood protection check
  7201.             if {[flood $nick $uhand]} {
  7202.               return
  7203.             }
  7204.             # gamefaqs requires splitting of the search
  7205.             regexp -nocase -- {^(.+?) in (.+?)$} $search - system region
  7206.             if {![info exists system] || ![info exists region]} {
  7207.               put_output $where "Error! Correct usage: !gamefaqs system in region \[system = nds/gba/gc/wii/ps2/psp/ps3/xbox/x360/pc; region = usa/jap/eur/aus\]"
  7208.               return
  7209.             }
  7210.             # call gamefaqs
  7211.             foreach line [incith::google::parse_output [gamefaqs $system $region]] {
  7212.               put_output $where "$incith::google::gamefaqs_prepend$line"
  7213.             }
  7214.             break
  7215.           }
  7216.         }
  7217.       }
  7218.       # check for !locate
  7219.       if {$incith::google::locate_results > 0} {
  7220.         foreach bind [split $incith::google::locate_binds " "] {
  7221.           if {[string match -nocase $bind $trigger] == 1} {
  7222.             # flood protection check
  7223.             if {[flood $nick $uhand]} {
  7224.               return
  7225.             }
  7226.             # call locate
  7227.             if {![string match "*.*" $search]} {
  7228.               set nsearch [lindex [split [getchanhost $search $where] @] 1]
  7229.               if {[string length $nsearch]} { set search $nsearch }
  7230.             }
  7231.             foreach line [incith::google::parse_output [locate $search]] {
  7232.               put_output $where "$incith::google::locate_prepend$line"
  7233.             }
  7234.             break
  7235.           }
  7236.         }
  7237.       }
  7238.       # check for !blog
  7239.       if {$incith::google::blog_results > 0} {
  7240.         foreach bind [split $incith::google::blog_binds " "] {
  7241.           if {[string match -nocase $bind $trigger] == 1} {
  7242.             # flood protection check
  7243.             if {[flood $nick $uhand]} {
  7244.               return
  7245.             }
  7246.             # call blogsearch.google
  7247.             foreach line [incith::google::parse_output [blog $search]] {
  7248.               put_output $where "$incith::google::blog_prepend$line"
  7249.             }
  7250.             break
  7251.           }
  7252.         }
  7253.       }
  7254.       # check for !ebay
  7255.       if {$incith::google::ebay_results > 0} {
  7256.         foreach bind [split $incith::google::ebay_binds " "] {
  7257.           if {[string match -nocase $bind $trigger] == 1} {
  7258.             # flood protection check
  7259.             if {[flood $nick $uhand]} {
  7260.               return
  7261.             }
  7262.             # call ebay
  7263.             foreach line [incith::google::parse_output [ebay $search]] {
  7264.               put_output $where "$incith::google::ebay_prepend$line"
  7265.             }
  7266.             break
  7267.           }
  7268.         }
  7269.       }
  7270.       # check for !popular
  7271.       if {$incith::google::popular_results > 0} {
  7272.         foreach bind [split $incith::google::popular_binds " "] {
  7273.           if {[string match -nocase $bind $trigger] == 1} {
  7274.             # flood protection check
  7275.             if {[flood $nick $uhand]} {
  7276.               return
  7277.             }
  7278.             # call popular
  7279.             foreach line [incith::google::parse_output [popular $search]] {
  7280.               put_output $where "$incith::google::popular_prepend$line"
  7281.             }
  7282.             break
  7283.           }
  7284.         }
  7285.       }
  7286.       # check for customized any triggers
  7287.       if {$incith::google::my_custom > 0} {
  7288.         foreach bind $incith::google::my_customs {
  7289.           foreach sbind [split [lindex [split $bind :] 0]] {
  7290.             if {[string match -nocase $sbind $trigger] == 1} {
  7291.               # invoke customized trigger with phrase
  7292.               # no need to flood protect this, if we do
  7293.               # it may trigger erroneously
  7294.               set text [join [lrange [split $bind :] 2 end] :]
  7295.               if {$::incith::google::custom_words > 0} {
  7296.                 set remaps [regexp -inline -all {%%((?:end|[0-9]{1,2}|[0-9]{1,2}-(?:[0-9]{1,2}|end)))%%} $text]
  7297.                 foreach {junk remap} $remaps {
  7298.                   if {[regexp -nocase {^((?:end|[0-9]{1,2}))$} $remap - rnum]} {
  7299.                     if {[string equal -nocase "end" $rnum]} {
  7300.                       set real [llength [split $search]]
  7301.                     } else {
  7302.                       set real [expr {$remap -1}]
  7303.                     }
  7304.                     regsub -all "$junk" $text "[lindex [split $search] $real]" text
  7305.                   } elseif {[regexp -nocase {^([0-9]{1,2})-((?:[0-9]{1,2}|end))$} $remap - rstart rend]} {
  7306.                     if {![string equal -nocase "end" $rend]} { set real [expr {$rend -1}] } else { set real [llength [split $search]] }
  7307.                     regsub -all "$junk" $text "[join [lrange [split $search] [expr {${rstart}-1}] $real]]" text
  7308.                   }
  7309.                 }
  7310.               }
  7311.               regsub -all -- {%search%} $text "$search" text
  7312.               send_output "$::incith::google::command_char[lindex [split $bind :] 1] $text" $where $nick $uhand
  7313.             }
  7314.           }
  7315.         }
  7316.       }
  7317.     }
  7318.  
  7319.     # PUT_OUTPUT
  7320.     # actually sends the output to the server
  7321.     proc put_output {where line} {
  7322.       if {$incith::google::notice_reply == 1} {
  7323.         putserv "NOTICE $where :$line"
  7324.       } else {
  7325.         putserv "PRIVMSG $where :$line"
  7326.       }
  7327.     }
  7328.  
  7329.     # PARSE_OUTPUT
  7330.     # prepares output for sending to a channel/user, calls line_wrap
  7331.     #
  7332.     proc parse_output {input} {
  7333.       set parsed_output [list] ; set parsed_current [list]
  7334.       if {[string match "*\n*" $incith::google::seperator] == 1} {
  7335.         set lastline ""
  7336.         foreach newline [split $input "\n"] {
  7337.           foreach line [incith::google::line_wrap $newline] {
  7338.             set fix ""
  7339.             # bold
  7340.             if {[expr {[regexp -all {\002} $lastline] & 1 }]} {
  7341.               append fix "\002"
  7342.             }
  7343.             # underline
  7344.             if {[expr {[regexp -all {\037} $lastline] & 1 }]} {
  7345.               append fix "\037"
  7346.             }
  7347.             # color
  7348.             if {[expr {[regexp -all {\003} $lastline] & 1 }]} {
  7349.               if {[set i [string last "\003" $lastline]] != -1} {
  7350.                 set lc [string range $lastline [expr {$i + 1}] [expr {$i + 5}]]
  7351.                 if {![regexp {^[0-9]+\,[0-9+]$} $lc]} {
  7352.                   if {[regexp {^[0-9]+$} [string range $lc 0 1]]} {
  7353.                     append fix "\003[string range $lc 0 1]"
  7354.                   }
  7355.                 } else {
  7356.                   append fix "\003$lc"
  7357.                 }
  7358.               }
  7359.             }
  7360.             # add fix+line to output
  7361.             if {[string length [string map {" " ""} [stripcodes bcruag $line]]]} {
  7362.               lappend parsed_output "$fix$line"
  7363.             }
  7364.             set lastline "$fix$line"
  7365.           }
  7366.         }
  7367.       } else {
  7368.         set input [string trimright $input $incith::google::seperator]
  7369.         set lastline ""
  7370.         foreach line [incith::google::line_wrap $input] {
  7371.           # initialize fix each iteration
  7372.           set fix ""
  7373.           # add bold
  7374.           if {[expr {[regexp -all {\002} $lastline] & 1 }]} {
  7375.             append fix "\002"
  7376.           }
  7377.           # add underline
  7378.           if {[expr {[regexp -all {\037} $lastline] & 1 }]} {
  7379.             append fix "\037"
  7380.           }
  7381.           # add color
  7382.           if {[expr {[regexp -all {\003} $lastline] & 1 }]} {
  7383.             if {[set i [string last "\003" $lastline]] != -1} {
  7384.               set lc [string range $lastline [expr {$i + 1}] [expr {$i + 5}]]
  7385.               if {![regexp {^[0-9]{1,2}\,[0-9]{1,2}$} $lc]} {
  7386.                 if {[regexp {^[0-9]{1,2}} [string range $lc 0 1]]} {
  7387.                   append fix "\003[string range $lc 0 1]"
  7388.                 }
  7389.               } else {
  7390.                 append fix "\003$lc"
  7391.               }
  7392.             }
  7393.           }
  7394.           # add fix+line to output
  7395.           if {[string length [string map {" " ""} [stripcodes bcruag $line]]]} {
  7396.             lappend parsed_output "$fix$line"
  7397.           }
  7398.           set lastline "$fix$line"
  7399.         }
  7400.       }
  7401.       return $parsed_output
  7402.     }
  7403.  
  7404.     # LINE_WRAP
  7405.     # takes a long line in, and chops it before the specified length
  7406.     # http://forum.egghelp.org/viewtopic.php?t=6690
  7407.     #
  7408.     proc line_wrap {str {splitChr { }}} {
  7409.       set out [set cur {}]
  7410.       set i 0
  7411.       set len $incith::google::split_length
  7412.       #regsub -all "\002" $str "<ZQ" str
  7413.       #regsub -all "\037" $str "<ZX" str
  7414.       #regsub -all "\003" $str "<ZJ" str
  7415.       foreach word [split [set str][set str ""] $splitChr] {
  7416.         if {[incr i [string len $word]] > $len} {
  7417.           #regsub -all "<ZQ" $cur "\002" cur
  7418.           #regsub -all "<ZX" $cur "\037" cur
  7419.           #regsub -all "<ZJ" $cur "\003" cur
  7420.           lappend out [join $cur $splitChr]
  7421.           set cur [list $word]
  7422.           set i [string len $word]
  7423.         } else {
  7424.           lappend cur $word
  7425.         }
  7426.         incr i
  7427.       }
  7428.       #regsub -all "<ZQ" $cur "\002" cur
  7429.       #regsub -all "<ZX" $cur "\037" cur
  7430.       #regsub -all "<ZJ" $cur "\003" cur
  7431.       lappend out [join $cur $splitChr]
  7432.     }
  7433.  
  7434.     # FLOOD_INIT
  7435.     # modified from bseen
  7436.     #
  7437.     variable flood_data
  7438.     variable flood_array
  7439.     proc flood_init {} {
  7440.       if {$incith::google::ignore < 1} {
  7441.         return 0
  7442.       }
  7443.       if {![string match *:* $incith::google::flood]} {
  7444.         putlog "$incith::google::version: variable flood not set correctly."
  7445.         return 1
  7446.       }
  7447.       set incith::google::flood_data(flood_num) [lindex [split $incith::google::flood :] 0]
  7448.       set incith::google::flood_data(flood_time) [lindex [split $incith::google::flood :] 1]
  7449.       set i [expr $incith::google::flood_data(flood_num) - 1]
  7450.       while {$i >= 0} {
  7451.         set incith::google::flood_array($i) 0
  7452.         incr i -1
  7453.       }
  7454.     }
  7455.     ; flood_init
  7456.  
  7457.     # FLOOD
  7458.     # updates and returns a users flood status
  7459.     #
  7460.     proc flood {nick uhand} {
  7461.       if {$incith::google::ignore < 1} {
  7462.         return 0
  7463.       }
  7464.       if {$incith::google::flood_data(flood_num) == 0} {
  7465.         return 0
  7466.       }
  7467.       set i [expr ${incith::google::flood_data(flood_num)} - 1]
  7468.       while {$i >= 1} {
  7469.         set incith::google::flood_array($i) $incith::google::flood_array([expr $i - 1])
  7470.         incr i -1
  7471.       }
  7472.       set incith::google::flood_array(0) [unixtime]
  7473.       if {[expr [unixtime] - $incith::google::flood_array([expr ${incith::google::flood_data(flood_num)} - 1])] <= ${incith::google::flood_data(flood_time)}} {
  7474.         putlog "$incith::google::version: flood detected from ${nick}."
  7475.         putserv "notice $nick :$incith::google::version: flood detected, placing you on ignore for $::incith::google::ignore minute(s)! :P"
  7476.         newignore [join [maskhost *!*[string trimleft $uhand ~]]] $incith::google::version flooding $incith::google::ignore
  7477.         return 1
  7478.       } else {
  7479.         return 0
  7480.       }
  7481.     }
  7482.  
  7483.  
  7484.     # AUTOMAGIC CHARSET ENCODING SUPPORT
  7485.     # on the fly encoding support
  7486.     #
  7487.     proc incithdecode {text} {
  7488.       global incithcharset
  7489.       if {[lsearch -exact [encoding names] $incithcharset] != -1} {
  7490.         set text [encoding convertfrom $incithcharset $text]
  7491.       }
  7492.       return $text
  7493.     }
  7494.  
  7495.     proc incithencode {text} {
  7496.       global incithcharset
  7497.       if {[lsearch -exact [encoding names] $incithcharset] != -1} {
  7498.         set text [encoding convertto $incithcharset $text]
  7499.       }
  7500.       return $text
  7501.     }
  7502.  
  7503.     # utf-8 sucks for displaying any language using extended ascii, this helps alleviate that.
  7504.     # correct utf-8 problems before they even appear.
  7505.     proc utf8encodefix {country input} {
  7506.       if {[lsearch -exact [encoding names] [set encoding_found [lindex [split [lindex $incith::google::encode_strings [lsearch -glob $incith::google::encode_strings "${country}:*"]] :] 1]]]} {
  7507.         if {![string match "" $encoding_found]} { set input [encoding convertto $encoding_found $input] }
  7508.       }
  7509.       return $input
  7510.     }
  7511.  
  7512.     # Wikipedia/Wikimedia subtag-decoder...
  7513.     # decodes those silly subtags
  7514.     #
  7515.     proc subtagDecode {text} {
  7516.       set url ""
  7517.       regsub -all {\.([0-9a-fA-F][0-9a-fA-F])} $text {[format %c 0x\1]} text
  7518.       set text [subst $text]
  7519.       regsub -all "\r\n" $text "\n" text
  7520.       foreach byte [split [encoding convertto "utf-8" $text] ""] {
  7521.         scan $byte %c i
  7522.         if { $i < 33 } {
  7523.           append url [format %%%02X $i]
  7524.         } else {
  7525.           append url $byte
  7526.         }
  7527.       }
  7528.       return [string map {% .} $url]
  7529.     }
  7530.  
  7531.     # Vocabulary Aversion
  7532.     # This converts swear words into appropriate words for IRC
  7533.     # this is rather rudementary, is probably a better way to do this but meh..
  7534.     #
  7535.     proc vocabaversion {text} {
  7536.       set newtext ""
  7537.       foreach element [split $text] {
  7538.         set violation 0
  7539.         foreach vocabulary $incith::google::aversion {
  7540.           set swear [lindex [split $vocabulary :] 0]
  7541.           set avert [join [lrange [split $vocabulary :] 1 end]]
  7542.           if {[string match -nocase "$swear" $element] && $avert != ""} {
  7543.             append newtext "$avert "
  7544.             set violation 1
  7545.             break
  7546.           }
  7547.         }
  7548.         if {$violation == 0} { append newtext "$element " }
  7549.       }
  7550.       return [string trim $newtext]
  7551.     }
  7552.  
  7553.     # Description Decode
  7554.     # convert html codes into characters - credit perplexa (urban dictionary)
  7555.     #
  7556.     proc descdecode {text} {
  7557.       # code below is neccessary to prevent numerous html markups
  7558.       # from appearing in the output (ie, &quot;, &#5671;, etc)
  7559.       # stolen (borrowed is a better term) from perplexa's urban
  7560.       # dictionary script..
  7561.       if {[string match *&* $text]} {
  7562.         global incithcharset
  7563.         set escapes {
  7564.         &nbsp; \xa0 &iexcl; \xa1 &cent; \xa2 &pound; \xa3 &curren; \xa4
  7565.         &yen; \xa5 &brvbar; \xa6 &sect; \xa7 &uml; \xa8 &copy; \xa9
  7566.         &ordf; \xaa &laquo; \xab &not; \xac &shy; \xad &reg; \xae
  7567.         &macr; \xaf &deg; \xb0 &plusmn; \xb1 &sup2; \xb2 &sup3; \xb3
  7568.         &acute; \xb4 &micro; \xb5 &para; \xb6 &middot; \xb7 &cedil; \xb8
  7569.         &sup1; \xb9 &ordm; \xba &raquo; \xbb &frac14; \xbc &frac12; \xbd
  7570.         &frac34; \xbe &iquest; \xbf &Agrave; \xc0 &Aacute; \xc1 &Acirc; \xc2
  7571.         &Atilde; \xc3 &Auml; \xc4 &Aring; \xc5 &AElig; \xc6 &Ccedil; \xc7
  7572.         &Egrave; \xc8 &Eacute; \xc9 &Ecirc; \xca &Euml; \xcb &Igrave; \xcc
  7573.         &Iacute; \xcd &Icirc; \xce &Iuml; \xcf &ETH; \xd0 &Ntilde; \xd1
  7574.         &Ograve; \xd2 &Oacute; \xd3 &Ocirc; \xd4 &Otilde; \xd5 &Ouml; \xd6
  7575.         &times; \xd7 &Oslash; \xd8 &Ugrave; \xd9 &Uacute; \xda &Ucirc; \xdb
  7576.         &Uuml; \xdc &Yacute; \xdd &THORN; \xde &szlig; \xdf &agrave; \xe0
  7577.         &aacute; \xe1 &acirc; \xe2 &atilde; \xe3 &auml; \xe4 &aring; \xe5
  7578.         &aelig; \xe6 &ccedil; \xe7 &egrave; \xe8 &eacute; \xe9 &ecirc; \xea
  7579.         &euml; \xeb &igrave; \xec &iacute; \xed &icirc; \xee &iuml; \xef
  7580.         &eth; \xf0 &ntilde; \xf1 &ograve; \xf2 &oacute; \xf3 &ocirc; \xf4
  7581.         &otilde; \xf5 &ouml; \xf6 &divide; \xf7 &oslash; \xf8 &ugrave; \xf9
  7582.         &uacute; \xfa &ucirc; \xfb &uuml; \xfc &yacute; \xfd &thorn; \xfe
  7583.         &yuml; \xff &fnof; \u192 &Alpha; \u391 &Beta; \u392 &Gamma; \u393 &Delta; \u394
  7584.         &Epsilon; \u395 &Zeta; \u396 &Eta; \u397 &Theta; \u398 &Iota; \u399
  7585.         &Kappa; \u39A &Lambda; \u39B &Mu; \u39C &Nu; \u39D &Xi; \u39E
  7586.         &Omicron; \u39F &Pi; \u3A0 &Rho; \u3A1 &Sigma; \u3A3 &Tau; \u3A4
  7587.         &Upsilon; \u3A5 &Phi; \u3A6 &Chi; \u3A7 &Psi; \u3A8 &Omega; \u3A9
  7588.         &alpha; \u3B1 &beta; \u3B2 &gamma; \u3B3 &delta; \u3B4 &epsilon; \u3B5
  7589.         &zeta; \u3B6 &eta; \u3B7 &theta; \u3B8 &iota; \u3B9 &kappa; \u3BA
  7590.         &lambda; \u3BB &mu; \u3BC &nu; \u3BD &xi; \u3BE &omicron; \u3BF
  7591.         &pi; \u3C0 &rho; \u3C1 &sigmaf; \u3C2 &sigma; \u3C3 &tau; \u3C4
  7592.         &upsilon; \u3C5 &phi; \u3C6 &chi; \u3C7 &psi; \u3C8 &omega; \u3C9
  7593.         &thetasym; \u3D1 &upsih; \u3D2 &piv; \u3D6 &bull; \u2022
  7594.         &hellip; \u2026 &prime; \u2032 &Prime; \u2033 &oline; \u203E
  7595.         &frasl; \u2044 &weierp; \u2118 &image; \u2111 &real; \u211C
  7596.         &trade; \u2122 &alefsym; \u2135 &larr; \u2190 &uarr; \u2191
  7597.         &rarr; \u2192 &darr; \u2193 &harr; \u2194 &crarr; \u21B5
  7598.         &lArr; \u21D0 &uArr; \u21D1 &rArr; \u21D2 &dArr; \u21D3 &hArr; \u21D4
  7599.         &forall; \u2200 &part; \u2202 &exist; \u2203 &empty; \u2205
  7600.         &nabla; \u2207 &isin; \u2208 &notin; \u2209 &ni; \u220B &prod; \u220F
  7601.         &sum; \u2211 &minus; \u2212 &lowast; \u2217 &radic; \u221A
  7602.         &prop; \u221D &infin; \u221E &ang; \u2220 &and; \u2227 &or; \u2228
  7603.         &cap; \u2229 &cup; \u222A &int; \u222B &there4; \u2234 &sim; \u223C
  7604.         &cong; \u2245 &asymp; \u2248 &ne; \u2260 &equiv; \u2261 &le; \u2264
  7605.         &ge; \u2265 &sub; \u2282 &sup; \u2283 &nsub; \u2284 &sube; \u2286
  7606.         &supe; \u2287 &oplus; \u2295 &otimes; \u2297 &perp; \u22A5
  7607.         &sdot; \u22C5 &lceil; \u2308 &rceil; \u2309 &lfloor; \u230A
  7608.         &rfloor; \u230B &lang; \u2329 &rang; \u232A &loz; \u25CA
  7609.         &spades; \u2660 &clubs; \u2663 &hearts; \u2665 &diams; \u2666
  7610.         &quot; \x22 &amp; \x26 &lt; \x3C &gt; \x3E O&Elig; \u152 &oelig; \u153
  7611.         &Scaron; \u160 &scaron; \u161 &Yuml; \u178 &circ; \u2C6
  7612.         &tilde; \u2DC &ensp; \u2002 &emsp; \u2003 &thinsp; \u2009
  7613.         &zwnj; \u200C &zwj; \u200D &lrm; \u200E &rlm; \u200F &ndash; \u2013
  7614.         &mdash; \u2014 &lsquo; \u2018 &rsquo; \u2019 &sbquo; \u201A
  7615.         &ldquo; \u201C &rdquo; \u201D &bdquo; \u201E &dagger; \u2020
  7616.         &Dagger; \u2021 &permil; \u2030 &lsaquo; \u2039 &rsaquo; \u203A
  7617.         &euro; \u20AC &apos; \u0027 &lrm; "" &rlm; "" &#8236; "" &#8237; ""
  7618.         &#8238; "" &#8212; \u2014
  7619.         }
  7620.         set text [string map $escapes $text]
  7621.         # enable transcoding html elements?
  7622.         if {$::incith::google::dirty_decode > 0} {
  7623.           if {![string equal $incithcharset [encoding system]]} { set text [encoding convertfrom $incithcharset $text] }
  7624.           set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $text]
  7625.           regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
  7626.           regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
  7627.           regsub -all -- {\\x([[:xdigit:]]{1,2})} $text {[format %c [scan "\1" %x]]} text
  7628.           set text [subst "$text"]
  7629.           if {![string equal $incithcharset [encoding system]]} { set text [encoding convertto $incithcharset $text] }
  7630.         }
  7631.       }
  7632.       # correct possible bleedover of bold or underline
  7633.       set fix "" ;
  7634.       if {[expr {[regexp -all {\002} $text] & 1 }]} {
  7635.         append fix "\002"
  7636.       }
  7637.       if {[expr {[regexp -all {\037} $text] & 1 }]} {
  7638.         append fix "\037"
  7639.       }
  7640.       set text "$text$fix"
  7641.       return $text
  7642.      
  7643.     }
  7644.  
  7645.     # URL Decode
  7646.     # Decodes all of the %00 strings in a url and returns it
  7647.     #
  7648.     proc urldecode {text} {
  7649.       set url ""
  7650.       # tcl filter required because we are using SUBST command below
  7651.       # this will escape any sequence which could potentially trigger
  7652.       # the interpreter..
  7653.         regsub -all -- \\\\ $text \\\\\\\\ text
  7654.         regsub -all -- \\\[ $text \\\\\[ text
  7655.         regsub -all -- \\\] $text \\\\\] text
  7656.         regsub -all -- \\\} $text \\\\\} text
  7657.         regsub -all -- \\\{ $text \\\\\{ text
  7658.         regsub -all -- \\\" $text \\\\\" text
  7659.        regsub -all -- \\\$ $text \\\\\$ text
  7660.      # end tcl filter
  7661.      regsub -all {\%([0-9a-fA-F][0-9a-fA-F])} $text {[format %c 0x\1]} text
  7662.      set text [subst $text]
  7663.      foreach byte [split $text ""] {
  7664.        scan $byte %c i
  7665.        if { $i < 33 || $i > 127 } {
  7666.          append url [format %%%02X $i]
  7667.        } else {
  7668.          append url $byte
  7669.        }
  7670.      }
  7671.      return $url
  7672.    }
  7673.    # Un Gzip
  7674.    # Unzips those silly g-zipped wikis
  7675.    #
  7676.    proc ungzip {html metas} {
  7677.      if {$::incith::google::use_gzip > 0} {
  7678.        if {![info exists ::incith_nozlib]} {
  7679.          foreach {name value} $metas {
  7680.            if {[regexp -nocase ^Content-Encoding$ $name]} {
  7681.              if {[string equal -nocase "gzip" $value]} {
  7682.               if {![info exists ::incith_trf]} {
  7683.                  if {[catch {set html [zlib inflate [string range $html 10 [expr { [string length $html] - 8 } ]]]} error]} { return $html }
  7684.                } else {
  7685.                  set html [zip -mode decompress -nowrap 1 [string range $html 10 [expr { [string length $html] - 8 } ]]]
  7686.                }
  7687.                break
  7688.              }
  7689.            }
  7690.          }
  7691.        }
  7692.      }
  7693.      return $html
  7694.    }
  7695.  
  7696.    # URL Encode
  7697.    # Encodes anything not a-zA-Z0-9 into %00 strings...
  7698.    #
  7699.    proc urlencode {text type {enc ""}} {
  7700.      if {[string length $enc]} {
  7701.        set text [encoding convertto $enc $text]
  7702.      }
  7703.      set url ""
  7704.      foreach byte [split $text ""] {
  7705.        scan $byte %c i
  7706.        if {$i < 65 || $i > 122} {
  7707.          append url [format %%%02X $i]
  7708.        } else {
  7709.          append url $byte
  7710.        }
  7711.      }
  7712.      if {$type == 1} {
  7713.        return [string map {%25 . %3A : %2D - %2F / %2E . %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 %80 _ % .} $url]
  7714.      } else {
  7715.        return [string map {%2D - %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $url]
  7716.      }
  7717.    }
  7718.  }
  7719. }
  7720.  
  7721. putlog " - UNOFFICIAL $incith::google::version loaded."
  7722.  
  7723. # EOF
Advertisement
Add Comment
Please, Sign In to add comment