BT.Modules.tcl 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875
  1. ##########################################################
  2. #
  3. # BLackToolS
  4. # Modules TCL
  5. #
  6. # BLaCkShaDoW ProductionS
  7. ##########################################################
  8. set black(gag_file) "scripts/BlackTools/FILES/$username.gag.txt"
  9. if {![file exists $black(gag_file)]} {
  10. set file [open $black(gag_file) w]
  11. close $file
  12. }
  13. proc check:stats:entries {oldpath newpath} {
  14. global botnick
  15. if {![file exists $newpath]} {
  16. set file [open $newpath w]
  17. close $file
  18. }
  19. if {[file exists $oldpath]} {
  20. set file [open $oldpath r]
  21. set w [read -nonewline $file]
  22. close $file
  23. if {$w != ""} {
  24. set data [split $w "\n"]
  25. foreach entry $data {
  26. set file [open $newpath a]
  27. puts $file "$entry"
  28. close $file
  29. }
  30. set file [open $oldpath w]
  31. close $file
  32. }
  33. }
  34. }
  35. set old_stats_dir "$username.stats.db"
  36. set new_stats_dir "scripts/BlackTools/FILES/$username.stats.txt"
  37. check:stats:entries $old_stats_dir $new_stats_dir
  38. proc check:away {oldpath newpath} {
  39. global black
  40. if {![file exists $newpath]} {
  41. set file [open $newpath w]
  42. close $file
  43. }
  44. if {[file exists $oldpath]} {
  45. set file [open $oldpath r]
  46. set w [gets $file]
  47. close $file
  48. if {$w != ""} {
  49. set file [open $newpath a]
  50. puts $file "$w"
  51. close $file
  52. }
  53. set file [open $oldpath w]
  54. close $file
  55. }
  56. }
  57. set old_away_dir "$username.away.txt"
  58. set new_away_dir "scripts/BlackTools/FILES/$username.away.txt"
  59. check:away $old_away_dir $new_away_dir
  60. proc check:badchan:entries {chan oldpath newpath} {
  61. global botnick
  62. if {![file exists $newpath]} {
  63. set file [open $newpath w]
  64. close $file
  65. }
  66. if {[file exists $oldpath]} {
  67. set file [open $oldpath r]
  68. set w [read -nonewline $file]
  69. close $file
  70. if {$w != ""} {
  71. set data [split $w "\n"]
  72. foreach entry $data {
  73. set file [open $newpath a]
  74. puts $file "$chan $entry NONE"
  75. close $file
  76. }
  77. set file [open $oldpath w]
  78. close $file
  79. }
  80. }
  81. }
  82. proc check:module {oldpath newpath} {
  83. global botnick
  84. if {![file exists $newpath]} {
  85. set file [open $newpath w]
  86. close $file
  87. }
  88. if {[file exists $oldpath]} {
  89. set file [open $oldpath r]
  90. set w [read -nonewline $file]
  91. close $file
  92. if {$w != ""} {
  93. set data [split $w "\n"]
  94. foreach entry $data {
  95. set file [open $newpath a]
  96. puts $file "$entry"
  97. close $file
  98. }
  99. set file [open $oldpath w]
  100. close $file
  101. }
  102. }
  103. }
  104. set old_status_dir "$username.status.txt"
  105. set new_status_dir "scripts/BlackTools/FILES/$username.status.txt"
  106. check:module $old_status_dir $new_status_dir
  107. set old_seen_dir "$username.Seen.db"
  108. set new_seen_dir "scripts/BlackTools/FILES/$username.Seen.db"
  109. check:module $old_seen_dir $new_seen_dir
  110. proc check:greet:entries {chan oldpath newpath} {
  111. global botnick
  112. if {![file exists $newpath]} {
  113. set file [open $newpath w]
  114. close $file
  115. }
  116. if {[file exists $oldpath]} {
  117. set file [open $oldpath r]
  118. set w [read -nonewline $file]
  119. close $file
  120. if {$w != ""} {
  121. set data [split $w "\n"]
  122. foreach entry $data {
  123. set file [open $newpath a]
  124. puts $file "$chan 0 $entry"
  125. close $file
  126. }
  127. set file [open $oldpath w]
  128. close $file
  129. }
  130. }
  131. }
  132. proc check:anunt:entries {chan oldpath newpath} {
  133. global botnick
  134. if {![file exists $newpath]} {
  135. set file [open $newpath w]
  136. close $file
  137. }
  138. if {[file exists $oldpath]} {
  139. set file [open $oldpath r]
  140. set w [read -nonewline $file]
  141. close $file
  142. if {$w != ""} {
  143. set data [split $w "\n"]
  144. foreach entry $data {
  145. set file [open $newpath a]
  146. puts $file "$chan $entry"
  147. close $file
  148. }
  149. set file [open $oldpath w]
  150. close $file
  151. }
  152. }
  153. }
  154. proc check:broadcast:entries {oldpath newpath} {
  155. global botnick
  156. if {![file exists $newpath]} {
  157. set file [open $newpath w]
  158. close $file
  159. }
  160. if {[file exists $oldpath]} {
  161. set file [open $oldpath r]
  162. set w [read -nonewline $file]
  163. close $file
  164. if {$w != ""} {
  165. set data [split $w "\n"]
  166. foreach entry $data {
  167. set file [open $newpath a]
  168. puts $file "$entry"
  169. close $file
  170. }
  171. set file [open $oldpath w]
  172. close $file
  173. }
  174. }
  175. }
  176. set old_broadcast_dir "logs/broadcast.txt"
  177. set new_broadcast_dir "scripts/BlackTools/FILES/$username.autobroadcast.txt"
  178. check:broadcast:entries $old_broadcast_dir $new_broadcast_dir
  179. foreach chan [join [channels]] {
  180. set old_greet_dir "logs/greet($chan).txt"
  181. set new_greet_dir "scripts/BlackTools/FILES/$username.greets.txt"
  182. set old_leave_dir "logs/leave($chan).txt"
  183. set new_leave_dir "scripts/BlackTools/FILES/$username.leave.txt"
  184. set old_badchan_dir "logs/badchan($chan).txt"
  185. set new_badchan_dir "scripts/BlackTools/FILES/$username.badchannels.txt"
  186. set old_anunt_dir "logs/anunt($chan).txt"
  187. set new_anunt_dir "scripts/BlackTools/FILES/$username.announce.txt"
  188. set old_topic_dir "logs/topic($chan).txt"
  189. set new_topic_dir "scripts/BlackTools/FILES/$username.topic.txt"
  190. check:greet:entries $chan $old_leave_dir $new_greet_dir
  191. check:greet:entries $chan $old_leave_dir $new_leave_dir
  192. check:badchan:entries $chan $old_badchan_dir $new_badchan_dir
  193. check:anunt:entries $chan $old_anunt_dir $new_anunt_dir
  194. check:anunt:entries $chan $old_topic_dir $new_topic_dir
  195. }
  196. if {![info exists anuntpublic:show_running]} {
  197. timer $black(anunttime) anuntpublic:show
  198. set anuntpublic:show_running 1
  199. }
  200. if {![info exists times_topic_running]} {
  201. timer $black(topic_time) times_topic
  202. set times_topic_running 1
  203. }
  204. if {![info exists antibotidle:module_running]} {
  205. set sdir "scripts/BlackTools/FILES/$username.status.txt"
  206. set file [open $sdir "r"]
  207. set database [read -nonewline $file]
  208. close $file
  209. set data [split $database "\n"]
  210. if {$data != ""} {
  211. foreach line $data {
  212. set type [lindex [split $line] 0]
  213. set stats [lindex [split $line] 1]
  214. if {($type == "antibotidle:module") && ($stats == "ON")} {
  215. timer $black(noidlemax) antibotidle:module
  216. set antibotidle:module_running 1
  217. }
  218. }
  219. }
  220. }
  221. if {![info exists broadcastpublic:show_running]} {
  222. set sdir "scripts/BlackTools/FILES/$username.status.txt"
  223. set file [open $sdir "r"]
  224. set database [read -nonewline $file]
  225. close $file
  226. set data [split $database "\n"]
  227. if {$data != ""} {
  228. foreach line $data {
  229. set type [lindex [split $line] 0]
  230. set stats [lindex [split $line] 1]
  231. if {($type == "broadcastpublic:show") && ($stats == "ON")} {
  232. timer $black(bttime) broadcastpublic:show
  233. set broadcastpublic:show_running 1
  234. }
  235. }
  236. }
  237. }
  238. proc blacktools:tell:prv {nick host hand type arg} {
  239. global botnick black
  240. set char(p) [lindex $black(cmdchar) 0]
  241. if {[string match -nocase "none" "$char(p)"]} {
  242. set char(p) ""
  243. }
  244. set replace(%botnick%) $botnick
  245. set replace(%char%) $char(p)
  246. set replace(%msg%) [lrange [split $arg] 0 end]
  247. set replace(%msg.1%) [lindex [split $arg] 0]
  248. set replace(%msg.2%) [lindex [split $arg] 1]
  249. set replace(%msg.3%) [lindex [split $arg] 2]
  250. set replace(%msg.4%) [lrange [split $arg] 1 end]
  251. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  252. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  253. if {[info exists black(say.$getlang.$type)]} {
  254. set reply [string map [array get replace] $black(say.$getlang.$type)]
  255. puthelp "PRIVMSG $nick :$reply"
  256. }
  257. }
  258. proc blacktools:tell {nick host hand chan chan1 type arg} {
  259. global black botnick
  260. set char(p) [lindex $black(cmdchar) 0]
  261. if {[string match -nocase "none" "$char(p)"]} {
  262. set char(p) ""
  263. }
  264. set replace(%botnick%) $botnick
  265. set replace(%char%) $char(p)
  266. set replace(%chan%) $chan
  267. set replace(%msg%) [join [lrange $arg 0 end]]
  268. set replace(%msg.set%) [join [lrange [split $arg] 1 end]]
  269. set replace(%msg.1%) [lindex $arg 0]
  270. set replace(%msg.2%) [lindex $arg 1]
  271. set replace(%msg.3%) [lindex $arg 2]
  272. set replace(%msg.4%) [lindex $arg 3]
  273. set replace(%msg.5%) [lrange $arg 4 end]
  274. set replace(%msg.6%) [lrange $arg 3 end]
  275. set replace(%msg.7%) [lrange $arg 2 end]
  276. set replace(%msg.8%) [join [lrange $arg 1 end]]
  277. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  278. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  279. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  280. if {$getmethod == ""} { set getmethod "1" }
  281. if {[info exists black(say.$getlang.$type)]} {
  282. set reply [string map [array get replace] $black(say.$getlang.$type)]
  283. if {$getmethod == "1"} {
  284. putserv "NOTICE $nick :$reply"
  285. } else {
  286. putserv "PRIVMSG $chan1 :$reply"
  287. }
  288. }
  289. }
  290. ######################## Flood Protection #######################
  291. proc flood:join:protection {nick host hand chan} {
  292. global black count
  293. if {[channel get $chan greet] || [channel get $chan count] || [channel get $chan antijoinflood]} {
  294. set joinflood [channel get $chan joinflood]
  295. if {$joinflood == ""} {set joinflood "4:5"}
  296. set number [scan $joinflood %\[^:\]]
  297. set time [scan $joinflood %*\[^:\]:%s]
  298. foreach tmr [utimers] {
  299. if {[string match "*count(flood:join:$chan)*" [join [lindex $tmr 1]]]} {
  300. killutimer [lindex $tmr 2]
  301. }
  302. }
  303. if {[info exists black(turnOnFlood:$chan)]} {
  304. return
  305. }
  306. if {![info exists count(flood:join:$chan)]} {
  307. set count(flood:join:$chan) 0
  308. }
  309. incr count(flood:join:$chan)
  310. utimer $time [list remove:flood:join $chan]
  311. if {$count(flood:join:$chan) >= $number} {
  312. set black(turnOnFlood:$chan) 1
  313. utimer 60 [list unset black(turnOnFlood:$chan)]
  314. return
  315. }
  316. }
  317. }
  318. proc remove:flood:join {chan} {
  319. global count
  320. if {[info exists count(flood:join:$chan)]} {
  321. unset count(flood:join:$chan)
  322. }
  323. }
  324. ########################### TCL #################################
  325. proc tclpublic {nick host hand chan arg} {
  326. global black
  327. set type 0
  328. set chan1 "$chan"
  329. set the_script [lindex [split $arg] 1]
  330. set who [lindex [split $arg] 0]
  331. tcl:process $nick $host $hand $chan $chan1 $type $the_script $who
  332. }
  333. proc tcl:process {nick host hand chan chan1 type the_script who} {
  334. global black
  335. if {($who == "") && ($type == "0")} {
  336. blacktools:tell $nick $host $hand $chan $chan1 tcl.15 none
  337. return
  338. }
  339. if {($who == "") && ($type == "1")} {
  340. blacktools:tell $nick $host $hand $chan $chan1 tcl.16 none
  341. return
  342. }
  343. switch $who {
  344. list {
  345. set scripts ""
  346. set file [open "$black(configname)" r]
  347. set w [read -nonewline $file]
  348. close $file
  349. set data [split $w "\n"]
  350. foreach line $data {
  351. if {[string match -nocase "source $black(dirname)/*" $line]} {
  352. set the_split [split $line "/"]
  353. set the_script [lindex $the_split 1]
  354. lappend scripts $the_script
  355. }
  356. }
  357. blacktools:tell $nick $host $hand $chan $chan1 tcl.1 none
  358. foreach txt [wordwrap [join $scripts ", "] 250 ,] {
  359. blacktools:tell $nick $host $hand $chan $chan1 tcl.17 $txt
  360. }
  361. }
  362. load {
  363. if {$the_script == ""} {
  364. blacktools:tell $nick $host $hand $chan $chan1 tcl.2 none
  365. return
  366. }
  367. set black(tcl_load) [catch {source "$black(dirname)/$the_script"} black(tcl_load_error)]
  368. if {$black(tcl_load) == "1"} {
  369. blacktools:tell $nick $host $hand $chan $chan1 tcl.3 "$the_script [split $black(tcl_load_error)]"
  370. return
  371. }
  372. set file [open "$black(configname)" r]
  373. set w [read -nonewline $file]
  374. close $file
  375. set counter -1
  376. set data [split $w "\n"]
  377. set tcl_position -1
  378. set found_it 0
  379. foreach line $data {
  380. if {[string match -nocase "source $black(dirname)/*" $line]} {
  381. set the_split [split $line "/"]
  382. set script [lindex $the_split 1]
  383. if {[string equal -nocase $script $the_script]} {
  384. set found_it 1
  385. }
  386. }
  387. }
  388. if {$found_it == 1} {
  389. blacktools:tell $nick $host $hand $chan $chan1 tcl.4 $the_script
  390. return
  391. }
  392. set file [open "$black(configname)" a]
  393. puts $file "source $black(dirname)/$the_script"
  394. close $file
  395. rehash
  396. blacktools:tell $nick $host $hand $chan $chan1 tcl.5 $the_script
  397. }
  398. unload {
  399. if {$the_script == ""} {
  400. blacktools:tell $nick $host $hand $chan $chan1 tcl.6 $the_script
  401. return
  402. }
  403. if {[string match "*BlackTools*" $the_script]} {
  404. blacktools:tell $nick $host $hand $chan $chan1 tcl.18 none
  405. return
  406. }
  407. set file [open "$black(configname)" r]
  408. set w [read -nonewline $file]
  409. close $file
  410. set counter -1
  411. set data [split $w "\n"]
  412. set tcl_position -1
  413. set found_it 0
  414. foreach line $data {
  415. set counter [expr $counter + 1]
  416. if {[string match -nocase "*source $black(dirname)/*" $line]} {
  417. set the_split [split $line "/"]
  418. set script [lindex $the_split 1]
  419. if {[string equal -nocase $script $the_script]} {
  420. set found_it 1
  421. set tcl_position $counter
  422. }
  423. }
  424. }
  425. if {$found_it == 0} {
  426. blacktools:tell $nick $host $hand $chan $chan1 tcl.7 $the_script
  427. return
  428. }
  429. set delete [lreplace $data $tcl_position $tcl_position]
  430. set file [open "$black(configname)" "w"]
  431. puts $file [join $delete "\n"]
  432. close $file
  433. rehash
  434. blacktools:tell $nick $host $hand $chan $chan1 tcl.8 $the_script
  435. }
  436. all {
  437. set the_files [glob -directory $black(dirname) "*.tcl"]
  438. set counter 0
  439. set current_tcl ""
  440. foreach file $the_files {
  441. set counter [expr $counter + 1]
  442. }
  443. if {$counter > 30} {
  444. blacktools:tell $nick $host $hand $chan $chan1 tcl.9 $counter
  445. } else { blacktools:tell $nick $host $hand $chan $chan1 tcl.10 $counter
  446. }
  447. set counter 0
  448. foreach file $the_files {
  449. set counter [expr $counter + 1]
  450. set split_file [split $file "/"]
  451. set the_file [lindex $split_file 1]
  452. set status [check:if:load $the_file]
  453. if {$counter < 30} {
  454. if {$status == "1"} {
  455. lappend current_tcl "\002$the_file\002"
  456. } else {
  457. lappend current_tcl $the_file
  458. }
  459. }
  460. }
  461. foreach txt [wordwrap [join $current_tcl ", "] 250 ,] {
  462. blacktools:tell $nick $host $hand $chan $chan1 tcl.17 $txt
  463. }
  464. }
  465. info {
  466. if {$the_script == ""} {
  467. blacktools:tell $nick $host $hand $chan $chan1 tcl.11 none
  468. return
  469. }
  470. set status_valid [check:if:valid $the_script]
  471. set status [check:if:load $the_script]
  472. if {$status_valid == "0"} {
  473. blacktools:tell $nick $host $hand $chan $chan1 tcl.12 $the_script
  474. return
  475. }
  476. if {$status == "0"} {
  477. blacktools:tell $nick $host $hand $chan $chan1 tcl.13 $the_script
  478. } else {
  479. blacktools:tell $nick $host $hand $chan $chan1 tcl.14 $the_script
  480. }
  481. }
  482. default {
  483. blacktools:tell $nick $host $hand $chan $chan1 tcl.15 none
  484. }
  485. }
  486. }
  487. proc check:if:valid {tcl} {
  488. global black
  489. set the_files [glob -directory $black(dirname) "*.tcl"]
  490. foreach file $the_files {
  491. set split_file [split $file "/"]
  492. set the_file [lindex $split_file 1]
  493. if {[string equal -nocase $tcl $the_file]} {
  494. return 1
  495. }
  496. }
  497. return 0
  498. }
  499. proc check:if:load {tcl} {
  500. global black
  501. set file [open "$black(configname)" r]
  502. set w [read -nonewline $file]
  503. close $file
  504. set data [split $w "\n"]
  505. set found_it 0
  506. foreach line $data {
  507. if {[string match -nocase "source $black(dirname)/*" $line]} {
  508. set the_split [split $line "/"]
  509. set script [lindex $the_split 1]
  510. if {[string equal -nocase $script $tcl]} {
  511. set found_it 1
  512. }
  513. }
  514. }
  515. if {$found_it == 1} {
  516. return 1
  517. } else {
  518. return 0
  519. }
  520. }
  521. ########################## Login ###############################
  522. proc loginpublic {my} {
  523. global botnick black
  524. if {[info exists black(logged)]} {
  525. unset black(logged)
  526. }
  527. if {[info exists black(notlogged)]} {
  528. unset black(notlogged)
  529. }
  530. putquick "$black(login)"
  531. putquick "MODE $botnick :$black(xmod)"
  532. }
  533. proc publiclogin:Cmd {nick host hand chan arg} {
  534. global botnick black
  535. putquick "$black(login)"
  536. putquick "MODE $botnick :$black(xmod)"
  537. blacktools:tell:prv $nick $host $hand login.1 $black(chanserv)
  538. }
  539. ################################# reban ################################
  540. proc rebanpublic {nick host hand chan} {
  541. global black
  542. if {[channel get $chan xban]} {
  543. set host "$nick![getchanhost $nick $chan]"
  544. set getxtime [channel get $chan xbantime]
  545. set getxlevel [channel get $chan xbanlevel]
  546. if {$getxlevel == "0"} { set getxlevel "100" }
  547. if {$getxtime == "0"} { set getxtime "1" }
  548. foreach ban [banlist $chan] {
  549. set reason [lindex $ban 1]
  550. if {[string match -nocase [string tolower [lindex $ban 0]] $host]} {
  551. putquick "PRIVMSG $black(chanserv) :ban $chan [lindex $ban 0] $getxtime $getxlevel $reason"
  552. }
  553. }
  554. }
  555. }
  556. ################################# XTOOLS ################################
  557. proc toolspublic {chan type} {
  558. global botnick black
  559. if {![channel get $chan xtools]} {
  560. return
  561. }
  562. if {$type == "op"} {
  563. if {![onchan "$black(chanserv)" $chan] && ![botisop $chan]} {
  564. return
  565. }
  566. putquick "PRIVMSG $black(chanserv) :unban $chan $botnick"
  567. putquick "PRIVMSG $black(chanserv) :op $chan $botnick"
  568. return
  569. }
  570. if {$type == "unban"} {
  571. putquick "PRIVMSG $black(chanserv) :unban $chan $botnick"
  572. return
  573. }
  574. if {$type == "invite" || $type == "limit"} {
  575. putquick "PRIVMSG $black(chanserv) :invite $chan $botnick"
  576. return
  577. }
  578. if {$type == "key"} {
  579. putquick "PRIVMSG $black(chanserv) :invite $chan $botnick"
  580. return
  581. }
  582. }
  583. ################################# Key Need ######################################
  584. proc keyneed {chan type} {
  585. global black
  586. if {![validchan $chan]} {
  587. return
  588. }
  589. if {$type == "key"} {
  590. if {![regexp {k} [channel get $chan chanmode]]} {
  591. return
  592. } else {
  593. set the_key [lindex [split [channel get $chan chanmode]] 1]
  594. if {$the_key == ""} { return }
  595. putserv "JOIN $chan :$the_key"
  596. }
  597. }
  598. }
  599. ################################# Clone Scan ###################################
  600. proc scannerpublic {nick host hand chan arg} {
  601. global black count
  602. set c [lindex [split $arg] 0]
  603. set type 0
  604. set chan1 "$chan"
  605. if {[regexp {^[&#]} $c] && [matchattr $hand nm|- $chan]} {
  606. set chan "$c"
  607. }
  608. scanner:process $nick $host $hand $chan $chan1
  609. }
  610. proc scanner:process {nick host hand chan chan1} {
  611. global botnick black
  612. array set clones [list]
  613. if {![validchan $chan]} {
  614. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  615. return
  616. }
  617. if {![onchan $botnick $chan]} {
  618. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  619. return
  620. }
  621. blacktools:tell $nick $host $hand $chan $chan1 clonescan.4 none
  622. if {[channel get $chan clonescan-maxclone] == 0} {
  623. set maxclone $black(maxclone)
  624. } else { set maxclone [channel get $chan clonescan-maxclone] }
  625. if {!($maxclone >= "2")} { return }
  626. foreach user [chanlist $chan] {
  627. set host [string tolower [lindex [split [getchanhost $user $chan] @] 1]]
  628. if {![string match "*.undernet.org*" $host]} {
  629. if {![info exists c($host:$chan)]} {
  630. set c($host:$chan) 0
  631. }
  632. set c($host:$chan) [expr $c($host:$chan) +1]
  633. lappend clones($user) $host
  634. if {$c($host:$chan) >= $maxclone} {
  635. foreach clon [lsort -unique [array names clones]] {
  636. set hosts [string tolower [lindex [split [getchanhost $clon $chan] @] 1]]
  637. if {$host == $hosts} {
  638. lappend clona($host) [join $clon " , "]
  639. }
  640. }
  641. blacktools:tell $nick $host $hand $chan $chan1 clonescan.1 "$c($host:$chan) $host [lsort -unique $clona($host)]"
  642. }
  643. }
  644. }
  645. utimer 3 [list blacktools:tell $nick $host $hand $chan $chan1 clonescan.2 none]
  646. }
  647. proc clonescanner {minute hour day month year} {
  648. global black botnick
  649. foreach chan [channels] {
  650. set replace(%chan%) $chan
  651. if {[channel get $chan clonescan]} {
  652. set getlang [string tolower [channel get $chan lang]]
  653. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  654. if {[channel get $chan clonescan-maxclone] == 0} {
  655. set maxclone $black(maxclone)
  656. } else { set maxclone [channel get $chan clonescan-maxclone] }
  657. if {$maxclone < "2"} { return }
  658. putlog "Scaning for clones on $chan.."
  659. foreach user [chanlist $chan] {
  660. set host [string tolower [lindex [split [getchanhost $user $chan] @] 1]]
  661. set replace(%host%) $host
  662. if {![info exists c($host:$chan)]} {
  663. set c($host:$chan) 0
  664. }
  665. array set clones [list]
  666. if {![string match "*.undernet.org*" $host]} {
  667. set c($host:$chan) [expr $c($host:$chan) +1]
  668. lappend clones($user) $host
  669. if {$c($host:$chan) >= $maxclone} {
  670. foreach clon [array names clones] {
  671. set hosts [string tolower [lindex [split [getchanhost $clon $chan] @] 1]]
  672. if {$host == $hosts} {
  673. lappend clona($host) [join $clon " , "]
  674. }
  675. }
  676. set replace(%num%) $c($host:$chan)
  677. set replace(%clone%) [lsort -unique $clona($host)]
  678. if {[channel get $chan clonescan-action] == "" || [string equal -nocase [channel get $chan clonescan-action] "message"]} {
  679. putserv "NOTICE @$chan :[string map [array get replace] $black(say.$getlang.clonescan.3)]"
  680. } else {
  681. set banmask "*!*@$host"
  682. if {[channel get $chan clonescan-bantime] == 0} {
  683. set bantime $black(clonebtime)
  684. } else { set bantime [channel get $chan clonescan-bantime] }
  685. set reason [channel get $chan clonescan-banreason]
  686. if {$reason == ""} {
  687. set reason [string map [array get replace] [string map [array get replace] $black(say.$getlang.clonescan.5)]]
  688. }
  689. blacktools:banner:2 $banmask $botnick $chan $reason $bantime
  690. }
  691. }
  692. }
  693. }
  694. }
  695. }
  696. }
  697. ################################### gag ###############################
  698. proc gag:process {gagger time reason nick hand host chan chan1 type} {
  699. global botnick black
  700. set char(p) [lindex $black(cmdchar) 0]
  701. if {[string match -nocase "none" "$char(p)"]} {
  702. set char(p) ""
  703. }
  704. set handle [nick2hand $gagger]
  705. if {![validchan $chan]} {
  706. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  707. return
  708. }
  709. if {![onchan $botnick $chan]} {
  710. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  711. return
  712. }
  713. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  714. return
  715. }
  716. if {[matchattr $hand nm|- $chan]} {
  717. if {($gagger == "") && ($type == "0")} {
  718. blacktools:tell $nick $host $hand $chan $chan1 gag.1 none
  719. return
  720. }
  721. if {($gagger == "") && ($type == "1")} {
  722. blacktools:tell $nick $host $hand $chan $chan1 gag.2 none
  723. return
  724. }
  725. }
  726. if {($gagger == "") && ($type == "0")} {
  727. blacktools:tell $nick $host $hand $chan $chan1 gag.3 none
  728. return
  729. }
  730. if {($gagger == "") && ($type == "1")} {
  731. blacktools:tell $nick $host $hand $chan $chan1 gag.4 none
  732. return
  733. }
  734. if {[matchattr $handle $black(exceptflags) $chan]} {
  735. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  736. return
  737. }
  738. if {[string equal -nocase $gagger "-list"]} {
  739. set counter "0"
  740. set file [open $black(gag_file) "r"]
  741. set database [read -nonewline $file]
  742. close $file
  743. set data [split $database "\n"]
  744. if {$database == ""} {
  745. blacktools:tell $nick $host $hand $chan $chan1 gag.7 none
  746. blacktools:tell $nick $host $hand $chan $chan1 gag.8 none
  747. return
  748. }
  749. foreach line $data {
  750. set counter [expr $counter +1]
  751. set hostentry [lindex [split $line] 1]
  752. set chanentry [lindex [split $line] 0]
  753. set timeentry [lindex [split $line] 2]
  754. set reason [join [lrange [split $line] 3 end]]
  755. blacktools:tell $nick $host $hand $chan $chan1 gag.7 none
  756. blacktools:tell $nick $host $hand $chan $chan1 gag.9 "$counter $hostentry [duration [expr $timeentry - [unixtime]]]"
  757. blacktools:tell $nick $host $hand $chan $chan1 gag.14 "$reason"
  758. }
  759. return
  760. }
  761. if {[isbotnick $gagger]} {
  762. return
  763. }
  764. if {![botisop $chan]} {
  765. blacktools:tell $nick $host $hand $chan $chan1 gl.noop none
  766. return
  767. }
  768. if {$reason == ""} {
  769. set reason [channel get $chan gag-reason]
  770. if {$reason == ""} {
  771. set getlang [string tolower [channel get $chan lang]]
  772. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  773. set reason $black(say.$getlang.gag.6)
  774. }
  775. }
  776. if {[isvoice $gagger $chan]} {
  777. putquick "MODE $chan -v $gagger"
  778. }
  779. if {[isop $gagger $chan]} {
  780. blacktools:tell $gagger $host $hand $chan $chan1 gag.12 "$gagger"
  781. return
  782. }
  783. if {[onchan $gagger $chan]} {
  784. set mask *!*@[lindex [split [getchanhost $gagger $chan] "@"] 1]
  785. } else { blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan "$gagger"
  786. return
  787. }
  788. set getlang [string tolower [channel get $chan lang]]
  789. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  790. set replace(%chan%) $chan
  791. set replace(%time%) $time
  792. set replace(%gagger%) $gagger
  793. set gag_user_message [string map [array get replace] $black(say.$getlang.gag.10)]
  794. set gag_chan_message [string map [array get replace] $black(say.$getlang.gag.11)]
  795. putquick "PRIVMSG $chan :$gag_chan_message"
  796. putquick "PRIVMSG $gagger :$gag_user_message"
  797. putquick "MODE $chan +b $mask"
  798. set seconds [expr $time * 60]
  799. set gag_time "[expr [unixtime] + $seconds]"
  800. set gag_act "$chan $mask $gag_time $reason"
  801. set counter "0"
  802. set file [open $black(gag_file) "r"]
  803. set database [read -nonewline $file]
  804. close $file
  805. set data [split $database "\n"]
  806. foreach line $data {
  807. set counter [expr $counter +1]
  808. set hostentry [lindex [split $line] 1]
  809. set chanentry [lindex [split $line] 0]
  810. set timeentry [lindex [split $line] 2]
  811. if {[string match -nocase $mask $hostentry] && [string match -nocase $chanentry $chan]} {
  812. blacktools:tell $gagger $host $hand $chan $chan1 gag.13 "$gagger $mask"
  813. if {$line != ""} {
  814. set counter [expr $counter -1]
  815. set delete [lreplace $data $counter $counter]
  816. set files [open $black(gag_file) "w"]
  817. puts $files [join $delete "\n"]
  818. close $files
  819. }
  820. }
  821. }
  822. set file [open $black(gag_file) "r"]
  823. set data [read -nonewline $file]
  824. close $file
  825. if {$data == ""} {
  826. set files [open $black(gag_file) "w"]
  827. close $files
  828. }
  829. set file [open $black(gag_file) "a"]
  830. puts $file "$gag_act"
  831. close $file
  832. }
  833. proc gagpublic {nick host hand chan arg} {
  834. global black
  835. set gagger [lindex [split $arg] 0]
  836. set time [lindex [split $arg] 1]
  837. set reason [lrange [split $arg] 2 end]
  838. set type 0
  839. set handle [nick2hand $gagger]
  840. set chan1 "$chan"
  841. foreach c [channels] {
  842. set backchan [channel get $c backchan]
  843. if {[string match -nocase $chan $backchan] && [channel get $c chanreport]} {
  844. set chan "$c"
  845. }
  846. }
  847. if {[regexp {^[&#]} $gagger] && [matchattr $hand nm|- $chan]} {
  848. set chan "$gagger"
  849. set gagger [lindex [split $arg] 1]
  850. set time [lindex [split $arg] 2]
  851. set reason [lrange [split $arg] 3 end]
  852. }
  853. if {![regexp {^[0-9]} $time]} {
  854. set reason [lrange [split $arg] 2 end]
  855. set time [channel get $chan gag-time]
  856. if {$time == "0"} {
  857. set time $black(gag_time)
  858. }
  859. }
  860. set split_text [split $gagger ","]
  861. if {$split_text != ""} {
  862. foreach txt $split_text {
  863. gag:process $txt $time $reason $nick $hand $host $chan $chan1 $type
  864. }
  865. } else { gag:process $gagger $time $reason $nick $hand $host $chan $chan1 $type }
  866. }
  867. ################################# ungag ###############################
  868. proc ungagpublic {nick host hand chan arg} {
  869. global black
  870. set gagger [lindex [split $arg] 0]
  871. set type 0
  872. set chan1 "$chan"
  873. foreach c [channels] {
  874. set backchan [channel get $c backchan]
  875. if {[string match -nocase $chan $backchan] && [channel get $c chanreport]} {
  876. set chan "$c"
  877. }
  878. }
  879. if {[regexp {^[&#]} $gagger] && [matchattr $hand nm|- $chan]} {
  880. set chan "$gagger"
  881. set gagger [lindex [split $arg] 1]
  882. }
  883. set split_text [split $gagger ","]
  884. if {$split_text != ""} {
  885. foreach txt $split_text {
  886. ungag:process $txt $nick $hand $host $chan $chan1 $type
  887. }
  888. } else { ungag:process $gagger $nick $hand $host $chan $chan1 $type }
  889. }
  890. proc ungag:process {gagger nick hand host chan chan1 type} {
  891. global black
  892. if {![validchan $chan]} {
  893. return
  894. }
  895. if {[matchattr $hand nm|- $chan]} {
  896. if {($gagger == "") && ($type == "0")} {
  897. blacktools:tell $nick $host $hand $chan $chan1 ungag.1 none
  898. return
  899. }
  900. if {($gagger == "") && ($type == "1")} {
  901. blacktools:tell $nick $host $hand $chan $chan1 ungag.2 none
  902. return
  903. }
  904. }
  905. if {($gagger == "") && ($type == "0")} {
  906. blacktools:tell $nick $host $hand $chan $chan1 ungag.3 none
  907. return
  908. }
  909. if {($gagger == "") && ($type == "1")} {
  910. blacktools:tell $nick $host $hand $chan $chan1 ungag.4 none
  911. return
  912. }
  913. if {[onchan $gagger $chan]} {
  914. set mask *!*@[lindex [split [getchanhost $gagger $chan] "@"] 1]
  915. } else {
  916. set mask $gagger
  917. }
  918. set counter 0
  919. set file [open $black(gag_file) "r"]
  920. set database [read -nonewline $file]
  921. close $file
  922. set data [split $database "\n"]
  923. foreach line $data {
  924. set counter [expr $counter + 1]
  925. set chanentry [lindex [split $line] 0]
  926. set hostentry [lindex $line 1]
  927. if {[string match -nocase $hostentry $mask] && [string match -nocase $chanentry $chan]} {
  928. set found_gag 1
  929. if {$line != ""} {
  930. set counter [expr $counter - 1]
  931. set delete [lreplace $data $counter $counter]
  932. set files [open $black(gag_file) "w"]
  933. puts $files [join $delete "\n"]
  934. close $files
  935. }
  936. }
  937. }
  938. set file [open $black(gag_file) "r"]
  939. set data [read -nonewline $file]
  940. close $file
  941. if {$data == ""} {
  942. set files [open $black(gag_file) "w"]
  943. close $files
  944. }
  945. if {![info exists found_gag]} {
  946. blacktools:tell $nick $host $hand $chan $chan1 ungag.5 $mask
  947. return
  948. } else {
  949. blacktools:tell $nick $host $hand $chan $chan1 ungag.6 $mask
  950. putquick "MODE $chan -b $mask"
  951. foreach user [chanlist $chan] {
  952. set the_mask *!*@[lindex [split [getchanhost $user $chan] "@"] 1]
  953. if {[string match -nocase $the_mask $mask]} {
  954. set found_one 1
  955. lappend object_found "$user"
  956. }
  957. }
  958. if {[info exists found_one]} {
  959. set getlang [string tolower [channel get $chan lang]]
  960. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  961. set replace(%chan%) $chan
  962. set replace(%gagger%) $object_found
  963. set ungag_user_message [string map [array get replace] $black(say.$getlang.ungag.7)]
  964. set ungag_chan_message [string map [array get replace] $black(say.$getlang.ungag.8)]
  965. puthelp "PRIVMSG $gagger :$ungag_user_message"
  966. puthelp "PRIVMSG $chan :$ungag_chan_message"
  967. }
  968. }
  969. }
  970. proc gag:reban {nick host hand chan args} {
  971. global black
  972. set bans [lindex $args 1]
  973. if {![botisop $chan]} { return }
  974. set file [open $black(gag_file) "r"]
  975. set database [read -nonewline $file]
  976. close $file
  977. set data [split $database "\n"]
  978. foreach line $data {
  979. set chanentry [lindex [split $line] 0]
  980. set hostentry [lindex [split $line] 1]
  981. if {[string match -nocase $bans $hostentry] && [string match -nocase $chanentry $chan]} {
  982. putserv "MODE $chan +b $bans"
  983. }
  984. }
  985. }
  986. proc gag:autounban {minute hour day month year} {
  987. global black
  988. set counter "0"
  989. set file [open $black(gag_file) "r"]
  990. set database [read -nonewline $file]
  991. close $file
  992. set data [split $database "\n"]
  993. foreach line $data {
  994. set time_show [lindex [split $line] 2]
  995. if {[duration [expr $time_show - [unixtime]]] == "0 seconds"} {
  996. lappend gag_list $time_show
  997. }
  998. }
  999. if {[info exists gag_list]} {
  1000. gag:autounban:check $gag_list
  1001. }
  1002. }
  1003. proc gag:autounban:check {list} {
  1004. global black
  1005. set list [join $list]
  1006. foreach tm $list {
  1007. if {$tm != ""} {
  1008. set file [open $black(gag_file) "r"]
  1009. set database [read -nonewline $file]
  1010. close $file
  1011. set data [split $database "\n"]
  1012. set i [lsearch -glob $data "* $tm *"]
  1013. if {$i > -1} {
  1014. set line [lindex $data $i]
  1015. set mask [lindex [split $line] 1]
  1016. set chan [lindex [split $line] 0]
  1017. set delete [lreplace $data $i $i]
  1018. set file [open $black(gag_file) "w"]
  1019. puts $file [join $delete "\n"]
  1020. close $file
  1021. }
  1022. }
  1023. pushmode $chan -b $mask
  1024. foreach user [chanlist $chan] {
  1025. set the_mask *!*@[lindex [split [getchanhost $user $chan] "@"] 1]
  1026. if {[string match -nocase $the_mask $mask]} {
  1027. set found_one 1
  1028. lappend object_found "$user"
  1029. }
  1030. }
  1031. }
  1032. if {[info exists found_one]} {
  1033. set getlang [string tolower [channel get $chan lang]]
  1034. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1035. set replace(%chan%) $chan
  1036. set replace(%gagger%) [join $object_found ", "]
  1037. set ungag_chan_message [string map [array get replace] $black(say.$getlang.ungag.8)]
  1038. puthelp "PRIVMSG $chan :$ungag_chan_message"
  1039. }
  1040. set file [open $black(gag_file) "r"]
  1041. set data [read -nonewline $file]
  1042. close $file
  1043. if {$data == ""} {
  1044. set files [open $black(gag_file) "w"]
  1045. close $files
  1046. }
  1047. }
  1048. ############################# Topic refresh #########################
  1049. proc refreshpublic {nick host hand chan arg} {
  1050. global botnick black
  1051. set thetopic [topic $chan]
  1052. puthelp "TOPIC $chan :$black(topics)"
  1053. puthelp "TOPIC $chan :$thetopic"
  1054. }
  1055. proc times_topic {} {
  1056. global black
  1057. foreach chan [channels] {
  1058. if {[channel get $chan topicrefresh] } {
  1059. set thetopic [topic $chan]
  1060. puthelp "TOPIC $chan :$black(topics)"
  1061. puthelp "TOPIC $chan :$thetopic"
  1062. }
  1063. }
  1064. timer $black(topic_time) times_topic
  1065. return 1
  1066. }
  1067. ################################ count ####################################
  1068. proc countpublic {nick host hand chan arg} {
  1069. global black
  1070. set type 0
  1071. set chan1 "$chan"
  1072. set why [lindex [split $arg] 0]
  1073. if {[regexp {^[&#]} $why] && [matchattr $hand nm|M $why]} {
  1074. set chan "$why"
  1075. set why [lindex [split $arg] 1]
  1076. }
  1077. count:process $nick $host $hand $chan $chan1 $why $type
  1078. }
  1079. proc count:process {nick host hand chan chan1 why type} {
  1080. global botnick black
  1081. set char(p) [lindex $black(cmdchar) 0]
  1082. if {[string match -nocase "none" "$char(p)"]} {
  1083. set char(p) ""
  1084. }
  1085. if {($why == "") && ($type == "0")} {
  1086. blacktools:tell $nick $host $hand $chan $chan1 count.1 none
  1087. return
  1088. }
  1089. if {($why == "") && ($type == "1")} {
  1090. blacktools:tell $nick $host $hand $chan $chan1 count.2 none
  1091. return
  1092. }
  1093. if {![validchan $chan]} {
  1094. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  1095. return
  1096. }
  1097. if {![onchan $botnick $chan]} {
  1098. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  1099. return
  1100. }
  1101. switch $why {
  1102. on {
  1103. if {[channel get $chan count]} {
  1104. blacktools:tell $nick $host $hand $chan $chan1 count.3 none
  1105. return
  1106. }
  1107. channel set $chan +count
  1108. channel set $chan count-date [clock format [unixtime] -format "%m/%d/%Y"]
  1109. blacktools:tell $nick $host $hand $chan $chan1 count.5 none
  1110. }
  1111. off {
  1112. if {![channel get $chan count]} {
  1113. blacktools:tell $nick $host $hand $chan $chan1 count.4 none
  1114. return
  1115. }
  1116. channel set $chan -count
  1117. channel set $chan count-date ""
  1118. blacktools:tell $nick $host $hand $chan $chan1 count.6 none
  1119. }
  1120. display {
  1121. set stats [channel get $chan countnumber]
  1122. blacktools:tell $nick $host $hand $chan $chan1 count.7 $stats
  1123. }
  1124. reset {
  1125. channel set $chan countnumber 0
  1126. channel set $chan count-date ""
  1127. blacktools:tell $nick $host $hand $chan $chan1 count.8 none
  1128. }
  1129. }
  1130. }
  1131. proc countpublic:join {nick host hand chan} {
  1132. global black
  1133. if {![validchan $chan]} { return }
  1134. if {[isbotnick $nick]} { return }
  1135. if {[channel get $chan count]} {
  1136. if {[info exists black(turnOnFlood:$chan)]} {
  1137. return
  1138. }
  1139. if {[channel get $chan count-date] == ""} {
  1140. channel set $chan count-date [clock format [unixtime] -format "%m/%d/%Y"]
  1141. }
  1142. set stats [channel get $chan countnumber]
  1143. set stats [expr $stats +1]
  1144. channel set $chan countnumber $stats
  1145. set replace(%num%) $stats
  1146. set replace(%chan%) $chan
  1147. set replace(%time%) [channel get $chan count-date]
  1148. set countmessage [channel get $chan count-message]
  1149. if {$countmessage == ""} {
  1150. set getlang [string tolower [channel get $chan lang]]
  1151. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1152. set countmessage $black(say.$getlang.count.9)
  1153. }
  1154. putquick "NOTICE $nick :[string map [array get replace] $countmessage]"
  1155. }
  1156. }
  1157. ############################### Private ##########################
  1158. proc privatepublic {nick host hand chan arg} {
  1159. global black
  1160. set type 0
  1161. set chan1 "$chan"
  1162. set why [lindex [split $arg] 0]
  1163. set user [lindex [split $arg] 1]
  1164. set host [lindex [split $arg] 2]
  1165. if {[regexp {^[&#]} $why] && [matchattr $hand nm|- $chan]} {
  1166. set chan "$why"
  1167. set why [lindex [split $arg] 1]
  1168. set user [lindex [split $arg] 2]
  1169. set host [lindex [split $arg] 3]
  1170. }
  1171. private:process $nick $host $hand $chan $chan1 $why $user $host $type
  1172. }
  1173. proc private:process {nick host hand chan chan1 why user host type} {
  1174. global botnick black
  1175. set char(p) [lindex $black(cmdchar) 0]
  1176. if {[string match -nocase "none" "$char(p)"]} {
  1177. set char(p) ""
  1178. }
  1179. set flags "-|f"
  1180. if {[matchattr $hand nm|- $chan]} {
  1181. if {($why == "") && ($type == "0")} {
  1182. blacktools:tell $nick $host $hand $chan $chan1 private.1 none
  1183. return
  1184. }
  1185. if {($why == "") && ($type == "1")} {
  1186. blacktools:tell $nick $host $hand $chan $chan1 private.2 none
  1187. return
  1188. }
  1189. }
  1190. if {($why == "") && ($type == "0")} {
  1191. blacktools:tell $nick $host $hand $chan $chan1 private.3 none
  1192. return
  1193. }
  1194. if {($why == "") && ($type == "1")} {
  1195. blacktools:tell $nick $host $hand $chan $chan1 private.4 none
  1196. return
  1197. }
  1198. if {![validchan $chan]} {
  1199. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  1200. return
  1201. }
  1202. if {![onchan $botnick $chan]} {
  1203. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  1204. return
  1205. }
  1206. if {([regexp -nocase -- {(#[0-9]+|on|off|add|list|del)} $why tmp privat]) && (![regexp -nocase -- {\S#} $why])} {
  1207. switch $privat {
  1208. on {
  1209. channel set $chan +private
  1210. blacktools:tell $nick $host $hand $chan $chan1 private.5 none
  1211. }
  1212. off {
  1213. channel set $chan -private
  1214. blacktools:tell $nick $host $hand $chan $chan1 private.6 none
  1215. }
  1216. add {
  1217. if {[validuser $user]} {
  1218. chattr $user $flags $chan
  1219. blacktools:tell $nick $host $hand $chan $chan1 private.7 $user
  1220. return
  1221. }
  1222. adduser $user $host
  1223. chattr $user $flags $chan
  1224. blacktools:tell $nick $host $hand $chan $chan1 private.8 "$user $host"
  1225. }
  1226. del {
  1227. if {[validuser $user]} {
  1228. chattr $user -|-f $chan
  1229. blacktools:tell $nick $host $hand $chan $chan1 private.9 $user
  1230. } else { blacktools:tell $nick $host $hand $chan $chan1 private.10 $user
  1231. return
  1232. }
  1233. }
  1234. list {
  1235. set list [userlist $flags $chan]
  1236. blacktools:tell $nick $host $hand $chan $chan1 private.11 $list
  1237. }
  1238. }
  1239. }
  1240. }
  1241. proc private:module {nick host hand chan} {
  1242. global black botnick
  1243. set getreason [channel get $chan private-reason]
  1244. if {$getreason == ""} {
  1245. set getlang [string tolower [channel get $chan lang]]
  1246. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1247. set getreason $black(say.$getlang.private.12)
  1248. }
  1249. set getbantime [channel get $chan private-bantime]
  1250. if {$getbantime == "0"} { set getbantime $black(privatebantime) }
  1251. set handle [nick2hand $nick]
  1252. set mask "*!*@[lindex [split $host @] 1]"
  1253. if {[channel get $chan private]} {
  1254. if {[matchattr $handle nm|oMASOVf $chan]} {
  1255. return
  1256. }
  1257. newchanban $chan $mask $botnick $getreason $getbantime
  1258. }
  1259. }
  1260. ############################### BadChan ###########################
  1261. proc badchanpublic {nick host hand chan arg} {
  1262. global black
  1263. set why [lindex [split $arg] 0]
  1264. set type1 0
  1265. set chan1 "$chan"
  1266. set bdchan [join [lindex [split $arg] 1]]
  1267. set type [lindex [split $arg] 2]
  1268. set reason [join [lrange [split $arg] 2 end]]
  1269. if {[string equal -nocase $why "list"] || [string equal -nocase $why "status"]} {
  1270. set type [lindex [split $arg] 1]
  1271. }
  1272. if {[string equal -nocase $type "-global"]} {
  1273. set reason [join [lrange [split $arg] 3 end]]
  1274. }
  1275. if {[regexp {^[&#]} $why] && [matchattr $hand nm|M $why]} {
  1276. set chan "$why"
  1277. set why [lindex [split $arg] 1]
  1278. set bdchan [join [lindex [split $arg] 2]]
  1279. set type [lindex [split $arg] 3]
  1280. set reason [join [lrange [split $arg] 3 end]]
  1281. if {[string equal -nocase $why "list"] || [string equal -nocase $why "status"]} {
  1282. set type [lindex [split $arg] 3]
  1283. }
  1284. if {[string equal -nocase $type "-global"]} {
  1285. set reason [join [lrange [split $arg] 4 end]]
  1286. }
  1287. }
  1288. badchan:process $nick $host $hand $chan $chan1 $why $bdchan $type $type1 $reason
  1289. }
  1290. proc badchan:process {nick host hand chan chan1 why bdchan type type1 reason} {
  1291. global botnick black username
  1292. set dir "scripts/BlackTools/FILES/$username.badchannels.txt"
  1293. set local ""
  1294. set char(p) [lindex $black(cmdchar) 0]
  1295. if {[matchattr $hand nm|- $chan]} {
  1296. if {($why == "") && ($type == "0")} {
  1297. blacktools:tell $nick $host $hand $chan $chan1 badchan.3 none
  1298. return
  1299. }
  1300. if {($why == "") && ($type == "1")} {
  1301. blacktools:tell $nick $host $hand $chan $chan1 badchan.4 none
  1302. return
  1303. }
  1304. }
  1305. if {($why == "") && ($type == "0")} {
  1306. blacktools:tell $nick $host $hand $chan $chan1 badchan.1 none
  1307. return
  1308. }
  1309. if {($why == "") && ($type == "1")} {
  1310. blacktools:tell $nick $host $hand $chan $chan1 badchan.2 none
  1311. return
  1312. }
  1313. if {![validchan $chan]} {
  1314. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  1315. return
  1316. }
  1317. if {![onchan $botnick $chan]} {
  1318. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  1319. return
  1320. }
  1321. if {[string match -nocase "none" "$char(p)"]} {
  1322. set char(p) ""
  1323. }
  1324. switch $why {
  1325. on {
  1326. if {[channel get $chan antibadchan]} {
  1327. blacktools:tell $nick $host $hand $chan $chan1 badchan.5 none
  1328. return
  1329. }
  1330. channel set $chan +antibadchan
  1331. blacktools:tell $nick $host $hand $chan $chan1 badchan.6 none
  1332. }
  1333. off {
  1334. if {![channel get $chan antibadchan]} {
  1335. blacktools:tell $nick $host $hand $chan $chan1 badchan.7 none
  1336. return
  1337. }
  1338. channel set $chan -antibadchan
  1339. blacktools:tell $nick $host $hand $chan $chan1 badchan.8 none
  1340. }
  1341. add {
  1342. if {$bdchan == ""} {
  1343. if {[matchattr $hand mn]} {
  1344. blacktools:tell $nick $host $hand $chan $chan1 badchan.9 none
  1345. return
  1346. } else {
  1347. blacktools:tell $nick $host $hand $chan $chan1 badchan.10 none
  1348. return
  1349. }
  1350. }
  1351. if {$reason == ""} {
  1352. set reason "NONE"
  1353. }
  1354. if {[matchattr $hand mn] && [string equal -nocase $type "-global"]} {
  1355. set file [open $dir a]
  1356. puts $file "GLOBAL $bdchan $reason"
  1357. close $file
  1358. set local "Global-List"
  1359. } else {
  1360. set file [open $dir a]
  1361. puts $file "$chan $bdchan $reason"
  1362. close $file
  1363. set local "Local-List"
  1364. }
  1365. if {$reason == "NONE"} {
  1366. blacktools:tell $nick $host $hand $chan $chan1 badchan.11 "$local $bdchan $reason"
  1367. } else {
  1368. blacktools:tell $nick $host $hand $chan $chan1 badchan.12 "$local $bdchan $reason"
  1369. }
  1370. }
  1371. list {
  1372. set file [open $dir "r"]
  1373. set check_global 0
  1374. set found_it 0
  1375. set w [read -nonewline $file]
  1376. close $file
  1377. set data [split $w "\n"]
  1378. set counter 0
  1379. if {$data == ""} {
  1380. blacktools:tell $nick $host $hand $chan $chan1 badchan.13 none
  1381. return
  1382. }
  1383. if {[matchattr $hand mn] && [string equal -nocase $type "-global"]} {
  1384. set check_global 1
  1385. }
  1386. blacktools:tell $nick $host $hand $chan $chan1 badchan.14 none
  1387. foreach line $data {
  1388. set mainchan [lindex [split $line] 0]
  1389. set badchan [lindex [split $line] 1]
  1390. set reason [join [lrange [split $line] 2 end]]
  1391. if {$check_global == 1} {
  1392. if {[string equal -nocase $mainchan "GLOBAL"]} {
  1393. set counter [expr $counter +1]
  1394. set found_it 1
  1395. if {$reason == "NONE"} {
  1396. blacktools:tell $nick $host $hand $chan $chan1 badchan.15 "$counter $badchan"
  1397. } else {
  1398. blacktools:tell $nick $host $hand $chan $chan1 badchan.16 "$counter $badchan $reason"
  1399. }
  1400. }
  1401. } else {
  1402. if {[string equal -nocase $mainchan $chan]} {
  1403. set found_it 1
  1404. set counter [expr $counter +1]
  1405. if {$reason == "NONE"} {
  1406. blacktools:tell $nick $host $hand $chan $chan1 badchan.17 "$counter $badchan"
  1407. } else {
  1408. blacktools:tell $nick $host $hand $chan $chan1 badchan.18 "$counter $badchan $reason"
  1409. }
  1410. }
  1411. }
  1412. }
  1413. if {$found_it == 0} {
  1414. blacktools:tell $nick $host $hand $chan $chan1 badchan.19 none
  1415. }
  1416. }
  1417. del {
  1418. set check_global 0
  1419. set found_it 0
  1420. set line_count 0
  1421. if {$bdchan == ""} {
  1422. if {[matchattr $hand mn]} {
  1423. blacktools:tell $nick $host $hand $chan $chan1 badchan.20 none
  1424. return
  1425. } else {
  1426. blacktools:tell $nick $host $hand $chan $chan1 badchan.21 none
  1427. return
  1428. }
  1429. }
  1430. if {[matchattr $hand mn] && [string equal -nocase $type "-global"]} {
  1431. set check_global 1
  1432. }
  1433. set file [open $dir "r"]
  1434. set data [read -nonewline $file]
  1435. close $file
  1436. set lines [split $data "\n"]
  1437. foreach line $lines {
  1438. set line_count [expr $line_count + 1]
  1439. set mainchan [lindex [split $line] 0]
  1440. set badchan [lindex [split $line] 1]
  1441. if {$check_global == 1} {
  1442. if {[string equal -nocase $mainchan "GLOBAL"] && [string equal -nocase $badchan $bdchan]} {
  1443. set found_it 1
  1444. blacktools:tell $nick $host $hand $chan $chan1 badchan.22 "$badchan"
  1445. if {$line != ""} {
  1446. set line_count [expr $line_count - 1]
  1447. set delete [lreplace $lines $line_count $line_count]
  1448. set files [open $dir "w"]
  1449. puts $files [join $delete "\n"]
  1450. close $files
  1451. }
  1452. }
  1453. } else {
  1454. if {[string equal -nocase $mainchan $chan] && [string equal -nocase $badchan $bdchan]} {
  1455. set found_it 1
  1456. if {$line != ""} {
  1457. set line_count [expr $line_count - 1]
  1458. set delete [lreplace $lines $line_count $line_count]
  1459. set files [open $dir "w"]
  1460. puts $files [join $delete "\n"]
  1461. close $files
  1462. }
  1463. blacktools:tell $nick $host $hand $chan $chan1 badchan.23 "$badchan"
  1464. }
  1465. }
  1466. }
  1467. if {$found_it == 0} {
  1468. blacktools:tell $nick $host $hand $chan $chan1 badchan.24 none
  1469. }
  1470. }
  1471. find {
  1472. set found_it 0
  1473. set counter 0
  1474. set check_global 0
  1475. if {$bdchan == ""} {
  1476. if {[matchattr $hand mn]} {
  1477. blacktools:tell $nick $host $hand $chan $chan1 badchan.25 none
  1478. return
  1479. } else {
  1480. blacktools:tell $nick $host $hand $chan $chan1 badchan.26 none
  1481. return
  1482. }
  1483. }
  1484. if {[matchattr $hand mn] && [string equal -nocase $type "-global"]} {
  1485. set check_global 1
  1486. }
  1487. set file [open $dir "r"]
  1488. set data [read -nonewline $file]
  1489. close $file
  1490. set lines [split $data "\n"]
  1491. foreach line $lines {
  1492. set mainchan [lindex [split $line] 0]
  1493. set badchan [lindex [split $line] 1]
  1494. if {$check_global == 1} {
  1495. if {[string equal -nocase $mainchan "GLOBAL"] && [string match -nocase $bdchan $badchan]} {
  1496. set counter [expr $counter + 1]
  1497. set found_it 1
  1498. set reason [join [lrange [split $line] 2 end]]
  1499. if {$reason == "NONE"} { set reason "\"Default reason\"" }
  1500. blacktools:tell $nick $host $hand $chan $chan1 badchan.27 "$counter $badchan $reason"
  1501. }
  1502. } else {
  1503. if {[string equal -nocase $mainchan $chan] && [string match -nocase $bdchan $badchan]} {
  1504. set counter [expr $counter + 1]
  1505. set found_it 1
  1506. set reason [join [lrange [split $line] 2 end]]
  1507. blacktools:tell $nick $host $hand $chan $chan1 badchan.28 "$counter $badchan $reason"
  1508. }
  1509. }
  1510. }
  1511. if {$found_it == 0} {
  1512. blacktools:tell $nick $host $hand $chan $chan1 badchan.24 none
  1513. }
  1514. }
  1515. status {
  1516. set check_global 0
  1517. if {[matchattr $hand mn] && [string equal -nocase $type "-global"]} {
  1518. set check_global 1
  1519. }
  1520. if {[channel get $chan antibadchan]} { set status ONLINE } else { set status OFFLINE }
  1521. blacktools:tell $nick $host $hand $chan $chan1 badchan.29 $status
  1522. if {$check_global == 1} {
  1523. set total_chans [get:badchan:stats "GLOBAL"]
  1524. blacktools:tell $nick $host $hand $chan $chan1 badchan.30 $total_chans
  1525. } else {
  1526. set total_chans [get:badchan:stats $chan]
  1527. blacktools:tell $nick $host $hand $chan $chan1 badchan.31 $total_chans
  1528. }
  1529. if {[channel get $chan badchan-reason] == ""} {
  1530. set getlang [string tolower [channel get $chan lang]]
  1531. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1532. set reason $black(say.$getlang.badchan.39)
  1533. } else { set reason [join [channel get $chan badchan-reason]]}
  1534. if {[channel get $chan badchan-bantime] == 0} { set bantime $black(badcbantime)} else { set bantime [channel get $chan badchan-bantime]}
  1535. blacktools:tell $nick $host $hand $chan $chan1 badchan.32 $reason
  1536. blacktools:tell $nick $host $hand $chan $chan1 badchan.33 $bantime
  1537. }
  1538. set {
  1539. switch $bdchan {
  1540. reason {
  1541. if {$reason == ""} {
  1542. blacktools:tell $nick $host $hand $chan $chan1 badchan.34 none
  1543. return
  1544. }
  1545. channel set $chan badchan-reason "$reason"
  1546. blacktools:tell $nick $host $hand $chan $chan1 badchan.35 $reason
  1547. }
  1548. bantime {
  1549. if {$type == ""} {
  1550. blacktools:tell $nick $host $hand $chan $chan1 badchan.36 none
  1551. return
  1552. }
  1553. channel set $chan badchan-bantime $type
  1554. blacktools:tell $nick $host $hand $chan $chan1 badchan.37 $type
  1555. }
  1556. default {
  1557. blacktools:tell $nick $host $hand $chan $chan1 badchan.38 none
  1558. }
  1559. }
  1560. }
  1561. default {
  1562. if {[matchattr $hand mn]} {
  1563. blacktools:tell $nick $host $hand $chan $chan1 badchan.3 none
  1564. } else {
  1565. blacktools:tell $nick $host $hand $chan $chan1 badchan.1 none
  1566. }
  1567. }
  1568. }
  1569. }
  1570. proc get:badchan:stats {type} {
  1571. global black username
  1572. set dir "scripts/BlackTools/FILES/$username.badchannels.txt"
  1573. set counter 0
  1574. set file [open $dir "r"]
  1575. set data [read -nonewline $file]
  1576. close $file
  1577. set lines [split $data "\n"]
  1578. foreach line $lines {
  1579. set mainchan [lindex [split $line] 0]
  1580. if {[string equal -nocase $type $mainchan]} {
  1581. set counter [expr $counter + 1]
  1582. }
  1583. }
  1584. return $counter
  1585. }
  1586. proc badchanpublic:join {nick host hand chan} {
  1587. global black
  1588. set ::bad_chan $chan
  1589. if {[matchattr $hand $black(exceptflags) $chan]} {
  1590. return
  1591. }
  1592. if {![validchan $chan]} { return }
  1593. if {![botisop $chan]} { return }
  1594. if {[isbotnick $nick]} { return }
  1595. if {[channel get $chan antibadchan]} {
  1596. utimer 5 [list putquick "WHOIS $nick $nick"]
  1597. bind RAW - 319 badchan:execute
  1598. }
  1599. }
  1600. proc badchan:execute {from keyword arguments } {
  1601. global botnick black badchan username
  1602. set chan $::bad_chan
  1603. set dir "scripts/BlackTools/FILES/$username.badchannels.txt"
  1604. set arguments [join $arguments]
  1605. set nick [string tolower [lindex $arguments 1]]
  1606. set channels [string tolower [lrange $arguments 2 end]]
  1607. set banmask *!*@[lindex [split [getchanhost $nick $chan] "@"] 1]
  1608. if {![onchan $nick $chan]} {
  1609. return
  1610. }
  1611. set file [open $dir "r"]
  1612. set database [read -nonewline $file]
  1613. set bantime ""
  1614. close $file
  1615. set data [split $database "\n"]
  1616. foreach line $data {
  1617. set mainchan [lindex [split $line] 0]
  1618. if {[string equal -nocase $chan $mainchan] || [string equal -nocase "GLOBAL" $mainchan]} {
  1619. set readchan [lindex [split $line] 1]
  1620. set reason [join [lrange [split $line] 2 end]]
  1621. foreach c [join $channels] {
  1622. set ch [string trimleft $c ":@+"]
  1623. if {[string equal -nocase $readchan $ch]} {
  1624. if {[string equal -nocase "LOCAL" $mainchan]} {
  1625. if {[channel get $chan badchan-reason] == 0} {
  1626. set bantime $black(badcbantime)
  1627. } else { set bantime [channel get $chan badchan-reason] }
  1628. } else { set bantime $black(badcbantime) }
  1629. if {[string equal -nocase $chan $mainchan] && [string equal -nocase $reason "NONE"]} {
  1630. if {[channel get $chan badchan-reason] == ""} {
  1631. set getlang [string tolower [channel get $chan lang]]
  1632. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1633. set reason $black(say.$getlang.badchan.39)
  1634. } else { set reason [join [channel get $chan badchan-reason]]
  1635. }
  1636. }
  1637. if {[string equal -nocase "GLOBAL" $mainchan] && [string equal -nocase $reason "NONE"]} {
  1638. set getlang [string tolower [channel get $chan lang]]
  1639. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1640. set reason $black(say.$getlang.badchan.39)
  1641. }
  1642. set badchan($banmask:$chan) $reason
  1643. lappend badchan(channels:$banmask:$chan) $readchan
  1644. }
  1645. }
  1646. }
  1647. }
  1648. if {[info exists badchan(checkagain:$banmask:$chan)]} {
  1649. if {[info exists badchan($banmask:$chan)]} {
  1650. set bywho "[join $badchan(channels:$banmask:$chan) ","]"
  1651. bad:add:word $chan $banmask $bywho
  1652. set replace(%chan%) $chan
  1653. set reason [string map [array get replace] $badchan($banmask:$chan)]
  1654. blacktools:banner:2 $banmask "BADCHAN" $chan $reason $bantime
  1655. unset badchan(checkagain:$banmask:$chan)
  1656. unset badchan($banmask:$chan)
  1657. unset badchan(channels:$banmask:$chan)
  1658. return
  1659. }
  1660. unset badchan(checkagain:$banmask:$chan)
  1661. return
  1662. }
  1663. if {[info exists badchan($banmask:$chan)]} {
  1664. set replace(%badchans%) [join $badchan(channels:$banmask:$chan) ", "]
  1665. set getlang [string tolower [channel get $chan lang]]
  1666. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1667. set get_message $black(say.$getlang.badchan.40)
  1668. set message [string map [array get replace] $get_message]
  1669. putquick "PRIVMSG $nick :\[$chan\] $message"
  1670. utimer 30 [list badchan:check:again $nick $chan]
  1671. unset badchan($banmask:$chan)
  1672. unset badchan(channels:$banmask:$chan)
  1673. set badchan(checkagain:$banmask:$chan) 1
  1674. } else {
  1675. if {[info exists badchan(checkagain:$banmask:$chan]} {
  1676. unset badchan(checkagain:$banmask:$chan
  1677. }
  1678. if {[info exists badchan($banmask:$chan)]} {
  1679. unset badchan($banmask:$chan)
  1680. }
  1681. if {[info exists badchan(channels:$banmask:$chan)]} {
  1682. unset badchan(channels:$banmask:$chan)
  1683. }
  1684. }
  1685. unbind RAW - 319 badchan:execute
  1686. }
  1687. proc badchan:check:again {nick chan} {
  1688. putquick "WHOIS $nick $nick"
  1689. set ::bad_chan $chan
  1690. bind RAW - 319 badchan:execute
  1691. }
  1692. proc badchan:nickchange {nick host hand chan newnick} {
  1693. global badchan
  1694. set found_time 0
  1695. set current_time ""
  1696. foreach tmr [utimers] {
  1697. if {[string match -nocase "*badchan:check:again $nick $chan*" [join [lindex $tmr 1]]]} {
  1698. set current_time [get:timer:time $nick $chan]
  1699. set found_time 1
  1700. killutimer [lindex $tmr 2]
  1701. }
  1702. }
  1703. if {$found_time == "1"} {
  1704. utimer $current_time [list badchan:check:again $newnick $chan]
  1705. }
  1706. }
  1707. proc badchan:split {nick host hand chan args} {
  1708. global badchan
  1709. badchan:part $nick $host $hand $chan "none"
  1710. }
  1711. proc badchan:kick {nick host hand chan kicked reason} {
  1712. global badchan
  1713. badchan:part $kicked $host $hand $chan "none"
  1714. }
  1715. proc badchan:part {nick host hand chan arg} {
  1716. global badchan
  1717. if {![validchan $chan]} { return }
  1718. set banmask *!*@[lindex [split [getchanhost $nick $chan] "@"] 1]
  1719. foreach tmr [utimers] {
  1720. if {[string match -nocase "*badchan:check:again $nick $chan*" [join [lindex $tmr 1]]]} {
  1721. killutimer [lindex $tmr 2]
  1722. }
  1723. }
  1724. if {[info exists badchan(checkagain:$banmask:$chan)]} {
  1725. unset badchan(checkagain:$banmask:$chan)
  1726. }
  1727. if {[info exists badchan($banmask:$chan)]} {
  1728. unset badchan($banmask:$chan)
  1729. }
  1730. if {[info exists badchan(channels:$banmask:$chan)]} {
  1731. unset badchan(channels:$banmask:$chan)
  1732. }
  1733. }
  1734. proc get:timer:time {nick chan} {
  1735. global scrabble
  1736. set time_left 0
  1737. foreach tmr [utimers] {
  1738. if {[string match -nocase "*badchan:check:again $nick $chan*" [join [lindex $tmr 1]]]} {
  1739. set time_left [lindex $tmr 0]
  1740. }
  1741. }
  1742. return $time_left
  1743. }
  1744. ################################# Antitake ##################################
  1745. proc dontdeoppublic {nick host hand chan args} {
  1746. global black botnick
  1747. set dnick [lindex $args 1]
  1748. set handle [nick2hand $nick]
  1749. if {[channel get $chan dontdeop] } {
  1750. if {[string match -nocase $nick $botnick]} {
  1751. return
  1752. }
  1753. if {![matchattr $handle $black(exceptflags) $chan]} {
  1754. putquick "MODE $chan -o $nick"
  1755. putquick "MODE $chan +o $dnick"
  1756. set getlang [string tolower [channel get $chan lang]]
  1757. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1758. puthelp "NOTICE $nick :$black(say.$getlang.antitake.1)"
  1759. }
  1760. }
  1761. }
  1762. proc dontoppublic {nick host hand chan args} {
  1763. global black botnick
  1764. set onick [lindex $args 1]
  1765. set handle [nick2hand $nick]
  1766. if {[channel get $chan dontop]} {
  1767. if {[string match -nocase $nick $botnick]} {
  1768. return
  1769. }
  1770. if {[string match -nocase $onick $botnick]} {
  1771. return
  1772. }
  1773. if {![matchattr $handle $black(exceptflags) $chan]} {
  1774. putquick "MODE $chan -o $nick"
  1775. putquick "MODE $chan -o $onick"
  1776. set getlang [string tolower [channel get $chan lang]]
  1777. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1778. puthelp "NOTICE $nick :$black(say.$getlang.antitake.2)"
  1779. }
  1780. }
  1781. }
  1782. ################################# Anunt ###################################
  1783. proc anuntpublic {nick host hand chan arg} {
  1784. global black
  1785. set type 0
  1786. set chan1 "$chan"
  1787. set who [lindex [split $arg] 0]
  1788. set message [join [lrange [split $arg] 1 end]]
  1789. set number [lindex [split $arg] 1]
  1790. if {[regexp {^[&#]} $who] && [matchattr $hand nm|M $who]} {
  1791. set chan "$who"
  1792. set who [lindex [split $arg] 1]
  1793. set message [join [lrange [split $arg] 2 end]]
  1794. set number [lindex [split $arg] 2]
  1795. }
  1796. anunt:process $nick $host $hand $chan $chan1 $who $message $number $type
  1797. }
  1798. proc anunt:process {nick host hand chan chan1 who message number type} {
  1799. global botnick black username
  1800. set char(p) [lindex $black(cmdchar) 0]
  1801. set new_dir "scripts/BlackTools/FILES/$username.announce.txt"
  1802. if {[string match -nocase "none" "$char(p)"]} {
  1803. set char(p) ""
  1804. }
  1805. if {($who == "") && ($type == "0")} {
  1806. blacktools:tell $nick $host $hand $chan $chan1 anunt.1 none
  1807. return
  1808. }
  1809. if {($who == "") && ($type == "1")} {
  1810. blacktools:tell $nick $host $hand $chan $chan1 anunt.2 none
  1811. return
  1812. }
  1813. if {![validchan $chan]} {
  1814. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  1815. return
  1816. }
  1817. if {![onchan $botnick $chan]} {
  1818. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  1819. return
  1820. }
  1821. switch $who {
  1822. on {
  1823. channel set $chan +anunt
  1824. blacktools:tell $nick $host $hand $chan $chan1 anunt.3 none
  1825. }
  1826. off {
  1827. channel set $chan -anunt
  1828. blacktools:tell $nick $host $hand $chan $chan1 anunt.4 none
  1829. }
  1830. add {
  1831. if {$message == ""} {
  1832. blacktools:tell $nick $host $hand $chan $chan1 anunt.12 none
  1833. return
  1834. }
  1835. set file [open $new_dir a]
  1836. puts $file "$chan $message"
  1837. close $file
  1838. blacktools:tell $nick $host $hand $chan $chan1 anunt.5 none
  1839. blacktools:tell $nick $host $hand $chan $chan1 anunt.6 $message
  1840. }
  1841. list {
  1842. set file [open $new_dir "r"]
  1843. set w [read -nonewline $file]
  1844. close $file
  1845. set data [split $w "\n"]
  1846. set i 0
  1847. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 anunt.7 none
  1848. return
  1849. }
  1850. blacktools:tell $nick $host $hand $chan $chan1 anunt.8 none
  1851. foreach line $data {
  1852. set read_chan [lindex [split $line] 0]
  1853. if {[string match -nocase $read_chan $chan]} {
  1854. set i [expr $i +1]
  1855. set message [join [lrange [split $line] 1 end]]
  1856. blacktools:tell $nick $host $hand $chan $chan1 anunt.6 "$i. $message"
  1857. }
  1858. }
  1859. }
  1860. del {
  1861. array set anuntdel [list]
  1862. if {![regexp {^[0-9]} $number]} {
  1863. blacktools:tell $nick $host $hand $chan $chan1 anunt.9 none
  1864. return
  1865. }
  1866. set file [open $new_dir "r"]
  1867. set data [read -nonewline $file]
  1868. close $file
  1869. set lines [split $data "\n"]
  1870. set counter -1
  1871. set line_counter -1
  1872. set current_place -1
  1873. foreach line $lines {
  1874. set line_counter [expr $line_counter + 1]
  1875. set read_chan [lindex [split $line] 0]
  1876. if {[string match -nocase $read_chan $chan]} {
  1877. set counter [expr $counter + 1]
  1878. set anuntdel($counter) $line_counter
  1879. }
  1880. }
  1881. foreach place [array names anuntdel] {
  1882. if {$place == [expr $number - 1]} {
  1883. set current_place $anuntdel($place)
  1884. }
  1885. }
  1886. if {$current_place == "-1"} {
  1887. blacktools:tell $nick $host $hand $chan $chan1 anunt.13 $number
  1888. return
  1889. }
  1890. set delete [lreplace $lines $current_place $current_place]
  1891. set files [open $new_dir "w"]
  1892. puts $files [join $delete "\n"]
  1893. close $files
  1894. set file [open $new_dir "r"]
  1895. set data [read -nonewline $file]
  1896. close $file
  1897. if {$data == ""} {
  1898. set files [open $new_dir "w"]
  1899. close $files
  1900. }
  1901. blacktools:tell $nick $host $hand $chan $chan1 anunt.10 $number
  1902. blacktools:tell $nick $host $hand $chan $chan1 anunt.11 none
  1903. }
  1904. }
  1905. }
  1906. proc anuntpublic:show {} {
  1907. global black
  1908. foreach chan [channels] {
  1909. if {[validchan $chan]} {
  1910. if {[channel get $chan anunt]} {
  1911. lappend black(anunt:chans) [join $chan]
  1912. }
  1913. }
  1914. }
  1915. if {[info exists black(anunt:chans)]} {
  1916. anunt:time
  1917. } else {
  1918. timer $black(anunttime) anuntpublic:show
  1919. return 1
  1920. }
  1921. }
  1922. proc anunt:time {} {
  1923. global black
  1924. if {![info exists black(anunt:count:chans)]} {
  1925. set black(anunt:count:chans) 0
  1926. }
  1927. set current_chan [lindex $black(anunt:chans) $black(anunt:count:chans)]
  1928. set black(anunt:count:chans) [expr $black(anunt:count:chans) + 1]
  1929. if {$current_chan != ""} {
  1930. anunt:show $current_chan
  1931. anunt:time
  1932. } else {
  1933. unset black(anunt:count:chans)
  1934. unset black(anunt:chans)
  1935. timer $black(anunttime) anuntpublic:show
  1936. return 1
  1937. }
  1938. }
  1939. proc anunt:show {chan} {
  1940. global black count username
  1941. set new_dir "scripts/BlackTools/FILES/$username.announce.txt"
  1942. set temp_dir "scripts/BlackTools/FILES/announce.temp.txt"
  1943. if {![file exists $temp_dir]} {
  1944. set file [open $temp_dir w]
  1945. close $file
  1946. } else {
  1947. set file [open $temp_dir w]
  1948. close $file
  1949. }
  1950. set file [open $new_dir "r"]
  1951. set data [read -nonewline $file]
  1952. close $file
  1953. if {$data != ""} {
  1954. set lines [split $data "\n"]
  1955. foreach line $lines {
  1956. set read_chan [lindex [split $line] 0]
  1957. if {[string match -nocase $read_chan $chan]} {
  1958. set file [open $temp_dir "a"]
  1959. puts $file [join [lrange [split $line] 1 end]]
  1960. close $file
  1961. }
  1962. }
  1963. }
  1964. set file [open $temp_dir "r"]
  1965. set data [read -nonewline $file]
  1966. close $file
  1967. if {$data != ""} {
  1968. if {![info exists count(anunt:$chan)]} {
  1969. set count(anunt:$chan) 0
  1970. }
  1971. set lines [split $data "\n"]
  1972. set line [lindex $lines $count(anunt:$chan)]
  1973. if {$line == ""} {
  1974. set count(anunt:$chan) 0
  1975. set line [lindex $lines $count(anunt:$chan)]
  1976. }
  1977. set split_line [split $line "~"]
  1978. incr count(anunt:$chan)
  1979. foreach mes $split_line {
  1980. if {$black(anunthow) == "1"} {
  1981. puthelp "PRIVMSG $chan :\001ACTION $mes\001"
  1982. } else {
  1983. puthelp "PRIVMSG $chan :$mes"
  1984. }
  1985. }
  1986. }
  1987. set file [open $temp_dir "w"]
  1988. close $file
  1989. }
  1990. ################################## TimeBan #############################
  1991. proc timeban:module {nick host hand chan} {
  1992. global botnick
  1993. if {[channel get $chan showtime]} {
  1994. set host "$nick![getchanhost $nick $chan]"
  1995. foreach ban [banlist $chan] {
  1996. if {[string match -nocase [string tolower [lindex $ban 0]] $host]} {
  1997. set reason "[lindex $ban 1]"
  1998. set bantime "[lindex $ban 2]"
  1999. set totalday [expr $bantime - [unixtime]]
  2000. if {$totalday >= 86400} {
  2001. set daysfull [expr $totalday/86400]
  2002. set days [expr int($daysfull)]
  2003. set dayssub [expr 86400*$days]
  2004. set totalhour [expr $totalday - $dayssub]
  2005. }
  2006. if {$totalday < 86400} {
  2007. set totalhour $totalday
  2008. set days 0
  2009. }
  2010. if {$totalhour >= 3600} {
  2011. set hoursfull [expr $totalhour/3600]
  2012. set hours [expr int($hoursfull)]
  2013. set hourssub [expr 3600*$hours]
  2014. set totalmin [expr $totalhour - $hourssub]
  2015. }
  2016. if {$totalhour < 3600} {
  2017. set totalmin $totalhour
  2018. set hours 0
  2019. }
  2020. if {$totalmin >= 60} {
  2021. set minsfull [expr $totalmin/60]
  2022. set mins [expr int($minsfull)]
  2023. }
  2024. if {$totalmin < 60} {
  2025. set mins 0
  2026. }
  2027. if {$days < 1} {set zi "0 days, "} elseif {$days == 1} {set zi "$days day, "} {set zi "$days days, "}
  2028. if {$hours < 1} {set ora "0"} else { set ora "$hours" }
  2029. set minut "$mins"
  2030. set re "$reason \[$zi$ora:$minut\]"
  2031. if {[lindex $ban 2] == 0} {
  2032. set expire "\[Never\]"
  2033. set re "$reason $expire"
  2034. }
  2035. putquick "MODE $chan +b [lindex $ban 0]"
  2036. putquick "KICK $chan $nick :$re"
  2037. }
  2038. }
  2039. }
  2040. }
  2041. ############################### AutoBroadcast ############################
  2042. proc broadcastpublic:module {nick host hand chan arg} {
  2043. global black sdir
  2044. set char(p) [lindex $black(cmdchar) 0]
  2045. if {[string match -nocase "none" "$char(p)"]} {
  2046. set char(p) ""
  2047. }
  2048. set chan1 "$chan"
  2049. set who [lindex [split $arg] 0]
  2050. set message [join [lrange [split $arg] 1 end]]
  2051. set number [lindex [split $arg] 1]
  2052. if {$who == ""} { blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.1 none
  2053. return
  2054. }
  2055. broadcast:process $nick $host $hand $chan $chan1 $who $message $number
  2056. }
  2057. proc broadcast:process {nick host hand chan chan1 who message number} {
  2058. global botnick black username
  2059. set message [join $message]
  2060. set sdir "scripts/BlackTools/FILES/$username.status.txt"
  2061. set char(p) [lindex $black(cmdchar) 0]
  2062. if {[string match -nocase "none" "$char(p)"]} {
  2063. set char(p) ""
  2064. }
  2065. set dir "scripts/BlackTools/FILES/$username.autobroadcast.txt"
  2066. set lin 0
  2067. switch $who {
  2068. on {
  2069. set type "broadcastpublic:show ON"
  2070. foreach tmr [timers] {
  2071. if {[string match "*broadcastpublic:show*" [join [lindex $tmr 1]]]} {
  2072. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.3 none
  2073. return
  2074. }
  2075. }
  2076. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.4 none
  2077. set file [open $sdir "r"]
  2078. set database [read -nonewline $file]
  2079. close $file
  2080. set data [split $database "\n"]
  2081. foreach line $data {
  2082. set lin [expr $lin +1]
  2083. set who [lindex [split $line] 0]
  2084. set stats [lindex [split $line] 1]
  2085. if {[string match -nocase "broadcastpublic:show" $who]} {
  2086. if {$line != ""} {
  2087. set num [expr $lin - 1]
  2088. set delete [lreplace $data $num $num]
  2089. set files [open $sdir "w"]
  2090. puts $files [join $delete "\n"]
  2091. close $files
  2092. }
  2093. }
  2094. }
  2095. set file [open $sdir "r"]
  2096. set data [read -nonewline $file]
  2097. close $file
  2098. if {$data == ""} {
  2099. set files [open $sdir "w"]
  2100. close $files
  2101. }
  2102. set file [open $sdir "a"]
  2103. puts $file "$type"
  2104. close $file
  2105. timer $black(bttime) broadcastpublic:show
  2106. set broadcastpublic:show_running 1
  2107. }
  2108. off {
  2109. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.5 none
  2110. set type "broadcastpublic:show OFF"
  2111. foreach tmr [timers] {
  2112. if {[string match -nocase "*broadcastpublic:show*" [join [lindex $tmr 1]]]} {
  2113. killtimer [lindex $tmr 2]
  2114. }
  2115. }
  2116. set file [open $sdir "r"]
  2117. set database [read -nonewline $file]
  2118. close $file
  2119. set data [split $database "\n"]
  2120. foreach line $data {
  2121. set lin [expr $lin +1]
  2122. set who [lindex [split $line] 0]
  2123. set stats [lindex [split $line] 1]
  2124. if {[string match -nocase "broadcastpublic:show" $who]} {
  2125. if {$line != ""} {
  2126. set num [expr $lin - 1]
  2127. set delete [lreplace $data $num $num]
  2128. set files [open $sdir "w"]
  2129. puts $files [join $delete "\n"]
  2130. close $files
  2131. }
  2132. }
  2133. }
  2134. set file [open $sdir "r"]
  2135. set data [read -nonewline $file]
  2136. close $file
  2137. if {$data == ""} {
  2138. set files [open $sdir "w"]
  2139. close $files
  2140. }
  2141. set file [open $sdir "a"]
  2142. puts $file "$type"
  2143. close $file
  2144. if {[info exists broadcastpublic:show_running]} {
  2145. unset broadcastpublic:show_running
  2146. }
  2147. }
  2148. add {
  2149. if {$message == ""} {
  2150. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.12 none
  2151. return
  2152. }
  2153. set file [open $dir a]
  2154. puts $file $message
  2155. close $file
  2156. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.6 none
  2157. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.7 $message
  2158. }
  2159. list {
  2160. set file [open $dir "r"]
  2161. set w [read -nonewline $file]
  2162. close $file
  2163. set data [split $w "\n"]
  2164. set i 0
  2165. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.8 none
  2166. return
  2167. }
  2168. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.9 none
  2169. foreach mes $data {
  2170. set i [expr $i +1]
  2171. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.7 "$i. $mes"
  2172. }
  2173. }
  2174. del {
  2175. if {![regexp {^[0-9]} $number]} {
  2176. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.10 none
  2177. return
  2178. }
  2179. set file [open $dir "r"]
  2180. set data [read -nonewline $file]
  2181. close $file
  2182. set lines [split $data "\n"]
  2183. set i [expr $number - 1]
  2184. set delete [lreplace $lines $i $i]
  2185. set files [open $dir "w"]
  2186. puts $files [join $delete "\n"]
  2187. close $files
  2188. set file [open $dir "r"]
  2189. set data [read -nonewline $file]
  2190. close $file
  2191. if {$data == ""} {
  2192. set files [open $dir "w"]
  2193. close $files
  2194. }
  2195. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.11 $number
  2196. }
  2197. }
  2198. }
  2199. proc broadcastpublic:show {} {
  2200. global black username
  2201. set dir "scripts/BlackTools/FILES/$username.autobroadcast.txt"
  2202. if {![info exists black(broadcast:count)]} {
  2203. set black(broadcast:count) 0
  2204. }
  2205. set file [open $dir "r"]
  2206. set data [read -nonewline $file]
  2207. close $file
  2208. if {$data != ""} {
  2209. set lines [split $data "\n"]
  2210. set line [lindex $lines $black(broadcast:count)]
  2211. if {$line == ""} {
  2212. set black(broadcast:count) 0
  2213. set line [lindex $lines $black(broadcast:count)]
  2214. }
  2215. set black(broadcast:count) [expr $black(broadcast:count) +1]
  2216. set split_line [split $line "~"]
  2217. foreach chan [channels] {
  2218. if {[validchan $chan] && [isdynamic $chan] && (![channel get $chan silent])} {
  2219. foreach mes $split_line {
  2220. if {$black(bthow) == "1"} {
  2221. puthelp "PRIVMSG $chan :\001ACTION $mes\001"
  2222. } else {
  2223. puthelp "PRIVMSG $chan :$mes"
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. timer $black(bttime) broadcastpublic:show
  2230. return
  2231. }
  2232. ################################# Limit ###################################
  2233. proc limitpublic {nick host hand chan arg} {
  2234. global black
  2235. set why [lindex [split $arg] 0]
  2236. set lm [lindex [split $arg] 1]
  2237. set type 0
  2238. set chan1 "$chan"
  2239. if {[regexp {^[&#]} $why] && [matchattr $hand nm|- $chan]} {
  2240. set chan "$why"
  2241. set why [lindex [split $arg] 1]
  2242. set lm [lindex [split $arg] 2]
  2243. }
  2244. limit:process $nick $host $hand $chan $chan1 $why $lm $type
  2245. }
  2246. proc limit:process {nick host hand chan chan1 why lm type} {
  2247. global botnick black
  2248. set char(p) [lindex $black(cmdchar) 0]
  2249. if {[string match -nocase "none" "$char(p)"]} {
  2250. set char(p) ""
  2251. }
  2252. if {[matchattr $hand nm|- $chan]} {
  2253. if {($why == "") && ($type == "0")} {
  2254. blacktools:tell $nick $host $hand $chan $chan1 limit.1 none
  2255. return
  2256. }
  2257. if {($why == "") && ($type == "1")} {
  2258. blacktools:tell $nick $host $hand $chan $chan1 limit.2 none
  2259. return
  2260. }
  2261. }
  2262. if {($why == "") && ($type == "0")} {
  2263. blacktools:tell $nick $host $hand $chan $chan1 limit.3 none
  2264. return
  2265. }
  2266. if {($why == "") && ($type == "1")} {
  2267. blacktools:tell $nick $host $hand $chan $chan1 limit.4 none
  2268. return
  2269. }
  2270. if {![validchan $chan]} {
  2271. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  2272. return
  2273. }
  2274. if {![onchan $botnick $chan]} {
  2275. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  2276. return
  2277. }
  2278. set usersnum [llength [chanlist $chan]]
  2279. set setnum [channel get $chan blacklimit]
  2280. if {([regexp -nocase -- {(#[0-9]+|on|off|set|on|off)} $why tmp lmt]) && (![regexp -nocase -- {\S#} $why])} {
  2281. switch $lmt {
  2282. on {
  2283. set limt [channel get $chan blacklimit]
  2284. channel set $chan +limit
  2285. blacktools:tell $nick $host $hand $chan $chan1 limit.5 none
  2286. if {($limt != "0")} {
  2287. putserv "MODE $chan +l [expr $usersnum + $limt]"
  2288. } else {
  2289. putserv "MODE $chan +l [expr $usersnum + 10]"
  2290. channel set $chan blacklimit 10
  2291. blacktools:tell $nick $host $hand $chan $chan1 limit.6 none
  2292. }
  2293. }
  2294. off {
  2295. channel set $chan -limit
  2296. blacktools:tell $nick $host $hand $chan $chan1 limit.7 none
  2297. putquick "MODE $chan -l"
  2298. }
  2299. set {
  2300. if {![regexp {^[0-9]} $lm]} {
  2301. blacktools:tell $nick $host $hand $chan $chan1 limit.8 none
  2302. return
  2303. }
  2304. if {$lm < 2} { blacktools:tell $nick $host $hand $chan $chan1 limit.9 none
  2305. channel set $chan blacklimit 2
  2306. putserv "MODE $chan +l [expr $usersnum + $lm]"
  2307. blacktools:tell $nick $host $hand $chan $chan1 limit.10 none
  2308. return
  2309. }
  2310. if {$lm > 500} { blacktools:tell $nick $host $hand $chan $chan1 limit.11 none
  2311. return
  2312. }
  2313. channel set $chan blacklimit $lm
  2314. blacktools:tell $nick $host $hand $chan $chan1 limit.12 $lm
  2315. putserv "MODE $chan +l [expr $usersnum + $lm]"
  2316. }
  2317. }
  2318. }
  2319. }
  2320. proc limit:timer {min hour day mon year} {
  2321. global black
  2322. foreach chan [channels] {
  2323. if {[channel get $chan limit]} {
  2324. set usersnum [llength [chanlist $chan]]
  2325. set setnum [channel get $chan blacklimit]
  2326. if {$setnum == "0"} { set setnum "10" }
  2327. if {![botisop $chan]} { return 0 }
  2328. set chanmode [getchanmode $chan]
  2329. if {[string match "*l*" "$chanmode"]} {
  2330. set lim [lindex $chanmode 1]
  2331. } else { set lim "0" }
  2332. if {$usersnum > $lim} { set dif [expr $usersnum - $lim] } else { set dif [expr $lim - $usersnum] }
  2333. if {($dif >= $setnum) || ($dif <= $setnum)} {
  2334. putserv "MODE $chan +l [expr $usersnum + $setnum]"
  2335. }
  2336. }
  2337. }
  2338. }
  2339. ################################# Topic ###################################
  2340. proc topicpublic {nick host hand chan arg} {
  2341. global black
  2342. set nop [lindex [split $arg] 0]
  2343. set char(p) [lindex $black(cmdchar) 0]
  2344. if {[string match -nocase "none" "$char(p)"]} {
  2345. set char(p) ""
  2346. }
  2347. set type 0
  2348. set chan1 "$chan"
  2349. set tp [join [lrange [split $arg] 1 end]]
  2350. set number [lindex [split $arg] 1]
  2351. if {[regexp {^[&#]} $nop] && [matchattr $hand nm|M $nop]} {
  2352. set chan "$nop"
  2353. set nop [lindex [split $arg] 1]
  2354. set tp [join [lrange [split $arg] 2 end]]
  2355. set number [lindex [split $arg] 2]
  2356. }
  2357. topic:process $nick $host $hand $chan $chan1 $nop $tp $number $type
  2358. }
  2359. proc topic:process {nick host hand chan chan1 nop tp number type} {
  2360. global botnick black username
  2361. set char(p) [lindex $black(cmdchar) 0]
  2362. if {[string match -nocase "none" "$char(p)"]} {
  2363. set char(p) ""
  2364. }
  2365. set new_dir "scripts/BlackTools/FILES/$username.topic.txt"
  2366. if {($nop == "") && ($type == "0")} {
  2367. blacktools:tell $nick $host $hand $chan $chan1 topic.1 none
  2368. return
  2369. }
  2370. if {($nop == "") && ($type == "1")} {
  2371. blacktools:tell $nick $host $hand $chan $chan1 topic.2 none
  2372. return
  2373. }
  2374. if {![validchan $chan]} {
  2375. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  2376. return
  2377. }
  2378. if {![onchan $botnick $chan]} {
  2379. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  2380. return
  2381. }
  2382. switch $nop {
  2383. save {
  2384. set t [join [topic $chan]]
  2385. if {$t == ""} { blacktools:tell $nick $host $hand $chan $chan1 topic.3 none
  2386. return
  2387. }
  2388. set file [open $new_dir a]
  2389. puts $file $t
  2390. close $file
  2391. blacktools:tell $nick $host $hand $chan $chan1 topic.4 none
  2392. }
  2393. add {
  2394. if {$tp == ""} {
  2395. blacktools:tell $nick $host $hand $chan $chan1 topic.13 none
  2396. return
  2397. }
  2398. set file [open $new_dir a]
  2399. puts $file "$chan $tp"
  2400. close $file
  2401. blacktools:tell $nick $host $hand $chan $chan1 topic.5 none
  2402. }
  2403. list {
  2404. set file [open $new_dir "r"]
  2405. set w [read -nonewline $file]
  2406. close $file
  2407. set data [split $w "\n"]
  2408. set i 0
  2409. set found_it 0
  2410. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 topic.6 none
  2411. return
  2412. }
  2413. blacktools:tell $nick $host $hand $chan $chan1 topic.7 none
  2414. foreach line $data {
  2415. set read_chan [lindex [split $line] 0]
  2416. if {[string match -nocase $read_chan $chan]} {
  2417. set found_it 1
  2418. set topic [join [lrange [split $line] 1 end]]
  2419. set i [expr $i +1]
  2420. blacktools:tell $nick $host $hand $chan $chan1 topic.8 "$i. $topic"
  2421. }
  2422. }
  2423. if {$found_it == 0} {
  2424. blacktools:tell $nick $host $hand $chan $chan1 topic.6 none
  2425. return
  2426. }
  2427. }
  2428. del {
  2429. array set topicdel [list]
  2430. if {![regexp {^[0-9]} $number]} {
  2431. blacktools:tell $nick $host $hand $chan $chan1 topic.9 none
  2432. return
  2433. }
  2434. set file [open $new_dir "r"]
  2435. set data [read -nonewline $file]
  2436. close $file
  2437. set lines [split $data "\n"]
  2438. set counter -1
  2439. set line_counter -1
  2440. set current_place -1
  2441. foreach line $lines {
  2442. set line_counter [expr $line_counter + 1]
  2443. set read_chan [lindex [split $line] 0]
  2444. if {[string match -nocase $read_chan $chan]} {
  2445. set counter [expr $counter + 1]
  2446. set topicdel($counter) $line_counter
  2447. }
  2448. }
  2449. foreach place [array names topicdel] {
  2450. if {$place == [expr $number - 1]} {
  2451. set current_place $topicdel($place)
  2452. }
  2453. }
  2454. if {$current_place == "-1"} {
  2455. blacktools:tell $nick $host $hand $chan $chan1 topic.14 $number
  2456. return
  2457. }
  2458. set delete [lreplace $lines $current_place $current_place]
  2459. set files [open $new_dir "w"]
  2460. puts $files [join $delete "\n"]
  2461. close $files
  2462. set file [open $new_dir "r"]
  2463. set data [read -nonewline $file]
  2464. close $file
  2465. if {$data == ""} {
  2466. set files [open $new_dir "w"]
  2467. close $files
  2468. }
  2469. blacktools:tell $nick $host $hand $chan $chan1 topic.10 $number
  2470. }
  2471. set {
  2472. array set topicset [list]
  2473. if {![regexp {^[0-9]} $number]} {
  2474. blacktools:tell $nick $host $hand $chan $chan1 topic.11 none
  2475. return
  2476. }
  2477. set file [open $new_dir "r"]
  2478. set data [read -nonewline $file]
  2479. close $file
  2480. set lines [split $data "\n"]
  2481. set counter -1
  2482. set line_counter -1
  2483. set current_place -1
  2484. foreach line $lines {
  2485. set line_counter [expr $line_counter + 1]
  2486. set read_chan [lindex [split $line] 0]
  2487. if {[string match -nocase $read_chan $chan]} {
  2488. set counter [expr $counter + 1]
  2489. set topicdel($counter) $line_counter
  2490. }
  2491. }
  2492. foreach place [array names topicdel] {
  2493. if {$place == [expr $number - 1]} {
  2494. set current_place $topicdel($place)
  2495. }
  2496. }
  2497. if {$current_place == "-1"} {
  2498. blacktools:tell $nick $host $hand $chan $chan1 topic.15 $number
  2499. return
  2500. }
  2501. set current_line [lindex $lines $current_place]
  2502. set line [join [lrange [split $current_line] 1 end]]
  2503. putquick "TOPIC $chan :Setting topic.."
  2504. putserv "TOPIC $chan :$line"
  2505. blacktools:tell $nick $host $hand $chan $chan1 topic.12 $number
  2506. }
  2507. lock {
  2508. set gettopic [topic $chan]
  2509. if {$gettopic == ""} {
  2510. blacktools:tell $nick $host $hand $chan $chan1 topic.16 none
  2511. return
  2512. }
  2513. channel set $chan +topiclock
  2514. channel set $chan topicset $gettopic
  2515. blacktools:tell $nick $host $hand $chan $chan1 topic.17 none
  2516. }
  2517. unlock {
  2518. if {![channel get $chan topiclock]} {
  2519. blacktools:tell $nick $host $hand $chan $chan1 topic.18 none
  2520. }
  2521. channel set $chan -topiclock
  2522. channel set $chan topicset ""
  2523. blacktools:tell $nick $host $hand $chan $chan1 topic.19 none
  2524. }
  2525. }
  2526. }
  2527. proc topic:change {nick host hand chan arg} {
  2528. global black
  2529. set thetopic [channel get $chan topicset]
  2530. set handle [nick2hand $nick]
  2531. set getlang [string tolower [channel get $chan lang]]
  2532. if {![botisop $chan]} { return }
  2533. if {[isbotnick $nick]} { return }
  2534. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  2535. if {[channel get $chan topiclock]} {
  2536. if {![matchattr $handle nm|M $chan]} {
  2537. putserv "TOPIC $chan :$thetopic"
  2538. if {[info exists black(say.$getlang.topic.20)]} {
  2539. putserv "NOTICE $nick :$black(say.$getlang.topic.20)"
  2540. }
  2541. } else {
  2542. channel set $chan topicset [topic $chan]
  2543. }
  2544. }
  2545. }
  2546. proc topiclock:verify {nick host hand chan args} {
  2547. global black
  2548. set onick [lindex $args 1]
  2549. if {![validchan $chan]} { return }
  2550. if {[isbotnick $onick] && [channel get $chan topiclock]} {
  2551. if {[channel get $chan topicset] != ""} {
  2552. set thetopic [topic $chan]
  2553. set locktopic [channel get $chan topicset]
  2554. if {$thetopic != $locktopic} {
  2555. putserv "TOPIC $chan :$locktopic"
  2556. }
  2557. }
  2558. }
  2559. }
  2560. proc topiclock:join {nick host hand chan} {
  2561. global black
  2562. if {![validchan $chan]} { return }
  2563. if {![isbotnick $nick]} {
  2564. return
  2565. }
  2566. if {[llength [chanlist $chan]] > 1} {
  2567. return
  2568. }
  2569. utimer 5 [list topiclock:join:act $chan]
  2570. }
  2571. proc topiclock:join:act {chan} {
  2572. global black
  2573. if {![botisop $chan]} {
  2574. return
  2575. }
  2576. if {[channel get $chan topiclock]} {
  2577. if {[channel get $chan topicset] != ""} {
  2578. set thetopic [topic $chan]
  2579. set locktopic [channel get $chan topicset]
  2580. if {$thetopic != $locktopic} {
  2581. putserv "TOPIC $chan :$locktopic"
  2582. }
  2583. }
  2584. }
  2585. }
  2586. ################################# Seen ###################################
  2587. proc seen:save:2 {nick chan host type time staytimer reason} {
  2588. global black username
  2589. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2590. set lin 0
  2591. set j 0
  2592. set who "$type $chan $nick $host $time $staytimer $reason"
  2593. set file [open $seendir "r"]
  2594. set database [read -nonewline $file]
  2595. close $file
  2596. set data [split $database "\n"]
  2597. foreach line $data {
  2598. set lin [expr $lin +1]
  2599. set userentry [lindex [split $line] 2]
  2600. set chanentry [lindex [split $line] 1]
  2601. if {[string equal -nocase $userentry $nick] && [string match -nocase $chanentry $chan]} {
  2602. set joined [lindex [split $line] 0]
  2603. if {$joined == "JOIN"} {
  2604. set j [lindex [split $line] 4]
  2605. if {![regexp {^[0-9]} $j] || ($j == "")} {
  2606. set j 0
  2607. }
  2608. }
  2609. set who "$type $chan $nick $host $time $j $reason"
  2610. if {$line != ""} {
  2611. set num [expr $lin - 1]
  2612. set delete [lreplace $data $num $num]
  2613. set files [open $seendir "w"]
  2614. puts $files [join $delete "\n"]
  2615. close $files
  2616. }
  2617. }
  2618. }
  2619. set file [open $seendir "r"]
  2620. set data [read -nonewline $file]
  2621. close $file
  2622. if {$data == ""} {
  2623. set files [open $seendir "w"]
  2624. close $files
  2625. }
  2626. set file [open $seendir "a"]
  2627. puts $file "$who"
  2628. close $file
  2629. }
  2630. proc seen:save:1 {nick chan host type time staytimer} {
  2631. global black username
  2632. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2633. set lin 0
  2634. set who "$type $chan $nick $host $time $staytimer"
  2635. set file [open $seendir "r"]
  2636. set database [read -nonewline $file]
  2637. close $file
  2638. set data [split $database "\n"]
  2639. foreach line $data {
  2640. set lin [expr $lin +1]
  2641. set userentry [lindex [split $line] 2]
  2642. set chanentry [lindex [split $line] 1]
  2643. if {[string equal -nocase $userentry $nick] && [string match -nocase $chanentry $chan]} {
  2644. if {$line != ""} {
  2645. set num [expr $lin - 1]
  2646. set delete [lreplace $data $num $num]
  2647. set files [open $seendir "w"]
  2648. puts $files [join $delete "\n"]
  2649. close $files
  2650. }
  2651. }
  2652. }
  2653. set file [open $seendir "r"]
  2654. set data [read -nonewline $file]
  2655. close $file
  2656. if {$data == ""} {
  2657. set files [open $seendir "w"]
  2658. close $files
  2659. }
  2660. set file [open $seendir "a"]
  2661. puts $file "$who"
  2662. close $file
  2663. }
  2664. proc seen:join {nick host hand chan} {
  2665. global botnick username
  2666. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2667. if {![validchan $chan]} { return}
  2668. if {![channel get $chan seen]} {
  2669. return
  2670. }
  2671. if {[isbotnick $nick]} { return }
  2672. set time [unixtime]
  2673. set host "*!$host"
  2674. set type "JOIN"
  2675. set staytimer "0"
  2676. seen:save:1 $nick $chan $host $type $time $staytimer
  2677. }
  2678. proc seen:part {nick host hand chan arg} {
  2679. global botnick username
  2680. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2681. if {![validchan $chan]} { return }
  2682. if {![channel get $chan seen]} {
  2683. return
  2684. }
  2685. set time [unixtime]
  2686. set staytimer "0"
  2687. set type "PART"
  2688. set reason [join [lrange [split $arg] 0 end]]
  2689. if {$reason == ""} { set reason "No Reason" }
  2690. set host "*!$host"
  2691. if {[isbotnick $nick]} { return }
  2692. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  2693. }
  2694. proc seen:sign {nick host hand chan arg} {
  2695. global botnick username
  2696. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2697. if {![validchan $chan]} { return }
  2698. if {![channel get $chan seen]} {
  2699. return 0
  2700. }
  2701. set time [unixtime]
  2702. set staytimer "0"
  2703. set type "SIGN"
  2704. set host "*!$host"
  2705. set reason [join [lrange [split $arg] 0 end]]
  2706. if {$reason == ""} { set reason "No Reason" }
  2707. if {[isbotnick $nick]} { return }
  2708. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  2709. }
  2710. proc seen:kick {nick host hand chan kicked reason} {
  2711. global botnick username
  2712. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2713. if {![validchan $chan]} { return }
  2714. if {![channel get $chan seen]} {
  2715. return
  2716. }
  2717. set lin 0
  2718. set j 0
  2719. set time [unixtime]
  2720. set hosted [getchanhost $kicked $chan]
  2721. set hosted "*!$hosted"
  2722. set reason [join [lrange [split $reason] 1 end]]
  2723. if {$reason == ""} { set reason "No Reason" }
  2724. if {[isbotnick $kicked]} { return }
  2725. set who "KICK $chan $kicked $hosted $time 0 $reason"
  2726. set file [open $seendir "r"]
  2727. set database [read -nonewline $file]
  2728. close $file
  2729. set data [split $database "\n"]
  2730. foreach line $data {
  2731. set lin [expr $lin +1]
  2732. set userentry [lindex [split $line] 2]
  2733. set chanentry [lindex [split $line] 1]
  2734. if {[string equal -nocase $kicked $userentry] && [string match -nocase $chanentry $chan]} {
  2735. set joined [lindex [split $line] 0]
  2736. if {$joined == "JOIN"} {
  2737. set j [lindex [split $line] 4]
  2738. if {![regexp {^[0-9]} $j] || ($j == "")} {
  2739. set j 0
  2740. }
  2741. }
  2742. set who "KICK $chan $kicked $hosted $time $j $reason"
  2743. if {$line != ""} {
  2744. set num [expr $lin - 1]
  2745. set delete [lreplace $data $num $num]
  2746. set files [open $seendir "w"]
  2747. puts $files [join $delete "\n"]
  2748. close $files
  2749. }
  2750. }
  2751. }
  2752. set file [open $seendir "r"]
  2753. set data [read -nonewline $file]
  2754. close $file
  2755. if {$data == ""} {
  2756. set files [open $seendir "w"]
  2757. close $files
  2758. }
  2759. set file [open $seendir "a"]
  2760. puts $file "$who"
  2761. close $file
  2762. }
  2763. proc seen:split {nick host hand chan args} {
  2764. global botnick username
  2765. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2766. if {![validchan $chan]} { return }
  2767. if {![channel get $chan seen]} {
  2768. return
  2769. }
  2770. set time [unixtime]
  2771. set staytimer "0"
  2772. set type "SPLIT"
  2773. set host "*!$host"
  2774. set reason [join [lrange [split $args] 0 end]]
  2775. if {[isbotnick $nick]} { return }
  2776. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  2777. }
  2778. proc seen:changenick {nick host hand chan newnick} {
  2779. global botnick username
  2780. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2781. if {![validchan $chan]} { return }
  2782. if {![channel get $chan seen]} {
  2783. return
  2784. }
  2785. set time [unixtime]
  2786. set host "*!$host"
  2787. set staytimer "0"
  2788. set type "NICKCHANGE"
  2789. if {[isbotnick $nick]} { return }
  2790. seen:save:2 $nick $chan $host $type $time $staytimer $newnick
  2791. }
  2792. proc seenpublic {nick host hand chan arg} {
  2793. global black
  2794. if {![channel get $chan seen]} {
  2795. return
  2796. }
  2797. set type 0
  2798. set chan1 "$chan"
  2799. set what [lindex [split $arg] 0]
  2800. if {[regexp {^[&#]} $what] && [matchattr $hand nm|- $chan]} {
  2801. set chan1 "$chan"
  2802. set chan "$what"
  2803. set what [lindex [split $arg] 1]
  2804. }
  2805. seen:process $nick $host $hand $chan $chan1 $what $type
  2806. }
  2807. proc seen:process {nick host hand chan chan1 what type} {
  2808. global black count botnick username
  2809. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  2810. set number [scan $black(seenflood) %\[^:\]]
  2811. set timer [scan $black(seenflood) %*\[^:\]:%s]
  2812. set i 0
  2813. set char(p) [lindex $black(cmdchar) 0]
  2814. array set seensort [list]
  2815. if {[string match -nocase "none" "$char(p)"]} {
  2816. set char(p) ""
  2817. }
  2818. if {($what == "") && ($type == "0")} {
  2819. blacktools:tell $nick $host $hand $chan $chan1 seen.1 none
  2820. return
  2821. }
  2822. if {($what == "") && ($type == "1")} {
  2823. blacktools:tell $nick $host $hand $chan $chan1 seen.2 none
  2824. return
  2825. }
  2826. if {![validchan $chan]} {
  2827. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  2828. return
  2829. }
  2830. if {![onchan $botnick $chan]} {
  2831. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  2832. return
  2833. }
  2834. foreach tmr [utimers] {
  2835. if {[string match "*count(flood:$host:$chan)*" [join [lindex $tmr 1]]]} {
  2836. killutimer [lindex $tmr 2]
  2837. }
  2838. }
  2839. if {![info exists count(flood:$host:$chan)]} {
  2840. set count(flood:$host:$chan) 0
  2841. }
  2842. incr count(flood:$host:$chan)
  2843. utimer $timer [list unset count(flood:$host:$chan)]
  2844. if {$count(flood:$host:$chan) == "$number"} {
  2845. blacktools:tell $nick $host $hand $chan $chan1 seen.5 none
  2846. return
  2847. }
  2848. if {[string equal -nocase $what $nick] && ($chan1 == $chan)} { blacktools:tell $nick $host $hand $chan $chan1 seen.6 $nick
  2849. return
  2850. }
  2851. if {[onchan $what $chan]} { blacktools:tell $nick $host $hand $chan $chan1 seen.7 $what
  2852. return
  2853. }
  2854. set file [open $seendir "r"]
  2855. set database [read -nonewline $file]
  2856. close $file
  2857. set data [split $database "\n"]
  2858. set length_data [llength $data]
  2859. for {set j $length_data} {$j >= 0} {set j [expr $j - 1]} {
  2860. set line [lindex $data $j]
  2861. if {$line != ""} {
  2862. set userentry [lindex [split $line] 2]
  2863. set chanentry [lindex [split $line] 1]
  2864. set host [lindex [split $line] 3]
  2865. if {$what == "*!*@*"} { return 0 }
  2866. if {([string equal -nocase $userentry $what] || [string match -nocase $what $userentry] || [string match -nocase $what $host]) && [string match -nocase $chanentry $chan]} {
  2867. set i [expr $i +1]
  2868. if {$i < 6} {
  2869. lappend entry $userentry
  2870. }
  2871. set seenfound 1
  2872. set host [string trim $host "*!~"]
  2873. set tm [lindex [split $line] 4]
  2874. set jointime [lindex [split $line] 5]
  2875. set newnick [lindex [split $line] 6]
  2876. set reason [join [lrange [split $line] 6 end]]
  2877. if {!([regexp {^[0-9]} $jointime]) || ($jointime == "")} {
  2878. set jointime 0
  2879. set reason [join [lrange [split $line] 5 end]]
  2880. }
  2881. if {$reason == ""} { set reason "No Reason" }
  2882. set output [duration [expr [unixtime] - $tm]]
  2883. set staytime [expr [unixtime] - $jointime]
  2884. set staytime [duration [expr $tm - $jointime]]
  2885. set getlang [string tolower [channel get $chan lang]]
  2886. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  2887. set date [clock format $tm -format %d.%m.]
  2888. set hour [clock format $tm -format %H:%M]
  2889. set top_seenlist ""
  2890. set entry [lsort -unique $entry]
  2891. set seensort($tm) $j
  2892. foreach line [lsort -integer -decreasing [array names seensort]] {
  2893. lappend top_seenlist $seensort($line)
  2894. }
  2895. set current_line [lindex $top_seenlist 0]
  2896. set line [lindex $data $current_line]
  2897. set latest_entry [lindex [split $line] 2]
  2898. set host [lindex [split $line] 3]
  2899. set host [string trim $host "*!~"]
  2900. set tm [lindex [split $line] 4]
  2901. set jointime [lindex [split $line] 5]
  2902. set newnick [lindex [split $line] 6]
  2903. set reason [join [lrange [split $line] 6 end]]
  2904. if {!([regexp {^[0-9]} $jointime]) || ($jointime == "")} {
  2905. set jointime 0
  2906. set reason [lrange [split $line] 5 end]
  2907. }
  2908. if {$reason == ""} { set reason "No Reason" }
  2909. set output [duration [expr [unixtime] - $tm]]
  2910. set staytime [expr [unixtime] - $jointime]
  2911. set staytime [duration [expr $tm - $jointime]]
  2912. set getlang [string tolower [channel get $chan lang]]
  2913. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  2914. set date [clock format $tm -format %d.%m.]
  2915. set hour [clock format $tm -format %H:%M]
  2916. set replace(%latest%) $latest_entry
  2917. set replace(%num%) [llength $entry]
  2918. set replace(%entry%) "[join $entry ", "]"
  2919. set replace(%host%) "$host"
  2920. set replace(%output%) "$output"
  2921. set replace(%date%) "($date $hour)"
  2922. set replace(%newnick%) "$newnick"
  2923. set replace(%userentry%) "$userentry"
  2924. set replace(%chan%) "$chan"
  2925. set replace(%reason%) "$reason"
  2926. set replace(%staytime%) "$staytime"
  2927. if {$jointime == "0"} { set staymsg "[string map [array get replace] $black(say.$getlang.seen.8)]"
  2928. set replace(%staymsg%) "$staymsg"
  2929. } else {
  2930. set staymsg "[string map [array get replace] $black(say.$getlang.seen.9)]"
  2931. set replace(%staymsg%) "$staymsg"
  2932. }
  2933. if {[llength $entry] > 1} {
  2934. set found_many 1
  2935. if {[lindex [split $line] 0] == "PART"} {
  2936. set reply "[string map [array get replace] $black(say.$getlang.seen.21)]"
  2937. }
  2938. if {[lindex [split $line] 0] == "SIGN"} {
  2939. set reply "[string map [array get replace] $black(say.$getlang.seen.22)]"
  2940. }
  2941. if {[lindex [split $line] 0] == "JOIN"} {
  2942. if {[onchan $latest_entry $chan]} {
  2943. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  2944. set replace(%nowon%) "$nowon"
  2945. } else {
  2946. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  2947. set replace(%nowon%) "$nowon"
  2948. }
  2949. set reply "[string map [array get replace] $black(say.$getlang.seen.23)]"
  2950. }
  2951. if {[lindex [split $line] 0] == "SPLIT"} {
  2952. set reply "[string map [array get replace] $black(say.$getlang.seen.24)]"
  2953. }
  2954. if {[lindex [split $line] 0] == "KICK"} {
  2955. set reply "[string map [array get replace] $black(say.$getlang.seen.25)]"
  2956. }
  2957. if {[lindex [split $line] 0] == "NICKCHANGE"} {
  2958. if {[onchan $newnick $chan]} {
  2959. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  2960. set replace(%nowon%) "$nowon"
  2961. } else {
  2962. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  2963. set replace(%nowon%) "$nowon"
  2964. }
  2965. set reply "[string map [array get replace] $black(say.$getlang.seen.26)]"
  2966. }
  2967. } else {
  2968. if {[lindex [split $line] 0] == "PART"} {
  2969. set reply "[string map [array get replace] $black(say.$getlang.seen.12)]"
  2970. }
  2971. if {[lindex [split $line] 0] == "SIGN"} {
  2972. set reply "[string map [array get replace] $black(say.$getlang.seen.13)]"
  2973. }
  2974. if {[lindex [split $line] 0] == "JOIN"} {
  2975. if {[onchan $userentry $chan]} {
  2976. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  2977. set replace(%nowon%) "$nowon"
  2978. } else {
  2979. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  2980. set replace(%nowon%) "$nowon"
  2981. }
  2982. set reply "[string map [array get replace] $black(say.$getlang.seen.14)]"
  2983. }
  2984. if {[lindex [split $line] 0] == "SPLIT"} {
  2985. set reply "[string map [array get replace] $black(say.$getlang.seen.15)]"
  2986. }
  2987. if {[lindex [split $line] 0] == "KICK"} {
  2988. set reply "[string map [array get replace] $black(say.$getlang.seen.16)]"
  2989. }
  2990. if {[lindex [split $line] 0] == "NICKCHANGE"} {
  2991. if {[onchan $newnick $chan]} {
  2992. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  2993. set replace(%nowon%) "$nowon"
  2994. } else {
  2995. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  2996. set replace(%nowon%) "$nowon"
  2997. }
  2998. set reply "[string map [array get replace] $black(say.$getlang.seen.17)]"
  2999. }
  3000. }
  3001. }
  3002. set method "NOTICE"
  3003. set onwho "$nick"
  3004. set how [channel get $chan seen-method]
  3005. switch [string tolower $how] {
  3006. notice {
  3007. set method "NOTICE"
  3008. set onwho "$nick"
  3009. }
  3010. privmsg {
  3011. set method "PRIVMSG"
  3012. set onwho "$chan1"
  3013. }
  3014. }
  3015. }
  3016. }
  3017. if {[info exists reply]} {
  3018. puthelp "$method $onwho :$reply"
  3019. }
  3020. if {![info exists seenfound]} {
  3021. blacktools:tell $nick $host $hand $chan $chan1 seen.18 $what
  3022. }
  3023. }
  3024. proc seen:entry:delete {minute hour day month year} {
  3025. global black username
  3026. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  3027. set file [open $seendir "r"]
  3028. set database [read -nonewline $file]
  3029. close $file
  3030. set data [split $database "\n"]
  3031. set counter 0
  3032. putlog "\[BlackTools\] Checking for expired seen records.."
  3033. foreach line $data {
  3034. set tm [lindex [split $line] 4]
  3035. set read_days [expr [expr [expr [expr [unixtime] - $tm] / 60]] / 1440]
  3036. if {$read_days >= $black(seen:expire:time)} {
  3037. set counter [expr $counter + 1]
  3038. lappend expire_list $tm
  3039. }
  3040. }
  3041. if {[info exists expire_list]} {
  3042. seen:delete:action $counter $expire_list
  3043. }
  3044. }
  3045. proc seen:delete:action {counter list} {
  3046. global black username
  3047. set seendir "scripts/BlackTools/FILES/$username.Seen.db"
  3048. set list [join $list]
  3049. foreach tm $list {
  3050. if {$tm != ""} {
  3051. set file [open $seendir "r"]
  3052. set database [read -nonewline $file]
  3053. close $file
  3054. set data [split $database "\n"]
  3055. set i [lsearch -glob $data "* $tm *"]
  3056. if {$i > -1} {
  3057. set line [lindex $data $i]
  3058. set delete [lreplace $data $i $i]
  3059. set file [open $seendir "w"]
  3060. puts $file [join $delete "\n"]
  3061. close $file
  3062. }
  3063. }
  3064. }
  3065. putlog "\[BlackTools\] Found $counter expired SEEN records."
  3066. }
  3067. ############################### Greet #####################################
  3068. proc greetpublic {nick host hand chan arg} {
  3069. global black
  3070. set who [lindex [split $arg] 0]
  3071. set type 0
  3072. set chan1 "$chan"
  3073. set greet [join [lrange [split $arg] 1 end]]
  3074. set number [lindex [split $arg] 1]
  3075. if {[regexp {^[&#]} $who] && [matchattr $hand nm|M $who]} {
  3076. set chan "$who"
  3077. set who [lindex [split $arg] 1]
  3078. set greet [join [lrange [split $arg] 2 end]]
  3079. set number [lindex [split $arg] 2]
  3080. }
  3081. greet:process $who $greet $number $type $nick $host $hand $chan $chan1
  3082. }
  3083. proc greet:process {who greet number type nick host hand chan chan1} {
  3084. global botnick black username
  3085. set char(p) [lindex $black(cmdchar) 0]
  3086. set new_dir "scripts/BlackTools/FILES/$username.greets.txt"
  3087. if {[string match -nocase "none" "$char(p)"]} {
  3088. set char(p) ""
  3089. }
  3090. if {($who == "") && ($type == "0")} {
  3091. blacktools:tell $nick $host $hand $chan $chan1 greet.1 none
  3092. return
  3093. }
  3094. if {($who == "") && ($type == "1")} {
  3095. blacktools:tell $nick $host $hand $chan $chan1 greet.2 none
  3096. return
  3097. }
  3098. if {![validchan $chan]} {
  3099. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  3100. return
  3101. }
  3102. if {![onchan $botnick $chan]} {
  3103. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  3104. return
  3105. }
  3106. switch $who {
  3107. on {
  3108. channel set $chan +greet
  3109. blacktools:tell $nick $host $hand $chan $chan1 greet.3 none
  3110. }
  3111. off {
  3112. channel set $chan -greet
  3113. blacktools:tell $nick $host $hand $chan $chan1 greet.4 none
  3114. }
  3115. add {
  3116. set counter -1
  3117. set file [open $new_dir "r"]
  3118. set w [read -nonewline $file]
  3119. close $file
  3120. set data [split $w "\n"]
  3121. set current -1
  3122. foreach line $data {
  3123. set counter [expr $counter + 1]
  3124. set channel [lindex [split $line] 0]
  3125. if {[string equal -nocase $chan $channel]} {
  3126. set status [lindex [split $line] 1]
  3127. if {$status == "1"} {
  3128. set message [join [lrange [split $line] 2 end]]
  3129. set delete [lreplace $data $counter $counter]
  3130. set file [open $new_dir "w"]
  3131. puts $file [join $delete "\n"]
  3132. close $file
  3133. set file [open $new_dir a]
  3134. puts $file "$chan 0 $message"
  3135. close $file
  3136. }
  3137. }
  3138. }
  3139. set file [open $new_dir a]
  3140. puts $file "$chan 1 $greet"
  3141. close $file
  3142. blacktools:tell $nick $host $hand $chan $chan1 greet.5 none
  3143. blacktools:tell $nick $host $hand $chan $chan1 greet.6 $greet
  3144. }
  3145. list {
  3146. set file [open $new_dir "r"]
  3147. set w [read -nonewline $file]
  3148. close $file
  3149. set data [split $w "\n"]
  3150. set i 0
  3151. set found_it 0
  3152. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 greet.7 none
  3153. return
  3154. }
  3155. blacktools:tell $nick $host $hand $chan $chan1 greet.8 none
  3156. foreach mes $data {
  3157. set channel [lindex [split $mes] 0]
  3158. if {[string equal -nocase $channel $chan]} {
  3159. set i [expr $i +1]
  3160. set found_it 1
  3161. set message [join [lrange [split $mes] 2 end]]
  3162. set status [lindex [split $mes] 1]
  3163. if {$status == 1} {
  3164. blacktools:tell $nick $host $hand $chan $chan1 greet.6 "\002\[ON\]\002 $i. $message"
  3165. } else {
  3166. blacktools:tell $nick $host $hand $chan $chan1 greet.6 "\[OFF\] $i. $message"
  3167. }
  3168. }
  3169. }
  3170. if {$found_it == "0"} {
  3171. blacktools:tell $nick $host $hand $chan $chan1 greet.7 none
  3172. } else {
  3173. blacktools:tell $nick $host $hand $chan $chan1 greet.11 none
  3174. }
  3175. }
  3176. del {
  3177. set file [open $new_dir "r"]
  3178. set w [read -nonewline $file]
  3179. close $file
  3180. set data [split $w "\n"]
  3181. set counter 0
  3182. foreach line $data {
  3183. set the_greet [join [lrange [split $line] 2 end]]
  3184. set channel [lindex [split $line] 0]
  3185. if {[string equal -nocase $channel $chan] && [string match -nocase $greet $the_greet]} {
  3186. set counter [expr $counter + 1]
  3187. }
  3188. }
  3189. for {set j 0} {$j < $counter} {incr j} {
  3190. set file [open $new_dir "r"]
  3191. set w [read -nonewline $file]
  3192. close $file
  3193. set data [split $w "\n"]
  3194. set i [lsearch -glob $data "* $greet"]
  3195. if {$i > -1} {
  3196. set line [lindex $data $i]
  3197. set delete [lreplace $data $i $i]
  3198. set file [open $new_dir "w"]
  3199. puts $file [join $delete "\n"]
  3200. close $file
  3201. }
  3202. }
  3203. set file [open $new_dir "r"]
  3204. set w [read -nonewline $file]
  3205. close $file
  3206. if {$w == ""} {
  3207. set file [open $new_dir "w"]
  3208. close $file
  3209. }
  3210. blacktools:tell $nick $host $hand $chan $chan1 greet.10 $counter
  3211. }
  3212. set {
  3213. set counter -1
  3214. set list_counter 0
  3215. array set greetset [list]
  3216. set current_place -1
  3217. set last_message ""
  3218. set last_place -1
  3219. if {$number == ""} {
  3220. blacktools:tell $nick $host $hand $chan $chan1 greet.12 none
  3221. return
  3222. }
  3223. set file [open $new_dir "r"]
  3224. set w [read -nonewline $file]
  3225. close $file
  3226. set data [split $w "\n"]
  3227. foreach line $data {
  3228. set counter [expr $counter + 1]
  3229. set channel [lindex [split $line] 0]
  3230. if {[string equal -nocase $channel $chan]} {
  3231. set list_counter [expr $list_counter + 1]
  3232. set greetset($list_counter) $counter
  3233. }
  3234. }
  3235. foreach place [array names greetset] {
  3236. if {$place == $number} {
  3237. set current_place $greetset($place)
  3238. }
  3239. }
  3240. if {$current_place == "-1"} {
  3241. blacktools:tell $nick $host $hand $chan $chan1 greet.13 none
  3242. return
  3243. }
  3244. set current_line [lindex $data $current_place]
  3245. set status [lindex [split $current_line] 1]
  3246. if {$status == "1"} {
  3247. blacktools:tell $nick $host $hand $chan $chan1 greet.14 none
  3248. }
  3249. set current_message [join [lrange [split $current_line] 2 end]]
  3250. set file [open $new_dir "r"]
  3251. set w [read -nonewline $file]
  3252. close $file
  3253. set data [split $w "\n"]
  3254. set counter -1
  3255. foreach line $data {
  3256. set counter [expr $counter + 1]
  3257. set channel [lindex [split $line] 0]
  3258. set message [join [lrange [split $line] 2 end]]
  3259. if {[string equal -nocase $chan $channel]} {
  3260. set status [lindex [split $line] 1]
  3261. if {$status == "1"} {
  3262. set delete [lreplace $data $counter $counter]
  3263. set last_place $counter
  3264. set last_message $message
  3265. set file [open $new_dir "w"]
  3266. puts $file [join $delete "\n"]
  3267. close $file
  3268. }
  3269. }
  3270. }
  3271. set file [open $new_dir "r"]
  3272. set w [read -nonewline $file]
  3273. close $file
  3274. set data [split $w "\n"]
  3275. set insert [linsert $data $last_place "$chan 0 $last_message"]
  3276. set file [open $new_dir w]
  3277. puts $file [join $insert "\n"]
  3278. close $file
  3279. set file [open $new_dir "r"]
  3280. set w [read -nonewline $file]
  3281. close $file
  3282. set data [split $w "\n"]
  3283. set delete [lreplace $data $current_place $current_place]
  3284. set file [open $new_dir "w"]
  3285. puts $file [join $delete "\n"]
  3286. close $file
  3287. set file [open $new_dir "r"]
  3288. set w [read -nonewline $file]
  3289. close $file
  3290. set data [split $w "\n"]
  3291. set insert [linsert $data $current_place "$chan 1 $current_message"]
  3292. set file [open $new_dir w]
  3293. puts $file [join $insert "\n"]
  3294. close $file
  3295. blacktools:tell $nick $host $hand $chan $chan1 greet.15 $number
  3296. }
  3297. }
  3298. }
  3299. proc greetpublic:join {nick host hand chan} {
  3300. global black username count
  3301. set new_dir "scripts/BlackTools/FILES/$username.greets.txt"
  3302. set current_greet ""
  3303. if {![validchan $chan]} { return }
  3304. if {[channel get $chan greet]} {
  3305. if {[isbotnick $nick]} { return }
  3306. if {[info exists black(turnOnFlood:$chan)]} {
  3307. return
  3308. }
  3309. set replace(%nick%) $nick
  3310. set file [open $new_dir "r"]
  3311. set data [read -nonewline $file]
  3312. close $file
  3313. if {$data == ""} { return }
  3314. set lines [split $data "\n"]
  3315. foreach line $lines {
  3316. set channel [lindex [split $line] 0]
  3317. set status [lindex [split $line] 1]
  3318. if {[string equal -nocase $channel $chan] && ($status == "1")} {
  3319. set message [join [lrange [split $line] 2 end]]
  3320. set current_greet $message
  3321. }
  3322. }
  3323. set the_message [string map [array get replace] $current_greet]
  3324. set split_message [split $the_message "~"]
  3325. foreach message $split_message {
  3326. if {$black(howgreet) == "1"} {
  3327. puthelp "NOTICE $nick :$message"
  3328. } else { puthelp "PRIVMSG $nick :$message" }
  3329. }
  3330. }
  3331. }
  3332. ################################ Leave ###################################
  3333. proc leavepublic {nick host hand chan arg} {
  3334. global black
  3335. set who [lindex [split $arg] 0]
  3336. set type 0
  3337. set chan1 "$chan"
  3338. set leave [join [lrange [split $arg] 1 end]]
  3339. set number [lindex [split $arg] 1]
  3340. if {[regexp {^[&#]} $who] && [matchattr $hand nm|M $who]} {
  3341. set chan "$who"
  3342. set who [lindex [split $arg] 1]
  3343. set leave [join [lrange [split $arg] 2 end]]
  3344. set number [lindex [split $arg] 2]
  3345. }
  3346. leave:process $who $leave $number $type $nick $host $hand $chan $chan1
  3347. }
  3348. proc leave:process {who leave number type nick host hand chan chan1} {
  3349. global botnick black username
  3350. set char(p) [lindex $black(cmdchar) 0]
  3351. set new_dir "scripts/BlackTools/FILES/$username.leave.txt"
  3352. if {[string match -nocase "none" "$char(p)"]} {
  3353. set char(p) ""
  3354. }
  3355. if {($who == "") && ($type == "0")} {
  3356. blacktools:tell $nick $host $hand $chan $chan1 leave.1 none
  3357. return
  3358. }
  3359. if {($who == "") && ($type == "1")} {
  3360. blacktools:tell $nick $host $hand $chan $chan1 leave.2 none
  3361. return
  3362. }
  3363. if {![validchan $chan]} {
  3364. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  3365. return
  3366. }
  3367. if {![onchan $botnick $chan]} {
  3368. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  3369. return
  3370. }
  3371. switch $who {
  3372. on {
  3373. channel set $chan +leave
  3374. blacktools:tell $nick $host $hand $chan $chan1 leave.3 none
  3375. }
  3376. off {
  3377. channel set $chan -leave
  3378. blacktools:tell $nick $host $hand $chan $chan1 leave.4 none
  3379. }
  3380. add {
  3381. set counter -1
  3382. set file [open $new_dir "r"]
  3383. set w [read -nonewline $file]
  3384. close $file
  3385. set data [split $w "\n"]
  3386. set current -1
  3387. foreach line $data {
  3388. set counter [expr $counter + 1]
  3389. set channel [lindex [split $line] 0]
  3390. if {[string equal -nocase $chan $channel]} {
  3391. set status [lindex [split $line] 1]
  3392. if {$status == "1"} {
  3393. set message [join [lrange [split $line] 2 end]]
  3394. set delete [lreplace $data $counter $counter]
  3395. set file [open $new_dir "w"]
  3396. puts $file [join $delete "\n"]
  3397. close $file
  3398. set file [open $new_dir a]
  3399. puts $file "$chan 0 $message"
  3400. close $file
  3401. }
  3402. }
  3403. }
  3404. set file [open $new_dir a]
  3405. puts $file "$chan 1 $leave"
  3406. close $file
  3407. blacktools:tell $nick $host $hand $chan $chan1 leave.5 none
  3408. blacktools:tell $nick $host $hand $chan $chan1 leave.6 $leave
  3409. }
  3410. list {
  3411. set file [open $new_dir "r"]
  3412. set w [read -nonewline $file]
  3413. close $file
  3414. set data [split $w "\n"]
  3415. set i 0
  3416. set found_it 0
  3417. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 leave.7 none
  3418. return
  3419. }
  3420. blacktools:tell $nick $host $hand $chan $chan1 leave.8 none
  3421. foreach mes $data {
  3422. set channel [lindex [split $mes] 0]
  3423. if {[string equal -nocase $channel $chan]} {
  3424. set i [expr $i +1]
  3425. set found_it 1
  3426. set message [join [lrange [split $mes] 2 end]]
  3427. set status [lindex [split $mes] 1]
  3428. if {$status == 1} {
  3429. blacktools:tell $nick $host $hand $chan $chan1 leave.6 "\002\[ON\]\002 $i. $message"
  3430. } else {
  3431. blacktools:tell $nick $host $hand $chan $chan1 leave.6 "\[OFF\] $i. $message"
  3432. }
  3433. }
  3434. }
  3435. if {$found_it == "0"} {
  3436. blacktools:tell $nick $host $hand $chan $chan1 leave.7 none
  3437. } else {
  3438. blacktools:tell $nick $host $hand $chan $chan1 leave.11 none
  3439. }
  3440. }
  3441. del {
  3442. set file [open $new_dir "r"]
  3443. set w [read -nonewline $file]
  3444. close $file
  3445. set data [split $w "\n"]
  3446. set counter 0
  3447. foreach line $data {
  3448. set the_leave [join [lrange [split $line] 2 end]]
  3449. set channel [lindex [split $line] 0]
  3450. if {[string equal -nocase $channel $chan] && [string match -nocase $leave $the_leave]} {
  3451. set counter [expr $counter + 1]
  3452. }
  3453. }
  3454. for {set j 0} {$j < $counter} {incr j} {
  3455. set file [open $new_dir "r"]
  3456. set w [read -nonewline $file]
  3457. close $file
  3458. set data [split $w "\n"]
  3459. set i [lsearch -glob $data "* $leave"]
  3460. if {$i > -1} {
  3461. set line [lindex $data $i]
  3462. set delete [lreplace $data $i $i]
  3463. set file [open $new_dir "w"]
  3464. puts $file [join $delete "\n"]
  3465. close $file
  3466. }
  3467. }
  3468. set file [open $new_dir "r"]
  3469. set w [read -nonewline $file]
  3470. close $file
  3471. if {$w == ""} {
  3472. set file [open $new_dir "w"]
  3473. close $file
  3474. }
  3475. blacktools:tell $nick $host $hand $chan $chan1 leave.10 $counter
  3476. }
  3477. set {
  3478. set counter -1
  3479. set list_counter 0
  3480. array set leaveset [list]
  3481. set current_place -1
  3482. set last_message ""
  3483. set last_place -1
  3484. if {$number == ""} {
  3485. blacktools:tell $nick $host $hand $chan $chan1 leave.12 none
  3486. return
  3487. }
  3488. set file [open $new_dir "r"]
  3489. set w [read -nonewline $file]
  3490. close $file
  3491. set data [split $w "\n"]
  3492. foreach line $data {
  3493. set counter [expr $counter + 1]
  3494. set channel [lindex [split $line] 0]
  3495. if {[string equal -nocase $channel $chan]} {
  3496. set list_counter [expr $list_counter + 1]
  3497. set leaveset($list_counter) $counter
  3498. }
  3499. }
  3500. foreach place [array names leaveset] {
  3501. if {$place == $number} {
  3502. set current_place $leaveset($place)
  3503. }
  3504. }
  3505. if {$current_place == "-1"} {
  3506. blacktools:tell $nick $host $hand $chan $chan1 leave.13 none
  3507. return
  3508. }
  3509. set current_line [lindex $data $current_place]
  3510. set status [lindex [split $current_line] 1]
  3511. if {$status == "1"} {
  3512. blacktools:tell $nick $host $hand $chan $chan1 leave.14 none
  3513. }
  3514. set current_message [join [lrange [split $current_line] 2 end]]
  3515. set file [open $new_dir "r"]
  3516. set w [read -nonewline $file]
  3517. close $file
  3518. set data [split $w "\n"]
  3519. if {$data == ""} {
  3520. set file [open $new_dir "w"]
  3521. close $file
  3522. }
  3523. set file [open $new_dir "r"]
  3524. set w [read -nonewline $file]
  3525. close $file
  3526. set data [split $w "\n"]
  3527. set counter -1
  3528. foreach line $data {
  3529. set counter [expr $counter + 1]
  3530. set channel [lindex [split $line] 0]
  3531. set message [join [lrange [split $line] 2 end]]
  3532. if {[string equal -nocase $chan $channel]} {
  3533. set status [lindex [split $line] 1]
  3534. if {$status == "1"} {
  3535. set delete [lreplace $data $counter $counter]
  3536. set last_place $counter
  3537. set last_message $message
  3538. set file [open $new_dir "w"]
  3539. puts $file [join $delete "\n"]
  3540. close $file
  3541. }
  3542. }
  3543. }
  3544. set file [open $new_dir "r"]
  3545. set w [read -nonewline $file]
  3546. close $file
  3547. set data [split $w "\n"]
  3548. set insert [linsert $data $last_place "$chan 0 $last_message"]
  3549. set file [open $new_dir w]
  3550. puts $file [join $insert "\n"]
  3551. close $file
  3552. set file [open $new_dir "r"]
  3553. set w [read -nonewline $file]
  3554. close $file
  3555. set data [split $w "\n"]
  3556. set delete [lreplace $data $current_place $current_place]
  3557. set file [open $new_dir "w"]
  3558. puts $file [join $delete "\n"]
  3559. close $file
  3560. set file [open $new_dir "r"]
  3561. set w [read -nonewline $file]
  3562. close $file
  3563. set data [split $w "\n"]
  3564. set insert [linsert $data $current_place "$chan 1 $current_message"]
  3565. set file [open $new_dir w]
  3566. puts $file [join $insert "\n"]
  3567. close $file
  3568. blacktools:tell $nick $host $hand $chan $chan1 leave.15 $number
  3569. }
  3570. }
  3571. }
  3572. proc leavepublic:part {nick host hand chan args} {
  3573. global black username count
  3574. set new_dir "scripts/BlackTools/FILES/$username.leave.txt"
  3575. set current_leave ""
  3576. set number [scan $black(leaveflood) %\[^:\]]
  3577. set time [scan $black(leaveflood) %*\[^:\]:%s]
  3578. if {![validchan $chan]} { return }
  3579. if {[channel get $chan leave]} {
  3580. if {[isbotnick $nick]} { return }
  3581. foreach tmr [utimers] {
  3582. if {[string match "*count(leaveflood:$chan)*" [join [lindex $tmr 1]]]} {
  3583. killutimer [lindex $tmr 2]
  3584. }
  3585. }
  3586. if {[info exists black(leavestopped:$chan)]} {
  3587. return
  3588. }
  3589. if {![info exists count(leaveflood:$chan)]} {
  3590. set count(leaveflood:$chan) 0
  3591. }
  3592. incr count(leaveflood:$chan)
  3593. utimer $time [list unset count(leaveflood:$chan)]
  3594. if {$count(leaveflood:$chan) >= $number} {
  3595. set black(leavestopped:$chan) 1
  3596. utimer 60 [list unset black(leavestopped:$chan)]
  3597. return
  3598. }
  3599. set replace(%nick%) $nick
  3600. set file [open $new_dir "r"]
  3601. set data [read -nonewline $file]
  3602. close $file
  3603. if {$data == ""} { return }
  3604. set lines [split $data "\n"]
  3605. foreach line $lines {
  3606. set channel [lindex [split $line] 0]
  3607. set status [lindex [split $line] 1]
  3608. if {[string equal -nocase $channel $chan] && ($status == "1")} {
  3609. set message [join [lrange [split $line] 2 end]]
  3610. set current_greet $message
  3611. }
  3612. }
  3613. set the_message [string map [array get replace] $current_greet]
  3614. set split_message [split $the_message "~"]
  3615. foreach message $split_message {
  3616. if {$black(howleave) == "1"} {
  3617. puthelp "NOTICE $nick :$message"
  3618. } else { puthelp "PRIVMSG $nick :$message" }
  3619. }
  3620. }
  3621. }
  3622. ################################ Idle ###################################
  3623. proc antidlepublic {nick host hand chan arg} {
  3624. global black
  3625. set char(p) [lindex $black(cmdchar) 0]
  3626. if {[string match -nocase "none" "$char(p)"]} {
  3627. set char(p) ""
  3628. }
  3629. set type1 0
  3630. set chan1 "$chan"
  3631. set why [lindex [split $arg] 0]
  3632. set type [lindex [split $arg] 1]
  3633. set user [lindex [split $arg] 1]
  3634. set host [lindex [split $arg] 2]
  3635. if {[regexp {^[&#]} $why] && [matchattr $hand nm|M $why]} {
  3636. set chan "$why"
  3637. set why [lindex [split $arg] 1]
  3638. set type [lindex [split $arg] 2]
  3639. set user [lindex [split $arg] 2]
  3640. set host [lindex [split $arg] 3]
  3641. }
  3642. antidle:process $why $type $type1 $user $host $nick $hand $chan $chan1
  3643. }
  3644. proc antidle:process {why type type1 user host nick hand chan chan1} {
  3645. global botnick black
  3646. set flag "-|f"
  3647. set char(p) [lindex $black(cmdchar) 0]
  3648. if {[string match -nocase "none" "$char(p)"]} {
  3649. set char(p) ""
  3650. }
  3651. set handle [nick2hand $user]
  3652. if {($why == "") && ($type1 == "0")} {
  3653. blacktools:tell $nick $host $hand $chan $chan1 idle.1 none
  3654. return
  3655. }
  3656. if {($why == "") && ($type1 == "1")} {
  3657. blacktools:tell $nick $host $hand $chan $chan1 idle.3 none
  3658. return
  3659. }
  3660. if {![validchan $chan]} {
  3661. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  3662. return
  3663. }
  3664. if {![onchan $botnick $chan]} {
  3665. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  3666. return
  3667. }
  3668. switch $why {
  3669. on {
  3670. channel set $chan +antidle
  3671. blacktools:tell $nick $host $hand $chan $chan1 idle.7 none
  3672. }
  3673. off {
  3674. channel set $chan -antidle
  3675. blacktools:tell $nick $host $hand $chan $chan1 idle.8 none
  3676. }
  3677. op {
  3678. if {$type == ""} { blacktools:tell $nick $host $hand $chan $chan1 idle.9 none
  3679. return
  3680. }
  3681. if {[string match -nocase $type "on"]} {
  3682. if {[channel get $chan antidle]} { set antidle "on" } else { set antidle "off"}
  3683. if {$antidle == "off"} { blacktools:tell $nick $host $hand $chan $chan1 idle.10 none
  3684. return
  3685. }
  3686. channel set $chan +antididle
  3687. blacktools:tell $nick $host $hand $chan $chan1 idle.11 none
  3688. }
  3689. if {[string match -nocase $type "off"]} {
  3690. if {[channel get $chan antidle]} { set antidle "on" } else { set antidle "off"}
  3691. if {$antidle == "off"} { blacktools:tell $nick $host $hand $chan $chan1 idle.10 none
  3692. return
  3693. }
  3694. channel set $chan -antididle
  3695. blacktools:tell $nick $host $hand $chan $chan1 idle.12 none
  3696. }
  3697. }
  3698. voice {
  3699. if {$type == ""} { blacktools:tell $nick $host $hand $chan $chan1 idle.13 none
  3700. return
  3701. }
  3702. if {[string match -nocase $type "on"]} {
  3703. if {[channel get $chan antidle]} { set antidle "on" } else { set antidle "off"}
  3704. if {$antidle == "off"} { blacktools:tell $nick $host $hand $chan $chan1 idle.10 none
  3705. return
  3706. }
  3707. channel set $chan +antividle
  3708. blacktools:tell $nick $host $hand $chan $chan1 idle.14 none
  3709. }
  3710. if {[string match -nocase $type "off"]} {
  3711. if {[channel get $chan antidle]} { set antidle "on" } else { set antidle "off"}
  3712. if {$antidle == "off"} { blacktools:tell $nick $host $hand $chan $chan1 idle.10 none
  3713. return
  3714. }
  3715. channel set $chan -antividle
  3716. blacktools:tell $nick $host $hand $chan $chan1 idle.15 none
  3717. }
  3718. }
  3719. add {
  3720. if {$user == ""} { blacktools:tell $nick $host $hand $chan $chan1 idle.16 none
  3721. return
  3722. }
  3723. if {[onchan $user $chan]} {
  3724. set getuser [nick2hand $user]
  3725. if {$getuser != "*"} {
  3726. set user $getuser
  3727. }
  3728. }
  3729. if {[validuser $user]} {
  3730. chattr $user $flag $chan
  3731. blacktools:tell $nick $host $hand $chan $chan1 idle.18 $user
  3732. } else {
  3733. set hosts [getchanhost $user $chan]
  3734. set uhost "*!*@[lindex [split $hosts @] 1]"
  3735. adduser $user $uhost
  3736. chattr $user $flag $chan
  3737. blacktools:tell $nick $host $hand $chan $chan1 idle.19 "$user $uhost"
  3738. }
  3739. }
  3740. list {
  3741. set list [userlist "-|f" $chan]
  3742. blacktools:tell $nick $host $hand $chan $chan1 idle.20 "none"
  3743. if {$list == ""} {set list "NONE"}
  3744. blacktools:tell $nick $host $hand $chan $chan1 idle.21 "$list"
  3745. }
  3746. del {
  3747. if {[onchan $user $chan]} {
  3748. set getuser [nick2hand $user]
  3749. if {$getuser != "*"} {
  3750. set user $getuser
  3751. }
  3752. }
  3753. if {![validuser $user]} {
  3754. blacktools:tell $nick $host $hand $chan $chan1 idle.22 "$user"
  3755. return
  3756. }
  3757. if {![matchattr $user "-|f" $chan]} {
  3758. blacktools:tell $nick $host $hand $chan $chan1 idle.23 "$user"
  3759. return
  3760. }
  3761. chattr $user -|-f $chan
  3762. blacktools:tell $nick $host $hand $chan $chan1 idle.24 "$user"
  3763. }
  3764. }
  3765. }
  3766. proc idlewhoispublic {min hour day mon year} {
  3767. global black botnick
  3768. if {([scan $min %d]+([scan $hour %d]*60)) % $black(idleinterval) == 0} {
  3769. if {[info exists black(idle_chans)]} {
  3770. unset black(idle_chans)
  3771. }
  3772. foreach chan [channels] {
  3773. if {[channel get $chan antidle] && [botisop $chan]} {
  3774. lappend black(idle_chans) $chan
  3775. }
  3776. }
  3777. if {[info exists black(idle_chans)]} {
  3778. black:check:idle
  3779. }
  3780. }
  3781. }
  3782. proc black:check:idle {} {
  3783. global black botnick
  3784. foreach chan $black(idle_chans) {
  3785. putlog "\[BlackTools\] Scanning for idle on $chan"
  3786. foreach user [chanlist $chan] {
  3787. set handle [nick2hand $user]
  3788. if {[isop $user $chan] || [isvoice $user $chan]} {
  3789. if {$user != $botnick} {
  3790. putserv "WHOIS $user $user"
  3791. }
  3792. }
  3793. }
  3794. }
  3795. bind raw - 317 idleprocespublic
  3796. }
  3797. proc idleprocespublic {nick int arg} {
  3798. global black
  3799. set nick [string tolower [lindex $arg 1]]
  3800. set handle [nick2hand $nick]
  3801. set idler [string tolower [lindex $arg 2]]
  3802. set minutesidle [expr $idler / 60]
  3803. foreach chan $black(idle_chans) {
  3804. if {[onchan $nick $chan]} {
  3805. set idlevoicetime [channel get $chan idlevoicemax]
  3806. if {$idlevoicetime == "0"} { set idlevoicetime "$black(idlevoicemax)" }
  3807. set idleoptime [channel get $chan idleopmax]
  3808. if {$idleoptime == "0"} { set idleoptime "$black(idleopmax)" }
  3809. if {[channel get $chan antividle]} {
  3810. if {![matchattr $handle "-|gf" $chan]} {
  3811. if {$minutesidle > $idlevoicetime} {
  3812. putquick "MODE $chan -v $nick"
  3813. }
  3814. }
  3815. }
  3816. if {[channel get $chan antididle]} {
  3817. if {![matchattr $handle "-|af" $chan]} {
  3818. if {$minutesidle > $idleoptime} {
  3819. putquick "MODE $chan -o $nick"
  3820. }
  3821. }
  3822. }
  3823. }
  3824. }
  3825. # unbind raw - 317 idleprocespublic
  3826. }
  3827. ##################################Auto User Expire ################################
  3828. proc user:autoexpire {minute hour day month year} {
  3829. global black
  3830. set counter 0
  3831. set max_time [expr 86400 * $black(user_expire_time)]
  3832. foreach user [userlist] {
  3833. set laston [getuser $user laston]
  3834. if {$laston == ""} {
  3835. set laston [getuser $user XTRA created]
  3836. } else {
  3837. set laston [lindex $laston 0]
  3838. }
  3839. set user_time [expr [unixtime] - $laston]
  3840. if {$user_time > $max_time} {
  3841. set counter [expr $counter + 1]
  3842. deluser $user
  3843. }
  3844. }
  3845. putlog "\[BlackTools\] User Auto Expire : Found $counter expired users."
  3846. }
  3847. ######################################### AntiBotIdle #############################
  3848. proc botidlepublic {nick host hand chan arg} {
  3849. global black botnick username
  3850. set sdir "scripts/BlackTools/FILES/$username.status.txt"
  3851. set what [lindex [split $arg] 0]
  3852. set lin 0
  3853. set chan1 "$chan"
  3854. set char(p) [lindex $black(cmdchar) 0]
  3855. if {[string match -nocase "none" "$char(p)"]} {
  3856. set char(p) ""
  3857. }
  3858. if {$what == ""} { blacktools:tell $nick $host $hand $chan $chan1 antibotidle.1 none
  3859. return
  3860. }
  3861. botidle:process $nick $host $hand $chan $chan1 $what
  3862. }
  3863. proc botidle:process {nick host hand chan chan1 what} {
  3864. global botnick black sdir username
  3865. set lin 0
  3866. switch -exact -- [string tolower $what] {
  3867. on {
  3868. set type "antibotidle:module ON"
  3869. foreach tmr [timers] {
  3870. if {[string match "*antibotidle:module*" [join [lindex $tmr 1]]]} {
  3871. blacktools:tell $nick $host $hand $chan $chan1 antibotidle.3 none
  3872. return
  3873. }
  3874. }
  3875. set file [open $sdir "r"]
  3876. set database [read -nonewline $file]
  3877. close $file
  3878. set data [split $database "\n"]
  3879. foreach line $data {
  3880. set lin [expr $lin +1]
  3881. set who [lindex [split $line] 0]
  3882. set stats [lindex [split $line] 1]
  3883. if {[string match -nocase "antibotidle:module" $who]} {
  3884. if {$line != ""} {
  3885. set num [expr $lin - 1]
  3886. set delete [lreplace $data $num $num]
  3887. set files [open $sdir "w"]
  3888. puts $files [join $delete "\n"]
  3889. close $files
  3890. }
  3891. }
  3892. }
  3893. set file [open $sdir "r"]
  3894. set data [read -nonewline $file]
  3895. close $file
  3896. if {$data == ""} {
  3897. set files [open $sdir "w"]
  3898. close $files
  3899. }
  3900. set file [open $sdir "a"]
  3901. puts $file "$type"
  3902. close $file
  3903. blacktools:tell $nick $host $hand $chan $chan1 antibotidle.4 none
  3904. timer $black(noidlemax) antibotidle:module
  3905. set antibotidle:module_running 1
  3906. }
  3907. off {
  3908. blacktools:tell $nick $host $hand $chan $chan1 antibotidle.5 none
  3909. set type "antibotidle:module OFF"
  3910. foreach tmr [timers] {
  3911. if {[string match "*antibotidle:module*" [join [lindex $tmr 1]]]} {
  3912. killtimer [lindex $tmr 2]
  3913. }
  3914. }
  3915. set file [open $sdir "r"]
  3916. set database [read -nonewline $file]
  3917. close $file
  3918. set data [split $database "\n"]
  3919. foreach line $data {
  3920. set lin [expr $lin +1]
  3921. set who [lindex [split $line] 0]
  3922. set stats [lindex [split $line] 1]
  3923. if {[string match -nocase "antibotidle:module" $who]} {
  3924. if {$line != ""} {
  3925. set num [expr $lin - 1]
  3926. set delete [lreplace $data $num $num]
  3927. set files [open $sdir "w"]
  3928. puts $files [join $delete "\n"]
  3929. close $files
  3930. }
  3931. }
  3932. }
  3933. set file [open $sdir "r"]
  3934. set data [read -nonewline $file]
  3935. close $file
  3936. if {$data == ""} {
  3937. set files [open $sdir "w"]
  3938. close $files
  3939. }
  3940. set file [open $sdir "a"]
  3941. puts $file "$type"
  3942. close $file
  3943. if {[info exists antibotidle:module_running]} {
  3944. unset antibotidle:module_running
  3945. }
  3946. }
  3947. }
  3948. }
  3949. proc antibotidle:module {} {
  3950. global black
  3951. putquick "PRIVMSG $black(noobject) :"
  3952. timer $black(noidlemax) antibotidle:module
  3953. return
  3954. }
  3955. ################################## next #######################################
  3956. proc black:next:join {nick host hand chan} {
  3957. global black
  3958. set counter 0
  3959. set time [unixtime]
  3960. set handle [nick2hand $nick]
  3961. set lang [channel get $chan lang]
  3962. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  3963. if {[channel get $chan next]} {
  3964. if {[matchattr $handle $black(exceptflags) $chan]} {
  3965. putserv "MODE $chan +v $nick"
  3966. return
  3967. }
  3968. if {[isbotnick $nick]} {
  3969. black:next:joincheck $chan
  3970. return
  3971. }
  3972. if {[info exists black(next:$chan:list)]} {
  3973. if {[lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]] == -1} {
  3974. set black(next:$chan:list) [linsert $black(next:$chan:list) end $nick]
  3975. set black(next:$chan:$nick:time) $time
  3976. }
  3977. } else {
  3978. set black(next:$chan:list) $nick
  3979. set black(next:$chan:$nick:time) $time
  3980. }
  3981. foreach name $black(next:$chan:list) {
  3982. set get_hand [nick2hand $name]
  3983. if {$name != ""} {
  3984. if {![matchattr $get_hand $black(exceptflags) $chan]} {
  3985. if {[onchan $name $chan]} {
  3986. set counter [expr $counter +1]
  3987. }
  3988. }
  3989. }
  3990. }
  3991. set backchan [channel get $chan next-backchan]
  3992. set replace(%counter%) $counter
  3993. set replace(%nick%) $nick
  3994. set replace(%chan%) $chan
  3995. if {($backchan != "") && [validchan $backchan]} {
  3996. set message [string map [array get replace] $black(say.$lang.next.6)]
  3997. puthelp "NOTICE $backchan :$message"
  3998. }
  3999. set message [string map [array get replace] $black(say.$lang.next.1)]
  4000. puthelp "NOTICE $nick :$message"
  4001. }
  4002. }
  4003. proc black:next:clear:all {nick chan} {
  4004. global black
  4005. if {[lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]] > -1} {
  4006. set position [lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]]
  4007. set black(next:$chan:list) [lreplace $black(next:$chan:list) $position $position]
  4008. }
  4009. if {[info exists black(next:$chan:$nick:time)]} {
  4010. unset black(next:$chan:$nick:time)
  4011. }
  4012. if {[info exists black(next:$chan:list)]} {
  4013. if {$black(next:$chan:list) == ""} {
  4014. unset black(next:$chan:list)
  4015. }
  4016. }
  4017. }
  4018. proc black:next:clear {nick chan} {
  4019. global black
  4020. if {[lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]] > -1} {
  4021. set position [lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]]
  4022. set black(next:$chan:list) [lreplace $black(next:$chan:list) $position $position]
  4023. }
  4024. if {[info exists black(next:$chan:$nick:time)]} {
  4025. unset black(next:$chan:$nick:time)
  4026. }
  4027. }
  4028. proc black:next:joincheck {chan} {
  4029. global black
  4030. if {[info exists black(next:$chan:list)]} {
  4031. foreach user [join $black(next:$chan:list)] {
  4032. if {(![onchan $user $chan]) || [isvoice $user $chan] || [isop $user $chan]} {
  4033. black:next:clear:all $user $chan
  4034. }
  4035. }
  4036. }
  4037. }
  4038. proc black:next:part {nick host hand chan arg} {
  4039. global black
  4040. if {![validchan $chan]} { return }
  4041. if {[channel get $chan next]} {
  4042. if {![info exists black(next:$chan:list)]} {
  4043. return
  4044. }
  4045. black:next:clear:all $nick $chan
  4046. }
  4047. }
  4048. proc black:next:sign {nick host hand chan arg} {
  4049. global black
  4050. if {[channel get $chan next]} {
  4051. if {![info exists black(next:$chan:list)]} {
  4052. return
  4053. }
  4054. black:next:clear:all $nick $chan
  4055. }
  4056. }
  4057. proc black:next:split {nick host hand chan args} {
  4058. global black
  4059. if {[channel get $chan next]} {
  4060. if {![info exists black(next:$chan:list)]} {
  4061. return
  4062. }
  4063. black:next:clear:all $nick $chan
  4064. }
  4065. }
  4066. proc black:next:kick {nick host hand chan kicked arg} {
  4067. global black
  4068. if {[channel get $chan next]} {
  4069. if {![info exists black(next:$chan:list)]} {
  4070. return
  4071. }
  4072. black:next:clear:all $kicked $chan
  4073. }
  4074. }
  4075. proc black:next:mode {nick host hand chan moded mod_nick} {
  4076. global black
  4077. if {[channel get $chan next]} {
  4078. if {($moded == "+v") || ($moded == "+o")} {
  4079. if {![info exists black(next:$chan:list)]} {
  4080. return
  4081. }
  4082. black:next:clear:all $mod_nick $chan
  4083. }
  4084. }
  4085. }
  4086. proc black:next:chnick {nick host hand chan newnick} {
  4087. global black
  4088. if {[channel get $chan next]} {
  4089. if {[info exists black(next:$chan:served)]} {
  4090. if {[lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $nick]] > -1} {
  4091. set position [lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $nick]]
  4092. set black(next:$chan:served) [lreplace $black(next:$chan:served) $position $position]
  4093. set black(next:$chan:served) [linsert $black(next:$chan:served) $position $newnick]
  4094. }
  4095. }
  4096. if {[info exists black(next:$chan:list)]} {
  4097. if {[lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]] > -1} {
  4098. set position [lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $nick]]
  4099. set black(next:$chan:list) [lreplace $black(next:$chan:list) $position $position]
  4100. set black(next:$chan:list) [linsert $black(next:$chan:list) $position $newnick]
  4101. set black(next:$chan:$newnick:time) $black(next:$chan:$nick:time)
  4102. }
  4103. }
  4104. }
  4105. }
  4106. proc nextpublic:cmd {nick host hand chan arg} {
  4107. global black
  4108. set option [lindex [split $arg] 0]
  4109. set chan1 $chan
  4110. foreach c [channels] {
  4111. set backchan [channel get $c next-backchan]
  4112. if {[string match -nocase $chan $backchan] && [channel get $c next]} {
  4113. set chan "$c"
  4114. }
  4115. }
  4116. nextpublic:process $nick $host $hand $chan $chan1 $option
  4117. }
  4118. proc nextpublic:process {nick host hand chan chan1 option} {
  4119. global black
  4120. if {![channel get $chan next]} {
  4121. return
  4122. }
  4123. if {$option != ""} {
  4124. switch -exact -- [string tolower $option] {
  4125. list {
  4126. set counter 0
  4127. blacktools:tell $nick $host $hand $chan $chan1 next.7 none
  4128. if {![info exists black(next:$chan:list)]} {
  4129. blacktools:tell $nick $host $hand $chan $chan1 next.8 none
  4130. return
  4131. }
  4132. if {$black(next:$chan:list) == ""} {
  4133. blacktools:tell $nick $host $hand $chan $chan1 next.8 none
  4134. return
  4135. }
  4136. foreach name $black(next:$chan:list) {
  4137. if {$name != ""} {
  4138. set get_hand [nick2hand $name]
  4139. if {![matchattr $get_hand $black(exceptflags) $chan]} {
  4140. set counter [expr $counter + 1]
  4141. lappend field_name "$counter. $name "
  4142. }
  4143. }
  4144. }
  4145. if {![info exists field_name]} {
  4146. blacktools:tell $nick $host $hand $chan $chan1 next.8 none
  4147. return
  4148. }
  4149. blacktools:tell $nick $host $hand $chan $chan1 next.9 [join $field_name]
  4150. }
  4151. }
  4152. return
  4153. }
  4154. if {![info exists black(next:$chan:list)]} {
  4155. blacktools:tell $nick $host $hand $chan $chan1 next.10 none
  4156. return
  4157. }
  4158. if {[llength black(next:$chan:list)] < 0} {
  4159. blacktools:tell $nick $host $hand $chan $chan1 next.10 none
  4160. return
  4161. }
  4162. set current_nick [lindex $black(next:$chan:list) 0]
  4163. set backchan [channel get $chan next-backchan]
  4164. set lang [channel get $chan lang]
  4165. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  4166. set replace(%current%) $current_nick
  4167. set replace(%nick%) $nick
  4168. set replace(%hand%) $hand
  4169. set message [string map [array get replace] $black(say.$lang.next.11)]
  4170. if {($backchan != "") && [validchan $backchan]} {
  4171. puthelp "PRIVMSG $backchan :$message"
  4172. }
  4173. set time [duration [expr [unixtime] - $black(next:$chan:$current_nick:time)]]
  4174. set message_1 [string map [array get replace] $black(say.$lang.next.2)]
  4175. puthelp "NOTICE $current_nick :$message_1"
  4176. blacktools:tell $nick $host $hand $chan $chan1 next.3 "$current_nick $time"
  4177. black:next:clear $current_nick $chan
  4178. putserv "MODE $chan +v $current_nick"
  4179. if {[info exists black(next:$chan:served)]} {
  4180. if {[lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $current_nick]] == -1} {
  4181. set black(next:$chan:served) [linsert $black(next:$chan:served) end $current_nick]
  4182. }
  4183. } else {
  4184. set black(next:$chan:served) $current_nick
  4185. }
  4186. }
  4187. proc helpedpublic:cmd {nick host hand chan arg} {
  4188. global black
  4189. set user [lindex [split $arg] 0]
  4190. set chan1 $chan
  4191. foreach c [channels] {
  4192. set backchan [channel get $c next-backchan]
  4193. if {[string match -nocase $chan $backchan] && [channel get $c next]} {
  4194. set chan "$c"
  4195. }
  4196. }
  4197. helpedpublic:process $nick $host $hand $chan $chan1 $user
  4198. }
  4199. proc helpedpublic:process {nick host hand chan chan1 user} {
  4200. global black
  4201. set handle [nick2hand $user]
  4202. if {![channel get $chan next]} {
  4203. return
  4204. }
  4205. if {[isbotnick $user]} { return }
  4206. if {[matchattr $handle $black(exceptflags) $chan]} {
  4207. return
  4208. }
  4209. if {$user == ""} {
  4210. blacktools:tell $nick $host $hand $chan $chan1 next.12 none
  4211. return
  4212. }
  4213. if {![onchan $user $chan]} {
  4214. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $user
  4215. return
  4216. }
  4217. if {[info exists black(next:$chan:list)]} {
  4218. if {([lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $user]] > -1)} {
  4219. blacktools:tell $nick $host $hand $chan $chan1 next.13 $user
  4220. return
  4221. }
  4222. }
  4223. if {[info exists black(next:$chan:served)]} {
  4224. if {[lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $user]] > -1} {
  4225. set entry_find 1
  4226. set position [lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $user]]
  4227. set black(next:$chan:served) [lreplace $black(next:$chan:served) $position $position]
  4228. }
  4229. } else {
  4230. blacktools:tell $nick $host $hand $chan $chan1 next.14 $user
  4231. return
  4232. }
  4233. if {![info exists entry_find]} {
  4234. blacktools:tell $nick $host $hand $chan $chan1 next.14 $user
  4235. return
  4236. }
  4237. set backchan [channel get $chan next-backchan]
  4238. set lang [channel get $chan lang]
  4239. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  4240. set replace(%current%) $user
  4241. set replace(%nick%) $nick
  4242. set replace(%hand%) $hand
  4243. set replace(%chan%) $chan
  4244. set message [string map [array get replace] $black(say.$lang.next.15)]
  4245. if {($backchan != "") && [validchan $backchan]} {
  4246. puthelp "PRIVMSG $backchan :$message"
  4247. }
  4248. if {[isvoice $user $chan]} {
  4249. putserv "MODE $chan -v $user"
  4250. }
  4251. set message_1 [string map [array get replace] $black(say.$lang.next.4)]
  4252. puthelp "NOTICE $user :$message_1"
  4253. }
  4254. proc noidlepublic:cmd {nick host hand chan arg} {
  4255. global black
  4256. set user [lindex [split $arg] 0]
  4257. set chan1 $chan
  4258. foreach c [channels] {
  4259. set backchan [channel get $c next-backchan]
  4260. if {[string match -nocase $chan $backchan] && [channel get $c next]} {
  4261. set chan "$c"
  4262. }
  4263. }
  4264. noidlepublic:process $nick $host $hand $chan $chan1 $user
  4265. }
  4266. proc noidlepublic:process {nick host hand chan chan1 user} {
  4267. global black
  4268. set handle [nick2hand $user]
  4269. if {![channel get $chan next]} {
  4270. return
  4271. }
  4272. if {[isbotnick $user]} { return }
  4273. if {[matchattr $handle $black(exceptflags) $chan]} {
  4274. return
  4275. }
  4276. if {$user == ""} {
  4277. blacktools:tell $nick $host $hand $chan $chan1 next.16 none
  4278. return
  4279. }
  4280. if {![onchan $user $chan]} {
  4281. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $user
  4282. return
  4283. }
  4284. if {[info exists black(next:$chan:list)]} {
  4285. if {([lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $user]] > -1)} {
  4286. blacktools:tell $nick $host $hand $chan $chan1 next.13 $user
  4287. return
  4288. }
  4289. }
  4290. if {([lsearch -exact [string tolower $black(next:$chan:served)] [string tolower $user]] > -1) || [info exists black(next:$chan:$nick:served)]} {
  4291. blacktools:tell $nick $host $hand $chan $chan1 next.17 $user
  4292. return
  4293. }
  4294. set backchan [channel get $chan next-backchan]
  4295. set lang [channel get $chan lang]
  4296. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  4297. if {[channel get $chan next-noidlereason] == ""} {
  4298. set replace(%chan%) $chan
  4299. set message [string map [array get replace] $black(say.$lang.next.5)]
  4300. set reason $message
  4301. } else { set reason [channel get $chan next-noidlereason] }
  4302. if {[channel get $chan next-bantime] == "0"} {
  4303. set time $black(nextbantime)
  4304. } else { set time [channel get $chan next-bantime] }
  4305. set banmask *!*@[lindex [split [getchanhost $user $chan] "@"] 1]
  4306. newchanban $chan $banmask "NOIDLE" $reason $time
  4307. }
  4308. proc skippublic:cmd {nick host hand chan arg} {
  4309. global black
  4310. set user [lindex [split $arg] 0]
  4311. set chan1 $chan
  4312. foreach c [channels] {
  4313. set backchan [channel get $c next-backchan]
  4314. if {[string match -nocase $chan $backchan] && [channel get $c next]} {
  4315. set chan "$c"
  4316. }
  4317. }
  4318. skippublic:process $nick $host $hand $chan $chan1 $user
  4319. }
  4320. proc skippublic:process {nick host hand chan chan1 user} {
  4321. global black
  4322. if {![channel get $chan next]} {
  4323. return
  4324. }
  4325. if {$user == ""} {
  4326. blacktools:tell $nick $host $hand $chan $chan1 next.18 none
  4327. return
  4328. }
  4329. if {![onchan $user $chan]} {
  4330. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $user
  4331. return
  4332. }
  4333. if {[info exists black(next:$chan:list)]} {
  4334. if {[lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $user]] > -1} {
  4335. set position [lsearch -exact [string tolower $black(next:$chan:list)] [string tolower $user]]
  4336. } else {
  4337. blacktools:tell $nick $host $hand $chan $chan1 next.14 $user
  4338. }
  4339. } else {
  4340. blacktools:tell $nick $host $hand $chan $chan1 next.10 none
  4341. return
  4342. }
  4343. set black(next:$chan:list) [lreplace $black(next:$chan:list) $position $position]
  4344. set black(next:$chan:list) [linsert $black(next:$chan:list) end $user]
  4345. blacktools:tell $nick $host $hand $chan $chan1 next.19 $user
  4346. }
  4347. proc black:next:checklist {min hour day mon year} {
  4348. global black
  4349. if {([scan $min %d]+([scan $hour %d]*60)) % 5 == 0} {
  4350. foreach chan [channels] {
  4351. if {[channel get $chan next]} {
  4352. black:next:joincheck $chan
  4353. }
  4354. }
  4355. }
  4356. }
  4357. ############################## login check ##############################
  4358. proc black:login:yes {nick host hand text {dest ""}} {
  4359. global black
  4360. if {$nick == "X"} {
  4361. if {[info exists black(logged)]} { return }
  4362. set black(logged) 1
  4363. putlog "\[BlackTools\] Login succeded"
  4364. }
  4365. }
  4366. proc black:login:no {nick host hand text {dest ""}} {
  4367. global black
  4368. if {$nick == "X"} {
  4369. set black(notlogged) 1
  4370. putlog "\[BlackTools\] Login unsuccesful"
  4371. }
  4372. }
  4373. proc timer:login:check {min hour day mon year} {
  4374. global black
  4375. if {[info exists black(logged)]} { return }
  4376. if {[info exists black(notlogged)]} { return }
  4377. if {![info exists black(logged)] && ![info exists black(notlogged)] } {
  4378. loginpublic my
  4379. }
  4380. }
  4381. proc add:home:chan {chan} {
  4382. global black
  4383. addchan:stats $chan "HOMECHAN" "NONE"
  4384. channel add $chan
  4385. }