BT.Core.tcl 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479
  1. ###########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. ###########################################################################
  5. ############################ CORE TCL #################################
  6. ###########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. ###########################################################################
  16. ########################## Default protection flags #######################
  17. set black(exceptflags) "nmo|HAagMOVSo"
  18. set black(accessflags) "nmo|MAO"
  19. set black(localflags) "-|MAOV"
  20. set black(glflags) "nmo"
  21. set black(tclconfig) "$black(backdir)/$black(tclname)"
  22. set black(tempdir) "$black(backdir)/BlackTools/temp"
  23. set black(banflag) "B"
  24. set black(current_modif) "1615556948"
  25. set black(current_size) "75"
  26. ############################### Information files ############################
  27. set black(files_file) "$black(dirname)/BlackTools/FILES"
  28. if {![file exists $black(files_file)]} {
  29. file mkdir $black(files_file)
  30. }
  31. if {![file exists $black(backdir)]} {
  32. file mkdir $black(backdir)
  33. }
  34. set black(files_file) "$black(backdir)/BlackTools/FILES"
  35. set black(s_file) "$black(backdir)/BlackTools/FILES/$username.suspend.txt"
  36. set black(status_file) "$black(backdir)/BlackTools/FILES/$username.status.txt"
  37. set black(seen_file) "$black(backdir)/BlackTools/FILES/$username.seen_db.txt"
  38. set black(uptime_file) "$black(backdir)/BlackTools/FILES/$username.uptime.txt"
  39. set black(bans_file) "$black(backdir)/BlackTools/FILES/$username.bans.txt"
  40. set black(join_file) "$black(backdir)/BlackTools/FILES/$username.othermodule.txt"
  41. set black(extra_file) "$black(backdir)/BlackTools/FILES/$username.flags.txt"
  42. set black(add_file) "$black(backdir)/BlackTools/FILES/$username.extra.txt"
  43. set black(quote_file) "$black(backdir)/BlackTools/FILES/$username.quote.txt"
  44. set black(notes_file) "$black(backdir)/BlackTools/FILES/$username.notes.txt"
  45. set black(alias_file) "$black(backdir)/BlackTools/FILES/$username.aliases.txt"
  46. set black(temp_banner) "$black(backdir)/BlackTools/temp/banner"
  47. set black(temp_motd) "$black(backdir)/BlackTools/temp/motd"
  48. set black(files) "$black(s_file) $black(status_file) $black(seen_file) $black(uptime_file) $black(bans_file) $black(join_file) $black(extra_file) $black(add_file) $black(quote_file) $black(notes_file) $black(alias_file)"
  49. if {[file isdirectory "text"]} {
  50. if {[file exists "text/motd"] && [file exists "text/banner"]} {
  51. if {[file exists $black(temp_banner)] && [file exists $black(temp_motd)]} {
  52. file rename -force $black(temp_banner) "text/banner"
  53. file rename -force $black(temp_motd) "text/motd"
  54. file delete -force $black(temp_banner)
  55. file delete -force $black(temp_motd)
  56. }
  57. }
  58. }
  59. foreach f $black(files) {
  60. if {![file exists $f]} {
  61. set file [open $f w]
  62. close $file
  63. }
  64. }
  65. ########################### mychar ############################
  66. proc blacktools:mychar {char hand} {
  67. global black
  68. set getchar [getuser $hand XTRA MYCHAR]
  69. if {[lsearch -exact $black(cmdchar) $char] < 0} {
  70. if {[string equal -nocase $getchar "none"]} {
  71. return 1
  72. }
  73. }
  74. if {($getchar == "") && ([lsearch -exact $black(cmdchar) $char] > 0)} {
  75. return 2
  76. }
  77. if {$getchar != ""} {
  78. if {[string equal -nocase $char $getchar]} {
  79. return 1
  80. }
  81. return 0
  82. }
  83. if {[lsearch -exact $black(cmdchar) $char] < 0} {
  84. return 0
  85. }
  86. }
  87. ########################### define colors #####################
  88. proc black:color {num hand text} {
  89. global black
  90. if {[validuser $hand]} {
  91. set getcolor [string tolower [getuser $hand XTRA OUTPUT_COLORS]]
  92. } else {
  93. set getcolor ""
  94. }
  95. if {$getcolor == ""} { set getcolor "[string tolower $black(default_colors)]" }
  96. set color1 [lindex $getcolor 0]
  97. set color2 [lindex $getcolor 1]
  98. set color3 [lindex $getcolor 2]
  99. set color4 [lindex $getcolor 3]
  100. set show_text ""
  101. foreach txt [split $text] {
  102. switch $num {
  103. 1 {
  104. lappend show_text [blacktools:getcolor $color2 $txt]
  105. }
  106. 2 {
  107. lappend show_text [blacktools:getcolor $color1 $txt]
  108. }
  109. 5 {
  110. lappend show_text [blacktools:getcolor $color3 $txt]
  111. }
  112. 4 {
  113. lappend show_text [blacktools:getcolor $color4 $txt]
  114. }
  115. 6 {
  116. if {[string match "<*>" $txt]} {
  117. lappend show_text [blacktools:getcolor $color4 $txt]
  118. } else {
  119. lappend show_text $txt
  120. }
  121. }
  122. }
  123. }
  124. return $show_text
  125. }
  126. proc blacktools:getcolor {color text} {
  127. global black
  128. if {![info exists black(color_inc)]} {
  129. set black(color_inc) 0
  130. }
  131. switch $color {
  132. black {
  133. return "\00301$text\003"
  134. }
  135. bold {
  136. return "\002$text\002"
  137. }
  138. red {
  139. return "\00304$text\003"
  140. }
  141. blue {
  142. return "\00312$text\003"
  143. }
  144. green {
  145. return "\00303$text\003"
  146. }
  147. yellow {
  148. return "\00308$text\003"
  149. }
  150. orange {
  151. return "\00307$text\003"
  152. }
  153. cyan {
  154. return "\00310$text\003"
  155. }
  156. grey {
  157. return "\00314$text\003"
  158. }
  159. brown {
  160. return "\00305$text\003"
  161. }
  162. purple {
  163. return "\00306$text\003"
  164. }
  165. pink {
  166. return "\00313$text\003"
  167. }
  168. underline {
  169. return "\037$text\037"
  170. }
  171. }
  172. return $text
  173. }
  174. proc black:color:set {hand arg} {
  175. global black
  176. set text ""
  177. if {[validuser $hand]} {
  178. set getcolor [string tolower [getuser $hand XTRA OUTPUT_COLORS]]
  179. } else {
  180. set getcolor ""
  181. }
  182. if {$getcolor == ""} { set getcolor "[string tolower $black(default_colors)]" }
  183. set color1 [lindex $getcolor 0]
  184. set color2 [lindex $getcolor 1]
  185. set color3 [lindex $getcolor 2]
  186. set color4 [lindex $getcolor 3]
  187. foreach txt [split $arg] {
  188. if {[string match "<*>" $txt]} {
  189. lappend text [blacktools:getcolor $color4 $txt]
  190. } elseif {[string match *%chan%* $txt] || [string match *\001* $txt]} {
  191. set rpc [string map {"\001" ""} $txt]
  192. lappend text [blacktools:getcolor $color2 $rpc]
  193. } elseif {[string match *\002* $txt]} {
  194. set rpc [string map {"\002" ""} $txt]
  195. lappend text [blacktools:getcolor $color1 $rpc]
  196. } elseif {[string match *\005* $txt]} {
  197. set rpc [string map {"\005" ""} $txt]
  198. lappend text [blacktools:getcolor $color3 $rpc]
  199. } elseif {[string match *\004* $txt]} {
  200. set rpc [string map {"\004" ""} $txt]
  201. lappend text [blacktools:getcolor $color4 $rpc]
  202. } else {
  203. lappend text $txt
  204. }
  205. }
  206. return [join $text]
  207. }
  208. ########################### Extra Settings ####################
  209. set black(extra_str) {
  210. antipub-reason badhost-reason antinotice-reason antictcp-reason antibadword-reason
  211. antilongtext-reason antibadquitpart-reason antijoinflood-reason
  212. antispam-reason antispam-message antirepeat-reason anticolor-reason antibold-reason
  213. antiunderline-reason anticaps-reason nickflood-reason badrealname-reason badnick-reason badident-reason
  214. antichanflood-reason private-reason clonescan-reason dr-reason vr-reason n-reason expirebans
  215. b-reason id-reason mb-reason w-reason w-message spam-reason bw-reason bot-reason gag-reason stick-reason troll-reason
  216. k-reason black-reason next-reason antipub-bantime badhost-bantime antinotice-bantime antictcp-bantime
  217. antibadword-bantime antilongtext-bantime antibadquitpart-bantime antijoinflood-bantime antijoinflood-userset
  218. antispam-bantime antirepeat-bantime anticolor-bantime antibold-bantime antiunderline-bantime
  219. anticaps-bantime badrealname-bantime badnick-bantime badident-bantime antichanflood-bantime repetitivechars-bantime
  220. joinflood chanflood private-bantime antilongtextmax antirepeat-setting idlevoicemax clonescan-maxclone
  221. idleopmax idlehalfopmax kickcount xbantime xbanlevel limit-default nickflood-bantime clonescan-bantime backchan
  222. dr-bantime vr-bantime n-bantime b-bantime id-bantime spam-bantime bw-bantime mb-bantime badnick-bmethod badnick-banwait
  223. bot-bantime gag-bantime b-bantime stick-bantime d-bantime badchan-bantime badchan-bmethod badchan-reason
  224. joincount jointime lang next-bantime greet-method leave-method url antipub-warn antinotice-warn
  225. antictcp-warn antibadword-warn antilongtext-warn antirepeat-warn anticolor-warn repetitivechars-warn
  226. antibold-warn antiunderline-warn anticaps-warn antichanflood-warn nickflood-warn nickflood-repeat
  227. antipub-banmethod antinotice-banmethod antictcp-banmethod antibadword-banmethod
  228. antilongtext-banmethod antirepeat-banmethod anticolor-banmethod antibold-banmethod repetitivechars-banmethod
  229. antiunderline-banmethod anticaps-banmethod nickflood-banmethod antichanflood-banmethod banmethod
  230. antipub-banmask badhost-banmask antinotice-banmask antictcp-banmask antibadword-banmask
  231. antilongtext-banmask antibadquitpart-banmask n-banmask inviteban-banmask antijoinflood-banmask
  232. antispam-banmask antispam-banmask antirepeat-banmask anticolor-banmask antibold-banmask
  233. antiunderline-banmask anticaps-banmask nickflood-banmask badrealname-banmask badnick-banmask repetitivechars-banmask
  234. antichanflood-banmask private-banmask dr-banmask vr-banmask stick-banmask badident-banmask
  235. b-banmask id-banmask spam-banmask bw-banmask bot-banmask gag-banmask black-banmask next-banmask
  236. voiceonmsg-linenum voiceonmsg-idletime inviteban-reason repetitivechars-reason inviteban-bantime badchan-banwait
  237. general-bantime general-banmask badchan-scantime clonescan-scantime antispam-scantime idle-scantime anunt-showtime
  238. quote-showtime voiceme-showtime quitpartmsgflood-char repetitivechars-char noproxy-reason noproxy-bantime noproxy-banmask
  239. }
  240. set black(extra_flag) {
  241. antipub antinotice antictcp antilongtext antibadword antispam spamjoinmessage antirepeat
  242. anticolor antibold antiunderline anticaps badrealname badnick badident repetitivechars
  243. antijoinflood antichanflood xtools antibadchan anunt limit clonescan seen autoop showbadchan showtroll
  244. autovoice leave topwords dontop dontdeop private silent quote note reportnick invisible forward
  245. showhandle showid showcount showtime showurl next voiceonmsg autotopic greet xonly nologged settingsaved
  246. idleop idlehalfop idlevoice vprotect oprotect hoprotect badquitpart quitpartcolor quitpartmsgflood badhost nickflood seenreply
  247. accessonly voiceme onlyonmode securemode strictsecured nextshortcmd inviteban quoteofday chanlink noproxy
  248. }
  249. set black(validcmds) "alias exempt login anunt link note q enable disable securemode cp troll badhost antispam badrealname badquitpart badident badnick badword unset greet leave topic vr dr n id spam bw mb black bl b stick ub sb banlist r man auto antipub private tcl h ignore idle version stats chat seen limit bt badchan us s info channels userlist chuser delhost addhost del delacc add unsuspend suspend delchan addchan die jump save restart rehash update nick msg omsg set mode cycle broadcast act say v ho o uptime status t k w ungag gag show clonescan topwords myset timer i badword next helped noidle skip"
  250. ########################## BackChan ############################
  251. proc blacktools:backchan:verify {nick host hand chan} {
  252. global black botnick
  253. set isbackchan ""
  254. if {![botisop $chan]} {
  255. return
  256. }
  257. foreach c [channels] {
  258. set backchan [join [setting:get $c backchan]]
  259. if {[string equal -nocase $backchan $chan]} {
  260. set isbackchan $c
  261. }
  262. }
  263. set getlang [string tolower [setting:get $chan lang]]
  264. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  265. if {$isbackchan != ""} {
  266. set gethost "$nick!$host"
  267. foreach b [blacktools:banlist:ban $isbackchan] {
  268. set cidr 0
  269. set read_host [lindex [split $b] 3]
  270. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  271. if {[regexp {[/]} $real_read_host]} {
  272. set read_ip [lindex [split $real_read_host @] 1]
  273. set theip [lindex [split $gethost @] 1]
  274. set cidr_ip [ipcidr $read_ip $theip]
  275. if {$cidr_ip == "1"} {
  276. set read_rest_ip [lindex [split $gethost @] 0]
  277. set read_theip [lindex [split $real_read_host @] 0]
  278. if {[string match -nocase $read_rest_ip $read_theip] || [string match -nocase $read_theip $read_rest_ip]} {
  279. set cidr 1
  280. }
  281. }
  282. }
  283. if {[string match -nocase $real_read_host $gethost] || [string match -nocase $gethost $real_read_host] || $cidr == "1"} {
  284. set replace(%msg.1%) $gethost
  285. set replace(%chan%) $isbackchan
  286. set replace(%msg.2%) $read_host
  287. set text [black:color:set $botnick $black(say.$getlang.backchan.1)]
  288. putserv "NOTICE @$chan :[string map [array get replace] $text]"
  289. }
  290. }
  291. }
  292. }
  293. ########################## AutoInvite ##########################
  294. proc autoinvite:kick {nick host hand chan kicked reason} {
  295. global black
  296. set handle [nick2hand $kicked]
  297. if {[matchattr $handle $black(exceptflags) $chan]} {
  298. set getinvite [string tolower [getuser $handle XTRA AUTOINVITE]]
  299. if {($getinvite == "") || ($getinvite == "0")} { return } else {
  300. putserv "INVITE $kicked $chan"
  301. }
  302. }
  303. }
  304. ############################# Flood Protection ############################
  305. proc msg:mass:unsilence {} {
  306. global black
  307. killignore *!*@*
  308. blacktools:tell:dcc antiflood.4 none
  309. }
  310. proc msg:flood:protection {nick host hand arg} {
  311. global black botnick
  312. set user [nick2hand $nick]
  313. set chan1 $nick
  314. set number [scan $black(msg:flood) %\[^:\]]
  315. set timer [scan $black(msg:flood) %*\[^:\]:%s]
  316. set mass_number [scan $black(mass:msg:flood) %\[^:\]]
  317. set mass_timer [scan $black(mass:msg:flood) %*\[^:\]:%s]
  318. if {[matchattr $hand n]} {
  319. return
  320. }
  321. foreach tmr [utimers] {
  322. if {[string match "*black(antiflood:$host:prot)*" [join [lindex $tmr 1]]]} {
  323. killutimer [lindex $tmr 2]
  324. }
  325. }
  326. foreach tmr [utimers] {
  327. if {[string match "*black(antiflood:prot)*" [join [lindex $tmr 1]]]} {
  328. killutimer [lindex $tmr 2]
  329. }
  330. }
  331. if {![info exists black(antiflood:$host:prot)]} {
  332. set black(antiflood:$host:prot) 0
  333. }
  334. if {![info exists black(antiflood:prot)]} {
  335. set black(antiflood:prot) 0
  336. }
  337. set black(antiflood:$host:prot) [expr $black(antiflood:$host:prot) + 1]
  338. set black(antiflood:prot) [expr $black(antiflood:prot) + 1]
  339. utimer $timer [list unset black(antiflood:$host:prot)]
  340. utimer $mass_timer [list unset black(antiflood:prot)]
  341. if {$black(antiflood:prot) >= $mass_number} {
  342. newignore "*!*@*" $botnick "MASS FLOOD DETECTED"
  343. blacktools:tell:dcc antiflood.3 "\002\[BT\]\002 MASS MSG FLOOD PROTECTION"
  344. utimer $black(mass:msg:silence_time) [list msg:mass:unsilence]
  345. return
  346. }
  347. if {$black(antiflood:$host:prot) >= $number} {
  348. if {[validuser $user]} {
  349. newignore "*!$host" $botnick "\002\[BT\]\002 MSG FLOOD PROTECTION" $black(msg:flood:ignore_access)
  350. blacktools:tell $nick "PRIV" $hand "" $chan1 antiflood.1 "$black(msg:flood:ignore_access)"
  351. blacktools:tell:dcc antiflood.2 "$host \002\[BT\]\002 MSG FLOOD PROTECTION"
  352. } else {
  353. newignore "*!$host" $botnick "\002\[BT\]\002 MSG FLOOD PROTECTION" $black(msg:flood:ignore_others)
  354. blacktools:tell:dcc antiflood.2 "$host \002\[BT\]\002 MSG FLOOD PROTECTION"
  355. }
  356. }
  357. }
  358. proc notc:flood:protection {nick host hand text dest} {
  359. global black botnick
  360. set number [scan $black(notice:flood) %\[^:\]]
  361. set timer [scan $black(notice:flood) %*\[^:\]:%s]
  362. if {$nick == $black(chanserv) || [string equal -nocase $nick "NICKSERV"]} {
  363. return
  364. }
  365. if {![isbotnick $dest]} {
  366. return
  367. }
  368. foreach tmr [utimers] {
  369. if {[string match "*black(antiflood:$host:notc)*" [join [lindex $tmr 1]]]} {
  370. killutimer [lindex $tmr 2]
  371. }
  372. }
  373. if {![info exists black(antiflood:$host:notc)]} {
  374. set black(antiflood:$host:notc) 0
  375. }
  376. set black(antiflood:$host:notc) [expr $black(antiflood:$host:notc) + 1]
  377. utimer $timer [list unset black(antiflood:$host:notc)]
  378. if {$black(antiflood:$host:notc) >= $number} {
  379. newignore "*!$host" $botnick "\002\[BT\]\002 NOTICE FLOOD PROTECTION" $black(notice:flood:notc_time)
  380. blacktools:tell:dcc antiflood.2 "$host \002\[BT\]\002 NOTICE FLOOD PROTECTION"
  381. }
  382. }
  383. ##################################### Time return ################################
  384. proc time_return_minute {the_time} {
  385. global black
  386. set minutes ""
  387. if {[regexp {^[0-9]} $the_time] && ![regexp {[A-Za-z]} $the_time]} {
  388. return $the_time
  389. }
  390. if {![regexp {^[0-9](.*)[A-Za-z]} $the_time]} {
  391. return -1
  392. }
  393. regsub -all {[A-Za-z]} $the_time "" number
  394. regsub -all {[0-9]} $the_time "" type
  395. switch [string tolower $type] {
  396. d {
  397. set minutes [expr $number * 1440]
  398. }
  399. m {
  400. set minutes "$number"
  401. }
  402. h {
  403. set minutes [expr $number * 60]
  404. }
  405. default {
  406. return -1
  407. }
  408. }
  409. return "$minutes"
  410. }
  411. ############################## Check Timer ################################
  412. if {![info exists bt_timers_running]} {
  413. timer 1 blacktools:timers:runtime
  414. set bt_timers_running 1
  415. }
  416. #Secured Timer
  417. if {![info exists securedtimer_running]} {
  418. utimer 30 [list securemode:timer]
  419. set securedtimer_running 1
  420. }
  421. ################################ check access ################################
  422. proc check:access {nick host hand chan chan1 users} {
  423. global black
  424. if {[matchattr $users -|M $chan] && [matchattr $hand -|M $chan]} {
  425. return 1
  426. } elseif {[matchattr $users -|M $chan] && [matchattr $hand -|A $chan]} {
  427. return 1
  428. } elseif {[matchattr $users m|- $chan] && [matchattr $hand -|M $chan]} {
  429. return 1
  430. } elseif {[matchattr $users m|- $chan] && [matchattr $hand m|- $chan] && (![matchattr $hand n|- $chan])} {
  431. return 1
  432. } elseif {[matchattr $users m|- $chan] && [matchattr $hand -|A $chan]} {
  433. return 1
  434. } elseif {[matchattr $users -|A $chan] && [matchattr $hand -|A $chan]} {
  435. return 1
  436. } elseif {[matchattr $users n|- $chan] && [matchattr $hand -|A $chan]} {
  437. return 1
  438. } elseif {[matchattr $users n|- $chan] && [matchattr $hand -|M $chan]} {
  439. return 1
  440. } elseif {[matchattr $users n|- $chan] && [matchattr $hand n|- $chan]} {
  441. return 1
  442. } elseif {[matchattr $users n|- $chan] && [matchattr $hand m|- $chan]} {
  443. return 1
  444. } elseif {[matchattr $users o|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand nm|- $chan])} {
  445. return 1
  446. } elseif {[matchattr $users o|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand m|- $chan])} {
  447. return 1
  448. } elseif {[matchattr $users o|- $chan] && [matchattr $hand -|M $chan]} {
  449. return 1
  450. } elseif {[matchattr $users m|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand n|- $chan])} {
  451. return 1
  452. } elseif {[matchattr $users n|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand n|- $chan])} {
  453. return 1
  454. } elseif {[matchattr $users m|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand m|- $chan])} {
  455. return 1
  456. } elseif {[matchattr $users n|- $chan] && [matchattr $hand o|- $chan] && (![matchattr $hand m|- $chan])} {
  457. return 1
  458. } elseif {[matchattr $users o|- $chan] && [matchattr $hand -|A $chan]} {
  459. return 1
  460. }
  461. return 0
  462. }
  463. proc check:global {hand} {
  464. global black
  465. if {[matchattr $hand n]} {
  466. return [blacktools:getlevelname 1 $hand]
  467. } elseif {[matchattr $hand m]} {
  468. return [blacktools:getlevelname 2 $hand]
  469. } elseif {[matchattr $hand o]} {
  470. return [blacktools:getlevelname 8 $hand]
  471. }
  472. return 0
  473. }
  474. ################################ Away set ####################################
  475. proc setaway {myaway} {
  476. global black
  477. set away [config:getinfo $black(tclconfig) "set black(default_away) \"*\""]
  478. set away [string map [list {\"} \" {\[} \[ {\]} \] {\?} \? {\\} \\] $away]
  479. if {$away == "" || $away == "i_have_no_away"} {
  480. return 0
  481. } else {
  482. putserv "AWAY :"
  483. putserv "AWAY :$away"
  484. return 1
  485. }
  486. }
  487. proc away:timer {} {
  488. global black
  489. set away_status [setaway "none"]
  490. }
  491. ############################### Config save ##################################
  492. proc config:save {f text_find text_replace} {
  493. global black
  494. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  495. set file_temp "temp.$timestamp"
  496. set found_it 0
  497. if {![file exists $file_temp]} {
  498. set file [open $file_temp w]
  499. close $file
  500. }
  501. set file [open $f r]
  502. set size [file size $f]
  503. set data [split [read $file $size] \n]
  504. close $file
  505. set file2 [open $file_temp a]
  506. foreach line $data {
  507. if {[string match -nocase $text_find $line]} {
  508. set found_it 1
  509. puts $file2 $text_replace
  510. } else {
  511. puts $file2 $line
  512. }
  513. }
  514. close $file2
  515. if {$found_it == "1"} {
  516. file delete $f
  517. file rename $file_temp $f
  518. } else {
  519. file delete $file_temp
  520. return 0
  521. }
  522. if {[file exists $file_temp]} {
  523. file delete $file_temp
  524. return 0
  525. }
  526. }
  527. proc config:getinfo {f text_find} {
  528. set file [open $f r]
  529. while {[gets $file line] != -1} {
  530. if {[string match -nocase $text_find $line]} {
  531. set found_line $line
  532. continue
  533. }
  534. }
  535. close $file
  536. if {![info exists found_line]} {
  537. return 0
  538. } else {
  539. regexp {\"((.*)\")(.*)} $found_line line
  540. set line [string map { "\"" ""} $line]
  541. return $line
  542. }
  543. }
  544. ############################### Ban Methods ##################################
  545. proc blacktools:banner:1 {nick bot chan host method linkchans} {
  546. global black botnick
  547. set num 0
  548. set temp_num 0
  549. set split_hand [split $bot ":"]
  550. set hand [string tolower [lindex $split_hand 0]]
  551. set said [lindex $split_hand 1]
  552. set banmask [return_mask [return_host_num $hand $chan $host] $host $nick]
  553. set finduser [finduser $banmask]
  554. if {$finduser != "*"} {
  555. if {[matchattr $finduser $black(exceptflags) $chan]} {
  556. return
  557. }
  558. }
  559. if {![botisop $chan] && ![setting:get $chan xonly]} {
  560. return
  561. }
  562. set getcount [setting:get $chan kickcount]
  563. set kcount [expr $getcount +1]
  564. setting:set $chan kickcount $kcount
  565. set xban 0
  566. set num [blacktools:ban:find_id]
  567. set xonly [blacktools:getxonly $chan]
  568. set bantime [blacktools:getbantime $chan $hand]
  569. set show_reason [blacktools:getreason $chan $hand 0 $num]
  570. set reason [blacktools:getreason $chan $hand 1 $num]
  571. blacktools:ban:method $nick $chan $banmask $hand $show_reason $bantime $method $xban $xonly $reason $said $linkchans $num $host
  572. }
  573. proc blacktools:getxonly {chan} {
  574. global black
  575. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  576. return 1
  577. }
  578. return 0
  579. }
  580. proc blacktools:getbantime {chan hand} {
  581. global black
  582. set bantime [setting:get $chan $hand-bantime]
  583. if {$bantime == ""} {
  584. set bantime [setting:get $chan general-bantime]
  585. if {$bantime == ""} {
  586. set bantime $black($hand:bantime)
  587. }
  588. }
  589. set checkbantime [time_return_minute $bantime]
  590. if {$checkbantime == "-1"} {
  591. set bantime [time_return_minute $black($hand:bantime)]
  592. } else {
  593. set bantime [time_return_minute $bantime]
  594. }
  595. return $bantime
  596. }
  597. proc blacktools:getreason {chan hand type id} {
  598. global black badchan
  599. if {[string match -nocase "*badchan,*" $hand]} {
  600. set split_hand [split $hand ","]
  601. } else {
  602. set split_hand [split $hand ":"]
  603. }
  604. set hand [lindex $split_hand 0]
  605. set bantime [setting:get $chan $hand-bantime]
  606. set getlang [string tolower [setting:get $chan lang]]
  607. if {$getlang == ""} {
  608. set getlang [string tolower $black(default_lang)]
  609. }
  610. if {$bantime == ""} {
  611. set bantime [setting:get $chan general-bantime]
  612. }
  613. if {$bantime == ""} {
  614. set bantime $black($hand:bantime)
  615. }
  616. set checkbantime [time_return_minute $bantime]
  617. if {$checkbantime == "-1"} {
  618. set bantime [time_return_minute $black($hand:bantime)]
  619. } else {
  620. set bantime [time_return_minute $bantime]
  621. }
  622. set reason_time [expr [unixtime] + [expr $bantime * 60]]
  623. if {[string equal -nocase $hand "NEXT"]} {
  624. set getreason [setting:get $chan $hand-noidlereason]
  625. } else {
  626. set getreason [setting:get $chan $hand-reason]
  627. }
  628. if {$getreason == ""} {
  629. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  630. if {[string equal -nocase $hand "NEXT"]} {
  631. set getreason $black(say.$getlang.$hand.5)
  632. } else {
  633. set getreason $black(say.$getlang.$hand.1)
  634. }
  635. }
  636. if {[string equal -nocase $hand "BADCHAN"]} {
  637. set banmask [lindex $split_hand 1]
  638. if {[string equal -nocase $badchan($banmask:$chan) $black(say.$getlang.$hand.5)]} {
  639. if {[setting:get $chan $hand-reason] != ""} {
  640. set getreason [join [setting:get $chan $hand-reason]]
  641. } else {
  642. set getreason $black(say.$getlang.badchan.5)
  643. }
  644. } else {
  645. if {[setting:get $chan $hand-reason] != ""} {
  646. set getreason [join [setting:get $chan $hand-reason]]
  647. } else {
  648. set getreason [join $badchan($banmask:$chan)]
  649. }
  650. }
  651. }
  652. set replace(%chan%) $chan
  653. set reason [string map [array get replace] $getreason]
  654. set thereason [encoding convertfrom utf-8 $reason]
  655. set getcount [setting:get $chan kickcount]
  656. set show_reason $thereason
  657. if {[setting:get $chan showid]} {
  658. set show_reason "$show_reason \[id: $id\]"
  659. }
  660. if {[setting:get $chan showtime] && $bantime != "0"} {
  661. set show_reason "$show_reason \[bantime: [return_reason_time [expr $reason_time - [unixtime]]]\]"
  662. } else {
  663. set show_reason "$show_reason"
  664. }
  665. if {[setting:get $chan showurl] && [setting:get $chan url] != "" && $bantime != "0"} {
  666. set show_reason "$show_reason - [join [setting:get $chan url]]"
  667. }
  668. if {[setting:get $chan showcount]} {
  669. set show_reason "$show_reason - $getcount -"
  670. }
  671. if {$type == "1"} {
  672. return $thereason
  673. }
  674. return $show_reason
  675. }
  676. proc blacktools:banner:2 {nick bot chan chan1 host link arg} {
  677. global black botnick
  678. set xban 0
  679. set num 0
  680. set temp_num 0
  681. if {[string match -nocase "*badchan,*" $bot]} {
  682. set split_hand [split $bot ","]
  683. } else {
  684. set split_hand [split $bot ":"]
  685. }
  686. set hand [string tolower [lindex $split_hand 0]]
  687. if {[string equal -nocase $hand "CLONESCAN"]} {
  688. set banmask $host
  689. } else {
  690. set banmask [return_mask [return_host_num $hand $chan $host] $host $nick]
  691. }
  692. set finduser [finduser $banmask]
  693. set said [lindex $split_hand 1]
  694. if {$finduser != "*"} {
  695. if {[matchattr $finduser $black(exceptflags) $chan]} {
  696. return
  697. }
  698. }
  699. if {![botisop $chan] && ![setting:get $chan xonly]} {
  700. return
  701. }
  702. if {[setting:get $chan xonly]} {
  703. set xban 1
  704. set getxtime [setting:get $chan xbantime]
  705. set getxlevel [setting:get $chan xbanlevel]
  706. if {$getxtime == ""} {
  707. set getxtime $black(chanserv:bantime)
  708. }
  709. if {$getxlevel == ""} {
  710. set getxlevel $black(chanserv:banlevel)
  711. }
  712. }
  713. set num [blacktools:ban:find_id]
  714. set getcount [setting:get $chan kickcount]
  715. set kcount [expr $getcount +1]
  716. setting:set $chan kickcount $kcount
  717. set getcount [setting:get $chan kickcount]
  718. set bantime [blacktools:getbantime $chan $hand]
  719. if {[string equal -nocase $hand "badchan"]} {
  720. set show_reason [blacktools:getreason $chan "$hand,$banmask" 0 $num]
  721. set thereason [blacktools:getreason $chan "$hand,$banmask" 1 $num]
  722. } else {
  723. set show_reason [blacktools:getreason $chan $hand 0 $num]
  724. set thereason [blacktools:getreason $chan $hand 1 $num]
  725. }
  726. if {[string equal -nocase $hand "CLONESCAN"]} {
  727. set clone [string map {"*!*@" ""} $banmask]
  728. set replace(%clone%) $clone
  729. set thereason [string map [array get replace] $thereason]
  730. set show_reason [string map [array get replace] $show_reason]
  731. }
  732. if {[string equal -nocase $hand "noproxy"]} {
  733. set replace(%isp%) [lindex $arg 0]
  734. set thereason [string map [array get replace] $thereason]
  735. set show_reason [string map [array get replace] $show_reason]
  736. }
  737. blacktools:addban $nick $banmask "$hand:$said" $chan $chan1 $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $num
  738. if {[onchan $black(chanserv) $chan] && $xban == "1"} {
  739. putserv "PRIVMSG $black(chanserv) :ban $chan $banmask $getxtime $getxlevel $show_reason"
  740. }
  741. if {$link == "0"} {
  742. set backchan [join [setting:get $chan backchan]]
  743. if {$backchan == ""} {
  744. return
  745. }
  746. if {!([validchan $backchan]) || !([onchan $botnick $backchan])} {
  747. return
  748. }
  749. if {[info exists black($chan:anounce)]} {
  750. return
  751. }
  752. if {![string equal -nocase $hand "CLONESCAN"] && ![string equal -nocase $hand "BADCHAN"]} {
  753. set black($chan:anounce) 1
  754. }
  755. set getlang [string tolower [setting:get $chan lang]]
  756. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  757. set thereason [blacktools:rem_comment_ban $thereason]
  758. if {$thereason == ""} { set thereason "N/A" }
  759. set bantime [time_return_minute $bantime]
  760. set bantime [expr $bantime * 60]
  761. set expire [return_time_2 $getlang $bantime]
  762. set replace(%banmask%) $banmask
  763. set replace(%bantime%) $expire
  764. set replace(%reason%) $show_reason
  765. set replace(%chan%) $chan
  766. set replace(%nick%) $botnick
  767. set text [black:color:set "" $black(say.$getlang.reportchan.1)]
  768. set reply [join $text]
  769. set reply [string map [array get replace] $reply]
  770. puthelp "PRIVMSG $backchan :$reply"
  771. if {[info exists black($chan:anounce)]} {
  772. utimer 5 [list unset black($chan:anounce)]
  773. }
  774. }
  775. }
  776. proc blacktools:banner:3 {mask hand chan chan1 reason bantime type sticky cmd nick banned prv} {
  777. global black botnick
  778. chanserv:ignore_remove
  779. set rcmd [lindex $cmd 0]
  780. set regex [lindex $cmd 1]
  781. set validhost 0
  782. set found_handle 0
  783. set finduser [finduser $mask]
  784. if {$finduser != "*"} {
  785. if {[matchattr $finduser $black(exceptflags) $chan]} {
  786. return
  787. }
  788. }
  789. foreach user [chanlist $chan] {
  790. if {[string equal -nocase $user $botnick]} {
  791. set uhost "$user![getchanhost $user $chan]"
  792. if {[string match -nocase $mask $uhost]} {
  793. set found_handle 1
  794. break
  795. }
  796. }
  797. set uhost "$user![getchanhost $user $chan]"
  798. if {[string match -nocase $mask $uhost]} {
  799. set handle [nick2hand $user]
  800. if {$handle != "*"} {
  801. if {[matchattr $handle $black(exceptflags) $chan]} {
  802. set found_handle 1
  803. break
  804. }
  805. }
  806. }
  807. }
  808. if {$found_handle == "1"} {
  809. return
  810. }
  811. if {([string match -nocase "*!*" $mask] && [string match -nocase "*@*" $mask]) || $regex == "REGEX"} {
  812. if {$regex != "REGEX"} {
  813. if {$type == "gl"} {
  814. set check_ban_exist [blacktools:ban:exists $mask "GLOBAL"]
  815. } else {
  816. set check_ban_exist [blacktools:ban:exists $mask $chan]
  817. }
  818. if {$check_ban_exist != ""} {
  819. if {$prv == "prv"} {
  820. blacktools:tell $nick $prv $hand $chan $chan1 gl.banexists "$mask $check_ban_exist"
  821. } else {
  822. blacktools:tell $nick $prv $hand $chan $chan1 gl.banexists "$mask $check_ban_exist"
  823. }
  824. return
  825. }
  826. }
  827. set validhost 1
  828. set thereason [encoding convertto utf-8 $reason]
  829. set replace(%chan%) $chan
  830. set replace(%botnick%) $botnick
  831. set thereason [string map [array get replace] $thereason]
  832. set reason [string map [array get replace] $reason]
  833. set show_bantime $bantime
  834. set split_hand [split $hand ":"]
  835. set gethand [lindex $split_hand 0]
  836. set found 1
  837. set bl 0
  838. set xban 0
  839. set num 0
  840. set temp_num 0
  841. set checkbantime [time_return_minute $bantime]
  842. if {$checkbantime == "-1"} {
  843. set bantime $bantime
  844. } else {
  845. set bantime [time_return_minute $bantime]
  846. }
  847. set getlang [string tolower [setting:get $chan lang]]
  848. set getmethod [getuser $gethand XTRA OUTPUT_TYPE]
  849. set userlang [string tolower [getuser $gethand XTRA OUTPUT_LANG]]
  850. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  851. if {$getmethod == ""} { set getmethod "0" }
  852. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  853. if {$type == ""} {
  854. if {![botisop $chan] && ![setting:get $chan xonly]} {
  855. if {$prv == "prv"} {
  856. blacktools:tell $nick $prv $hand $chan $chan1 gl.noop none
  857. } else {
  858. blacktools:tell $nick "" $hand $chan $chan1 gl.noop none
  859. }
  860. return
  861. }
  862. }
  863. if {$bantime == "-1"} {
  864. if {$prv == "prv"} {
  865. blacktools:tell $nick $prv $hand $chan $chan1 gl.instr "$rcmd"
  866. } else {
  867. blacktools:tell $nick "" $hand $chan $chan1 gl.instr "$rcmd"
  868. }
  869. return
  870. }
  871. set num [blacktools:ban:find_id]
  872. if {$rcmd == "b" && $type == "gl"} {
  873. if {$prv != "prv"} {
  874. set prv ""
  875. }
  876. if {$regex == "REGEX"} {
  877. blacktools:tell $nick $prv $hand $chan $chan1 b.13 $num
  878. } else {
  879. blacktools:tell $nick $prv $hand $chan $chan1 b.8 $num
  880. }
  881. }
  882. set current_time [unixtime]
  883. if {$bantime != "0"} {
  884. set reason_time [expr $current_time + [expr $bantime * 60]]
  885. } else {
  886. set reason_time 0
  887. }
  888. set getcount [setting:get $chan kickcount]
  889. set kcount [expr $getcount +1]
  890. setting:set $chan kickcount $kcount
  891. set getcount [setting:get $chan kickcount]
  892. blacktools:banner3_stats $rcmd $chan $gethand $type
  893. if {$bantime == "0"} {
  894. set bl 1
  895. }
  896. if {[string equal -nocase $regex "REGEX"]} {
  897. set bantype "REGEX"
  898. } else {
  899. set bantype "BAN"
  900. }
  901. if {$type == "gl"} {
  902. blacktools:addban:gl $nick $mask $hand "GLOBAL" $bantime $bantype "0" "1" $thereason $num
  903. blacktools:global:ban [channels] 0
  904. } else {
  905. if {$sticky == "1"} {
  906. blacktools:addban $nick $mask $hand $chan $chan1 $bantime $bantype "1" "0" $thereason $found $cmd $type $banned $prv $num
  907. who:chan $chan
  908. } elseif {$sticky == "2"} {
  909. blacktools:addban $nick $mask $hand $chan $chan1 $bantime $bantype "2" "0" $thereason $found $cmd $type $banned $prv $num
  910. troll:add $banned $mask $chan
  911. who:chan $chan
  912. } elseif {$sticky == "3"} {
  913. blacktools:addban $nick $mask $hand $chan $chan1 $bantime $bantype "3" "0" $thereason $found $cmd $type $banned $prv $num
  914. who:chan $chan
  915. } else {
  916. blacktools:addban $nick $mask $hand $chan $chan1 $bantime $bantype "0" "0" $thereason $found $cmd $type $banned $prv $num
  917. who:chan $chan
  918. }
  919. }
  920. if {$type != "gl"} {
  921. set backchan [join [setting:get $chan backchan]]
  922. if {$backchan == ""} {
  923. return
  924. }
  925. if {!([validchan $backchan]) || !([onchan $botnick $backchan])} {
  926. return
  927. }
  928. set reason [blacktools:rem_comment_ban $thereason]
  929. set show_reason [blacktools:setreason $chan $reason "" 0 $getcount "0" $num]
  930. if {$reason == ""} { set reason "N/A" }
  931. set bantime [time_return_minute $bantime]
  932. set bantime [expr $bantime * 60]
  933. set expire [return_time_2 $getlang $bantime]
  934. set black($chan:anounce) 1
  935. set replace(%banmask%) $mask
  936. if {$bantime != "0"} {
  937. set replace(%bantime%) $expire
  938. } else {
  939. set replace(%bantime%) "N/A"
  940. }
  941. set replace(%reason%) $show_reason
  942. set replace(%chan%) $chan
  943. set replace(%nick%) $gethand
  944. set text [black:color:set "" $black(say.$getlang.reportchan.1)]
  945. set reply [join $text]
  946. set reply [string map [array get replace] $reply]
  947. puthelp "PRIVMSG $backchan :$reply"
  948. }
  949. }
  950. if {$validhost == "0"} {
  951. if {$prv == "prv"} {
  952. blacktools:tell $nick "prv" $hand $chan $chan1 b.10 $mask
  953. } else {
  954. blacktools:tell $nick "" $hand $chan $chan1 b.10 $mask
  955. }
  956. }
  957. }
  958. proc blacktools:banner3_stats {cmd chan user type} {
  959. global black
  960. set text ""
  961. set counter 0
  962. if {$type == "gl"} {
  963. set bantype "BANS(GLOBAL)"
  964. set counts [getuser $user XTRA BANS(GLOBAL)]
  965. if {$counts == ""} { set counts 0 }
  966. set counts [expr $counts + 1]
  967. setuser $user XTRA BANS(GLOBAL) $counts
  968. return
  969. }
  970. set cmds [getuser $user XTRA CMD_STATS($chan)]
  971. if {$cmds == ""} {
  972. setuser $user XTRA CMD_STATS($chan) $cmd:1
  973. } else {
  974. set find_it [lsearch -glob $cmds "$cmd*"]
  975. set get_val [lindex $cmds $find_it]
  976. set split_val [split $get_val ":"]
  977. set getval [lindex $split_val 1]
  978. set counter [expr $getval + 1]
  979. set cmds [lreplace $cmds $find_it $find_it]
  980. if {[llength $cmds] > 0} {
  981. setuser $user XTRA CMD_STATS($chan) "$cmds $cmd:$counter"
  982. } else {
  983. setuser $user XTRA CMD_STATS($chan) $cmd:$counter
  984. }
  985. }
  986. set cmds_today [getuser $user XTRA CMD_STATS_TODAY($chan)]
  987. if {$cmds_today == ""} {
  988. setuser $user XTRA CMD_STATS_TODAY($chan) $cmd:1
  989. } else {
  990. set find_it [lsearch -glob $cmds_today "$cmd*"]
  991. set get_val [lindex $cmds_today $find_it]
  992. set split_val [split $get_val ":"]
  993. set getval [lindex $split_val 1]
  994. set counter [expr $getval + 1]
  995. set cmds_today [lreplace $cmds_today $find_it $find_it]
  996. if {[llength $cmds_today] > 0} {
  997. setuser $user XTRA CMD_STATS_TODAY($chan) "$cmds_today $cmd:$counter"
  998. } else {
  999. setuser $user XTRA CMD_STATS_TODAY($chan) $cmd:$counter
  1000. }
  1001. }
  1002. }
  1003. proc blacktools:global:ban {channels num} {
  1004. global black
  1005. set chan [lindex $channels $num]
  1006. who:chan $chan
  1007. set incnum [expr $num + 1]
  1008. if {[lindex $channels $incnum] != ""} {
  1009. utimer 5 [list blacktools:global:ban $channels $incnum]
  1010. }
  1011. }
  1012. proc blacktools:ban:method {nick chan host type reason bantime option xban xonly thereason said linkchans id truehost} {
  1013. global black
  1014. if {![info exists black(banmethod:memory)]} {
  1015. set black(banmethod:memory) ""
  1016. }
  1017. switch [string tolower $type] {
  1018. antipub {
  1019. set chanmode "1"
  1020. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(antipubmode) $black(antipubsecunde) "antipub" $thereason $said $linkchans $id $truehost
  1021. }
  1022. antinotice {
  1023. set chanmode "1"
  1024. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(antinoticemode) $black(antinoticesecunde) "antinotice" $thereason $said $linkchans $id $truehost
  1025. }
  1026. antictcp {
  1027. set chanmode "1"
  1028. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(antictcpmode) $black(antictcpsecunde) "antictcp" $thereason $said $linkchans $id $truehost
  1029. }
  1030. antibadword {
  1031. set chanmode "1"
  1032. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(badwordmode) $black(badwordsecunde) "antibadword" $thereason $said $linkchans $id $truehost
  1033. }
  1034. antilongtext {
  1035. set chanmode "1"
  1036. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(longmode) $black(longtimemode) "antilongtext" $thereason $said $linkchans $id $truehost
  1037. }
  1038. antirepeat {
  1039. set chanmode "1"
  1040. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(antirepeatmode) $black(antirepeatsecunde) "antirepeat" $thereason $said $linkchans $id $truehost
  1041. }
  1042. anticolor {
  1043. set chanmode "1"
  1044. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(anticolormode) $black(anticolorsecunde) "anticolor" $thereason $said $linkchans $id $truehost
  1045. }
  1046. antibold {
  1047. set chanmode "0"
  1048. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option "0" "0" "antibold" $thereason $said $linkchans $id $truehost
  1049. }
  1050. antiunderline {
  1051. set chanmode "0"
  1052. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option "0" "0" "antiunderline" $thereason $said $linkchans $id $truehost
  1053. }
  1054. anticaps {
  1055. set chanmode "0"
  1056. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option "0" "0" "anticaps" $thereason $said $linkchans $id $truehost
  1057. }
  1058. antichanflood {
  1059. set chanmode "1"
  1060. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(antichanflood:chanmode) $black(antichanflood:chanmodetime) "antichanflood" $thereason $said $linkchans $id $truehost
  1061. }
  1062. nickflood {
  1063. set chanmode "1"
  1064. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option $black(nickfloodmode) $black(nickfloodsecunde) "nickflood" $thereason $said $linkchans $id $truehost
  1065. }
  1066. repetitivechars {
  1067. set chanmode "0"
  1068. banmethod_action $nick $chan $host $type $reason $bantime $xban $xonly $chanmode $option "0" "0" "repetitivechars" $thereason $said $linkchans $id $truehost
  1069. }
  1070. }
  1071. }
  1072. proc banmethod_action {nick chan host type reason bantime xban xonly mode banmethod chanmode_type chanmode_time variable_name thereason said linkchans id truehost} {
  1073. global black
  1074. chanserv:ignore_remove
  1075. if {$variable_name == "nickflood"} {
  1076. set nick $said
  1077. set said ""
  1078. }
  1079. set num 0
  1080. set temp_num 0
  1081. set get_count ""
  1082. set time [unixtime]
  1083. set getlang [string tolower [setting:get $chan lang]]
  1084. if {![info exists black($variable_name:type_count:$host:$chan)]} {
  1085. set black($variable_name:type_count:$host:$chan) $time:0
  1086. } else {
  1087. set time_split [split $black($variable_name:type_count:$host:$chan) ":"]
  1088. set get_time [lindex $time_split 0]
  1089. set get_count [lindex $time_split 1]
  1090. set get_count [expr $get_count + 1]
  1091. set black($variable_name:type_count:$host:$chan) $time:$get_count
  1092. }
  1093. set time_split [split $black($variable_name:type_count:$host:$chan) ":"]
  1094. set get_time [lindex $time_split 0]
  1095. set get_count [lindex $time_split 1]
  1096. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1097. set warnmsg [setting:get $chan $variable_name-warn]
  1098. if {$warnmsg == ""} {
  1099. set warnmsg $black(say.$getlang.$variable_name.2)
  1100. }
  1101. set warnmsg [encoding convertfrom utf-8 $warnmsg]
  1102. set replace(%chan%) $chan
  1103. set replace(%nick%) $nick
  1104. set warnmsg [string map [array get replace] $warnmsg]
  1105. switch $banmethod {
  1106. 1 {
  1107. putserv "PRIVMSG $chan :\[WARN\] $nick - $warnmsg"
  1108. banmethod_memory:remove $host $chan $variable_name
  1109. }
  1110. 2 {
  1111. if {$xonly == "1"} {
  1112. putserv "PRIVMSG $black(chanserv) :kick $chan $nick $warnmsg"
  1113. return
  1114. }
  1115. putserv "KICK $chan $nick :\[WARN\] $warnmsg"
  1116. banmethod_memory:remove $host $chan $variable_name
  1117. }
  1118. 3 {
  1119. banmethod_action:ban $nick $chan $host $reason $xban $xonly $bantime $truehost $thereason
  1120. blacktools:addban $nick $host "$type:$said" $chan "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $id
  1121. if {$linkchans != ""} {
  1122. foreach c $linkchans {
  1123. set num [blacktools:ban:find_id]
  1124. set getcount [setting:get $c kickcount]
  1125. set kcount [expr $getcount +1]
  1126. setting:set $c kickcount $kcount
  1127. set xban 0
  1128. set xonly [blacktools:getxonly $c]
  1129. set bantime [blacktools:getbantime $c $variable_name]
  1130. set reason [blacktools:getreason $c $variable_name 0 $num]
  1131. set thereason [blacktools:getreason $c $variable_name 1 $num]
  1132. banmethod_action:ban $nick $c $host $reason $xban $xonly $bantime $truehost $thereason
  1133. blacktools:addban $nick $host "$type:$said" $c "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $num
  1134. }
  1135. }
  1136. if {$mode == "1"} {
  1137. set current_modes [getchanmode $chan]
  1138. set putmode ""
  1139. set chanmodes [string map {"+" ""} [split [lindex $current_modes 0] ""]]
  1140. foreach mod [split $chanmode_type ""] {
  1141. if {[lsearch $chanmodes $mod] < 0} {
  1142. lappend putmode $mod
  1143. }
  1144. }
  1145. if {$putmode != ""} {
  1146. putserv "MODE $chan +$putmode" -next ;utimer $chanmode_time [list putserv "MODE $chan -$putmode"]
  1147. }
  1148. }
  1149. banmethod_memory:remove $host $chan $variable_name
  1150. }
  1151. 4 {
  1152. if {$get_count == "0"} {
  1153. putserv "PRIVMSG $chan :\[WARN\] $nick - $warnmsg"
  1154. banmethod_memory:add $host
  1155. } else {
  1156. if {$xonly == "1"} {
  1157. putserv "PRIVMSG $black(chanserv) :kick $chan $nick $warnmsg"
  1158. banmethod_memory:remove $host $chan $variable_name
  1159. return
  1160. }
  1161. if {[onchan $nick $chan]} {
  1162. putserv "KICK $chan $nick :\[WARN\] $warnmsg"
  1163. }
  1164. banmethod_memory:remove $host $chan $variable_name
  1165. }
  1166. }
  1167. 5 {
  1168. if {$get_count == "0"} {
  1169. putserv "PRIVMSG $chan :\[WARN\] $nick - $warnmsg"
  1170. banmethod_memory:add $host
  1171. }
  1172. if {$get_count == "1"} {
  1173. if {$xonly == "1"} {
  1174. putserv "PRIVMSG $black(chanserv) :kick $chan $nick $warnmsg"
  1175. return
  1176. }
  1177. putserv "KICK $chan $nick :\[WARN\] $warnmsg"
  1178. }
  1179. if {$get_count >= "2"} {
  1180. banmethod_action:ban $nick $chan $host $reason $xban $xonly $bantime $truehost $thereason
  1181. blacktools:addban $nick $host "$type:$said" $chan "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $id
  1182. if {$linkchans != ""} {
  1183. foreach c $linkchans {
  1184. set num [blacktools:ban:find_id]
  1185. set getcount [setting:get $c kickcount]
  1186. set kcount [expr $getcount +1]
  1187. setting:set $c kickcount $kcount
  1188. set xban 0
  1189. set xonly [blacktools:getxonly $c]
  1190. set bantime [blacktools:getbantime $c $variable_name]
  1191. set reason [blacktools:getreason $c $variable_name 0 $num]
  1192. set thereason [blacktools:getreason $c $variable_name 1 $num]
  1193. banmethod_action:ban $nick $c $host $reason $xban $xonly $bantime $truehost $thereason
  1194. blacktools:addban $nick $host "$type:$said" $c "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $num
  1195. }
  1196. }
  1197. if {$mode == "1"} {
  1198. set current_modes [getchanmode $chan]
  1199. set putmode ""
  1200. set chanmodes [string map {"+" ""} [split [lindex $current_modes 0] ""]]
  1201. foreach mod [split $chanmode_type ""] {
  1202. if {[lsearch $chanmodes $mod] < 0} {
  1203. lappend putmode $mod
  1204. }
  1205. }
  1206. if {$putmode != ""} {
  1207. putserv "MODE $chan +$putmode" -next ;utimer $chanmode_time [list putserv "MODE $chan -$putmode"]
  1208. }
  1209. }
  1210. banmethod_memory:remove $host $chan $variable_name
  1211. }
  1212. }
  1213. 6 {
  1214. if {$get_count == "0"} {
  1215. if {$xonly == "1"} {
  1216. putserv "PRIVMSG $black(chanserv) :kick $chan $nick $warnmsg"
  1217. return
  1218. }
  1219. putserv "KICK $chan $nick :\[WARN\] $warnmsg"
  1220. banmethod_memory:add $host
  1221. } else {
  1222. banmethod_action:ban $nick $chan $host $reason $xban $xonly $bantime $truehost $thereason
  1223. blacktools:addban $nick $host "$type:$said" $chan "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $id
  1224. if {$linkchans != ""} {
  1225. foreach c $linkchans {
  1226. set num [blacktools:ban:find_id]
  1227. set getcount [setting:get $c kickcount]
  1228. set kcount [expr $getcount +1]
  1229. setting:set $c kickcount $kcount
  1230. set xban 0
  1231. set xonly [blacktools:getxonly $c]
  1232. set bantime [blacktools:getbantime $c $variable_name]
  1233. set reason [blacktools:getreason $c $variable_name 0 $num]
  1234. set thereason [blacktools:getreason $c $variable_name 1 $num]
  1235. banmethod_action:ban $nick $c $host $reason $xban $xonly $bantime $truehost $thereason
  1236. blacktools:addban $nick $host "$type:$said" $c "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $num
  1237. }
  1238. }
  1239. if {$mode == "1"} {
  1240. set current_modes [getchanmode $chan]
  1241. set putmode ""
  1242. set chanmodes [string map {"+" ""} [split [lindex $current_modes 0] ""]]
  1243. foreach mod [split $chanmode_type ""] {
  1244. if {[lsearch $chanmodes $mod] < 0} {
  1245. lappend putmode $mod
  1246. }
  1247. }
  1248. if {$putmode != ""} {
  1249. putserv "MODE $chan +$putmode" -next ;utimer $chanmode_time [list putserv "MODE $chan -$putmode"]
  1250. }
  1251. }
  1252. banmethod_memory:remove $host $chan $variable_name
  1253. }
  1254. }
  1255. 7 {
  1256. if {$get_count == "0"} {
  1257. if {[onchan $nick $chan]} {
  1258. set black($variable_name:type_count:$host:$chan) $time:0
  1259. putserv "PRIVMSG $chan :\[WARN\] $nick - $warnmsg"
  1260. banmethod_memory:add $host
  1261. }
  1262. } else {
  1263. banmethod_action:ban $nick $chan $host $reason $xban $xonly $bantime $truehost $thereason
  1264. blacktools:addban $nick $host "$type:$said" $chan "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $id
  1265. if {$linkchans != ""} {
  1266. foreach c $linkchans {
  1267. set num [blacktools:ban:find_id]
  1268. set getcount [setting:get $c kickcount]
  1269. set kcount [expr $getcount +1]
  1270. setting:set $c kickcount $kcount
  1271. set xban 0
  1272. set xonly [blacktools:getxonly $c]
  1273. set bantime [blacktools:getbantime $c $variable_name]
  1274. set reason [blacktools:getreason $c $variable_name 0 $num]
  1275. set thereason [blacktools:getreason $c $variable_name 1 $num]
  1276. banmethod_action:ban $nick $c $host $reason $xban $xonly $bantime $truehost $thereason
  1277. blacktools:addban $nick $host "$type:$said" $c "" $bantime "BAN" "0" "0" $thereason "0" "" "" "" 0 $num
  1278. }
  1279. }
  1280. if {$mode == "1"} {
  1281. set current_modes [getchanmode $chan]
  1282. set putmode ""
  1283. set chanmodes [string map {"+" ""} [split [lindex $current_modes 0] ""]]
  1284. foreach mod [split $chanmode_type ""] {
  1285. if {[lsearch $chanmodes $mod] < 0} {
  1286. lappend putmode $mod
  1287. }
  1288. }
  1289. if {$putmode != ""} {
  1290. putserv "MODE $chan +$putmode" -next ;utimer $chanmode_time [list putserv "MODE $chan -$putmode"]
  1291. }
  1292. }
  1293. banmethod_memory:remove $host $chan $variable_name
  1294. }
  1295. }
  1296. }
  1297. }
  1298. proc banmethod_memory:add {host} {
  1299. global black
  1300. if {[info exists black(banmethod:memory)]} {
  1301. if {[lsearch -exact [string tolower $black(banmethod:memory)] [string tolower $host]] < 0} {
  1302. lappend black(banmethod:memory) $black(banmethod:memory) $host
  1303. }
  1304. }
  1305. }
  1306. proc banmethod_memory:remove {host chan variable_name} {
  1307. global black
  1308. if {[info exists black($variable_name:type_count:$host:$chan)]} {
  1309. unset black($variable_name:type_count:$host:$chan)
  1310. }
  1311. }
  1312. proc banmethod_memory:autoremove {} {
  1313. global black
  1314. if {[info exists black(banmethod:memory)]} {
  1315. set split_out [split $black(banmethod:memory)]
  1316. foreach chan [channels] {
  1317. foreach host $split_out {
  1318. if {[info exists black(antipub:type_count:$host:$chan)]} {
  1319. unset black(antipub:type_count:$host:$chan)
  1320. }
  1321. if {[info exists black(antinotice:type_count:$host:$chan)]} {
  1322. unset black(antinotice:type_count:$host:$chan)
  1323. }
  1324. if {[info exists black(antictcp:type_count:$host:$chan)]} {
  1325. unset black(antictcp:type_count:$host:$chan)
  1326. }
  1327. if {[info exists black(antibadword:type_count:$host:$chan)]} {
  1328. unset black(antibadword:type_count:$host:$chan)
  1329. }
  1330. if {[info exists black(antilongtext:type_count:$host:$chan)]} {
  1331. unset black(antilongtext:type_count:$host:$chan)
  1332. }
  1333. if {[info exists black(antirepeat:type_count:$host:$chan)]} {
  1334. unset black(antirepeat:type_count:$host:$chan)
  1335. }
  1336. if {[info exists black(anticolor:type_count:$host:$chan)]} {
  1337. unset black(anticolor:type_count:$host:$chan)
  1338. }
  1339. if {[info exists black(antibold:type_count:$host:$chan)]} {
  1340. unset black(antibold:type_count:$host:$chan)
  1341. }
  1342. if {[info exists black(antiunderline:type_count:$host:$chan)]} {
  1343. unset black(antiunderline:type_count:$host:$chan)
  1344. }
  1345. if {[info exists black(anticaps:type_count:$host:$chan)]} {
  1346. unset black(anticaps:type_count:$host:$chan)
  1347. }
  1348. if {[info exists black(antichanflood:type_count:$host:$chan)]} {
  1349. unset black(antichanflood:type_count:$host:$chan)
  1350. }
  1351. if {[info exists black(nickflood:type_count:$host:$chan)]} {
  1352. unset black(nickflood:type_count:$host:$chan)
  1353. }
  1354. if {[lsearch -exact [string tolower $black(banmethod:memory)] [string tolower $host]] > -1} {
  1355. set position [lsearch -exact [string tolower $black(banmethod:memory)] [string tolower $host]]
  1356. set black(banmethod:memory) [lreplace $black(banmethod:memory) $position $position]
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. proc checkischanban_ub {nick truehost chan whois} {
  1363. global black
  1364. set banlist [chanbans $chan]
  1365. if {$nick == ""} {
  1366. set search_host "$truehost"
  1367. } else {
  1368. set search_host "$nick!$truehost"
  1369. }
  1370. set foundban 0
  1371. foreach ban $banlist {
  1372. set b [lindex $ban 0]
  1373. if {([matchaddr $b $search_host] && $whois == "1") || [matchaddr $search_host $b]} {
  1374. set foundban 1
  1375. break
  1376. }
  1377. }
  1378. return $foundban
  1379. }
  1380. proc checkischanban {nick truehost chan} {
  1381. global black
  1382. set banlist [chanbans $chan]
  1383. if {$nick == ""} {
  1384. set search_host "$truehost"
  1385. } else {
  1386. set search_host "$nick!$truehost"
  1387. }
  1388. set foundban 0
  1389. foreach ban $banlist {
  1390. set b [lindex $ban 0]
  1391. if {[matchaddr $search_host $b]} {
  1392. set foundban 1
  1393. break
  1394. }
  1395. }
  1396. return $foundban
  1397. }
  1398. proc returnchanbans {host chan} {
  1399. global black
  1400. set bans ""
  1401. set banlist [chanbans $chan]
  1402. foreach ban $banlist {
  1403. set b [lindex $ban 0]
  1404. if {[matchaddr $host $b]} {
  1405. lappend bans $b
  1406. }
  1407. }
  1408. return $bans
  1409. }
  1410. proc returnchanbans_ub {host chan whois} {
  1411. global black
  1412. set bans ""
  1413. set banlist [chanbans $chan]
  1414. foreach ban $banlist {
  1415. set b [lindex $ban 0]
  1416. if {([matchaddr $b $host] && $whois == "1") || [matchaddr $host $b]} {
  1417. lappend bans $b
  1418. }
  1419. }
  1420. return $bans
  1421. }
  1422. proc banmethod_action:ban {nick chan host reason xban xonly bantime truehost thereason} {
  1423. global black botnick
  1424. chanserv:ignore_remove
  1425. set reason [blacktools:rem_comment_ban $reason]
  1426. if {$xonly == "1"} {
  1427. set getxtime [setting:get $chan xbantime]
  1428. set getxlevel [setting:get $chan xbanlevel]
  1429. if {$getxlevel == ""} { set getxlevel $black(chanserv:banlevel)}
  1430. if {$getxtime == ""} { set getxtime $black(chanserv:bantime) }
  1431. putserv "PRIVMSG $black(chanserv) :ban $chan $host $getxtime $getxlevel $reason"
  1432. } else {
  1433. set alreadyban [checkischanban $nick $truehost $chan]
  1434. if {$alreadyban == "0"} {
  1435. putserv "MODE $chan +b $host"
  1436. }
  1437. putserv "KICK $chan $nick :$reason"
  1438. foreach user [chanlist $chan] {
  1439. set gethost "$user![getchanhost $user $chan]"
  1440. set real_host [string map [list \[ {\[} \] {\]} \\ {\\}] $gethost]
  1441. if {[string match -nocase $host $real_host] || [string match -nocase $real_host $host]} {
  1442. putserv "KICK $chan $user :$reason"
  1443. }
  1444. }
  1445. }
  1446. set backchan [join [setting:get $chan backchan]]
  1447. if {$backchan == ""} {
  1448. return
  1449. }
  1450. if {!([validchan $backchan]) || !([onchan $botnick $backchan])} {
  1451. return
  1452. }
  1453. if {[info exists black($chan:anounce)]} {
  1454. return
  1455. }
  1456. set black($chan:anounce) 1
  1457. set getlang [string tolower [setting:get $chan lang]]
  1458. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1459. if {$reason == ""} { set reason "N/A" }
  1460. set bantime [time_return_minute $bantime]
  1461. set bantime [expr $bantime * 60]
  1462. set expire [return_time_2 $getlang $bantime]
  1463. set replace(%banmask%) $host
  1464. set replace(%bantime%) $expire
  1465. set replace(%reason%) $reason
  1466. set replace(%chan%) $chan
  1467. set replace(%nick%) $botnick
  1468. set text [black:color:set "" $black(say.$getlang.reportchan.1)]
  1469. set reply [join $text]
  1470. set reply [string map [array get replace] $reply]
  1471. puthelp "PRIVMSG $backchan :$reply"
  1472. utimer 5 [list unset black($chan:anounce)]
  1473. }
  1474. ########################### User Protection ################################
  1475. proc protectpublic {nick host hand chan args} {
  1476. global black
  1477. set bans [lindex $args 1]
  1478. chanserv:ignore_remove
  1479. if {![botisop $chan] && ![setting:get $chan xonly]} {
  1480. return
  1481. }
  1482. if {$bans == "*!*@*"} { putserv "MODE $chan -b $bans"
  1483. return
  1484. }
  1485. if {[info exists black(logged)]} {
  1486. set massban [check:massban $bans $chan]
  1487. if {$massban == 1} {
  1488. if {![info exists black(massban_start:$chan)]} {
  1489. set black(massban_start:$chan) [unixtime]
  1490. putquick "PRIVMSG $black(chanserv) :unban $chan $bans"
  1491. utimer 60 [list massban:kick_unset $chan]
  1492. }
  1493. }
  1494. }
  1495. set list [userlist $black(exceptflags) $chan]
  1496. foreach user $list {
  1497. set hosts [getuser $user hosts]
  1498. foreach host $hosts {
  1499. if {[string match -nocase $bans $host] || [string match -nocase $host $bans]} {
  1500. if {[onchan $black(chanserv) $chan] && ([setting:get $chan xtools] || [setting:get $chan xonly])} {
  1501. putquick "PRIVMSG $black(chanserv) :unban $chan $bans"
  1502. } else {
  1503. putserv "MODE $chan -b $bans"
  1504. }
  1505. break
  1506. }
  1507. }
  1508. }
  1509. }
  1510. proc massban:kick {nick host hand chan kicked reason} {
  1511. global black
  1512. if {[info exists black(massban_start:$chan)]} {
  1513. if {[string equal -nocase $nick $black(chanserv)]} {
  1514. set lang [setting:get $chan lang]
  1515. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  1516. set reason_k $black(say.$lang.b.9)
  1517. regexp {\((.+)\) (.*)} $reason string user reason
  1518. if {$user != ""} {
  1519. putquick "PRIVMSG $black(chanserv) :suspend $chan $user $black(chanserv:suspend_time) $black(chanserv:suspend_level) $reason_k - [ctime $black(massban_start:$chan)]"
  1520. massban:kick_unset $chan
  1521. }
  1522. }
  1523. }
  1524. }
  1525. proc massban:kick_unset {chan} {
  1526. global black
  1527. if {[info exists black(massban_start:$chan)]} {
  1528. unset black(massban_start:$chan)
  1529. }
  1530. }
  1531. ########################### Text Wrapper ##################################
  1532. proc wordwrap {str {len 100} {splitChr { }}} {
  1533. set out [set cur {}]; set i 0
  1534. foreach word [split [set str][unset str] $splitChr] {
  1535. if {[incr i [string len $word]]>$len} {
  1536. lappend out [join $cur $splitChr]
  1537. set cur [list $word]
  1538. set i [string len $word]
  1539. } {
  1540. lappend cur $word
  1541. }
  1542. incr i
  1543. }
  1544. lappend out [join $cur $splitChr]
  1545. }
  1546. proc h:wrap {str {len 100} {splitChr {;}}} {
  1547. set out [set cur {}]; set i 0
  1548. foreach word [split [set str][unset str] $splitChr] {
  1549. if {[incr i [string len $word]]>$len} {
  1550. lappend out [join $cur $splitChr]
  1551. set cur [list $word]
  1552. set i [string len $word]
  1553. } {
  1554. lappend cur $word
  1555. }
  1556. incr i
  1557. }
  1558. lappend out [concat [join $cur $splitChr]]
  1559. }
  1560. ##################################Auto User Expire ################################
  1561. proc user:autoexpire {minute hour day month year} {
  1562. global black
  1563. set counter 0
  1564. if {$black(user_expire_time) == "0"} {
  1565. return
  1566. }
  1567. set max_time [expr 86400 * $black(user_expire_time)]
  1568. foreach user [userlist] {
  1569. if {[matchattr $user mno]} {
  1570. continue
  1571. }
  1572. set laston [getuser $user laston]
  1573. if {$laston == ""} {
  1574. set laston [getuser $user XTRA created]
  1575. } else {
  1576. set laston [lindex $laston 0]
  1577. }
  1578. set user_time [expr [unixtime] - $laston]
  1579. if {$user_time > $max_time} {
  1580. set counter [expr $counter + 1]
  1581. deluser $user
  1582. notes:remove:ondelete $user
  1583. alias:remove:ondelete $user
  1584. s:remove:ondelete $user
  1585. }
  1586. }
  1587. blacktools:tell:dcc userexpire.1 "$counter"
  1588. }
  1589. ################################# Message output ################################
  1590. proc blacktools:tell:h {nick host hand chan chan1 type arg} {
  1591. global black botnick lastbind
  1592. set split_hand [split $hand ":"]
  1593. set gethand [lindex $split_hand 0]
  1594. set replace(%botnick%) $botnick
  1595. set split_lastbind [split $lastbind ""]
  1596. set charbind [lindex $split_lastbind 0]
  1597. set text ""
  1598. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  1599. set charbind ""
  1600. }
  1601. if {[string equal $lastbind "*"]} { set charbind "" }
  1602. if {[string equal -nocase "**" $lastbind]} { set charbind "$botnick " }
  1603. if {[string equal -nocase "***" $lastbind]} { set charbind "$host" }
  1604. set replace(%msg.1%) [lindex [split $arg] 0]
  1605. set replace(%msg.2%) [lindex [split $arg] 1]
  1606. set replace(%msg.3%) [lindex [split $arg] 2]
  1607. set replace(%char%) $charbind
  1608. set replace(%chan%) $chan
  1609. set replace(%msg%) [join [lrange [split $arg] 0 end]]
  1610. set replace(%msg.set%) [join [lrange [split $arg] 1 end]]
  1611. set replace(%bind%) $lastbind
  1612. if {[validuser $hand]} {
  1613. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  1614. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  1615. } else {
  1616. set getlang ""
  1617. set getmethod ""
  1618. }
  1619. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1620. if {$getmethod == ""} { set getmethod $black(default_output) }
  1621. set text [black:color:set $gethand $black(say.$getlang.$type)]
  1622. set text [join $text]
  1623. set reply [string map [array get replace] $text]
  1624. foreach w [wordwrap $reply 440] {
  1625. if {[string equal -nocase $host "prv"]} {
  1626. putserv "PRIVMSG $nick :$w"
  1627. return
  1628. } elseif {[string equal -nocase [lindex $host 0] "dcc"]} {
  1629. set idx [lindex $host 1]
  1630. putidx $idx $w
  1631. return
  1632. }
  1633. switch $getmethod {
  1634. 0 {
  1635. putserv "NOTICE $nick :$w"
  1636. }
  1637. 1 {
  1638. putserv "PRIVMSG $chan1 :$w"
  1639. }
  1640. 2 {
  1641. putserv "PRIVMSG $nick :$w"
  1642. }
  1643. }
  1644. }
  1645. }
  1646. proc blacktools:tell_v2 {nick host hand chan chan1 type arg} {
  1647. global black botnick lastbind
  1648. set split_hand [split $hand ":"]
  1649. set gethand [lindex $split_hand 0]
  1650. set replace(%botnick%) $botnick
  1651. set split_lastbind [split $lastbind ""]
  1652. set charbind [lindex $split_lastbind 0]
  1653. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  1654. set charbind ""
  1655. }
  1656. set firstchar [lindex $black(cmdchar) 0]
  1657. if {[string equal $lastbind "*"]} { set charbind "" }
  1658. if {[string equal -nocase "**" $lastbind]} { set charbind "$botnick " }
  1659. if {[string equal -nocase "***" $lastbind]} {
  1660. set split_host [split $host ":"]
  1661. if {[lindex $split_host 1] == "chan"} {
  1662. set host [lindex $split_host 1]
  1663. set charbind [lindex $split_host 0]
  1664. } else {
  1665. set charbind "$host"
  1666. }
  1667. }
  1668. if {$charbind == ""} {
  1669. set charbind $firstchar
  1670. if {[validuser $hand]} {
  1671. set getchar [getuser $hand XTRA MYCHAR]
  1672. if {$getchar != ""} {
  1673. set charbind $getchar
  1674. }
  1675. }
  1676. }
  1677. set replace(%char%) $charbind
  1678. set replace(%firstchar%) $firstchar
  1679. set replace(%chan%) $chan
  1680. set replace(%botnick%) $botnick
  1681. set replace(%bind%) $lastbind
  1682. set counter 0
  1683. foreach a $arg {
  1684. incr counter
  1685. set replace(%msg.$counter%) $a
  1686. }
  1687. if {[validuser $gethand]} {
  1688. set getlang [string tolower [getuser $gethand XTRA OUTPUT_LANG]]
  1689. set getmethod [getuser $gethand XTRA OUTPUT_TYPE]
  1690. } else {
  1691. set getlang ""
  1692. set getmethod ""
  1693. }
  1694. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1695. if {$getmethod == ""} { set getmethod $black(default_output) }
  1696. if {[string equal -nocase "man.showtip" $type]} {
  1697. set len [llength $black(say.$getlang.$type)]
  1698. set random [expr int(rand()*$len)]
  1699. set gettext [lindex $black(say.$getlang.$type) $random]
  1700. set text [black:color:set $gethand $gettext]
  1701. } else {
  1702. set text [black:color:set $gethand $black(say.$getlang.$type)]
  1703. }
  1704. set text [join $text]
  1705. set reply [string map [array get replace] $text]
  1706. set reply [string map [list {\"} \" {\[} \[ {\]} \] {\?} \? {\\} \\] $reply]
  1707. if {[string equal -nocase $host "prv"]} {
  1708. putserv "PRIVMSG $nick :$reply"
  1709. return
  1710. } elseif {[string equal -nocase [lindex $host 0] "dcc"]} {
  1711. set idx [lindex $host 1]
  1712. putidx $idx $reply
  1713. return
  1714. } elseif {[string equal -nocase $host "chan"]} {
  1715. putserv "PRIVMSG $chan1 :$reply"
  1716. return
  1717. }
  1718. switch $getmethod {
  1719. 0 {
  1720. putserv "NOTICE $nick :$reply"
  1721. }
  1722. 1 {
  1723. if {[validchan $chan1]} {
  1724. if {[onchan $botnick $chan1]} {
  1725. putserv "PRIVMSG $chan1 :$reply"
  1726. } else {
  1727. putserv "NOTICE $nick :$reply"
  1728. }
  1729. } else { putserv "NOTICE $nick :$reply" }
  1730. }
  1731. 2 {
  1732. putserv "PRIVMSG $nick :$reply"
  1733. }
  1734. }
  1735. }
  1736. proc blacktools:tell {nick host hand chan chan1 type arg} {
  1737. global black botnick lastbind
  1738. set split_hand [split $hand ":"]
  1739. set gethand [lindex $split_hand 0]
  1740. set replace(%botnick%) $botnick
  1741. set split_lastbind [split $lastbind ""]
  1742. set charbind [lindex $split_lastbind 0]
  1743. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  1744. set charbind ""
  1745. }
  1746. set firstchar [lindex $black(cmdchar) 0]
  1747. if {[string equal $lastbind "*"]} { set charbind "" }
  1748. if {[string equal -nocase "**" $lastbind]} { set charbind "$botnick " }
  1749. if {[string equal -nocase "***" $lastbind]} {
  1750. set split_host [split $host ":"]
  1751. if {[lindex $split_host 1] == "chan"} {
  1752. set host [lindex $split_host 1]
  1753. set charbind [lindex $split_host 0]
  1754. } else {
  1755. set charbind "$host"
  1756. }
  1757. }
  1758. if {$charbind == ""} {
  1759. set charbind $firstchar
  1760. if {[validuser $hand]} {
  1761. set getchar [getuser $hand XTRA MYCHAR]
  1762. if {$getchar != ""} {
  1763. set charbind $getchar
  1764. }
  1765. }
  1766. }
  1767. set replace(!%chan%) "%chan%"
  1768. set replace(!%botnick%) "%botnick%"
  1769. set replace(%char%) $charbind
  1770. set replace(%firstchar%) $firstchar
  1771. set replace(%chan%) $chan
  1772. set replace(%msg%) [join [lrange [split $arg] 0 end]]
  1773. set replace(%msg.set%) [join [lrange [split $arg] 1 end]]
  1774. set replace(%msg.1%) [lindex [split $arg] 0]
  1775. set replace(%msg.2%) [lindex [split $arg] 1]
  1776. set replace(%msg.3%) [lindex [split $arg] 2]
  1777. set replace(%msg.4%) [lindex [split $arg] 3]
  1778. set replace(%msg.5%) [lrange [split $arg] 4 end]
  1779. set replace(%msg.6%) [join [lrange [split $arg] 3 end]]
  1780. set replace(%msg.7%) [lrange [split $arg] 2 end]
  1781. set replace(%msg.8%) [join [lrange [split $arg] 1 end]]
  1782. set replace(%msg.9%) [join [lrange [split $arg] 3 end]]
  1783. set replace(%msg.10%) [join [lrange [split $arg] 4 end]]
  1784. set replace(%msg.11%) [join [lrange [split $arg] 5 end]]
  1785. set replace(%msg.12%) [lindex [split $arg] 4]
  1786. set replace(%msg.13%) [lindex [split $arg] 5]
  1787. set replace(%msg.14%) [join [lrange [split $arg] 6 end]]
  1788. set replace(%msg.15%) [lindex [split $arg] 6]
  1789. set replace(%msg.16%) [join [lrange [split $arg] 7 end]]
  1790. set replace(%msg.17%) [lindex [split $arg] 7]
  1791. set replace(%msg.18%) [join [lrange [split $arg] 2 end]]
  1792. set replace(%msg.19%) [lindex [split $arg] 8]
  1793. set replace(%msg.20%) [join [lrange [split $arg] 8 end]]
  1794. set replace(%msg.21%) [lindex [split $arg] 9]
  1795. set replace(%bind%) $lastbind
  1796. if {[validuser $gethand]} {
  1797. set getlang [string tolower [getuser $gethand XTRA OUTPUT_LANG]]
  1798. set getmethod [getuser $gethand XTRA OUTPUT_TYPE]
  1799. } else {
  1800. set getlang ""
  1801. set getmethod ""
  1802. }
  1803. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  1804. if {$getmethod == ""} { set getmethod $black(default_output) }
  1805. if {[string equal -nocase "man.showtip" $type]} {
  1806. set len [llength $black(say.$getlang.$type)]
  1807. set random [expr int(rand()*$len)]
  1808. set gettext [lindex $black(say.$getlang.$type) $random]
  1809. set text [black:color:set $gethand $gettext]
  1810. } else {
  1811. set text [black:color:set $gethand $black(say.$getlang.$type)]
  1812. }
  1813. set text [join $text]
  1814. set reply [string map [array get replace] $text]
  1815. set reply [string map [list {\"} \" {\[} \[ {\]} \] {\?} \? {\\} \\] $reply]
  1816. if {[string equal -nocase $host "prv"]} {
  1817. putserv "PRIVMSG $nick :$reply"
  1818. return
  1819. } elseif {[string equal -nocase [lindex $host 0] "dcc"]} {
  1820. set idx [lindex $host 1]
  1821. putidx $idx $reply
  1822. return
  1823. } elseif {[string equal -nocase $host "chan"]} {
  1824. putserv "PRIVMSG $chan1 :$reply"
  1825. return
  1826. }
  1827. switch $getmethod {
  1828. 0 {
  1829. putserv "NOTICE $nick :$reply"
  1830. }
  1831. 1 {
  1832. if {[validchan $chan1]} {
  1833. if {[onchan $botnick $chan1]} {
  1834. putserv "PRIVMSG $chan1 :$reply"
  1835. } else {
  1836. putserv "NOTICE $nick :$reply"
  1837. }
  1838. } else { putserv "NOTICE $nick :$reply" }
  1839. }
  1840. 2 {
  1841. putserv "PRIVMSG $nick :$reply"
  1842. }
  1843. }
  1844. }
  1845. proc blacktools:tell:cmd {nick host hand chan chan1 prv type reply} {
  1846. global black
  1847. set text ""
  1848. if {[validuser $hand]} {
  1849. set getcolor [string tolower [getuser $hand XTRA OUTPUT_COLORS]]
  1850. } else {
  1851. set getcolor ""
  1852. }
  1853. if {$getcolor == ""} { set getcolor "[string tolower $black(default_colors)]" }
  1854. set color1 [lindex $getcolor 0]
  1855. set color2 [lindex $getcolor 1]
  1856. set color3 [lindex $getcolor 2]
  1857. set color4 [lindex $getcolor 3]
  1858. foreach txt $reply {
  1859. if {[string match "*<*" $txt] || [string match "*>*" $txt]} {
  1860. lappend text [blacktools:getcolor $color2 $txt]
  1861. } elseif {[string match *%chan%* $txt] || [string match *\001* $txt]} {
  1862. set rpc [string map {"\001" ""} $txt]
  1863. lappend text [blacktools:getcolor $color2 $rpc]
  1864. } elseif {[string match *\002* $txt]} {
  1865. set rpc [string map {"\002" ""} $txt]
  1866. lappend text [blacktools:getcolor $color1 $rpc]
  1867. } elseif {[string match *\005* $txt]} {
  1868. set rpc [string map {"\005" ""} $txt]
  1869. lappend text [blacktools:getcolor $color3 $rpc]
  1870. } elseif {[string match *\004* $txt]} {
  1871. set rpc [string map {"\004" ""} $txt]
  1872. lappend text [blacktools:getcolor $color4 $rpc]
  1873. } else {
  1874. lappend text $txt
  1875. }
  1876. }
  1877. if {[lindex $host 0] == "dcc"} {
  1878. set idx [lindex $host 1]
  1879. putidx $idx [join $text]
  1880. return
  1881. }
  1882. if {$prv == "1"} {
  1883. putserv "PRIVMSG $nick :[join $text]"
  1884. return
  1885. }
  1886. switch $type {
  1887. 0 {
  1888. putserv "NOTICE $nick :[join $text]"
  1889. }
  1890. 1 {
  1891. putserv "PRIVMSG $chan1 :[join $text]"
  1892. }
  1893. 2 {
  1894. putserv "PRIVMSG $nick :[join $text]"
  1895. }
  1896. }
  1897. }
  1898. proc blacktools:tell:dcc {type arg} {
  1899. global black botnick
  1900. set replace(%botnick%) $botnick
  1901. set replace(%msg%) [join [lrange $arg 0 end]]
  1902. set replace(%msg.set%) [join [lrange $arg 1 end]]
  1903. set replace(%msg.1%) [lindex $arg 0]
  1904. set replace(%msg.2%) [lindex $arg 1]
  1905. set replace(%msg.3%) [lindex $arg 2]
  1906. set replace(%msg.4%) [lindex $arg 3]
  1907. set replace(%msg.5%) [lrange $arg 4 end]
  1908. set replace(%msg.6%) [lrange $arg 3 end]
  1909. set replace(%msg.7%) [lrange $arg 2 end]
  1910. set replace(%msg.8%) [join [lrange $arg 1 end]]
  1911. set replace(%msg.9%) [join [lrange $arg 3 end]]
  1912. set replace(%msg.10%) [join [lrange $arg 4 end]]
  1913. set getlang [string tolower $black(default_lang)]
  1914. if {[info exists black(say.$getlang.$type)]} {
  1915. set text [black:color:set "" $black(say.$getlang.$type)]
  1916. set text [join $text]
  1917. set reply [string map [array get replace] $text]
  1918. putlog "$reply"
  1919. }
  1920. }
  1921. ############################## Channel Key Need ##################################
  1922. proc keyneed {chan type} {
  1923. global black
  1924. if {![validchan $chan]} {
  1925. return
  1926. }
  1927. if {$type == "key"} {
  1928. if {![regexp {k} [channel get $chan chanmode]]} {
  1929. return
  1930. } else {
  1931. set the_key [lindex [split [channel get $chan chanmode]] 1]
  1932. if {$the_key == ""} { return }
  1933. putserv "JOIN $chan :$the_key"
  1934. }
  1935. }
  1936. }
  1937. ############################### Check valid nickname #############################
  1938. proc check:validnickname {from keyword arguments } {
  1939. global nick config
  1940. set lastnick $::lastnick
  1941. set error [config:save $config "set nick \"*\"" "set nick \"$lastnick\""]
  1942. unbind RAW - 432 check:validnickname
  1943. }
  1944. proc check:chanserv {from keyword arguments } {
  1945. global black
  1946. set black(notlogged) 1
  1947. unbind RAW - 401 check:chanserv
  1948. }
  1949. ########################### check expired notes ############################
  1950. proc notes:autoexpire {minute hour day month year} {
  1951. global black
  1952. set counter 0
  1953. set file [open $black(notes_file) "r"]
  1954. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  1955. set temp "$black(tempdir)/notes_temp.$timestamp"
  1956. set tempwrite [open $temp w]
  1957. set counter 0
  1958. while {[gets $file line] != -1} {
  1959. set read_type [lindex [split $line] 0]
  1960. if {[string equal -nocase $read_type "INBOX"]} {
  1961. set read_user [lindex [split $line] 4]
  1962. foreach user [userlist] {
  1963. if {[info exists black(notes:announce:$user)]} {
  1964. unset black(notes:announce:$user)
  1965. }
  1966. if {[string equal -nocase $user $read_user]} {
  1967. set tm [lindex [split $line] 5]
  1968. set read_days [expr [expr [expr [expr [unixtime] - $tm] / 60]] / 1440]
  1969. set expiretime [string tolower [getuser $user XTRA NOTE_EXPIRE]]
  1970. if {$expiretime == ""} { set expiretime $black(notes:expiretime) }
  1971. if {$read_days >= $expiretime} {
  1972. continue
  1973. } else {
  1974. puts $tempwrite $line
  1975. }
  1976. }
  1977. }
  1978. } else {
  1979. puts $tempwrite $line
  1980. }
  1981. }
  1982. close $tempwrite
  1983. close $file
  1984. file rename -force $temp $black(notes_file)
  1985. }
  1986. ########################### remove notes on delete ############################
  1987. proc notes:remove:ondelete {user} {
  1988. global black
  1989. set file [open $black(notes_file) "r"]
  1990. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  1991. set temp "$black(tempdir)/notes_temp.$timestamp"
  1992. set tempwrite [open $temp w]
  1993. while {[gets $file line] != -1} {
  1994. set read_user [lindex [split $line] 4]
  1995. if {[string equal -nocase $user $read_user]} {
  1996. continue
  1997. } else {
  1998. puts $tempwrite $line
  1999. }
  2000. }
  2001. close $tempwrite
  2002. close $file
  2003. file rename -force $temp $black(notes_file)
  2004. if {[info exists black(notes:announce:$user)]} {
  2005. unset black(notes:announce:$user)
  2006. }
  2007. }
  2008. ########################### remove alias on delete ############################
  2009. proc alias:remove:ondelete {user} {
  2010. global black
  2011. set file [open $black(alias_file) "r"]
  2012. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  2013. set temp "$black(tempdir)/alias_temp.$timestamp"
  2014. set tempwrite [open $temp w]
  2015. while {[gets $file line] != -1} {
  2016. set read_user [lindex [split $line] 0]
  2017. if {[string equal -nocase $user $read_user]} {
  2018. continue
  2019. } else {
  2020. puts $tempwrite $line
  2021. }
  2022. }
  2023. close $tempwrite
  2024. close $file
  2025. file rename -force $temp $black(alias_file)
  2026. }
  2027. ######################## modif alias on change handle #########################
  2028. proc alias:change:update {user newuser} {
  2029. global black
  2030. set file [open $black(alias_file) "r"]
  2031. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  2032. set temp "$black(tempdir)/alias_temp.$timestamp"
  2033. set tempwrite [open $temp w]
  2034. set arguments ""
  2035. while {[gets $file line] != -1} {
  2036. set read_user [lindex [split $line] 0]
  2037. if {[string equal -nocase $user $read_user]} {
  2038. set arguments [lrange [split $line] 1 end]
  2039. continue
  2040. } else {
  2041. puts $tempwrite $line
  2042. }
  2043. }
  2044. if {$arguments != ""} {
  2045. puts $tempwrite "$newuser $arguments"
  2046. }
  2047. close $tempwrite
  2048. close $file
  2049. file rename -force $temp $black(alias_file)
  2050. }
  2051. ########################## Strip codes ###########################
  2052. proc strip:all {str} {
  2053. regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  2054. return $str
  2055. }
  2056. ######################## Check add handle #######################
  2057. proc check:handle {user nick host hand chan chan1} {
  2058. global black
  2059. set last_user $user
  2060. if {[validuser $user]} {
  2061. return $user
  2062. }
  2063. set user [string range $user 0 31]
  2064. if {[validuser $user]} {
  2065. blacktools:tell $nick $host $hand $chan $chan1 add.17 "$last_user $user"
  2066. return $user
  2067. }
  2068. set user [string range $user 0 11]
  2069. if {[validuser $user]} {
  2070. blacktools:tell $nick $host $hand $chan $chan1 add.17 "$last_user $user"
  2071. return $user
  2072. }
  2073. set user [string range $user 0 8]
  2074. if {[validuser $user]} {
  2075. blacktools:tell $nick $host $hand $chan $chan1 add.17 "$last_user $user"
  2076. return $user
  2077. }
  2078. }
  2079. ######################## return time ###########################
  2080. proc return_time_2 {getlang get_time} {
  2081. global black
  2082. set seconds [expr $get_time % 60]
  2083. set days [expr $get_time/86400]
  2084. set hours [expr [expr $get_time/3600] % 24];
  2085. set minutes [expr [expr $get_time / 60] % 60]
  2086. if {[string length $hours] == "1"} {
  2087. set hours "0$hours"
  2088. }
  2089. if {[string length $minutes] == "1"} {
  2090. set minutes "0$minutes"
  2091. }
  2092. if {[string length $seconds] == "1"} {
  2093. set seconds "0$seconds"
  2094. }
  2095. set output "$days $black(say.$getlang.timeout.4), $hours:$minutes:$seconds"
  2096. if {$get_time <= 0} {
  2097. return 0
  2098. } else {
  2099. return $output
  2100. }
  2101. }
  2102. proc return_reason_time {get_time} {
  2103. global black
  2104. set m "m"
  2105. set d "d"
  2106. set h "h"
  2107. set s "s"
  2108. set days [expr $get_time/86400]
  2109. set hours [expr [expr $get_time/3600] % 24];
  2110. set minutes [expr [expr $get_time / 60] % 60]
  2111. set seconds [expr $get_time % 60]
  2112. if {$days == "0"} {
  2113. if {$hours == "0"} {
  2114. if {$seconds > 0} {
  2115. return "$minutes$m:$seconds$s"
  2116. } else { return "$minutes$m" }
  2117. } else {
  2118. if {$minutes > 0} {
  2119. return "$hours$h:$minutes$m"
  2120. } else { return "$hours$h" }
  2121. }
  2122. } else {
  2123. if {$hours > 0} {
  2124. return "$days$d:$hours$h"
  2125. } else { return "$days$d" }
  2126. }
  2127. }
  2128. proc return_time {getlang get_time} {
  2129. global black
  2130. if {$get_time >= 31536000} {
  2131. set yearsfull [expr $get_time/31536000]
  2132. set years [expr int($yearsfull)]
  2133. set yearssub [expr 31536000*$years]
  2134. set totalday [expr $get_time - $yearssub]
  2135. }
  2136. if {$get_time < 31536000} {
  2137. set totalday $get_time
  2138. set years 0
  2139. }
  2140. if {$totalday >= 86400} {
  2141. set daysfull [expr $totalday/86400]
  2142. set days [expr int($daysfull)]
  2143. set dayssub [expr 86400*$days]
  2144. set totalhour [expr $totalday - $dayssub]
  2145. }
  2146. if {$totalday < 86400} {
  2147. set totalhour $totalday
  2148. set days 0
  2149. }
  2150. if {$totalhour >= 3600} {
  2151. set hoursfull [expr $totalhour/3600]
  2152. set hours [expr int($hoursfull)]
  2153. set hourssub [expr 3600*$hours]
  2154. set totalmin [expr $totalhour - $hourssub]
  2155. }
  2156. if {$totalhour < 3600} {
  2157. set totalmin $totalhour
  2158. set hours 0
  2159. }
  2160. if {$totalmin >= 60} {
  2161. set minsfull [expr $totalmin/60]
  2162. set mins [expr int($minsfull)]
  2163. }
  2164. if {$totalmin < 60} {
  2165. set mins 0
  2166. }
  2167. if {$years < 1} {
  2168. set yearstext ""
  2169. } elseif {$years == 1} {
  2170. set yearstext "$years $black(say.$getlang.timeout.1) "} {
  2171. set yearstext "$years $black(say.$getlang.timeout.2) "
  2172. }
  2173. if {$days < 1} {
  2174. set daystext ""
  2175. } elseif {$days == 1} {
  2176. set daystext "$days $black(say.$getlang.timeout.3) "
  2177. } else {
  2178. set daystext "$days $black(say.$getlang.timeout.4) "
  2179. }
  2180. if {$hours < 1} {
  2181. set hourstext ""
  2182. } elseif {$hours == 1} {
  2183. set hourstext "$hours $black(say.$getlang.timeout.5) "
  2184. } else {
  2185. set hourstext "$hours $black(say.$getlang.timeout.6) "
  2186. }
  2187. if {$mins < 1} {
  2188. set minstext ""
  2189. } elseif {$mins == 1} {
  2190. set minstext "$mins $black(say.$getlang.timeout.7)"
  2191. } else {
  2192. set minstext "$mins $black(say.$getlang.timeout.8)"
  2193. }
  2194. set output $yearstext$daystext$hourstext$minstext
  2195. if {$get_time < 60} {
  2196. set output "$get_time $black(say.$getlang.timeout.9)"
  2197. }
  2198. return $output
  2199. }
  2200. ############################## login check ##############################
  2201. proc black:login:yes {nick host hand text {dest ""}} {
  2202. global black
  2203. if {$nick == $black(chanserv)} {
  2204. set lang [string tolower $black(default_lang)]
  2205. if {[info exists black(logged)]} { return }
  2206. set black(logged) 1
  2207. blacktools:tell:dcc login.5 ""
  2208. }
  2209. }
  2210. proc black:login:no:failed {nick host hand text {dest ""}} {
  2211. global black
  2212. if {$nick == $black(chanserv)} {
  2213. set black(notlogged:failed) 1
  2214. set black(notlogged) 1
  2215. blacktools:tell:dcc login.4 ""
  2216. }
  2217. }
  2218. proc black:login:max {nick host hand text {dest ""}} {
  2219. global black
  2220. if {$nick == $black(chanserv)} {
  2221. set black(notlogged:failed) 1
  2222. set black(notlogged) 1
  2223. blacktools:tell:dcc login.6 ""
  2224. }
  2225. }
  2226. proc black:login:no:user {nick host hand text {dest ""}} {
  2227. global black
  2228. if {$nick == $black(chanserv)} {
  2229. set black(notlogged:failed) 1
  2230. set black(notlogged) 1
  2231. blacktools:tell:dcc login.7 ""
  2232. }
  2233. }
  2234. proc black:login:no:invalid {nick host hand text {dest ""}} {
  2235. global black
  2236. if {$nick == $black(chanserv)} {
  2237. set black(notlogged:invalid) 1
  2238. set black(notlogged) 1
  2239. blacktools:tell:dcc login.8 ""
  2240. }
  2241. }
  2242. proc timer:login:check {min hour day mon year} {
  2243. global black
  2244. if {$black(autologin) == "0"} {
  2245. return
  2246. }
  2247. if {[info exists black(logged)]} { return }
  2248. if {[info exists black(notlogged)] } {
  2249. loginpublic my
  2250. }
  2251. }
  2252. ############################ nickserv check #########################
  2253. proc black:nickserv:yes {nick host hand text {dest ""}} {
  2254. global black
  2255. if {[string equal -nocase $nick "NICKSERV"]} {
  2256. putserv "PRIVMSG $black(nickserv:host) :RELEASE $nick $black(nickserv:pass)"
  2257. putserv "PRIVMSG $black(nickserv:host) :IDENTIFY $black(nickserv:pass)"
  2258. blacktools:tell:dcc login.9 ""
  2259. }
  2260. }
  2261. proc black:nickserv:identify {nick host hand text {dest ""}} {
  2262. global black
  2263. if {[string equal -nocase $nick "NICKSERV"]} {
  2264. set black(identified) 1
  2265. blacktools:tell:dcc login.10 ""
  2266. }
  2267. }
  2268. proc black:nickserv:wrongpass {nick host hand text {dest ""}} {
  2269. global black
  2270. set lang [string tolower $black(default_lang)]
  2271. if {[string equal -nocase $nick "NICKSERV"]} {
  2272. set black(notidentified) $black(say.$lang.login.13)
  2273. blacktools:tell:dcc login.11 ""
  2274. }
  2275. }
  2276. proc black:nickserv:registered {} {
  2277. global black
  2278. if {[string equal -nocase $nick "NICKSERV"]} {
  2279. set black(notidentified) $black(say.$lang.login.15)
  2280. blacktools:tell:dcc login.16 ""
  2281. }
  2282. }
  2283. proc black:nickserv:release {nick host hand chan newnick} {
  2284. global black botnick
  2285. if {$black(nickserv:identify) == "1"} {
  2286. if {[isbotnick $nick] && [info exists black(identified)]} {
  2287. putserv "PRIVMSG $black(nickserv:host) :RELEASE $nick $black(nickserv:pass)"
  2288. }
  2289. }
  2290. }
  2291. ########################## user suspend process check ###############
  2292. proc s:remove:ondelete {user} {
  2293. global black
  2294. set file [open $black(s_file) "r"]
  2295. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  2296. set temp "$black(tempdir)/s_temp.$timestamp"
  2297. set tempwrite [open $temp w]
  2298. while {[gets $file line] != -1} {
  2299. set read_user [lindex [split $line] 1]
  2300. if {[string equal -nocase $user $read_user]} {
  2301. continue
  2302. } else {
  2303. puts $tempwrite $line
  2304. }
  2305. }
  2306. close $tempwrite
  2307. close $file
  2308. file rename -force $temp $black(s_file)
  2309. }
  2310. proc s:status {} {
  2311. global black
  2312. set entry_exists 0
  2313. set file [open $black(s_file) "r"]
  2314. while {[gets $file line] != -1} {
  2315. set entry_exists 1
  2316. }
  2317. close $file
  2318. return $entry_exists
  2319. }
  2320. proc s:process:timer {} {
  2321. global black
  2322. set entry_exists 0
  2323. set file [open $black(s_file) "r"]
  2324. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  2325. set temp "$black(tempdir)/s_temp.$timestamp"
  2326. set tempwrite [open $temp w]
  2327. while {[gets $file line] != -1} {
  2328. set entry_exists 1
  2329. set tm [lindex [split $line] 2]
  2330. set suspend_chan [lindex [split $line] 0]
  2331. set suspend_user [lindex [split $line] 1]
  2332. if {[expr $tm - [unixtime]] < 0} {
  2333. suspend:delete:action $suspend_user $suspend_chan
  2334. continue
  2335. } else {
  2336. puts $tempwrite $line
  2337. }
  2338. }
  2339. close $tempwrite
  2340. close $file
  2341. file rename -force $temp $black(s_file)
  2342. if {$entry_exists == "0"} {
  2343. if {[info exists black(s:timer_start)]} {
  2344. unset black(s:timer_start)
  2345. }
  2346. }
  2347. }
  2348. proc suspend:delete:action {user chan} {
  2349. global black username
  2350. set flags "-|-q"
  2351. set gl_flags "-q"
  2352. if {[string equal -nocase $chan "GLOBAL"]} {
  2353. chattr $user $gl_flags
  2354. } else {
  2355. chattr $user $flags $chan
  2356. }
  2357. }
  2358. proc check:if:bind {bind type} {
  2359. set found_it 0
  2360. set binds [binds raw]
  2361. foreach b $binds {
  2362. if {$bind == [lindex $b 4]} {
  2363. unbind RAW - $type $bind
  2364. }
  2365. }
  2366. }
  2367. ############################# no option ########################
  2368. proc check_option {nick host hand chan chan1 type type1 cmd} {
  2369. global black
  2370. if {$cmd == ""} { set cmd "set" }
  2371. if {$type == ""} {
  2372. switch $type1 {
  2373. 0 {
  2374. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $cmd
  2375. }
  2376. 1 {
  2377. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $cmd
  2378. }
  2379. 2 {
  2380. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $cmd
  2381. }
  2382. }
  2383. return 0
  2384. }
  2385. return 1
  2386. }
  2387. ########################### first join ########################
  2388. proc first:join {nick host hand chan} {
  2389. global black botnick
  2390. if {[string equal -nocase $nick $botnick]} {
  2391. if {![info exists black(firstjoin:$chan)]} {
  2392. blacktools:timers:load $chan
  2393. set black(firstjoin:$chan) 1
  2394. }
  2395. if {![info exists black(firstjoin)]} {
  2396. blacktools:timers:load "none"
  2397. set black(firstjoin) 1
  2398. }
  2399. blacktools:settings:save $chan 0
  2400. }
  2401. }
  2402. ########################### join count ########################
  2403. proc join:count {nick host hand chan} {
  2404. global black botnick
  2405. if {[string equal -nocase $nick $botnick]} {
  2406. if {[info exists black(abuse:$chan)]} {
  2407. unset black(abuse:$chan)
  2408. }
  2409. if {[info exists black(abuse:count:$chan)]} {
  2410. unset black(abuse:count:$chan)
  2411. }
  2412. }
  2413. set jointime [setting:get $chan jointime]
  2414. if {$jointime == ""} {
  2415. setting:set $chan jointime [unixtime]
  2416. }
  2417. set current [setting:get $chan joincount]
  2418. if {$current == ""} { set current 0 }
  2419. set current [expr $current + 1]
  2420. setting:set $chan joincount $current
  2421. }
  2422. ######################## Chan Flood Protection #######################
  2423. proc flood:join:protection {nick host hand chan} {
  2424. global black
  2425. if {[setting:get $chan greet] || [setting:get $chan antijoinflood] || [setting:get $chan antispam]} {
  2426. set joinflood [setting:get $chan joinflood]
  2427. if {$joinflood == ""} {set joinflood $black(joinflood:protect)}
  2428. set number [scan $joinflood %\[^:\]]
  2429. set time [scan $joinflood %*\[^:\]:%s]
  2430. foreach tmr [utimers] {
  2431. if {[string match "*black(countflood:join:$chan)*" [join [lindex $tmr 1]]]} {
  2432. killutimer [lindex $tmr 2]
  2433. }
  2434. }
  2435. if {[info exists black(turnOnFlood:$chan)]} {
  2436. return
  2437. }
  2438. if {![info exists black(countflood:join:$chan)]} {
  2439. set black(countflood:join:$chan) 0
  2440. }
  2441. set black(countflood:join:$chan) [expr $black(countflood:join:$chan) + 1]
  2442. utimer $time [list remove:flood:join $chan]
  2443. if {$black(countflood:join:$chan) >= $number} {
  2444. set black(turnOnFlood:$chan) 1
  2445. utimer 60 [list unset black(turnOnFlood:$chan)]
  2446. return
  2447. }
  2448. }
  2449. }
  2450. proc remove:flood:host {host chan} {
  2451. global black
  2452. if {[info exists black(countflood:$host:$chan)]} {
  2453. unset black(countflood:$host:$chan)
  2454. }
  2455. }
  2456. proc remove:flood:join {chan} {
  2457. global black
  2458. if {[info exists black(countflood:join:$chan)]} {
  2459. unset black(countflood:join:$chan)
  2460. }
  2461. }
  2462. proc remove:seenflood:host {the_host chan} {
  2463. global black
  2464. if {[info exists black(flood:$the_host:$chan)]} {
  2465. unset black(flood:$the_host:$chan)
  2466. }
  2467. }
  2468. ########################## max uptime ######################
  2469. proc maxuptime {min hour day mon year} {
  2470. global black uptime {server-online}
  2471. if {![file exists $black(uptime_file)]} {
  2472. return
  2473. }
  2474. set online [expr [unixtime] - ${server-online}]
  2475. set read_uptime [expr [unixtime] - $uptime]
  2476. set file [open $black(uptime_file) "r"]
  2477. set data [read -nonewline $file]
  2478. close $file
  2479. set get_uptime 0
  2480. set get_online 0
  2481. set get_uptime [lindex $data 0]
  2482. set get_online [lindex $data 1]
  2483. if {$read_uptime > $get_uptime} {
  2484. set add_uptime $read_uptime
  2485. } else {
  2486. set add_uptime $get_uptime
  2487. }
  2488. if {${server-online} != "0"} {
  2489. if {$online > $get_online} {
  2490. set add_online $online
  2491. } else {
  2492. set add_online $get_online
  2493. }
  2494. } else {
  2495. set add_online $get_online
  2496. }
  2497. set file [open $black(uptime_file) "w"]
  2498. puts $file "$add_uptime $add_online"
  2499. close $file
  2500. }
  2501. ############################## VERSION ################################
  2502. proc blackreply {nick host hand dest key text} {
  2503. global ctcp-version black
  2504. if {[string equal -nocase $key "version"]} {
  2505. set {ctcp-version} "Using \002$black(name) $black(vers)\002 coded by \002$black(author)\002 ($black(site))"
  2506. }
  2507. }
  2508. ########################### Return Mask ##############################
  2509. proc return_mask {type uhost user} {
  2510. global black
  2511. set ident [lindex [split $uhost "@"] 0]
  2512. set host [lindex [split $uhost @] 1]
  2513. switch $type {
  2514. 1 {
  2515. return "*!*@$host"
  2516. }
  2517. 2 {
  2518. return "*!$ident@$host"
  2519. }
  2520. 3 {
  2521. return "$user!$ident@$host"
  2522. }
  2523. 4 {
  2524. return "$user!*@*"
  2525. }
  2526. 5 {
  2527. return "*!$ident@*"
  2528. }
  2529. }
  2530. }
  2531. ########################### Return USERHOST Mask ####################
  2532. proc ub:get:host {from keyword arguments} {
  2533. global black
  2534. set hosts [lindex [split $arguments] 1]
  2535. set hostname [lindex [split $hosts "="] 1]
  2536. regsub {^[-+]} $hostname "" mask
  2537. set nickname [lindex [split $hosts "="] 0]
  2538. regsub {^:} $nickname "" nick
  2539. set fullmask "$nick!$mask"
  2540. set user $::uuser
  2541. set mask $fullmask
  2542. set nick $::unick
  2543. set hand $::uhand
  2544. set host $::uhost
  2545. set chan $::uchan
  2546. set chan1 $::uchan1
  2547. set type $::utype
  2548. set gl $::ugl
  2549. set cmd $::ucmd
  2550. set link $::ulink
  2551. set prv $::prv
  2552. if {$hosts == ":"} {
  2553. set mask $user
  2554. }
  2555. set vhost [lindex [split $mask @] 1]
  2556. if {[string equal -nocase $gl "1"] && [matchattr $hand nm]} {
  2557. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "1" $cmd "1" "" "" $prv
  2558. } elseif {[string equal -nocase $link "1"] && [matchattr $hand nm]} {
  2559. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "" "ub" "1" "1" "" $prv
  2560. } else {
  2561. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "" $cmd "1" "" "" $prv
  2562. }
  2563. check:if:bind "ub:get:host" "302"
  2564. }
  2565. proc sb:get:host {from keyword arguments} {
  2566. global black
  2567. set hosts [lindex [split $arguments] 1]
  2568. set hostname [lindex [split $hosts "="] 1]
  2569. regsub {^[-+]} $hostname "" mask
  2570. set nickname [lindex [split $hosts "="] 0]
  2571. regsub {^:} $nickname "" nick
  2572. set fullmask "$nick!$mask"
  2573. set what $::swhat
  2574. set bhost $fullmask
  2575. set nick $::snick
  2576. set hand $::shand
  2577. set host $::shost
  2578. set chan $::schan
  2579. set chan1 $::schan1
  2580. set type $::stype
  2581. set cmd $::scmd
  2582. if {$hosts == ":"} {
  2583. set bhost "-"
  2584. }
  2585. sb:process $bhost $what $nick $hand $host $chan $chan1 $type "sb" "1"
  2586. check:if:bind "sb:get:host" "302"
  2587. }
  2588. proc userhost:get:host {from keyword arguments} {
  2589. global black
  2590. set hosts [lindex [split $arguments] 1]
  2591. set hostname [lindex [split $hosts "="] 1]
  2592. regsub {^[-+]} $hostname "" mask
  2593. set nick $::bnick
  2594. set txt $::getnick
  2595. set hand $::userhand
  2596. set host $::userhost
  2597. set chan $::userchan
  2598. set chan1 $::userchan1
  2599. set type $::usertype
  2600. set bantime $::userbantime
  2601. set cmd $::usercmd
  2602. set rs $::userrs
  2603. set gl $::usergl
  2604. if {$hosts == ":"} {
  2605. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotexist $txt
  2606. } else {
  2607. bancmds:process $txt $mask $nick $hand $host $chan $chan1 $type $bantime $cmd $rs $gl
  2608. }
  2609. check:if:bind "userhost:get:host" "302"
  2610. }
  2611. proc userhost:act {why nick hand host chan chan1 type bantime cmd rs gl} {
  2612. global black
  2613. set split_hand [split $hand ":"]
  2614. set rcmd [lindex $cmd 0]
  2615. set regex [lindex $cmd 1]
  2616. set gethand [lindex $split_hand 0]
  2617. set cmd_status [btcmd:status $chan $gethand $rcmd 0]
  2618. set yes_whois 0
  2619. set why [strip:all $why]
  2620. if {$cmd_status == "1"} {
  2621. return
  2622. }
  2623. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  2624. return
  2625. }
  2626. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  2627. return
  2628. }
  2629. if {$why == ""} {
  2630. switch $type {
  2631. 0 {
  2632. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $rcmd
  2633. }
  2634. 1 {
  2635. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $rcmd
  2636. }
  2637. 2 {
  2638. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $rcmd
  2639. }
  2640. }
  2641. return 0
  2642. }
  2643. if {[validchan $chan] && ![onchan $why $chan] && $gl != "1"} {
  2644. set yes_whois 1
  2645. }
  2646. if {$gl == "1"} {
  2647. set yes_whois 1
  2648. }
  2649. if {$regex != "REGEX"} {
  2650. if {$rcmd != "troll"} {
  2651. if {(![regexp {\*} $why]) && $yes_whois == "1"} {
  2652. putserv "USERHOST :$why"
  2653. bind RAW - 302 userhost:get:host
  2654. set ::bnick $nick
  2655. set ::getnick $why
  2656. set ::userhand $hand
  2657. set ::userhost $host
  2658. set ::userchan $chan
  2659. set ::userchan1 $chan1
  2660. set ::usertype $type
  2661. set ::userbantime $bantime
  2662. set ::usercmd $cmd
  2663. set ::userrs $rs
  2664. set ::usergl $gl
  2665. return
  2666. }
  2667. }
  2668. }
  2669. bancmds:process $why $why $nick $hand $host $chan $chan1 $type $bantime $cmd $rs $gl
  2670. }
  2671. ########################### bancmds return host #######################
  2672. proc return_host_num {cmd chan host} {
  2673. global black
  2674. if {$cmd == "b:gl"} {
  2675. return [get:banmask "$cmd" $chan]
  2676. }
  2677. switch [string tolower $cmd] {
  2678. topwords {
  2679. set mask [get:mask "topwords" $chan]
  2680. set check_webchat [check:webchat $host]
  2681. if {$mask == "1" && $check_webchat == "1"} {
  2682. return "5"
  2683. } else {
  2684. return $mask
  2685. }
  2686. }
  2687. hello {
  2688. set mask [get:mask "hello" $chan]
  2689. set check_webchat [check:webchat $host]
  2690. if {$mask == "1" && $check_webchat == "1"} {
  2691. return "5"
  2692. } else {
  2693. return $mask
  2694. }
  2695. }
  2696. mb {
  2697. return "5"
  2698. }
  2699. clonescan {
  2700. return 1
  2701. }
  2702. default {
  2703. set mask [get:banmask $cmd $chan]
  2704. set check_webchat [check:webchat $host]
  2705. if {$mask == "1" && $check_webchat == "1"} {
  2706. return "5"
  2707. } else {
  2708. return $mask
  2709. }
  2710. }
  2711. }
  2712. }
  2713. proc check:webchat {host} {
  2714. global black
  2715. set webchat_found 0
  2716. set host "*!$host"
  2717. foreach h $black(webchat_hosts) {
  2718. if {[string match -nocase $h $host]} {
  2719. set webchat_found 1
  2720. break
  2721. }
  2722. }
  2723. return $webchat_found
  2724. }
  2725. ########################## bancmds process ###########################
  2726. proc bancmds:process {user mask nick hand host chan chan1 type bantime cmd rs gl} {
  2727. global black botnick
  2728. set rcmd [lindex $cmd 0]
  2729. set regex [lindex $cmd 1]
  2730. set split_hand [split $hand ":"]
  2731. set gethand [lindex $split_hand 0]
  2732. set comment ""
  2733. set cmd_status [btcmd:status $chan $gethand $rcmd 0]
  2734. if {$cmd_status == "1"} {
  2735. return
  2736. }
  2737. set getlang [string tolower [setting:get $chan lang]]
  2738. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  2739. set show_user $user
  2740. set handle [nick2hand $user]
  2741. if {[matchattr $gethand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  2742. return
  2743. }
  2744. if {[matchattr $gethand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  2745. return
  2746. }
  2747. if {![validchan $chan] && $gl == "0"} {
  2748. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  2749. return
  2750. }
  2751. if {$gl != "1"} {
  2752. set massban [check:massban $mask $chan]
  2753. if {$massban == "1"} {
  2754. blacktools:tell $nick $host $hand $chan $chan1 b.9 none
  2755. return
  2756. }
  2757. }
  2758. if {[isbotnick $user]} {
  2759. return
  2760. }
  2761. if {$gl != "1"} {
  2762. if {![onchan $botnick $chan]} {
  2763. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  2764. return
  2765. }
  2766. }
  2767. if {$gl != "1"} {
  2768. if {[matchattr $handle $black(exceptflags) $chan]} {
  2769. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2770. return
  2771. }
  2772. } else {
  2773. if {[matchattr $handle $black(glflags)]} {
  2774. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2775. return
  2776. }
  2777. }
  2778. set reason_cmds "b stick black mb"
  2779. if {$rs != "" && [lsearch -exact $reason_cmds $rcmd] > -1} {
  2780. set getreason $rs
  2781. } else {
  2782. if {$rs != ""} {
  2783. if {[regexp {(-comment)} $rs]} {
  2784. set split_it [wsplit $rs "-comment"]
  2785. } elseif {[regexp {(-com)} $rs]} {
  2786. set split_it [wsplit $rs "-com"]
  2787. } elseif {[regexp {(-c)} $rs]} {
  2788. set split_it [wsplit $rs "-c"]
  2789. }
  2790. set comment [concat [lindex $split_it 1]]
  2791. }
  2792. set getreason [setting:get $chan $rcmd-reason]
  2793. }
  2794. if {$getreason == ""} {
  2795. set getreason $black(say.$getlang.$rcmd.5)
  2796. if {$rcmd == "b"} {
  2797. set len [llength $getreason]
  2798. set random [expr int(rand()*$len)]
  2799. set getreason [lindex $getreason $random]
  2800. }
  2801. }
  2802. if {$comment != ""} {
  2803. set getreason "$getreason -c $comment"
  2804. }
  2805. if {![string equal -nocase "$rcmd" "black"] && ![string equal -nocase "$rcmd" "bl"] && ![string equal -nocase "$rcmd" "troll"] && ![string equal -nocase "$rcmd" "b"]} {
  2806. set getbantime [setting:get $chan $rcmd-bantime]
  2807. } else { set getbantime 0 }
  2808. if {[string equal -nocase "$rcmd" "b"] || [string equal -nocase "$rcmd" "stick"]} {
  2809. if {[time_return_minute $bantime] == [time_return_minute $black($rcmd:bantime)]} {
  2810. set setbantime [time_return_minute [setting:get $chan $rcmd-bantime]]
  2811. if {$setbantime == "-1"} {
  2812. set getbantime $bantime
  2813. } else {
  2814. set getbantime $setbantime
  2815. }
  2816. } else { set getbantime "" }
  2817. }
  2818. if {$getbantime == ""} {
  2819. set getbantime $bantime
  2820. }
  2821. if {$rcmd == "troll"} {
  2822. set getbantime $bantime
  2823. }
  2824. if {$gl != "1"} {
  2825. if {![onchan $user $chan] && $rcmd == "troll"} {
  2826. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $show_user
  2827. return
  2828. }
  2829. if {[regexp {\*} $mask] && $rcmd == "mb"} {
  2830. switch $type {
  2831. 0 {
  2832. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $rcmd
  2833. }
  2834. 1 {
  2835. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $rcmd
  2836. }
  2837. 2 {
  2838. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $rcmd
  2839. }
  2840. }
  2841. return
  2842. }
  2843. }
  2844. if {$gl != "1"} {
  2845. if {[onchan $user $chan]} {
  2846. set mask [return_mask [return_host_num $rcmd $chan [getchanhost $user $chan]] [getchanhost $user $chan] $user]
  2847. } elseif {![regexp {\*} $mask] && $regex != "REGEX"} {
  2848. set mask [return_mask [return_host_num $rcmd $chan $mask] $mask $user]
  2849. }
  2850. } else {
  2851. if {![regexp {\*} $mask] && $regex != "REGEX"} {
  2852. set mask [return_mask [return_host_num "$rcmd:gl" $chan $mask] $mask $user]
  2853. }
  2854. }
  2855. if {$gl != "1"} {
  2856. set list [userlist $black(exceptflags) $chan]
  2857. foreach u $list {
  2858. set hosts [getuser $u hosts]
  2859. foreach h $hosts {
  2860. if {[string match -nocase "$mask" $h]} {
  2861. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2862. return
  2863. }
  2864. }
  2865. }
  2866. if {$rcmd == "stick"} {
  2867. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "1" $cmd $nick $user $host
  2868. return
  2869. }
  2870. if {$rcmd == "troll"} {
  2871. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "2" $cmd $nick $user $host
  2872. return
  2873. }
  2874. if {$rcmd == "bot" && [onchan $user $chan]} {
  2875. set getreason "$getreason - $black(say.$getlang.$rcmd.8)"
  2876. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "3" $cmd $nick $user $host
  2877. return
  2878. }
  2879. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "" $cmd $nick $user $host
  2880. } elseif {$gl == "2"} {
  2881. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime "link" "" $cmd $nick $user $host
  2882. } elseif {$gl == "1"} {
  2883. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime "gl" "" $cmd $nick $user $host
  2884. }
  2885. }
  2886. proc check:massban {host chan} {
  2887. global black
  2888. set totuser [llength [chanlist $chan]]
  2889. set counter 0
  2890. foreach user [chanlist $chan] {
  2891. set gethost "$user![getchanhost $user $chan]"
  2892. if {[string match -nocase $host $gethost]} {
  2893. set counter [expr $counter + 1]
  2894. }
  2895. }
  2896. if {[expr 100 * $counter / $totuser] > $black(chanserv:percent_ban)} {
  2897. return 1
  2898. }
  2899. return 0
  2900. }
  2901. ################################## Join Auto Ban #############################
  2902. proc reason:details:module {nick host hand chan} {
  2903. global botnick black
  2904. if {![validchan $chan]} {
  2905. return
  2906. }
  2907. who:nick $nick $chan
  2908. }
  2909. proc blacktools:ban:chanexempt {mask dns chan} {
  2910. global black
  2911. set check_it [matchexempt $mask $chan]
  2912. if {$check_it == "1"} {
  2913. return $check_it
  2914. } else {
  2915. set check_it [matchexempt $mask]
  2916. }
  2917. if {$check_it == "1"} {
  2918. return $check_it
  2919. }
  2920. set check_it [matchexempt $dns $chan]
  2921. if {$check_it == "1"} {
  2922. return $check_it
  2923. } else {
  2924. set check_it [matchexempt $dns]
  2925. }
  2926. if {$check_it == "1"} {
  2927. return $check_it
  2928. }
  2929. return $check_it
  2930. }
  2931. proc blacktools:ban:exempt {mask} {
  2932. global black
  2933. set check_it [matchexempt $mask]
  2934. return $check_it
  2935. }
  2936. ############################ Ban Procedure #########################
  2937. proc blacktools:link_ban {chanlink first b nick hand char chan chan1 type return_time cmd reason num} {
  2938. global black
  2939. set first_chan [lindex $chanlink $first]
  2940. set counter [expr $first + 1]
  2941. if {$first_chan != ""} {
  2942. userhost:act $b $nick "$hand" $char $first_chan $chan1 $type $return_time $cmd $reason "2"
  2943. }
  2944. if {[lindex $chanlink $counter] != ""} {
  2945. utimer 5 [list blacktools:link_ban [link:chan:get $chan] $counter $b $nick $hand $char $chan $chan1 $type $return_time $cmd $reason 2]
  2946. }
  2947. }
  2948. proc blacktools:link_ban2 {chanlink first} {
  2949. global black
  2950. set first_chan [lindex $chanlink $first]
  2951. set counter [expr $first + 1]
  2952. if {$first_chan != ""} {
  2953. who:chan $first_chan
  2954. }
  2955. if {[lindex $chanlink $counter] != ""} {
  2956. utimer 5 [list blacktools:link_ban2 $chanlink $counter]
  2957. }
  2958. }
  2959. #http://wiki.tcl.tk/989
  2960. proc wsplit {string sep} {
  2961. set first [string first $sep $string]
  2962. if {$first == -1} {
  2963. return [list $string]
  2964. } else {
  2965. set l [string length $sep]
  2966. set left [string range $string 0 [expr {$first-1}]]
  2967. set right [string range $string [expr {$first+$l}] end]
  2968. return [concat [list $left] [wsplit $right $sep]]
  2969. }
  2970. }
  2971. ###
  2972. proc blacktools:regex_escape {text} {
  2973. global black
  2974. regsub -all {\W} $text {\\&} text
  2975. return "$text"
  2976. }
  2977. ###
  2978. proc who:nick {nick chan} {
  2979. global black
  2980. putquick "WHO :$nick"
  2981. set ::who_nick $nick
  2982. set ::who_nick_chan $chan
  2983. bind RAW - 352 get:nicklist
  2984. bind RAW - 315 end:nicklist
  2985. }
  2986. proc get:nicklist {from keyword arguments} {
  2987. global black
  2988. set who_nick $::who_nick
  2989. set chan $::who_nick_chan
  2990. set ident [lindex [split $arguments] 2]
  2991. set host [lindex [split $arguments] 3]
  2992. set nick [lindex [split $arguments] 5]
  2993. set realname [strip:all [lrange [split $arguments] 8 end]]
  2994. set uhost "$nick!$ident@$host"
  2995. if {[string equal -nocase $who_nick $nick]} {
  2996. set vhost [lindex [split $uhost @] 1]
  2997. blacktools:dns:join $nick $uhost $vhost "" $chan $realname
  2998. }
  2999. }
  3000. proc end:nicklist {from keyword arguments} {
  3001. global black
  3002. if {[info exists ::who_nick_chan]} {
  3003. unset ::who_nick_chan
  3004. }
  3005. if {[info exists ::who_nick]} {
  3006. unset ::who_nick
  3007. }
  3008. unbind RAW - 352 get:nicklist
  3009. unbind RAW - 315 end:nicklist
  3010. }
  3011. proc who:chan {chan} {
  3012. global black
  3013. if {![botisop $chan] && ![setting:get $chan xonly]} {
  3014. return
  3015. }
  3016. putquick "WHO :$chan"
  3017. set ::thechan $chan
  3018. bind RAW - 352 get:chanlist
  3019. bind RAW - 315 end:chanlist
  3020. }
  3021. proc mode:who:chan {chan} {
  3022. global black
  3023. putquick "WHO :$chan"
  3024. set ::thechan $chan
  3025. bind RAW - 352 get:chanlist
  3026. bind RAW - 315 end:chanlist
  3027. }
  3028. proc get:chanlist {from keyword arguments} {
  3029. global black
  3030. set chan [lindex [split $arguments] 1]
  3031. set ident [lindex [split $arguments] 2]
  3032. set host [lindex [split $arguments] 3]
  3033. set nick [lindex [split $arguments] 5]
  3034. set realname [lrange [split $arguments] 8 end]
  3035. set thechan $::thechan
  3036. set uhost "$nick!$ident@$host"
  3037. if {[string equal -nocase $thechan $chan]} {
  3038. blacktools:auto:ban $nick $uhost $thechan $realname
  3039. }
  3040. }
  3041. proc end:chanlist {from keyword arguments} {
  3042. global black
  3043. unbind RAW - 352 get:chanlist
  3044. unbind RAW - 315 end:chanlist
  3045. if {[info exists ::thechan]} {
  3046. unset ::thechan
  3047. }
  3048. }
  3049. proc blacktools:auto:ban {nick uhost chan realname} {
  3050. global black
  3051. set vhost [lindex [split $uhost @] 1]
  3052. blacktools:dns:auto_ban $nick $uhost $vhost $chan $realname
  3053. }
  3054. proc blacktools:rem_comment {reason} {
  3055. global black
  3056. if {[regexp {(%C%)} $reason]} {
  3057. set is_comment 1
  3058. set split_it [wsplit $reason "%C%"]
  3059. set comment [concat [lindex $split_it 1]]
  3060. set reason [concat [lindex $split_it 0]]
  3061. }
  3062. return $reason
  3063. }
  3064. proc blacktools:rem_comment_ban {reason} {
  3065. global black
  3066. set split_it ""
  3067. if {[regexp {(-comment)} $reason]} {
  3068. set split_it [wsplit $reason "-comment"]
  3069. } elseif {[regexp {(-com)} $reason]} {
  3070. set split_it [wsplit $reason "-com"]
  3071. } elseif {[regexp {(-c)} $reason]} {
  3072. set split_it [wsplit $reason "-c"]
  3073. }
  3074. if {$split_it != ""} {
  3075. set comment [concat [lindex $split_it 1]]
  3076. set reason [concat [lindex $split_it 0]]
  3077. }
  3078. return $reason
  3079. }
  3080. proc blacktools:get_comment {reason} {
  3081. global black
  3082. set comment ""
  3083. if {[regexp {(%C%)} $reason]} {
  3084. set is_comment 1
  3085. set split_it [wsplit $reason "%C%"]
  3086. set comment [concat [lindex $split_it 1]]
  3087. }
  3088. if {$comment != ""} {
  3089. return $comment
  3090. } else { return -1 }
  3091. }
  3092. proc decr { int { n 1 } } {
  3093. if { [ catch {
  3094. uplevel incr $int -$n
  3095. } err ] } {
  3096. return -code error "decr: $err"
  3097. }
  3098. return [ uplevel set $int ]
  3099. }
  3100. proc blacktools:bl:setreason {chan reason bywho expire kcount gl id} {
  3101. global black
  3102. set split_hand [split $bywho ":"]
  3103. set cmd [lindex $split_hand 1]
  3104. set reason [blacktools:rem_comment $reason]
  3105. if {$expire != "0"} {
  3106. set expire [return_reason_time [expr $expire - [unixtime]]]
  3107. }
  3108. set show_reason "$reason"
  3109. if {$gl == "0"} {
  3110. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3111. set show_reason "$show_reason \[id: $id\]"
  3112. }
  3113. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3114. set show_reason "$show_reason \[bantime: $expire\]"
  3115. }
  3116. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3117. set show_reason "$show_reason - [join [setting:get $chan url]]"
  3118. }
  3119. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3120. set show_reason "$show_reason - $kcount -"
  3121. }
  3122. } elseif {$gl == "1"} {
  3123. if {[setting:get $chan showhandle]} {
  3124. set show_reason "\[$bywho\] (GLOBAL) $reason"
  3125. } else { set show_reason "(GLOBAL) $reason" }
  3126. if {[setting:get $chan showid]} {
  3127. set show_reason "$show_reason \[id: $id\]"
  3128. }
  3129. } else {
  3130. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3131. set show_reason "(REGEX) $show_reason \[id: $id\]"
  3132. }
  3133. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3134. set show_reason "(REGEX) $show_reason \[bantime: $expire\]"
  3135. }
  3136. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3137. set show_reason "(REGEX) $show_reason - [join [setting:get $chan url]]"
  3138. }
  3139. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3140. set show_reason "(REGEX) $show_reason - $kcount -"
  3141. }
  3142. }
  3143. return $show_reason
  3144. }
  3145. proc blacktools:setreason {chan reason bywho expire kcount gl id} {
  3146. global black
  3147. set split_hand [split $bywho ":"]
  3148. set gethand [lindex $split_hand 0]
  3149. set cmd [lindex $split_hand 1]
  3150. set reason [blacktools:rem_comment $reason]
  3151. if {$expire != "0"} {
  3152. set expire [return_reason_time [expr $expire - [unixtime]]]
  3153. }
  3154. if {$gl == "0"} {
  3155. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  3156. if {[setting:get $chan showhandle] && $gethand != ""} {
  3157. set show_reason "\[$gethand\] $reason"
  3158. } else { set show_reason "$reason" }
  3159. } else {
  3160. set show_reason "$reason"
  3161. }
  3162. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3163. set show_reason "$show_reason \[id: $id\]"
  3164. }
  3165. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3166. set show_reason "$show_reason \[bantime: $expire\]"
  3167. }
  3168. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3169. set show_reason "$show_reason - [join [setting:get $chan url]]"
  3170. }
  3171. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3172. set show_reason "$show_reason - $kcount -"
  3173. }
  3174. } elseif {$gl == "1"} {
  3175. if {[setting:get $chan showhandle]} {
  3176. set show_reason "\[$bywho\] (GLOBAL) $reason"
  3177. } else { set show_reason "(GLOBAL) $reason" }
  3178. if {[setting:get $chan showid]} {
  3179. set show_reason "$show_reason \[id: $id\]"
  3180. }
  3181. } elseif {$gl == "3"} {
  3182. if {[setting:get $chan showhandle]} {
  3183. set show_reason "\[$bywho\] (GLOBAL) (REGEX) $reason"
  3184. } else { set show_reason "(GLOBAL) (REGEX) $reason" }
  3185. } else {
  3186. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  3187. if {[setting:get $chan showhandle] && $gethand != ""} {
  3188. set show_reason "\[$gethand\] (REGEX) $reason"
  3189. } else { set show_reason "(REGEX) $reason" }
  3190. } else {
  3191. set show_reason "$reason"
  3192. }
  3193. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3194. set show_reason "(REGEX) $show_reason \[id: $id\]"
  3195. }
  3196. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3197. set show_reason "(REGEX) $show_reason \[bantime: $expire\]"
  3198. }
  3199. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3200. set show_reason "(REGEX) $show_reason - [join [setting:get $chan url]]"
  3201. }
  3202. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3203. set show_reason "(REGEX) $show_reason - $kcount -"
  3204. }
  3205. }
  3206. return $show_reason
  3207. }
  3208. proc blacktools:check:levelban {hand chan level} {
  3209. global black
  3210. if {[lsearch -exact -nocase $level "-c"] > -1} {
  3211. return ""
  3212. } elseif {[lsearch -nocase $level "-com"] > -1} {
  3213. return ""
  3214. } elseif {[lsearch -nocase $level "-comment"] > -1} {
  3215. return ""
  3216. }
  3217. set level [string map {"-" ""} $level]
  3218. set levels ""
  3219. if {[matchattr $hand o]} {
  3220. set levels "[string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]] [string tolower [blacktools:getlevelname 8 $hand]]"
  3221. set split_levels [split $levels " "]
  3222. foreach l $split_levels {
  3223. if {[string equal -nocase $l $level]} {
  3224. return $l
  3225. }
  3226. }
  3227. }
  3228. if {[matchattr $hand nm]} {
  3229. set levels "[string tolower [blacktools:getlevelname 2 $hand]] [string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]] [string tolower [blacktools:getlevelname 8 $hand]]"
  3230. set split_levels [split $levels " "]
  3231. foreach l $split_levels {
  3232. if {[string equal -nocase $l $level]} {
  3233. return $l
  3234. }
  3235. }
  3236. }
  3237. if {[matchattr $hand -|M $chan]} {
  3238. set levels "[string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]]"
  3239. set split_levels [split $levels " "]
  3240. foreach l $split_levels {
  3241. if {[string equal -nocase $l $level]} {
  3242. return $l
  3243. }
  3244. }
  3245. }
  3246. if {[matchattr $hand -|A $chan]} {
  3247. set levels "[string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]]"
  3248. set split_levels [split $levels " "]
  3249. foreach l $split_levels {
  3250. if {[string equal -nocase $l $level]} {
  3251. return $l
  3252. }
  3253. }
  3254. }
  3255. if {[matchattr $hand -|O $chan]} {
  3256. set levels "[string tolower [blacktools:getlevelname 5 $hand]]"
  3257. set split_levels [split $levels " "]
  3258. foreach l $split_levels {
  3259. if {[string equal -nocase $l $level]} {
  3260. return $l
  3261. }
  3262. }
  3263. }
  3264. return "0 [join [string toupper $levels] ", "]"
  3265. }
  3266. proc blacktools:check:levelub {hand chan level} {
  3267. global black
  3268. set getlevel ""
  3269. if {[string equal -nocase $level [blacktools:getlevelname 2 $hand]] || [string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3270. if {[matchattr $hand nm]} {
  3271. set getlevel [blacktools:getlevelname 2 $hand]
  3272. } elseif {[matchattr $hand o]} {
  3273. set getlevel [blacktools:getlevelname 8 $hand]
  3274. } elseif {[matchattr $hand -|M $chan]} {
  3275. set getlevel [blacktools:getlevelname 3 $hand]
  3276. } elseif {[matchattr $hand -|A $chan]} {
  3277. set getlevel [blacktools:getlevelname 4 $hand]
  3278. } elseif {[matchattr $hand -|O $chan]} {
  3279. set getlevel [blacktools:getlevelname 5 $hand]
  3280. }
  3281. if {[string equal -nocase $getlevel [blacktools:getlevelname 2 $hand]]} {
  3282. if {[string equal -nocase $level [blacktools:getlevelname 2 $hand]] || [string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3283. return 1
  3284. }
  3285. }
  3286. if {[string equal -nocase $getlevel [blacktools:getlevelname 8 $hand]]} {
  3287. if {[string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3288. return 1
  3289. }
  3290. }
  3291. if {[string equal -nocase $getlevel [blacktools:getlevelname 3 $hand]]} {
  3292. if {[string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3293. return 1
  3294. }
  3295. }
  3296. if {[string equal -nocase $getlevel [blacktools:getlevelname 4 $hand]]} {
  3297. if {[string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3298. return 1
  3299. }
  3300. }
  3301. if {[string equal -nocase $getlevel [blacktools:getlevelname 5 $hand]]} {
  3302. if {[string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3303. return 1
  3304. }
  3305. }
  3306. } else { return 0 }
  3307. return -1
  3308. }
  3309. ################################### Login ###############################
  3310. proc loginpublic:start {} {
  3311. global black botnick
  3312. if {$black(autologin) == "0"} {
  3313. return
  3314. }
  3315. if {[info exists black(logged)]} {
  3316. putlog "\002\[BT\]\002 Still logged.."
  3317. return
  3318. }
  3319. chanserv:ignore_remove
  3320. if {[info exists black(notlogged:invalid)]} {
  3321. unset black(notlogged:invalid)
  3322. }
  3323. if {[info exists black(notlogged:failed)]} {
  3324. unset black(notlogged:failed)
  3325. }
  3326. if {[info exists black(notlogged)]} {
  3327. unset black(notlogged)
  3328. }
  3329. putserv "PRIVMSG $black(hostchanserv) :login $black(username) $black(password)"
  3330. putserv "PRIVMSG $black(hostchanserv) :set lang EN"
  3331. putserv "MODE $botnick :$black(xmod)"
  3332. bind RAW - 401 check:chanserv
  3333. }
  3334. proc loginpublic {my} {
  3335. global botnick black
  3336. if {$black(autologin) == "0"} {
  3337. return
  3338. }
  3339. chanserv:ignore_remove
  3340. if {[info exists black(logged)]} {
  3341. unset black(logged)
  3342. }
  3343. if {[info exists black(notlogged)]} {
  3344. unset black(notlogged)
  3345. }
  3346. putserv "PRIVMSG $black(hostchanserv) :login $black(username) $black(password)"
  3347. putserv "MODE $botnick :$black(xmod)"
  3348. bind RAW - 401 check:chanserv
  3349. }
  3350. ########################## show line output ##########################
  3351. proc module:getinfo {nick host hand chan chan1 type text modul gl next} {
  3352. global black
  3353. set remain 0
  3354. set top ""
  3355. set split_modul [split $modul ":"]
  3356. set themodul [lindex $split_modul 0]
  3357. if {$themodul == "topwords" || $themodul == "topbans"} {
  3358. set maxentries "10"
  3359. } else {
  3360. set maxentries $black(modul:nr:entries)
  3361. }
  3362. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3363. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3364. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  3365. if {$getmethod == ""} { set getmethod $black(default_output) }
  3366. if {[string equal -nocase $next "-next"]} {
  3367. if {[info exists black($modul:more:$chan:$hand)]} {
  3368. if {$black($modul:more:$chan:$hand) >= $maxentries} {
  3369. for {set i $black($modul:show:$chan:$hand)} { $i < [expr $black($modul:show:$chan:$hand) + $maxentries] } { incr i } {
  3370. set current_text [lindex $text $i]
  3371. if {$themodul == "topwords" || $themodul == "topbans"} {
  3372. if {$current_text != ""} {
  3373. set nr_text [lindex [split $current_text] 0]
  3374. set read_nick [lindex [split $current_text] 1]
  3375. set counter [lindex [split $current_text] 2]
  3376. lappend top $read_nick:$nr_text:$counter
  3377. }
  3378. } else {
  3379. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3380. }
  3381. }
  3382. if {$themodul == "topwords" || $themodul == "topbans"} {
  3383. if {$black($modul:more:$chan:$hand) > 0} {
  3384. set remain 1
  3385. }
  3386. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3387. }
  3388. set black($modul:more:$chan:$hand) [expr $black($modul:more:$chan:$hand) - $maxentries]
  3389. if {$host == "prv"} {
  3390. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "1"
  3391. } else {
  3392. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "0"
  3393. }
  3394. set black($modul:show:$chan:$hand) [expr $black($modul:show:$chan:$hand) + $maxentries]
  3395. } else {
  3396. if {$black($modul:more:$chan:$hand) < 1} {
  3397. return
  3398. }
  3399. for {set i $black($modul:show:$chan:$hand)} { $i <= [expr $black($modul:show:$chan:$hand) + $black($modul:more:$chan:$hand)]} { incr i } {
  3400. set current_text [lindex $text $i]
  3401. if {$themodul == "topwords" || $themodul == "topbans"} {
  3402. if {$current_text != ""} {
  3403. set nr_text [lindex [split $current_text] 0]
  3404. set read_nick [lindex [split $current_text] 1]
  3405. set counter [lindex [split $current_text] 2]
  3406. lappend top $read_nick:$nr_text:$counter
  3407. }
  3408. } else {
  3409. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3410. }
  3411. }
  3412. if {$themodul == "topwords" || $themodul == "topbans"} {
  3413. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3414. }
  3415. set black($modul:more:$chan:$hand) [expr $black($modul:more:$chan:$hand) - $black($modul:show:$chan:$hand)]
  3416. }
  3417. foreach tmr [utimers] {
  3418. if {[string match -nocase "*module:getinfo:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  3419. killutimer [lindex $tmr 2]
  3420. }
  3421. }
  3422. utimer 30 [list module:getinfo:unset:more $chan $hand $modul]
  3423. if {$black($modul:more:$chan:$hand) < 1} {
  3424. switch $themodul {
  3425. badchan {
  3426. blacktools:tell $nick $host $hand $chan $chan1 $modul.4 none
  3427. }
  3428. notesinbox {
  3429. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3430. }
  3431. noteslist {
  3432. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3433. }
  3434. anunt {
  3435. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3436. }
  3437. tcl {
  3438. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3439. }
  3440. quote {
  3441. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3442. }
  3443. autobroadcast {
  3444. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3445. }
  3446. topwords {
  3447. }
  3448. topbans {
  3449. }
  3450. badword {
  3451. blacktools:tell $nick $host $hand $chan $chan1 antibadword.3 none
  3452. }
  3453. badquitpart {
  3454. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.3 none
  3455. }
  3456. default {
  3457. blacktools:tell $nick $host $hand $chan $chan1 $themodul.3 none
  3458. }
  3459. }
  3460. }
  3461. }
  3462. return
  3463. }
  3464. switch $themodul {
  3465. badchan {
  3466. if {$gl == "1"} {
  3467. blacktools:tell $nick $host $hand $chan $chan1 $modul.15 none
  3468. } else {
  3469. blacktools:tell $nick $host $hand $chan $chan1 $modul.14 none
  3470. }
  3471. }
  3472. anunt {
  3473. blacktools:tell $nick $host $hand $chan $chan1 $modul.8 none
  3474. }
  3475. tcl {
  3476. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3477. }
  3478. notesinbox {
  3479. }
  3480. noteslist {
  3481. }
  3482. quote {
  3483. blacktools:tell $nick $host $hand $chan $chan1 $modul.8 none
  3484. }
  3485. autobroadcast {
  3486. blacktools:tell $nick $host $hand $chan $chan1 $modul.9 none
  3487. }
  3488. topwords {
  3489. }
  3490. topbans {
  3491. }
  3492. badword {
  3493. blacktools:tell $nick $host $hand $chan $chan1 antibadword.7 none
  3494. }
  3495. badquitpart {
  3496. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.7 none
  3497. }
  3498. default {
  3499. blacktools:tell $nick $host $hand $chan $chan1 $themodul.7 none
  3500. }
  3501. }
  3502. set black($modul:ltext:$chan:$hand) [llength $text]
  3503. set black($modul:show:$chan:$hand) 0
  3504. if {$black($modul:ltext:$chan:$hand) > $maxentries} {
  3505. set black($modul:more:$chan:$hand) [expr $black($modul:ltext:$chan:$hand) - $maxentries]
  3506. for {set i 0} { $i < $maxentries } { incr i } {
  3507. set current_text [lindex $text $i]
  3508. if {$themodul == "topwords" || $themodul == "topbans"} {
  3509. if {$current_text != ""} {
  3510. set nr_text [lindex [split $current_text] 0]
  3511. set read_nick [lindex [split $current_text] 1]
  3512. set counter [lindex [split $current_text] 2]
  3513. lappend top $read_nick:$nr_text:$counter
  3514. }
  3515. } else {
  3516. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3517. }
  3518. }
  3519. if {$themodul == "topwords" || $themodul == "topbans"} {
  3520. if {$black($modul:more:$chan:$hand) > 0} {
  3521. set remain 1
  3522. }
  3523. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3524. }
  3525. set black($modul:show:$chan:$hand) [expr $black($modul:show:$chan:$hand) + $maxentries]
  3526. if {$black($modul:more:$chan:$hand) > 0} {
  3527. if {$host == "prv"} {
  3528. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "1"
  3529. } else {
  3530. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "0"
  3531. }
  3532. }
  3533. foreach tmr [utimers] {
  3534. if {[string match -nocase "*module:getinfo:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  3535. killutimer [lindex $tmr 2]
  3536. }
  3537. }
  3538. utimer 60 [list module:getinfo:unset:more $chan $hand $modul]
  3539. } else {
  3540. for {set i 0} { $i < $maxentries } { incr i } {
  3541. set current_text [lindex $text $i]
  3542. if {$themodul == "topwords" || $themodul == "topbans"} {
  3543. if {$current_text != ""} {
  3544. set nr_text [lindex [split $current_text] 0]
  3545. set read_nick [lindex [split $current_text] 1]
  3546. set counter [lindex [split $current_text] 2]
  3547. lappend top $read_nick:$nr_text:$counter
  3548. }
  3549. } else {
  3550. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3551. }
  3552. }
  3553. if {$themodul == "topwords" || $themodul == "topbans"} {
  3554. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3555. }
  3556. switch $themodul {
  3557. badchan {
  3558. blacktools:tell $nick $host $hand $chan $chan1 $modul.4 none
  3559. }
  3560. anunt {
  3561. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3562. }
  3563. tcl {
  3564. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3565. }
  3566. notesinbox {
  3567. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3568. }
  3569. noteslist {
  3570. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3571. }
  3572. quote {
  3573. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3574. }
  3575. autobroadcast {
  3576. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3577. }
  3578. topwords {
  3579. }
  3580. topbans {
  3581. }
  3582. badword {
  3583. blacktools:tell $nick $host $hand $chan $chan1 antibadword.3 none
  3584. }
  3585. badquitpart {
  3586. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.3 none
  3587. }
  3588. default {
  3589. blacktools:tell $nick $host $hand $chan $chan1 $themodul.3 none
  3590. }
  3591. }
  3592. }
  3593. }
  3594. proc module:getinfo:unset:more {chan hand modul} {
  3595. global black
  3596. if {[info exists black($modul:more:$chan:$hand)]} {
  3597. unset black($modul:more:$chan:$hand)
  3598. }
  3599. if {[info exists black($modul:ltext:$chan:$hand)]} {
  3600. unset black($modul:ltext:$chan:$hand)
  3601. }
  3602. if {[info exists black($modul:show:$chan:$hand)]} {
  3603. unset black($modul:show:$chan:$hand)
  3604. }
  3605. }
  3606. proc show:modul:info {nick host hand chan chan1 text modul remain} {
  3607. global black lastbind
  3608. set split_modul [split $modul ":"]
  3609. set themodul [lindex $split_modul 0]
  3610. set total [lindex $split_modul 1]
  3611. set otherchan 0
  3612. set top ""
  3613. if {$chan != $chan1} {
  3614. set otherchan 1
  3615. }
  3616. if {$text == ""} { return }
  3617. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3618. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3619. if {$themodul == "topwords" || $themodul == "topbans"} {
  3620. foreach entry $text {
  3621. set split_entry [split $entry ":"]
  3622. set nickname [lindex $split_entry 1]
  3623. set word_count [lindex $split_entry 0]
  3624. set place [lindex $split_entry 2]
  3625. lappend top "\002#$place\002. $nickname ($word_count)"
  3626. }
  3627. if {$remain == "1"} {
  3628. set split_lastbind [split $lastbind ""]
  3629. set charbind [lindex $split_lastbind 0]
  3630. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  3631. set charbind ""
  3632. }
  3633. set replace(%char%) $charbind
  3634. set replace(%chan%) $chan
  3635. if {[string equal -nocase $total "total"]} {
  3636. if {$otherchan == "1"} {
  3637. set others [string map [array get replace] $black(say.$getlang.$themodul.12)]
  3638. } else {
  3639. set others [string map [array get replace] $black(say.$getlang.$themodul.11)]
  3640. }
  3641. } elseif {[string equal -nocase $total "week"]} {
  3642. if {$otherchan == "1"} {
  3643. set others [string map [array get replace] $black(say.$getlang.$themodul.25)]
  3644. } else {
  3645. set others [string map [array get replace] $black(say.$getlang.$themodul.26)]
  3646. }
  3647. } else {
  3648. if {$otherchan == "1"} {
  3649. set others [string map [array get replace] $black(say.$getlang.$themodul.13)]
  3650. } else {
  3651. set others [string map [array get replace] $black(say.$getlang.$themodul.9)]
  3652. }
  3653. }
  3654. if {[string equal -nocase $total "total"]} {
  3655. blacktools:tell $nick $host $hand $chan $chan1 $themodul.1 "[join $top] $others"
  3656. } elseif {[string equal -nocase $total "week"]} {
  3657. blacktools:tell $nick $host $hand $chan $chan1 $themodul.24 "[join $top] $others"
  3658. } else {
  3659. blacktools:tell $nick $host $hand $chan $chan1 $themodul.2 "[join $top] $others"
  3660. }
  3661. } else {
  3662. if {[string equal -nocase $total "total"]} {
  3663. blacktools:tell $nick $host $hand $chan $chan1 $themodul.1 "[join $top]"
  3664. } elseif {[string equal -nocase $total "week"]} {
  3665. blacktools:tell $nick $host $hand $chan $chan1 $themodul.24 "[join $top]"
  3666. } else {
  3667. blacktools:tell $nick $host $hand $chan $chan1 $themodul.2 "[join $top]"
  3668. }
  3669. }
  3670. return
  3671. }
  3672. set num [lindex [split $text] 0]
  3673. set gettext [join [lrange [split $text] 1 end]]
  3674. set encoded [encoding convertfrom utf-8 $gettext]
  3675. set gettext [lindex [split $text] 0]
  3676. blacktools:tell $nick $host $hand $chan $chan1 gl.showline "$num [join $encoded]"
  3677. }
  3678. proc modul:remain {nick host hand count chan chan1 type modul gl prv} {
  3679. global black lastbind botnick
  3680. set otherchan 0
  3681. set charbind ""
  3682. if {$chan != $chan1} {
  3683. set otherchan 1
  3684. }
  3685. if {$count == "0"} { return }
  3686. set split_modul [split $modul ":"]
  3687. set themodul [lindex $split_modul 0]
  3688. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3689. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3690. set firstchar [lindex $black(cmdchar) 0]
  3691. if {[string equal $lastbind "*"]} {
  3692. set charbind "prv" } elseif {[string equal -nocase "**" $lastbind]} { set charbind "$botnick "
  3693. } elseif {[string equal -nocase "***" $lastbind]} {
  3694. set split_host [split $host ":"]
  3695. if {[lindex $split_host 1] == "chan"} {
  3696. set host [lindex $split_host 1]
  3697. set charbind [lindex $split_host 0]
  3698. } else {
  3699. set charbind "$host"
  3700. }
  3701. }
  3702. if {$charbind == ""} {
  3703. set charbind $firstchar
  3704. if {[validuser $hand]} {
  3705. set getchar [getuser $hand XTRA MYCHAR]
  3706. if {$getchar != ""} {
  3707. set charbind $getchar
  3708. }
  3709. }
  3710. }
  3711. if {$charbind == "prv"} { set charbind "" }
  3712. set replace(%char%) $charbind
  3713. set replace(%counter%) $count
  3714. set replace(%chan%) $chan
  3715. switch [string tolower $themodul] {
  3716. badchan {
  3717. if {$otherchan == "1" || $prv == "1"} {
  3718. set msg $black(say.$getlang.$modul.41)
  3719. } else {
  3720. set msg $black(say.$getlang.$modul.3)
  3721. }
  3722. if {$gl == "1"} {
  3723. set msg $black(say.$getlang.$modul.2)
  3724. }
  3725. }
  3726. anunt {
  3727. if {$otherchan == "1" || $prv == "1"} {
  3728. set msg $black(say.$getlang.$modul.14)
  3729. } else {
  3730. set msg $black(say.$getlang.$modul.9)
  3731. }
  3732. }
  3733. tcl {
  3734. set msg $black(say.$getlang.$modul.9)
  3735. }
  3736. notesinbox {
  3737. if {$otherchan == "1" || $prv == "1"} {
  3738. set msg $black(say.$getlang.$modul.16)
  3739. } else {
  3740. set msg $black(say.$getlang.$modul.15)
  3741. }
  3742. }
  3743. noteslist {
  3744. if {$otherchan == "1" || $prv == "1"} {
  3745. set msg $black(say.$getlang.$modul.16)
  3746. } else {
  3747. set msg $black(say.$getlang.$modul.15)
  3748. }
  3749. }
  3750. quote {
  3751. if {$otherchan == "1" || $prv == "1"} {
  3752. set msg $black(say.$getlang.$modul.14)
  3753. } else {
  3754. set msg $black(say.$getlang.$modul.9)
  3755. }
  3756. }
  3757. topwords {
  3758. set msg ""
  3759. }
  3760. topbans {
  3761. set msg ""
  3762. }
  3763. autobroadcast {
  3764. set msg $black(say.$getlang.$modul.12)
  3765. }
  3766. badword {
  3767. if {$otherchan == "1" || $prv == "1"} {
  3768. set msg $black(say.$getlang.antibadword.9)
  3769. } else {
  3770. set msg $black(say.$getlang.antibadword.8)
  3771. }
  3772. }
  3773. badquitpart {
  3774. if {$otherchan == "1" || $prv == "1"} {
  3775. set msg $black(say.$getlang.antibadquitpart.9)
  3776. } else {
  3777. set msg $black(say.$getlang.antibadquitpart.8)
  3778. }
  3779. }
  3780. default {
  3781. if {$otherchan == "1" || $prv == "1"} {
  3782. set msg $black(say.$getlang.$themodul.9)
  3783. } else {
  3784. set msg $black(say.$getlang.$themodul.8)
  3785. }
  3786. }
  3787. }
  3788. if {$msg == ""} {
  3789. return
  3790. }
  3791. blacktools:tell:cmd $nick $host $hand $chan $chan1 $prv $type [string map [array get replace] $msg]
  3792. }
  3793. ########################## Other Module Process ######################
  3794. proc othermodule:process {nick host hand chan chan1 who msg type modul} {
  3795. global black botnick
  3796. set cmd_status [btcmd:status $chan $hand $modul 0]
  3797. if {$cmd_status == "1"} {
  3798. return
  3799. }
  3800. if {[matchattr $hand q]} {
  3801. blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  3802. return
  3803. }
  3804. if {[matchattr $hand -|q $chan]} {
  3805. blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  3806. return
  3807. }
  3808. if {![validchan $chan]} {
  3809. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3810. return
  3811. }
  3812. if {![onchan $botnick $chan]} {
  3813. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  3814. return
  3815. }
  3816. switch $who {
  3817. on {
  3818. if {[string equal -nocase $modul "topic"]} {
  3819. return
  3820. }
  3821. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3822. setting:set $chan +$modul ""
  3823. }
  3824. off {
  3825. if {[string equal -nocase $modul "topic"]} {
  3826. return
  3827. }
  3828. blacktools:tell $nick $host $hand $chan $chan1 $modul.3 none
  3829. setting:set $chan -$modul ""
  3830. }
  3831. unset {
  3832. if {[string equal -nocase $modul "topic"]} {
  3833. putserv "TOPIC $chan :"
  3834. msg:del $chan $modul
  3835. blacktools:tell $nick $host $hand $chan $chan1 topic.4 none
  3836. }
  3837. }
  3838. set {
  3839. if {![string equal -nocase $modul "topic"]} {
  3840. if {$msg == ""} {
  3841. switch $type {
  3842. 0 {
  3843. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3844. }
  3845. 1 {
  3846. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $modul
  3847. }
  3848. 2 {
  3849. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $modul
  3850. }
  3851. }
  3852. return
  3853. }
  3854. }
  3855. if {[string equal -nocase $modul "topic"]} {
  3856. set thetopic [topic $chan]
  3857. set url [join [setting:get $chan url]]
  3858. if {$msg == ""} {
  3859. if {$url != ""} {
  3860. set gettopic [string map [list "([color:filter $url])" ""] [color:filter $thetopic]]
  3861. } else { set gettopic $thetopic }
  3862. set msg $gettopic
  3863. }
  3864. if {$msg == ""} {
  3865. blacktools:tell $nick $host $hand $chan $chan1 topic.2 none
  3866. return
  3867. }
  3868. if {$thetopic != $msg} {
  3869. blacktools:tell $nick $host $hand $chan $chan1 topic.1 $msg
  3870. if {$url != ""} {
  3871. putserv "TOPIC $chan :$msg ($url)"
  3872. } else { putserv "TOPIC $chan :$msg" }
  3873. } else {
  3874. blacktools:tell $nick $host $hand $chan $chan1 topic.3 $msg
  3875. }
  3876. msg:add $msg $chan $modul
  3877. return
  3878. }
  3879. msg:add $msg $chan $modul
  3880. blacktools:tell $nick $host $hand $chan $chan1 $modul.1 $msg
  3881. }
  3882. show {
  3883. set getline ""
  3884. set file [open $black(join_file) r]
  3885. while {[gets $file line] != -1} {
  3886. set read_modul [lindex [split $line] 0]
  3887. set read_chan [lindex [split $line] 1]
  3888. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $read_chan]} {
  3889. set read_msg [lrange [split $line] 2 end]
  3890. set getline [encoding convertfrom utf-8 $read_msg]
  3891. continue
  3892. }
  3893. }
  3894. close $file
  3895. blacktools:tell $nick $host $hand $chan $chan1 show.6 "$modul $getline"
  3896. }
  3897. default {
  3898. switch $type {
  3899. 0 {
  3900. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3901. }
  3902. 1 {
  3903. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $modul
  3904. }
  3905. 2 {
  3906. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $modul
  3907. }
  3908. }
  3909. }
  3910. }
  3911. }
  3912. proc msg:del {chan modul} {
  3913. global black
  3914. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  3915. set temp "$black(tempdir)/othermodule_temp.$timestamp"
  3916. set file [open $black(join_file) r]
  3917. set tempwrite [open $temp w]
  3918. while {[gets $file line] != -1} {
  3919. set read_modul [lindex [split $line] 0]
  3920. set read_chan [lindex [split $line] 1]
  3921. set enc_chan [encoding convertfrom utf-8 $read_chan]
  3922. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $enc_chan]} {
  3923. continue
  3924. } else {
  3925. puts $tempwrite $line
  3926. }
  3927. }
  3928. close $tempwrite
  3929. close $file
  3930. file rename -force $temp $black(join_file)
  3931. }
  3932. proc msg:add {msg chan modul} {
  3933. global black
  3934. set msg [encoding convertto utf-8 $msg]
  3935. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  3936. set temp "$black(tempdir)/othermodule_temp.$timestamp"
  3937. set file [open $black(join_file) r]
  3938. set tempwrite [open $temp w]
  3939. while {[gets $file line] != -1} {
  3940. set read_modul [lindex [split $line] 0]
  3941. set read_chan [lindex [split $line] 1]
  3942. set enc_chan [encoding convertfrom utf-8 $read_chan]
  3943. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $enc_chan]} {
  3944. continue
  3945. } else {
  3946. puts $tempwrite $line
  3947. }
  3948. }
  3949. close $tempwrite
  3950. close $file
  3951. file rename -force $temp $black(join_file)
  3952. set file [open $black(join_file) a]
  3953. set enc_chan [encoding convertto utf-8 $chan]
  3954. puts $file "[string toupper $modul] $enc_chan $msg"
  3955. close $file
  3956. }
  3957. ######################### Channel Remove Data ####################
  3958. proc delchan:all {chan} {
  3959. global black
  3960. if {$black(chanremove_all) == "0"} {
  3961. return
  3962. }
  3963. set files "$black(s_file) $black(seen_file) $black(bans_file) $black(join_file) $black(extra_file) $black(add_file) $black(quote_file)"
  3964. set split_files [split $files " "]
  3965. remove:chan:now $split_files 0 $chan
  3966. topwords:delete $chan
  3967. }
  3968. proc remove:chan:timer {minute hour day month year} {
  3969. global black
  3970. if {$black(chanremove_all) == "0"} {
  3971. return
  3972. }
  3973. set files "$black(s_file) $black(seen_file) $black(bans_file) $black(join_file) $black(extra_file) $black(add_file) $black(quote_file)"
  3974. set split_files [split $files " "]
  3975. remove:chan:now_timer $split_files 0
  3976. }
  3977. proc remove:chan:now_timer {files num} {
  3978. global black
  3979. set f [lindex $files $num]
  3980. if {[string match -nocase "*seen*" $f] || [string match -nocase *othermodule* $f]} {
  3981. set pos 1
  3982. } elseif {[string match -nocase "*bans*" $f]} {
  3983. set pos 2
  3984. } else {
  3985. set pos 0
  3986. }
  3987. set inc [expr $num + 1]
  3988. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  3989. set temp "$black(tempdir)/removechan_temp.$timestamp"
  3990. set file [open $f r]
  3991. set tempwrite [open $temp w]
  3992. while {[gets $file line] != -1} {
  3993. if {$line != ""} {
  3994. set chan [lindex [split $line] $pos]
  3995. set encoded [encoding convertfrom utf-8 $chan]
  3996. if {[regexp {^[&#]} $encoded] && ![validchan $encoded]} {
  3997. continue
  3998. } else {
  3999. puts $tempwrite $line
  4000. }
  4001. }
  4002. }
  4003. close $tempwrite
  4004. close $file
  4005. file rename -force $temp $f
  4006. if {[lindex $files $inc] != ""} {
  4007. utimer 3 [list remove:chan:now_timer $files $inc]
  4008. }
  4009. }
  4010. proc remove:chan:now {files num c} {
  4011. global black
  4012. set f [lindex $files $num]
  4013. if {[string match -nocase "*seen*" $f] || [string match -nocase *othermodule* $f]} {
  4014. set pos 1
  4015. } elseif {[string match -nocase "*bans*" $f]} {
  4016. set pos 2
  4017. } else {
  4018. set pos 0
  4019. }
  4020. set inc [expr $num + 1]
  4021. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4022. set temp "$black(tempdir)/removechan_temp.$timestamp"
  4023. set file [open $f r]
  4024. set tempwrite [open $temp w]
  4025. while {[gets $file line] != -1} {
  4026. if {$line != ""} {
  4027. set chan [lindex [split $line] $pos]
  4028. set encoded [encoding convertfrom utf-8 $chan]
  4029. if {[string equal -nocase $c $encoded]} {
  4030. continue
  4031. } else {
  4032. puts $tempwrite $line
  4033. }
  4034. }
  4035. }
  4036. close $tempwrite
  4037. close $file
  4038. file rename -force $temp $f
  4039. if {[lindex $files $inc] != ""} {
  4040. utimer 3 [list remove:chan:now $files $inc $c]
  4041. }
  4042. }
  4043. ########################### Extra settings ########################
  4044. proc btcmd:global:set {hand cmd type} {
  4045. global black
  4046. if {[lsearch -exact $black(validcmds) $cmd] < 0} {
  4047. return 2
  4048. }
  4049. if {[string equal -nocase "enable" $cmd]} {
  4050. return 3
  4051. }
  4052. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4053. set temp "$black(tempdir)/add_file_temp.$timestamp"
  4054. set file [open $black(add_file) r]
  4055. set tempwrite [open $temp w]
  4056. set cmd_found 0
  4057. set disable_type 0
  4058. while {[gets $file line] != -1} {
  4059. set c [lindex [split $line] 0]
  4060. set gettype [lindex [split $line] 1]
  4061. set comp [lindex [split $line] 2]
  4062. if {[string equal -nocase $c "disable"] && [string equal -nocase $gettype "global"] && [string equal -nocase $comp $cmd]} {
  4063. set cmd_found 1
  4064. continue
  4065. } else {
  4066. puts $tempwrite $line
  4067. }
  4068. }
  4069. close $tempwrite
  4070. close $file
  4071. file rename -force $temp $black(add_file)
  4072. if {$type == "1"} {
  4073. set file [open $black(add_file) a]
  4074. puts $file "DISABLE GLOBAL [string toupper $cmd] $type"
  4075. close $file
  4076. }
  4077. return $cmd_found
  4078. }
  4079. proc btcmd:gl:status {cmd} {
  4080. global black
  4081. set file [open $black(add_file) r]
  4082. set cmd_found 0
  4083. while {[gets $file line] != -1} {
  4084. set disable [lindex [split $line] 0]
  4085. set c [lindex [split $line] 1]
  4086. set gettype [lindex [split $line] 2]
  4087. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4088. set cmd_found 1
  4089. continue
  4090. }
  4091. }
  4092. close $file
  4093. return $cmd_found
  4094. }
  4095. proc btcmd:status {chan hand cmd menureply} {
  4096. global black
  4097. set cmd_found 0
  4098. set access ""
  4099. set split_hand [split $hand ":"]
  4100. set hand [lindex $split_hand 0]
  4101. if {[matchattr $hand -|M $chan]} {
  4102. set access "MANAGER"
  4103. } elseif {[matchattr $hand n]} {
  4104. set access "BOSS"
  4105. } elseif {[matchattr $hand m]} {
  4106. set access "OWNER"
  4107. } elseif {[matchattr $hand o]} {
  4108. set access "MASTER"
  4109. }
  4110. if {$menureply == "1"} {
  4111. set file [open $black(add_file) r]
  4112. while {[gets $file line] != -1} {
  4113. set disable [lindex [split $line] 0]
  4114. set c [lindex [split $line] 1]
  4115. set gettype [lindex [split $line] 2]
  4116. set disable_level [lindex [split $line] 3]
  4117. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4118. set cmd_found 1
  4119. continue
  4120. }
  4121. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4122. switch $access {
  4123. MANAGER {
  4124. if {$disable_level == "OWNER"} {
  4125. set cmd_found 1
  4126. }
  4127. if {$disable_level == "BOSS"} {
  4128. set cmd_found 1
  4129. }
  4130. if {$disable_level == "MANAGER"} {
  4131. set cmd_found 1
  4132. }
  4133. if {$disable_level == "MASTER"} {
  4134. set cmd_found 1
  4135. }
  4136. }
  4137. OWNER {
  4138. if {$disable_level == "BOSS"} {
  4139. set cmd_found 1
  4140. }
  4141. if {$disable_level == "OWNER"} {
  4142. set cmd_found 1
  4143. }
  4144. }
  4145. MASTER {
  4146. if {$disable_level == "BOSS"} {
  4147. set cmd_found 1
  4148. }
  4149. if {$disable_level == "OWNER"} {
  4150. set cmd_found 1
  4151. }
  4152. if {$disable_level == "MASTER"} {
  4153. set cmd_found 1
  4154. }
  4155. }
  4156. BOSS {
  4157. if {$disable_level == "BOSS"} {
  4158. set cmd_found 1
  4159. }
  4160. }
  4161. default {
  4162. set cmd_found 1
  4163. }
  4164. }
  4165. }
  4166. }
  4167. close $file
  4168. return $cmd_found
  4169. }
  4170. set file [open $black(add_file) r]
  4171. while {[gets $file line] != -1} {
  4172. set disable [lindex [split $line] 0]
  4173. set c [lindex [split $line] 1]
  4174. set gettype [lindex [split $line] 2]
  4175. set disable_level [lindex [split $line] 3]
  4176. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4177. set cmd_found 1
  4178. continue
  4179. }
  4180. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4181. switch $access {
  4182. MANAGER {
  4183. if {$disable_level == "OWNER"} {
  4184. set cmd_found 1
  4185. }
  4186. if {$disable_level == "BOSS"} {
  4187. set cmd_found 1
  4188. }
  4189. if {$disable_level == "MANAGER"} {
  4190. set cmd_found 1
  4191. }
  4192. if {$disable_level == "MASTER"} {
  4193. set cmd_found 1
  4194. }
  4195. }
  4196. OWNER {
  4197. if {$disable_level == "BOSS"} {
  4198. set cmd_found 1
  4199. }
  4200. if {$disable_level == "OWNER"} {
  4201. set cmd_found 1
  4202. }
  4203. }
  4204. MASTER {
  4205. if {$disable_level == "BOSS"} {
  4206. set cmd_found 1
  4207. }
  4208. if {$disable_level == "OWNER"} {
  4209. set cmd_found 1
  4210. }
  4211. if {$disable_level == "MASTER"} {
  4212. set cmd_found 1
  4213. }
  4214. }
  4215. BOSS {
  4216. if {$disable_level == "BOSS"} {
  4217. set cmd_found 1
  4218. }
  4219. }
  4220. default {
  4221. set cmd_found 1
  4222. }
  4223. }
  4224. }
  4225. }
  4226. if {$cmd_found == "0"} {
  4227. set user_cmd_status [getuser $hand XTRA $cmd\($chan\)]
  4228. if {$user_cmd_status == "OFF"} {
  4229. set cmd_found 1
  4230. }
  4231. }
  4232. close $file
  4233. return $cmd_found
  4234. }
  4235. proc btcmd:set:user {nick host hand chan chan1 user cmd type} {
  4236. global black
  4237. if {[lsearch -exact $black(validcmds) $cmd] < 0} {
  4238. return 2
  4239. }
  4240. set show_user $user
  4241. if {![validuser $user]} {
  4242. if {[onchan $user $chan]} {
  4243. set handle [nick2hand $user]
  4244. if {![validuser $handle]} {
  4245. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  4246. return
  4247. }
  4248. }
  4249. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  4250. return
  4251. }
  4252. set status [getuser $user XTRA $cmd\($chan\)]
  4253. switch $type {
  4254. 1 {
  4255. if {$status == "OFF"} {
  4256. blacktools:tell $nick $host $hand $chan $chan1 disable.5 "$cmd $show_user"
  4257. return
  4258. }
  4259. setuser $user XTRA $cmd\($chan\) OFF
  4260. blacktools:tell $nick $host $hand $chan $chan1 disable.4 "$cmd $show_user"
  4261. }
  4262. 0 {
  4263. if {$status == "OFF"} {
  4264. setuser $user XTRA $cmd\($chan\)
  4265. blacktools:tell $nick $host $hand $chan $chan1 enable.4 "$cmd $show_user"
  4266. return
  4267. }
  4268. blacktools:tell $nick $host $hand $chan $chan1 enable.5 "$cmd $show_user"
  4269. }
  4270. }
  4271. }
  4272. proc btcmd:getlevel {chan cmd} {
  4273. global black
  4274. set file [open $black(add_file) r]
  4275. set found_level ""
  4276. while {[gets $file line] != -1} {
  4277. set disable [lindex [split $line] 0]
  4278. set c [lindex [split $line] 1]
  4279. set gettype [lindex [split $line] 2]
  4280. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4281. set comp [lindex [split $line] 3]
  4282. set found_level $comp
  4283. }
  4284. }
  4285. close $file
  4286. return $found_level
  4287. }
  4288. proc btcmd:set {chan hand cmd type} {
  4289. global black
  4290. if {[lsearch -exact -nocase $black(validcmds) $cmd] < 0} {
  4291. return 2
  4292. }
  4293. if {[string equal -nocase "enable" $cmd]} {
  4294. return 3
  4295. }
  4296. if {[matchattr $hand -|M $chan]} {
  4297. set access "MANAGER"
  4298. } elseif {[matchattr $hand n]} {
  4299. set access "BOSS"
  4300. } elseif {[matchattr $hand m]} {
  4301. set access "OWNER"
  4302. } elseif {[matchattr $hand o]} {
  4303. set access "MASTER"
  4304. }
  4305. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4306. set temp "$black(tempdir)/add_file_temp.$timestamp"
  4307. set file [open $black(add_file) r]
  4308. set tempwrite [open $temp w]
  4309. set cmd_found 0
  4310. set disable_type 0
  4311. while {[gets $file line] != -1} {
  4312. set disable [lindex [split $line] 0]
  4313. set c [lindex [split $line] 1]
  4314. set gettype [lindex [split $line] 2]
  4315. set comp [lindex [split $line] 3]
  4316. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4317. set cmd_found 1
  4318. continue
  4319. } else {
  4320. puts $tempwrite $line
  4321. }
  4322. }
  4323. close $tempwrite
  4324. close $file
  4325. file rename -force $temp $black(add_file)
  4326. if {$type == "1"} {
  4327. set file [open $black(add_file) a]
  4328. puts $file "DISABLE $chan [string toupper $cmd] $access"
  4329. close $file
  4330. }
  4331. return $cmd_found
  4332. }
  4333. proc setting:set {chan setting msg} {
  4334. global black
  4335. set getsetting [string map {
  4336. "+" ""
  4337. "-" ""} $setting]
  4338. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4339. set temp "$black(tempdir)/extra_temp.$timestamp"
  4340. set file [open $black(extra_file) r]
  4341. set tempwrite [open $temp w]
  4342. while {[gets $file line] != -1} {
  4343. set c [lindex [split $line] 0]
  4344. set gettype [lindex [split $line] 1]
  4345. set comp [lindex [split $line] 2]
  4346. set comp [string map {
  4347. "+" ""
  4348. "-" ""} $comp]
  4349. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp $getsetting]} {
  4350. continue
  4351. } else {
  4352. puts $tempwrite $line
  4353. }
  4354. }
  4355. close $tempwrite
  4356. close $file
  4357. file rename -force $temp $black(extra_file)
  4358. if {[regexp {^[-]} $setting]} {
  4359. return
  4360. }
  4361. set file [open $black(extra_file) a]
  4362. if {[regexp {^[+]} $setting]} {
  4363. puts $file "$chan XTRA [string toupper $setting]"
  4364. } else {
  4365. puts $file "$chan XTRA [string toupper $setting] $msg"
  4366. }
  4367. close $file
  4368. }
  4369. proc setting:exists {setting} {
  4370. global black
  4371. set found_it 0
  4372. if {[regexp {^[+-]} $setting]} {
  4373. set setting [string map {
  4374. "+" ""
  4375. "-" ""} $setting]
  4376. }
  4377. if {[lsearch -exact [string tolower $black(extra_flag)] [string tolower $setting]] > -1} {
  4378. set found_it 1
  4379. } elseif {[lsearch -exact [string tolower $black(extra_str)] [string tolower $setting]] > -1} {
  4380. set found_it 2
  4381. }
  4382. return $found_it
  4383. }
  4384. proc setting:status {chan setting msg} {
  4385. global black
  4386. set status 0
  4387. if {[regexp {^[+-]} $setting]} {
  4388. set file [open $black(extra_file) r]
  4389. while {[gets $file line] != -1} {
  4390. set c [lindex [split $line] 0]
  4391. set gettype [lindex [split $line] 1]
  4392. set comp [lindex [split $line] 2]
  4393. set comp_map [string map {
  4394. "+" ""
  4395. "-" ""} $comp]
  4396. set setting [string map {
  4397. "+" ""
  4398. "-" ""} $setting]
  4399. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp_map $setting]} {
  4400. if {[regexp {^[+]} $comp]} {
  4401. set status 1
  4402. }
  4403. }
  4404. }
  4405. close $file
  4406. return $status
  4407. }
  4408. set file [open $black(extra_file) r]
  4409. while {[gets $file line] != -1} {
  4410. set c [lindex [split $line] 0]
  4411. set gettype [lindex [split $line] 1]
  4412. set comp [lindex [split $line] 2]
  4413. set getmsg [lrange [split $line] 3 end]
  4414. if {![regexp {^[+-]} $comp]} {
  4415. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp $setting] && [string equal -nocase $msg $getmsg]} {
  4416. set status 1
  4417. }
  4418. }
  4419. }
  4420. close $file
  4421. return $status
  4422. }
  4423. proc setting:get {chan setting} {
  4424. global black
  4425. if {![file exists $black(extra_file)]} {return 0}
  4426. set flag_setting 0
  4427. set found_it 0
  4428. set return ""
  4429. set file [open $black(extra_file) r]
  4430. set setting_exists [setting:exists $setting]
  4431. set setting [string map {
  4432. "+" ""
  4433. "-" ""} $setting]
  4434. if {$setting_exists == "1"} {
  4435. set flag_setting 1
  4436. }
  4437. while {[gets $file line] != -1} {
  4438. set c [lindex [split $line] 0]
  4439. set gettype [lindex [split $line] 1]
  4440. set comp [lindex [split $line] 2]
  4441. set getsetting [string map {
  4442. "+" ""
  4443. "-" ""} $comp]
  4444. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $getsetting $setting]} {
  4445. set found_it 1
  4446. set getmsg [lrange [split $line] 3 end]
  4447. if {$flag_setting == "0"} {
  4448. set return $getmsg
  4449. } else {
  4450. if {[regexp {^[+]} $comp]} {
  4451. set return 1
  4452. }
  4453. if {[regexp {^[-]} $comp]} {
  4454. set return 0
  4455. }
  4456. }
  4457. }
  4458. }
  4459. if {($found_it == "0") && ($flag_setting == "1")} {
  4460. set return 0
  4461. }
  4462. close $file
  4463. return $return
  4464. }
  4465. proc get:flags {chan} {
  4466. global black
  4467. set all ""
  4468. set file [open $black(extra_file) r]
  4469. while {[gets $file line] != -1} {
  4470. set c [lindex [split $line] 0]
  4471. set gettype [lindex [split $line] 1]
  4472. set comp [lindex [split $line] 2]
  4473. if {[string equal -nocase $chan $c]} {
  4474. if {[regexp {^[+]} $comp]} {
  4475. lappend all $comp
  4476. }
  4477. }
  4478. }
  4479. close $file
  4480. return $all
  4481. }
  4482. proc get:str {chan} {
  4483. global black
  4484. set all ""
  4485. set file [open $black(extra_file) r]
  4486. while {[gets $file line] != -1} {
  4487. set c [lindex [split $line] 0]
  4488. set gettype [lindex [split $line] 1]
  4489. set comp [lindex [split $line] 2]
  4490. set why [join [lrange [split $line] 3 end]]
  4491. if {[string equal -nocase $chan $c]} {
  4492. if {[regexp {^[+-]} $comp]} {
  4493. continue
  4494. } else {
  4495. lappend all $comp&&$why
  4496. }
  4497. }
  4498. }
  4499. close $file
  4500. return $all
  4501. }
  4502. proc blacktools:flag:exists {chan setting} {
  4503. global black
  4504. set flag_exists 0
  4505. set file [open $black(extra_file) r]
  4506. while {[gets $file line] != -1} {
  4507. set c [lindex [split $line] 0]
  4508. set comp [lindex [split $line] 2]
  4509. if {[regexp {^[+-]} $comp]} {
  4510. set comp [string map {"+" ""
  4511. "-" ""} $comp]
  4512. }
  4513. if {[regexp {^[+-]} $setting]} {
  4514. set setting [string map {"+" ""
  4515. "-" ""} $setting]
  4516. }
  4517. if {[string equal -nocase $c $chan]} {
  4518. if {[string equal -nocase $setting $comp]} {
  4519. set flag_exists 1
  4520. }
  4521. }
  4522. }
  4523. close $file
  4524. return $flag_exists
  4525. }
  4526. proc blacktools:ban:exists {mask chan} {
  4527. global black
  4528. set ban_exists ""
  4529. foreach b $black(bans) {
  4530. set read_chan [lindex [split $b] 2]
  4531. if {[string equal -nocase $chan $read_chan]} {
  4532. set read_host [lindex [split $b] 3]
  4533. set real_read_host [string map [list \[ {\[} \] {\]} \\ {\\}] $read_host]
  4534. if {[string equal -nocase $real_read_host $mask]} {
  4535. break
  4536. }
  4537. if {[string match -nocase $real_read_host $mask]} {
  4538. set ban_exists $read_host
  4539. break
  4540. }
  4541. }
  4542. }
  4543. return $ban_exists
  4544. }
  4545. proc blacktools:protect {nick chan} {
  4546. global black
  4547. if {[isop $nick $chan]} {
  4548. set oprotect [string tolower [setting:get $chan oprotect]]
  4549. if {$oprotect == "1"} {
  4550. return 1
  4551. }
  4552. }
  4553. if {[isvoice $nick $chan]} {
  4554. set vprotect [string tolower [setting:get $chan vprotect]]
  4555. if {$vprotect == "1"} {
  4556. return 1
  4557. }
  4558. }
  4559. if {[ishalfop $nick $chan]} {
  4560. set hoprotect [string tolower [setting:get $chan hoprotect]]
  4561. if {$hoprotect == "1"} {
  4562. return 1
  4563. }
  4564. }
  4565. return 0
  4566. }
  4567. ######################### bad quitpart colors ################
  4568. set black(badcolors) {
  4569. "*\x03*"
  4570. "*\037*"
  4571. "*\002*"
  4572. }
  4573. ###################### protect color filter ##################
  4574. proc color:filter {str} {
  4575. regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  4576. return $str
  4577. }
  4578. ###################### add extra (badwords, excepts) ##########
  4579. proc addextra:find:num {chan type num} {
  4580. global black
  4581. set ret 0
  4582. set file [open $black(add_file) r]
  4583. while {[gets $file line] != -1} {
  4584. set read_chan [lindex [split $line] 0]
  4585. set read_type [lindex [split $line] 1]
  4586. set read_num [lindex [split $line] 2]
  4587. set enc_chan [encoding convertfrom utf-8 $read_chan]
  4588. if {[string equal -nocase $enc_chan $chan] && [string equal -nocase $read_type $type]} {
  4589. if {$read_num == "$num"} {
  4590. set ret $read_num
  4591. }
  4592. }
  4593. }
  4594. close $file
  4595. return $ret
  4596. }
  4597. proc blacktools:ban:find_id {} {
  4598. global black
  4599. set lastid [blacktools:banlist:lastid]
  4600. set current [expr $lastid + 1]
  4601. return $current
  4602. }
  4603. proc check:file:word {chan text type} {
  4604. global black
  4605. set found_word ""
  4606. set get_pers ""
  4607. set split_w ""
  4608. set file [open $black(add_file) "r"]
  4609. while {[gets $file line] != -1} {
  4610. set c [lindex [split $line] 0]
  4611. set t [lindex [split $line] 1]
  4612. set w [join [lrange [split $line] 3 end]]
  4613. if {[string equal -nocase $t "BADWORD"] && [string equal -nocase $type "BADWORD"]} {
  4614. if {[regexp {[:]} $w]} {
  4615. set split_w [split $w ":"]
  4616. set w [join [lindex $split_w 0]]
  4617. }
  4618. }
  4619. if {[string match -nocase $c $chan] && [string match -nocase $w $text] && [string match -nocase $t $type]} {
  4620. set found_word $w
  4621. if {$split_w != ""} {
  4622. set get_pers [lindex $split_w 1]
  4623. }
  4624. }
  4625. }
  4626. close $file
  4627. if {$get_pers != "" && $found_word != ""} {
  4628. return "$found_word:$get_pers"
  4629. } else {
  4630. return $found_word
  4631. }
  4632. }
  4633. proc get:banmethod {cmd chan} {
  4634. global black
  4635. if {![validchan $chan]} { return }
  4636. set get_pers ""
  4637. if {[regexp {[:]} $cmd]} {
  4638. set split_cmd [split $cmd ":"]
  4639. set get_cmd [lindex [split $split_cmd] 0]
  4640. if {[string equal -nocase $get_cmd "antibadword"]} {
  4641. set get_pers [lindex [split $split_cmd] 1]
  4642. }
  4643. }
  4644. if {$get_pers != ""} {
  4645. return $get_pers
  4646. }
  4647. set get [setting:get $chan $cmd-banmethod]
  4648. if {$get != ""} {
  4649. return $get
  4650. } else {
  4651. set get [setting:get $chan banmethod]
  4652. if {$get != ""} {
  4653. return $get
  4654. } else {
  4655. return $black($cmd:banmethod)
  4656. }
  4657. }
  4658. }
  4659. proc get:banmask {cmd chan} {
  4660. global black
  4661. if {$cmd == "b:gl"} {
  4662. return $black($cmd:banmask)
  4663. }
  4664. if {![validchan $chan]} { return }
  4665. set get [setting:get $chan $cmd-banmask]
  4666. if {$get != ""} {
  4667. return $get
  4668. } else {
  4669. set get [setting:get $chan general-banmask]
  4670. if {$get != ""} {
  4671. return $get
  4672. } else {
  4673. return $black($cmd:banmask)
  4674. }
  4675. }
  4676. }
  4677. proc get:mask {cmd chan} {
  4678. global black
  4679. if {$cmd == "hello"} {
  4680. return $black($cmd:mask)
  4681. }
  4682. if {![validchan $chan]} { return }
  4683. set get [setting:get $chan $cmd-mask]
  4684. if {$get != ""} {
  4685. return $get
  4686. } else {
  4687. set get [setting:get $chan mask]
  4688. if {$get != ""} {
  4689. return $get
  4690. } else {
  4691. return $black($cmd:mask)
  4692. }
  4693. }
  4694. }
  4695. proc find:num {num chan type} {
  4696. global black
  4697. set ret 0
  4698. set file [open $black(add_file) r]
  4699. while {[gets $file line] != -1} {
  4700. set read_chan [lindex [split $line] 0]
  4701. set read_type [lindex [split $line] 1]
  4702. set read_num [lindex [split $line] 2]
  4703. set enc_chan [encoding convertfrom utf-8 $read_chan]
  4704. if {[string equal -nocase $enc_chan $chan] && [string equal -nocase $read_type $type]} {
  4705. if {$read_num == "$num"} {
  4706. set ret $read_num
  4707. }
  4708. }
  4709. }
  4710. close $file
  4711. return $ret
  4712. }
  4713. proc find:q:num {num chan} {
  4714. global black
  4715. set ret 0
  4716. set file [open $black(quote_file) r]
  4717. while {[gets $file line] != -1} {
  4718. set read_chan [lindex [split $line] 0]
  4719. set read_num [lindex [split $line] 2]
  4720. set enc_chan [encoding convertfrom utf-8 $read_chan]
  4721. if {[string equal -nocase $enc_chan $chan]} {
  4722. if {$read_num == "$num"} {
  4723. set ret $read_num
  4724. }
  4725. }
  4726. }
  4727. close $file
  4728. return $ret
  4729. }
  4730. proc find:note:num {num} {
  4731. global black
  4732. set ret 0
  4733. set file [open $black(notes_file) r]
  4734. while {[gets $file line] != -1} {
  4735. set read_num [lindex [split $line] 2]
  4736. if {$read_num == "$num"} {
  4737. set ret $read_num
  4738. }
  4739. }
  4740. close $file
  4741. return $ret
  4742. }
  4743. ####################### troll announce #######################
  4744. proc troll:add {banned mask chan} {
  4745. global black
  4746. set found_it 0
  4747. if {![info exists black(troll:$chan)]} {
  4748. set black(troll:$chan) ""
  4749. }
  4750. foreach troll $black(troll:$chan) {
  4751. set troll_split [split $troll ":"]
  4752. set nick [lindex $troll_split 0]
  4753. set host [lindex $troll_split 1]
  4754. if {[string equal -nocase $banned $nick]} {
  4755. set found_it 1
  4756. continue
  4757. }
  4758. }
  4759. if {$found_it == "1"} { return }
  4760. if {[lsearch -exact [string tolower $black(troll:$chan)] [string tolower $banned:$mask]] > -1} {
  4761. return
  4762. }
  4763. lappend black(troll:$chan) $banned:$mask
  4764. }
  4765. proc troll:del {mask chan} {
  4766. global black
  4767. if {![info exists black(troll:$chan)]} {
  4768. return
  4769. }
  4770. if {$black(troll:$chan) == ""} {
  4771. return
  4772. }
  4773. foreach troll $black(troll:$chan) {
  4774. set troll_split [split $troll ":"]
  4775. set nick [lindex $troll_split 0]
  4776. set host [lindex $troll_split 1]
  4777. if {[string equal -nocase $host $mask]} {
  4778. if {[lsearch -exact [string tolower $black(troll:$chan)] [string tolower $nick:$host]] > -1} {
  4779. set position [lsearch -exact [string tolower $black(troll:$chan)] [string tolower $nick:$host]]
  4780. set black(troll:$chan) [lreplace $black(troll:$chan) $position $position]
  4781. }
  4782. }
  4783. }
  4784. }
  4785. proc troll:show {nick host hand chan} {
  4786. global black
  4787. if {![setting:get $chan showtroll]} {
  4788. return
  4789. }
  4790. if {[info exists black(turnOnFlood:$chan)]} {
  4791. return
  4792. }
  4793. if {![info exists black(troll:$chan)]} {
  4794. return
  4795. }
  4796. if {$black(troll:$chan) == ""} {
  4797. return
  4798. }
  4799. if {[matchattr $hand $black(exceptflags) $chan]} {
  4800. set lang [setting:get $chan lang]
  4801. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  4802. set trolls ""
  4803. foreach troll $black(troll:$chan) {
  4804. set troll_split [split $troll ":"]
  4805. set tr [lindex $troll_split 0]
  4806. lappend trolls $tr
  4807. }
  4808. set getlang [string tolower [setting:get $chan lang]]
  4809. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  4810. set replace(%msg%) $trolls
  4811. set replace(%chan%) $chan
  4812. set text [black:color:set "" $black(say.$getlang.troll.6)]
  4813. putserv "NOTICE $nick :[join [string map [array get replace] $text]]"
  4814. }
  4815. }
  4816. ######################## BoT set code ###################
  4817. proc bot:setcode {} {
  4818. global black
  4819. set schars "` ! \" % ' & \[ \] ! / ; \ * ^ % $ \#"
  4820. set alphabet "a b c d e f g h i j k l m n o p q r s t u v w x y z"
  4821. set numbers "0 1 2 3 4 5 6 7 8 9"
  4822. set code ""
  4823. for {set i 0} { $i < 1 } { incr i} {
  4824. lappend code "[lindex [split $schars] [rand 7]] "
  4825. }
  4826. for {set i 0} { $i < 2 } { incr i} {
  4827. lappend code [lindex $alphabet [rand 26]]
  4828. }
  4829. for {set j 0} { $j < 3 } { incr j} {
  4830. lappend code [lindex $numbers [rand 10]]
  4831. }
  4832. for {set i 0} { $i < 1 } { incr i} {
  4833. lappend code " [lindex [split $schars] [rand 7]]"
  4834. }
  4835. return [join $code ""]
  4836. }
  4837. ################ Bans - KICKS Day Reset ##################
  4838. proc bans:day:reset {minute hour day month year} {
  4839. global black
  4840. foreach user [userlist] {
  4841. foreach chan [channels] {
  4842. set cmds_today [getuser $user XTRA CMD_STATS_TODAY($chan)]
  4843. if {$cmds_today != ""} {
  4844. setuser $user XTRA CMD_STATS_TODAY($chan)
  4845. }
  4846. }
  4847. }
  4848. }
  4849. ##################### voiceme logged #####################
  4850. proc voiceme:logged {from keyword arguments} {
  4851. global black
  4852. set nick $::vnick
  4853. set chan $::vchan
  4854. set hand $::vhand
  4855. set host $::vhost
  4856. set chan1 $chan
  4857. if {[string match -nocase "*is logged*" $arguments] || [string match -nocase "*is authed*" $arguments]} {
  4858. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  4859. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  4860. blacktools:tell $nick "prv" $hand $chan $chan1 voiceme.3 none
  4861. } else {
  4862. putserv "MODE $chan +v $nick"
  4863. blacktools:tell $nick "prv" $hand $chan $chan1 voiceme.3 none
  4864. }
  4865. }
  4866. unbind RAW - 330 voiceme:logged
  4867. }
  4868. proc voiceme:identified {from keyword arguments} {
  4869. global black
  4870. set nick $::vnick
  4871. set chan $::vchan
  4872. set hand $::vhand
  4873. set chan1 $chan
  4874. if {[string match -nocase "*has identified*" $arguments]} {
  4875. putserv "MODE $chan +v $nick"
  4876. blacktools:tell $nick "prv" $hand $chan $chan1 voiceme.3 none
  4877. }
  4878. unbind RAW - 307 voiceme:identified
  4879. }
  4880. ################################# reban ######################
  4881. proc rebanpublic {nick host hand chan} {
  4882. global black
  4883. if {[setting:get $chan xtools]} {
  4884. chanserv:ignore_remove
  4885. set host "$nick![getchanhost $nick $chan]"
  4886. set getxtime [setting:get $chan xbantime]
  4887. set getxlevel [setting:get $chan xbanlevel]
  4888. if {$getxlevel == ""} { set getxlevel $black(chanserv:banlevel) }
  4889. if {$getxtime == ""} { set getxtime $black(chanserv:bantime) }
  4890. foreach ban [banlist $chan] {
  4891. set reason [lindex $ban 1]
  4892. if {[string match -nocase [string tolower [lindex $ban 0]] $host]} {
  4893. putquick "PRIVMSG $black(chanserv) :ban $chan [lindex $ban 0] $getxtime $getxlevel $reason"
  4894. }
  4895. }
  4896. }
  4897. }
  4898. ######################### XTOOLS ##########################
  4899. proc toolspublic {chan type} {
  4900. global botnick black
  4901. if {![setting:get $chan xtools]} {
  4902. return
  4903. }
  4904. if {[info exists black(notlogged)]} {
  4905. return
  4906. }
  4907. chanserv:ignore_remove
  4908. if {$type == "op"} {
  4909. if {![onchan "$black(chanserv)" $chan] && ![botisop $chan]} {
  4910. return
  4911. }
  4912. putquick "PRIVMSG $black(chanserv) :unban $chan $botnick"
  4913. putquick "PRIVMSG $black(chanserv) :op $chan $botnick"
  4914. return
  4915. }
  4916. if {$type == "unban"} {
  4917. putquick "PRIVMSG $black(chanserv) :unban $chan $botnick"
  4918. return
  4919. }
  4920. if {$type == "invite" || $type == "limit"} {
  4921. putquick "PRIVMSG $black(chanserv) :invite $chan $botnick"
  4922. return
  4923. }
  4924. if {$type == "key"} {
  4925. putquick "PRIVMSG $black(chanserv) :invite $chan $botnick"
  4926. return
  4927. }
  4928. }
  4929. ######################### ABUSE #########################
  4930. proc abuse:ban:note {from keyword arguments} {
  4931. global black botnick
  4932. set chan [lindex [split $arguments] 1]
  4933. if {[setting:get $chan invisible]} {
  4934. return
  4935. }
  4936. abuse:suspend $chan
  4937. if {[info exists black(abuse:$chan)]} {
  4938. return
  4939. }
  4940. set replace(%chan%) $chan
  4941. set time [unixtime]
  4942. foreach user [userlist nm] {
  4943. set nonotes [getuser $user XTRA NO_NOTES]
  4944. if {$nonotes == ""} {
  4945. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  4946. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  4947. set black(notes:announce:$user) 1
  4948. set text [black:color:set $botnick $black(say.$getlang.abuse.2)]
  4949. set file [open $black(notes_file) a]
  4950. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  4951. close $file
  4952. }
  4953. }
  4954. set black(abuse:$chan) 1
  4955. blacktools:tell:dcc abuse.1 "$chan"
  4956. }
  4957. proc abuse:key:note {from keyword arguments} {
  4958. global black botnick
  4959. set chan [lindex [split $arguments] 1]
  4960. if {[setting:get $chan invisible]} {
  4961. return
  4962. }
  4963. abuse:suspend $chan
  4964. if {[info exists black(abuse:$chan)]} {
  4965. return
  4966. }
  4967. set replace(%chan%) $chan
  4968. set time [unixtime]
  4969. foreach user [userlist nm] {
  4970. set nonotes [getuser $user XTRA NO_NOTES]
  4971. if {$nonotes == ""} {
  4972. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  4973. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  4974. set black(notes:announce:$user) 1
  4975. set text [black:color:set $botnick $black(say.$getlang.abuse.6)]
  4976. set file [open $black(notes_file) a]
  4977. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  4978. close $file
  4979. }
  4980. }
  4981. set black(abuse:$chan) 3
  4982. blacktools:tell:dcc abuse.5 "$chan"
  4983. }
  4984. proc abuse:inviteonly:note {from keyword arguments} {
  4985. global black botnick
  4986. set chan [lindex [split $arguments] 1]
  4987. if {[setting:get $chan invisible]} {
  4988. return
  4989. }
  4990. abuse:suspend $chan
  4991. if {[info exists black(abuse:$chan)]} {
  4992. return
  4993. }
  4994. set replace(%chan%) $chan
  4995. set time [unixtime]
  4996. foreach user [userlist nm] {
  4997. set nonotes [getuser $user XTRA NO_NOTES]
  4998. if {$nonotes == ""} {
  4999. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5000. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5001. set black(notes:announce:$user) 1
  5002. set text [black:color:set $botnick $black(say.$getlang.abuse.4)]
  5003. set file [open $black(notes_file) a]
  5004. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5005. close $file
  5006. }
  5007. }
  5008. set black(abuse:$chan) 2
  5009. blacktools:tell:dcc abuse.3 "$chan"
  5010. }
  5011. proc abuse:restricted:note {from keyword arguments} {
  5012. global black botnick
  5013. set chan [lindex [split $arguments] 1]
  5014. if {[setting:get $chan invisible]} {
  5015. return
  5016. }
  5017. abuse:suspend $chan
  5018. if {[info exists black(abuse:$chan)]} {
  5019. return
  5020. }
  5021. set replace(%chan%) $chan
  5022. set time [unixtime]
  5023. foreach user [userlist nm] {
  5024. set nonotes [getuser $user XTRA NO_NOTES]
  5025. if {$nonotes == ""} {
  5026. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5027. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5028. set black(notes:announce:$user) 1
  5029. set text [black:color:set $botnick $black(say.$getlang.abuse.11)]
  5030. set file [open $black(notes_file) a]
  5031. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5032. close $file
  5033. }
  5034. }
  5035. set black(abuse:$chan) 5
  5036. blacktools:tell:dcc abuse.12 "$chan"
  5037. }
  5038. proc abuse:channelfull:note {from keyword arguments} {
  5039. global black botnick
  5040. set chan [lindex [split $arguments] 1]
  5041. if {[setting:get $chan invisible]} {
  5042. return
  5043. }
  5044. abuse:suspend $chan
  5045. if {[info exists black(abuse:$chan)]} {
  5046. return
  5047. }
  5048. set replace(%chan%) $chan
  5049. set time [unixtime]
  5050. foreach user [userlist nm] {
  5051. set nonotes [getuser $user XTRA NO_NOTES]
  5052. if {$nonotes == ""} {
  5053. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5054. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5055. set black(notes:announce:$user) 1
  5056. set text [black:color:set $botnick $black(say.$getlang.abuse.8)]
  5057. set file [open $black(notes_file) a]
  5058. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5059. close $file
  5060. }
  5061. }
  5062. set black(abuse:$chan) 4
  5063. blacktools:tell:dcc abuse.7 "$chan"
  5064. }
  5065. proc delchan:note {hand chan reason} {
  5066. global black botnick
  5067. set replace(%chan%) $chan
  5068. set replace(%reason%) $reason
  5069. set replace(%hand%) $hand
  5070. set time [unixtime]
  5071. foreach user [userlist n] {
  5072. set nonotes [getuser $user XTRA NO_NOTES]
  5073. if {$nonotes == ""} {
  5074. if {$user != $hand} {
  5075. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5076. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5077. set black(notes:announce:$user) 1
  5078. set text [black:color:set $botnick $black(say.$getlang.delchan.1)]
  5079. set file [open $black(notes_file) a]
  5080. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5081. close $file
  5082. }
  5083. }
  5084. }
  5085. }
  5086. proc suspendchan:note {hand chan reason} {
  5087. global black botnick
  5088. set replace(%chan%) $chan
  5089. set replace(%reason%) $reason
  5090. set replace(%hand%) $hand
  5091. set time [unixtime]
  5092. foreach user [userlist n] {
  5093. set nonotes [getuser $user XTRA NO_NOTES]
  5094. if {$nonotes == ""} {
  5095. if {$user != $hand} {
  5096. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5097. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5098. set black(notes:announce:$user) 1
  5099. set text [black:color:set $botnick $black(say.$getlang.suspend.2)]
  5100. set file [open $black(notes_file) a]
  5101. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5102. close $file
  5103. }
  5104. }
  5105. }
  5106. }
  5107. proc get:abuse:num {} {
  5108. global black
  5109. set temp_num 0
  5110. set num 0
  5111. while {$temp_num == 0} {
  5112. set get [find:note:num $num]
  5113. if {$get == "$num"} {
  5114. set num [expr $num + 1]
  5115. } else { set temp_num 1 }
  5116. }
  5117. return $num
  5118. }
  5119. proc abuse:suspend {chan} {
  5120. global black botnick
  5121. if {![info exists black(abuse:count:$chan)]} {
  5122. set black(abuse:count:$chan) 0
  5123. }
  5124. incr black(abuse:count:$chan)
  5125. if {$black(abuse:count:$chan) >= 30} {
  5126. channel set $chan +inactive
  5127. unset black(abuse:count:$chan)
  5128. blacktools:tell:dcc abuse.9 "$chan"
  5129. set replace(%msg.1%) $chan
  5130. set time [unixtime]
  5131. foreach user [userlist nm] {
  5132. set nonotes [getuser $user XTRA NO_NOTES]
  5133. if {$nonotes == ""} {
  5134. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  5135. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5136. set text [black:color:set $botnick $black(say.$getlang.abuse.10)]
  5137. set file [open $black(notes_file) a]
  5138. puts $file "INBOX $chan [get:abuse:num] 0 $user $time $botnick [string map [array get replace] $text]"
  5139. close $file
  5140. }
  5141. }
  5142. }
  5143. }
  5144. ################### CTCP VERSION REPLY ######################
  5145. proc ctcpvers {nickname hostname handle dest key arg} {
  5146. global black
  5147. if {![info exists ::versnick]} {return}
  5148. set text [split $arg]
  5149. set chan $::verschan
  5150. set chan1 $chan
  5151. set nick $::versnick
  5152. blacktools:tell $nick "" [nick2hand $nick] $chan $chan1 vers.3 "$nickname $text"
  5153. }
  5154. ######################## AutoVoice ########################
  5155. proc autovonjoin {nick host hand chan} {
  5156. if {[setting:get $chan autovoice]} {
  5157. pushmode $chan +v $nick
  5158. }
  5159. }
  5160. ######################## AutoOp ########################
  5161. proc autoponjoin {nick host hand chan} {
  5162. if {[setting:get $chan autoop]} {
  5163. pushmode $chan +o $nick
  5164. }
  5165. }
  5166. ######################## get level #####################
  5167. proc blacktools:getlevelname {num hand} {
  5168. global black
  5169. set split_hand [split $hand ":"]
  5170. set handle [lindex $split_hand 0]
  5171. if {[validuser $handle]} {
  5172. set getlang [string tolower [getuser $handle XTRA OUTPUT_LANG]]
  5173. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5174. } else { set getlang "[string tolower $black(default_lang)]" }
  5175. switch $num {
  5176. 1 {
  5177. return $black(say.$getlang.level.1)
  5178. }
  5179. 2 {
  5180. return $black(say.$getlang.level.2)
  5181. }
  5182. 3 {
  5183. return $black(say.$getlang.level.3)
  5184. }
  5185. 4 {
  5186. return $black(say.$getlang.level.4)
  5187. }
  5188. 5 {
  5189. return $black(say.$getlang.level.5)
  5190. }
  5191. 6 {
  5192. return $black(say.$getlang.level.6)
  5193. }
  5194. 7 {
  5195. return $black(say.$getlang.level.7)
  5196. }
  5197. 8 {
  5198. return $black(say.$getlang.level.8)
  5199. }
  5200. 9 {
  5201. return $black(say.$getlang.level.9)
  5202. }
  5203. }
  5204. }
  5205. ############################ hello #########################
  5206. proc blacktools:hello {nick host hand} {
  5207. global black botnick
  5208. if {[validuser $nick]} { return }
  5209. set mask [return_mask [return_host_num "hello" none $host] $host $nick]
  5210. set time [unixtime]
  5211. set getlang "[string tolower $black(default_lang)]"
  5212. adduser $nick $mask
  5213. adduser $nick "-telnet!*@*"
  5214. chattr $nick "n|-"
  5215. setuser $nick XTRA CHANMODIF(GLOBAL) $time:$botnick
  5216. save
  5217. blacktools:tell $nick "prv" $hand "" "" hello.1 $black(say.$getlang.level.1)
  5218. blacktools:tell $nick "prv" $hand "" "" hello.2 "$nick $black(name) $black(vers)"
  5219. blacktools:tell $nick "prv" $hand "" "" hello.3 "$mask"
  5220. blacktools:tell $nick "prv" $hand "" "" hello.4 none
  5221. }
  5222. ######################## chanserv ignore ###################
  5223. proc chanserv:ignore_remove {} {
  5224. global black
  5225. if {[info exists black(chanserv:ignore_host)]} {
  5226. if {[isignore $black(chanserv:ignore_host)]} {
  5227. killignore $black(chanserv:ignore_host)
  5228. }
  5229. }
  5230. }
  5231. ####################### getlastaction #######################
  5232. proc blacktools:getlastaction:join {nick host hand chan} {
  5233. global black
  5234. if {![isbotnick $nick]} {
  5235. set gettime [unixtime]
  5236. set black(lastaction:$chan) $gettime
  5237. }
  5238. return 0
  5239. }
  5240. proc blacktools:getlastaction:part {nick host hand chan arg} {
  5241. global black
  5242. blacktools:getlastaction:join $nick $host $hand $chan
  5243. }
  5244. proc blacktools:getlastaction:sign {nick host hand chan arg} {
  5245. global black
  5246. blacktools:getlastaction:join $nick $host $hand $chan
  5247. }
  5248. proc blacktools:getlastaction:kick {nick host hand chan kicked reason} {
  5249. global black
  5250. blacktools:getlastaction:join $nick $host $hand $chan
  5251. }
  5252. proc blacktools:getlastaction:text {nick host hand chan arg} {
  5253. global black botnick
  5254. if {![isbotnick $nick]} {
  5255. if {[validchan $chan]} {
  5256. black:setlastaction $chan
  5257. }
  5258. }
  5259. return 0
  5260. }
  5261. proc black:setlastaction {chan} {
  5262. global black
  5263. set black(lastaction:$chan) [unixtime]
  5264. }
  5265. proc blacktools:getlastaction:me {nick host hand chan keyword arg} {
  5266. global black
  5267. blacktools:getlastaction:join $nick $host $hand $chan
  5268. return
  5269. }
  5270. proc blacktools:getlastaction:split {nick host hand chan args} {
  5271. global black
  5272. blacktools:getlastaction:join $nick $host $hand $chan
  5273. return 0
  5274. }
  5275. proc blacktools:getlastaction:ban {nick host hand chan args} {
  5276. global black
  5277. blacktools:getlastaction:join $nick $host $hand $chan
  5278. return 0
  5279. }
  5280. ########################### protection list #####################
  5281. proc module:process:getbanhost {num} {
  5282. global black
  5283. switch $num {
  5284. 1 {
  5285. return "#1 - warn"
  5286. }
  5287. 2 {
  5288. return "#2 - kick"
  5289. }
  5290. 3 {
  5291. return "#3 - ban"
  5292. }
  5293. 4 {
  5294. return "#4 - warn -> kick"
  5295. }
  5296. 5 {
  5297. return "#5 - warn -> kick -> ban"
  5298. }
  5299. 6 {
  5300. return "#6 - kick -> ban"
  5301. }
  5302. 7 {
  5303. return "#7 - warn -> ban"
  5304. }
  5305. }
  5306. }
  5307. proc prot:module:process {nick host hand chan chan1 why except type number type1} {
  5308. global black botnick
  5309. set cmd_status [btcmd:status $chan $hand $type1 0]
  5310. if {$cmd_status == "1"} {
  5311. return
  5312. }
  5313. set num 0
  5314. set temp_num 0
  5315. set get_pers ""
  5316. set get_word ""
  5317. set except_add 0
  5318. set show_except $except
  5319. set line1 [string toupper $type1]
  5320. if {[string equal -nocase $type1 "securemode"]} {
  5321. set line1 "SECUREMODE-EXCEPT"
  5322. }
  5323. if {[string equal -nocase $type1 "clonescan"]} {
  5324. set line1 "CLONESCAN-EXCEPT"
  5325. }
  5326. if {$why == ""} {
  5327. switch $type {
  5328. 0 {
  5329. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $type1
  5330. }
  5331. 1 {
  5332. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $type1
  5333. }
  5334. 2 {
  5335. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $type1
  5336. }
  5337. }
  5338. return
  5339. }
  5340. if {![validchan $chan]} {
  5341. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  5342. return
  5343. }
  5344. switch -exact -- [string tolower $why] {
  5345. add {
  5346. if {$except == ""} {
  5347. if {$type == "0"} {
  5348. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "$type1"
  5349. }
  5350. if {$type == "1"} {
  5351. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "$type1"
  5352. }
  5353. if {$type == "2"} {
  5354. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "$type1"
  5355. }
  5356. return
  5357. }
  5358. while {$temp_num == 0} {
  5359. set get [addextra:find:num $chan $line1 $num]
  5360. if {$get == "$num"} {
  5361. set num [expr $num + 1]
  5362. } else { set temp_num 1 }
  5363. }
  5364. if {[regexp {[:]} $except] && [string equal -nocase $line1 "BADWORD"]} {
  5365. set split_check [split $except ":"]
  5366. set get_pers [lindex $split_check 1]
  5367. set get_word [lindex $split_check 0]
  5368. } elseif {[regexp {^[+]} $except] && ([string equal -nocase $line1 "BADWORD"] || [string equal -nocase $line1 "BADQUITPART"] || [string equal -nocase $line1 "BADREALNAME"] || [string equal -nocase $line1 "BADHOST"] || [string equal -nocase $line1 "BADNICK"] || [string equal -nocase $line1 "ANTIPUB"] || [string equal -nocase $line1 "ANTISPAM"] || [string equal -nocase $line1 "BADIDENT"] || [string equal -nocase $line1 "ANTISPAM"])} {
  5369. set except_add 1
  5370. }
  5371. set findword [prot:findword $chan $line1 $show_except]
  5372. if {$findword == "1"} {
  5373. blacktools:tell $nick $host $hand $chan $chan1 gl.wordexists $show_except
  5374. return
  5375. }
  5376. if {$get_pers != ""} {
  5377. if {![regexp {^[1234567]} $get_pers]} {
  5378. if {$type == "0"} {
  5379. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "$type1"
  5380. return
  5381. }
  5382. if {$type == "1"} {
  5383. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "$type1"
  5384. }
  5385. if {$type == "2"} {
  5386. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "$type1"
  5387. }
  5388. }
  5389. }
  5390. set enc_chan [encoding convertto utf-8 $chan]
  5391. set file [open $black(add_file) a]
  5392. puts $file "$enc_chan $line1 $num $except"
  5393. if {$get_pers != ""} {
  5394. blacktools:tell $nick $host $hand $chan $chan1 $type1.7 "$num $get_pers $get_word"
  5395. } elseif {$except_add == "1"} {
  5396. if {[string equal -nocase $type1 "BADWORD"]} {
  5397. blacktools:tell $nick $host $hand $chan $chan1 $type1.8 "$num [string map {"+" ""} $show_except]"
  5398. } elseif {[string equal -nocase $type1 "BADNICK"]} {
  5399. blacktools:tell $nick $host $hand $chan $chan1 $type1.11 "$num [string map {"+" ""} $show_except]"
  5400. } else {
  5401. blacktools:tell $nick $host $hand $chan $chan1 $type1.10 "$num [string map {"+" ""} $show_except]"
  5402. }
  5403. } else {
  5404. blacktools:tell $nick $host $hand $chan $chan1 $type1.6 "$num $show_except"
  5405. }
  5406. close $file
  5407. }
  5408. list {
  5409. array set protlist [list]
  5410. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  5411. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  5412. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  5413. set temp "$black(tempdir)/prot_temp.$timestamp"
  5414. set file [open $black(add_file) "r"]
  5415. set w [read -nonewline $file]
  5416. close $file
  5417. set data [split $w "\n"]
  5418. foreach line $data {
  5419. set read_chan [lindex [split $line] 0]
  5420. set enc_chan [encoding convertfrom utf-8 $read_chan]
  5421. set type [lindex [split $line] 1]
  5422. if {[string match -nocase $enc_chan $chan] && [string match -nocase $line1 $type]} {
  5423. set msg_num [lindex [split $line] 2]
  5424. set except [lrange [split $line] 3 end]
  5425. if {[string equal -nocase $type "BADWORD"]} {
  5426. set split_except [split $except ":"]
  5427. if {[lindex $split_except 1] != ""} {
  5428. set the_except [join [lindex $split_except 0]]
  5429. set banhost [module:process:getbanhost [lindex $split_except 1]]
  5430. set text [black:color:set $hand $banhost]
  5431. lappend protlist($msg_num) $the_except \[$text\]
  5432. } elseif {[regexp {^[+]} $except]} {
  5433. set text [black:color:set $hand $black(say.$userlang.gl.protexcept)]
  5434. lappend protlist($msg_num) [string map {"+" ""} $except] \[$text\]
  5435. } else { lappend protlist($msg_num) $except }
  5436. } else {
  5437. if {[regexp {^[+]} $except]} {
  5438. set text [black:color:set $hand $black(say.$userlang.gl.protexcept)]
  5439. lappend protlist($msg_num) [string map {"+" ""} $except] \[$text\]
  5440. } else {
  5441. lappend protlist($msg_num) $except
  5442. }
  5443. }
  5444. }
  5445. }
  5446. set tempwrite [open $temp w]
  5447. foreach msg [lsort -integer -increasing [array names protlist]] {
  5448. puts $tempwrite "$msg [join $protlist($msg)]"
  5449. }
  5450. close $tempwrite
  5451. set file [open $temp "r"]
  5452. set w [read -nonewline $file]
  5453. close $file
  5454. set data [split $w "\n"]
  5455. file delete $temp
  5456. module:getinfo $nick $host $hand $chan $chan1 $type $data "$type1" "0" $number
  5457. }
  5458. del {
  5459. if {![regexp {^[0-9]} $number]} {
  5460. if {$type == "0"} {
  5461. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "$type1"
  5462. }
  5463. if {$type == "1"} {
  5464. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "$type1"
  5465. }
  5466. if {$type == "2"} {
  5467. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "$type1"
  5468. }
  5469. return
  5470. }
  5471. set ret [addextra:find:num $chan $line1 $number]
  5472. if {$ret == 0} {
  5473. blacktools:tell $nick $host $hand $chan $chan1 $type1.4 $number
  5474. return
  5475. }
  5476. set file [open $black(add_file) "r"]
  5477. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  5478. set temp "$black(tempdir)/prot_temp.$timestamp"
  5479. set tempwrite [open $temp w]
  5480. while {[gets $file line] != -1} {
  5481. set read_num [lindex [split $line] 2]
  5482. set read_type [lindex [split $line] 1]
  5483. set read_chan [lindex [split $line] 0]
  5484. set enc_chan [encoding convertfrom utf-8 $read_chan]
  5485. if {[string equal $number $read_num] && [string equal -nocase $enc_chan $chan] && [string equal -nocase $read_type $line1]} {
  5486. continue
  5487. } else {
  5488. puts $tempwrite $line
  5489. }
  5490. }
  5491. close $tempwrite
  5492. close $file
  5493. file rename -force $temp $black(add_file)
  5494. blacktools:tell $nick $host $hand $chan $chan1 $type1.5 $number
  5495. }
  5496. default {
  5497. if {$type == "0"} {
  5498. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "$type1"
  5499. }
  5500. if {$type == "1"} {
  5501. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "$type1"
  5502. }
  5503. }
  5504. }
  5505. }
  5506. proc prot:findword {chan type word} {
  5507. global black
  5508. set found_it 0
  5509. set file [open $black(add_file) "r"]
  5510. set w [read -nonewline $file]
  5511. close $file
  5512. set data [split $w "\n"]
  5513. foreach line $data {
  5514. set read_chan [lindex [split $line] 0]
  5515. set enc_chan [encoding convertfrom utf-8 $read_chan]
  5516. set t [lindex [split $line] 1]
  5517. set w [join [lrange [split $line] 3 end]]
  5518. if {[string equal -nocase $enc_chan $chan] && [string match -nocase $t $type] && [string equal -nocase $word $w] && ![regexp {^[+]} $w] && ![regexp {^[+]} $word]} {
  5519. set found_it 1
  5520. } elseif {[string equal -nocase $enc_chan $chan] && [string match -nocase $t $type] && [string equal -nocase $word $w] && [regexp {^[+]} $w] && [regexp {^[+]} $word]} {
  5521. set found_it 1
  5522. }
  5523. }
  5524. return $found_it
  5525. }
  5526. ################################# forward ################################
  5527. proc forward:redirect {nick host hand arg} {
  5528. global black
  5529. set message [join [lrange [split $arg] 0 end]]
  5530. if {![validuser $hand]} {
  5531. foreach chan [channels] {
  5532. if {[setting:get $chan forward]} {
  5533. blacktools:tell $nick "chan" $hand $chan $chan forward.1 "$nick $message"
  5534. }
  5535. }
  5536. }
  5537. }
  5538. ################################# expirebans ##############################
  5539. proc blacktools:expirebans {min hour day mon year} {
  5540. global black
  5541. set channels ""
  5542. foreach chan [channels] {
  5543. if {[channel get $chan ban-time] != "0"} {
  5544. continue
  5545. }
  5546. if {[setting:get $chan expirebans] == "0"} {
  5547. continue
  5548. }
  5549. lappend channels $chan
  5550. }
  5551. if {$channels != ""} {
  5552. blacktools:expire:chan $channels 0
  5553. }
  5554. }
  5555. proc blacktools:expire:chan {channels num} {
  5556. global black
  5557. set chan [lindex $channels $num]
  5558. set gettime [setting:get $chan expirebans]
  5559. if {$gettime == ""} {
  5560. set gettime $black(default:bantime)
  5561. }
  5562. if {$gettime == "0"} {
  5563. set nextc [expr $num + 1]
  5564. if {[lindex $channels $nextc] != ""} {
  5565. blacktools:expire:chan $channels $nextc
  5566. }
  5567. return
  5568. }
  5569. set gettime [time_return_minute $gettime]
  5570. set seconds [expr $gettime * 60]
  5571. set unixtime [unixtime]
  5572. set banlist [chanbans $chan]
  5573. set maxtime [expr $unixtime + $seconds]
  5574. foreach ban $banlist {
  5575. if {[blacktools:sticky [lindex $ban 0] $chan] == 1} {
  5576. continue
  5577. }
  5578. if {[isbansticky [lindex $ban 0] $chan]} {
  5579. continue
  5580. }
  5581. if {[blacktools:isgag [lindex $ban 0] $chan] == 1} {
  5582. continue
  5583. }
  5584. set chanstime [expr $unixtime + [lindex $ban 2]]
  5585. if {$maxtime <= $chanstime} {
  5586. pushmode $chan -b [lindex $ban 0]
  5587. }
  5588. }
  5589. set nextc [expr $num + 1]
  5590. if {[lindex $channels $nextc] != ""} {
  5591. blacktools:expire:chan $channels $nextc
  5592. }
  5593. }
  5594. ################################ get lastban #####################################
  5595. proc blacktools:getlastban {} {
  5596. global black
  5597. set lastban ""
  5598. foreach b $black(bans) {
  5599. if {$b != ""} {
  5600. set expire [lindex [split $b] 5]
  5601. if {$expire != 0} {
  5602. set dif [expr $expire - [unixtime]]
  5603. if {$dif > 0 || $dif == 0} {
  5604. if {$lastban == ""} {
  5605. set lastban $dif
  5606. continue
  5607. }
  5608. if {$lastban >= $dif} {
  5609. set lastban $dif
  5610. continue
  5611. }
  5612. } else {
  5613. set lastban 60
  5614. break
  5615. }
  5616. }
  5617. }
  5618. }
  5619. if {$lastban == ""} {
  5620. set lastban -1
  5621. }
  5622. return $lastban
  5623. }
  5624. if {[file exists $black(bans_file)]} {
  5625. if {![info exists black(bans)]} {
  5626. set black(bans) [blacktools:banlist:all]
  5627. }
  5628. if {![info exists black(lastban_set)]} {
  5629. set lastban [blacktools:getlastban]
  5630. if {$lastban == "-1"} {
  5631. set black(lastban_set) 1
  5632. } else {
  5633. set black(lastban) $lastban
  5634. foreach tmr [utimers] {
  5635. if {[string match "*blacktools:autounban*" [join [lindex $tmr 1]]]} {
  5636. killutimer [lindex $tmr 2]
  5637. }
  5638. }
  5639. utimer $black(lastban) [list blacktools:autounban]
  5640. }
  5641. }
  5642. }
  5643. proc blacktools:ub:setlast {expire} {
  5644. global black
  5645. set lastban ""
  5646. if {[info exists black(lastban)]} {
  5647. if {$expire != 0} {
  5648. set dif [expr $expire - [unixtime]]
  5649. if {$dif > 0} {
  5650. if {$black(lastban) >= $dif} {
  5651. set lastban $dif
  5652. }
  5653. }
  5654. }
  5655. } else {
  5656. set lastban [expr $expire - [unixtime]]
  5657. }
  5658. if {$lastban != ""} {
  5659. if {$lastban < 0} {
  5660. set lastban 60
  5661. }
  5662. set black(lastban) $lastban
  5663. foreach tmr [utimers] {
  5664. if {[string match "*blacktools:autounban*" [join [lindex $tmr 1]]]} {
  5665. killutimer [lindex $tmr 2]
  5666. }
  5667. }
  5668. utimer $black(lastban) [list blacktools:autounban]
  5669. }
  5670. return 1
  5671. }
  5672. ################################ protection order ###############################
  5673. proc blacktools:protect:me {nick host hand chan keyword arg} {
  5674. if {[string equal -nocase $keyword "ACTION"]} {
  5675. blacktools:protect:pub $nick $host $hand $chan $arg
  5676. }
  5677. }
  5678. proc blacktools:protect:pub {nick host hand chan arg} {
  5679. global black
  5680. set pub_protect "antipub badword longtext repetitivechars color bold underline caps floodchan antirepeat"
  5681. foreach prot $pub_protect {
  5682. if {[string equal -nocase $prot "antipub"]} {
  5683. if {[setting:get $chan antipub]} {
  5684. set return [antipub:protect $nick $host $hand $chan $arg]
  5685. if {$return == "1"} {
  5686. break
  5687. }
  5688. }
  5689. }
  5690. if {[string equal -nocase $prot "badword"]} {
  5691. if {[setting:get $chan antibadword]} {
  5692. set return [antibadword:protect $nick $host $hand $chan $arg]
  5693. if {$return == "1"} {
  5694. break
  5695. }
  5696. }
  5697. }
  5698. if {[string equal -nocase $prot "longtext"]} {
  5699. if {[setting:get $chan antilongtext]} {
  5700. set return [antilongtext:protect $nick $host $hand $chan $arg]
  5701. if {$return == "1"} {
  5702. break
  5703. }
  5704. }
  5705. }
  5706. if {[string equal -nocase $prot "repetitivechars"]} {
  5707. if {[setting:get $chan repetitivechars]} {
  5708. set return [repetitivechars:protect $nick $host $hand $chan $arg]
  5709. if {$return == "1"} {
  5710. break
  5711. }
  5712. }
  5713. }
  5714. if {[string equal -nocase $prot "color"]} {
  5715. if {[setting:get $chan anticolor]} {
  5716. set return [anticolor:protect $nick $host $hand $chan $arg]
  5717. if {$return == "1"} {
  5718. break
  5719. }
  5720. }
  5721. }
  5722. if {[string equal -nocase $prot "bold"]} {
  5723. if {[setting:get $chan antibold]} {
  5724. set return [antibold:protect $nick $host $hand $chan $arg]
  5725. if {$return == "1"} {
  5726. break
  5727. }
  5728. }
  5729. }
  5730. if {[string equal -nocase $prot "underline"]} {
  5731. if {[setting:get $chan antiunderline]} {
  5732. set return [antiunderline:protect $nick $host $hand $chan $arg]
  5733. if {$return == "1"} {
  5734. break
  5735. }
  5736. }
  5737. }
  5738. if {[string equal -nocase $prot "caps"]} {
  5739. if {[setting:get $chan anticaps]} {
  5740. set return [anticaps:protect $nick $host $hand $chan $arg]
  5741. if {$return == "1"} {
  5742. break
  5743. }
  5744. }
  5745. }
  5746. if {[string equal -nocase $prot "floodchan"]} {
  5747. if {[setting:get $chan antichanflood]} {
  5748. set return [antifloodchan:protect $nick $host $hand $chan $arg]
  5749. if {$return == "1"} {
  5750. break
  5751. }
  5752. }
  5753. }
  5754. if {[string equal -nocase $prot "antirepeat"]} {
  5755. if {[setting:get $chan antirepeat]} {
  5756. set return [antirepeat:protect $nick $host $hand $chan $arg]
  5757. if {$return == "1"} {
  5758. break
  5759. }
  5760. }
  5761. }
  5762. }
  5763. }
  5764. ############################## ipcidr #############################
  5765. proc ipcidr {cidrAddr addr} {
  5766. global {cidr-support}
  5767. if {[info exists {cidr-support}]} {
  5768. if {${cidr-support} == "1"} {
  5769. set getip [lindex [split $cidrAddr "/"] 0]
  5770. set getcidr [lindex [split $cidrAddr "/"] 1]
  5771. set cidr [matchcidr $getip $addr $getcidr]
  5772. return $cidr
  5773. } else { return 0 }
  5774. } else { return 0 }
  5775. }
  5776. ######################### dns search ##############################
  5777. proc blacktools:dns:auto_ban {nick host vhost chan realname} {
  5778. global black
  5779. set check_dns [dns:checkexcept $host]
  5780. if {$check_dns == "1"} {
  5781. blacktools:auto:ban_act $nick $host "" $chan $realname
  5782. return
  5783. }
  5784. dnslookup $vhost dns:resolve:auto_ban $vhost $nick $host $chan $realname
  5785. }
  5786. proc dns:resolve:auto_ban {ip host status hostip nick fullhost chan realname} {
  5787. if {!$status} {
  5788. blacktools:auto:ban_act $nick $fullhost "" $chan $realname
  5789. } elseif {[string tolower $ip] == [string tolower $hostip]} {
  5790. blacktools:auto:ban_act $nick $fullhost $hostip $chan $realname
  5791. } else {
  5792. blacktools:auto:ban_act $nick $fullhost $ip $chan $realname
  5793. }
  5794. return 0
  5795. }
  5796. proc blacktools:dns:join {nick host vhost hand chan realname} {
  5797. global black
  5798. set check_dns [dns:checkexcept $host]
  5799. if {$check_dns == "1"} {
  5800. blacktools:join:autoban $nick "" "" $hand $chan $host $realname
  5801. return
  5802. }
  5803. if {[regexp {[/]} $host]} {
  5804. blacktools:join:autoban $nick "" "" $hand $chan $host $realname
  5805. return
  5806. }
  5807. dnslookup $vhost dns:resolve:join $vhost $nick $host $hand $chan $realname
  5808. }
  5809. proc blacktools:dns:sb {bhost what nick hand host vhost chan chan1 type cmd entry} {
  5810. global black
  5811. set check_dns [dns:checkexcept $bhost]
  5812. if {$check_dns == "1"} {
  5813. sb:act $bhost $what $nick $hand $host "" $chan $chan1 $type $cmd $entry
  5814. return
  5815. }
  5816. dnslookup $vhost dns:resolve:sb $vhost $what $nick $hand $bhost $vhost $chan $chan1 $type $cmd $entry
  5817. }
  5818. proc dns:resolve:sb {ip host status hostip what nick hand fullhost vhost chan chan1 type cmd entry} {
  5819. global black
  5820. if {!$status} {
  5821. sb:act $fullhost $what $nick $hand $host "" $chan $chan1 $type $cmd $entry
  5822. } elseif {[string tolower $ip] == [string tolower $hostip]} {
  5823. sb:act $fullhost $what $nick $hand $host $host $chan $chan1 $type $cmd $entry
  5824. } else {
  5825. sb:act $fullhost $what $nick $hand $host $ip $chan $chan1 $type $cmd $entry
  5826. }
  5827. return 0
  5828. }
  5829. proc blacktools:dns:ub {user mask nick hand host vhost chan chan1 type gl cmd whois link id prv} {
  5830. global black
  5831. set check_dns [dns:checkexcept $mask]
  5832. if {$check_dns == "1"} {
  5833. ub:act $user $mask $nick $hand "" "" $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5834. return
  5835. }
  5836. if {$id == "id"} {
  5837. ub:act $user $mask $nick $hand "" "" $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5838. return
  5839. }
  5840. dnslookup $vhost dns:resolve:ub $vhost $user $mask $nick $hand $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5841. }
  5842. proc dns:resolve:ub {ip host status hostip user mask nick hand chan chan1 type gl cmd whois link id prv} {
  5843. global black
  5844. if {!$status} {
  5845. ub:act $user $mask $nick $hand "" "" $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5846. } elseif {[string tolower $ip] == [string tolower $hostip]} {
  5847. ub:act $user $mask $nick $hand $host $host $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5848. } else {
  5849. ub:act $user $mask $nick $hand $ip $host $chan $chan1 $type $gl $cmd $whois $link $id $prv
  5850. }
  5851. return 0
  5852. }
  5853. proc dns:resolve:join {ip host status hostip nick fullhost hand chan realname} {
  5854. if {!$status} {
  5855. blacktools:join:autoban $nick $hostip "" $hand $chan $fullhost $realname
  5856. } elseif {[string tolower $ip] == [string tolower $hostip]} {
  5857. blacktools:join:autoban $nick $hostip $host $hand $chan $fullhost $realname
  5858. } else {
  5859. blacktools:join:autoban $nick $ip $host $hand $chan $fullhost $realname
  5860. }
  5861. return 0
  5862. }
  5863. proc dns:checkexcept {host} {
  5864. global black
  5865. set valid_except 0
  5866. if {$black(dns_onjoin) == 0} {
  5867. return 1
  5868. }
  5869. set host [lindex [split $host "@"] 1]
  5870. set check_ipv4 [regexp {^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$} $host]
  5871. set check_ipv6 [regexp {^([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})$} $host]
  5872. if {$check_ipv4 == 1 || $check_ipv6 == 1} {return 1}
  5873. foreach h $black(dns:host_excepts) {
  5874. if {[string match -nocase $h $host]} {
  5875. set valid_except 1
  5876. }
  5877. }
  5878. return $valid_except
  5879. }
  5880. ################################ Balist FULL ##############################
  5881. proc blacktools:banlistfull {from keyword arguments} {
  5882. global black botnick {net-type}
  5883. set chanbans ""
  5884. set chan [lindex [split $arguments] 1]
  5885. set getlang [string tolower [setting:get $chan lang]]
  5886. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  5887. if {${net-type} == "2"} { set maxbans 45 } elseif {${net-type} == "3"} { set maxbans 100 } elseif {${net-type} == "1"} { set maxbans 64 } elseif {${net-type} == "0"} { set maxbans 100 } else { set maxbans 45 }
  5888. set banlist [lsort -index 2 -integer -decreasing [chanbans $chan]]
  5889. set llength_banlist [llength $banlist]
  5890. if {[llength $banlist] > 0} {
  5891. foreach ban $banlist {
  5892. if {[blacktools:sticky [lindex $ban 0] $chan] == 1} {
  5893. continue
  5894. }
  5895. if {[isbansticky [lindex $ban 0] $chan]} {
  5896. continue
  5897. }
  5898. lappend chanbans [lindex $ban 0]
  5899. }
  5900. }
  5901. if {$chanbans != ""} {
  5902. set length_maxbans [llength [join $chanbans]]
  5903. if {$length_maxbans > $maxbans} {
  5904. set bans_to_remove [expr [expr $length_maxbans - $maxbans] + $black(fullbanlist_remove)]
  5905. } else {
  5906. set bans_to_remove $black(fullbanlist_remove)
  5907. }
  5908. if {![info exists black(onotice:$chan:fullbanlist)]} {
  5909. set replace(%maxbans%) $maxbans
  5910. set replace(%numbans%) $llength_banlist
  5911. set replace(%chan%) $chan
  5912. set text [black:color:set $botnick $black(say.$getlang.gl.fullbans)]
  5913. putserv "NOTICE @$chan :[string map [array get replace] $text]"
  5914. foreach tmr [utimers] {
  5915. if {[string match "*unset:mode_time:fullbanlist $chan*" [join [lindex $tmr 1]]]} {
  5916. killutimer [lindex $tmr 2]
  5917. }
  5918. }
  5919. putserv "MODE $chan +$black(fullbanlist_modes)"
  5920. utimer $black(fullbanlist_hold_mode) [list unset:mode_time:fullbanlist $chan]
  5921. }
  5922. set black(onotice:$chan:fullbanlist) 1
  5923. set banlist [lrange [join $chanbans] 0 [expr $bans_to_remove - 1]]
  5924. foreach ban $banlist {
  5925. pushmode $chan -b $ban
  5926. }
  5927. foreach tmr [utimers] {
  5928. if {[string match "*unset:flag:fullbanlist $chan*" [join [lindex $tmr 1]]]} {
  5929. killutimer [lindex $tmr 2]
  5930. }
  5931. }
  5932. utimer 30 [list unset:flag:fullbanlist $chan]
  5933. }
  5934. }
  5935. proc unset:mode_time:fullbanlist {chan} {
  5936. global black
  5937. putserv "MODE $chan -$black(fullbanlist_modes)"
  5938. }
  5939. proc unset:flag:fullbanlist {chan} {
  5940. global black
  5941. if {[info exists black(onotice:$chan:fullbanlist)]} {
  5942. unset black(onotice:$chan:fullbanlist)
  5943. }
  5944. }
  5945. ####################### Channel TCL Settings Save #########################
  5946. proc blacktools:settings:autosave {} {
  5947. global black
  5948. set channels ""
  5949. foreach chan [channels] {
  5950. if {[setting:get $chan settingsaved]} {
  5951. continue
  5952. } else {
  5953. lappend channels $chan
  5954. }
  5955. }
  5956. if {$channels != ""} {
  5957. blacktools:settings:save $channels 0
  5958. }
  5959. }
  5960. proc blacktools:settings:save {channels num} {
  5961. global black
  5962. set chan [lindex $channels $num]
  5963. #antipub
  5964. foreach line $black(antipubword) {
  5965. blacktools:setting:add "ANTIPUB" $chan $line
  5966. }
  5967. #badhost
  5968. foreach line $black(badhostword) {
  5969. blacktools:setting:add "BADHOST" $chan $line
  5970. }
  5971. #antibadword
  5972. foreach line $black(antibadword) {
  5973. blacktools:setting:add "BADWORD" $chan $line
  5974. }
  5975. #antibadquitpart
  5976. foreach line $black(badquitpartwords) {
  5977. blacktools:setting:add "BADQUITPART" $chan $line
  5978. }
  5979. #antispam
  5980. foreach line $black(spamword) {
  5981. blacktools:setting:add "ANTISPAM" $chan $line
  5982. }
  5983. #badrealname
  5984. foreach line $black(badfwords) {
  5985. blacktools:setting:add "BADREALNAME" $chan $line
  5986. }
  5987. #badnick
  5988. foreach line $black(badnickwords) {
  5989. blacktools:setting:add "BADNICK" $chan $line
  5990. }
  5991. #badident
  5992. foreach line $black(badidentwords) {
  5993. blacktools:setting:add "BADIDENT" $chan $line
  5994. }
  5995. set j [expr $num + 1]
  5996. setting:set $chan +settingsaved ""
  5997. if {[lindex $channels $j] != ""} {
  5998. blacktools:settings:save $channels $j
  5999. }
  6000. }
  6001. proc blacktools:setting:add {protname chan text} {
  6002. global black
  6003. set num 0
  6004. set temp_num 0
  6005. while {$temp_num == 0} {
  6006. set get [addextra:find:num $chan $protname $num]
  6007. if {$get == "$num"} {
  6008. set num [expr $num + 1]
  6009. } else { set temp_num 1 }
  6010. }
  6011. set findword [prot:findword $chan $protname $text]
  6012. if {$findword != "1"} {
  6013. set enc_chan [encoding convertto utf-8 $chan]
  6014. set file [open $black(add_file) a]
  6015. puts $file "$enc_chan $protname $num $text"
  6016. close $file
  6017. }
  6018. }
  6019. #################
  6020. ###########################################################################
  6021. ## END ##
  6022. ###########################################################################