BT.Core.tcl 179 KB

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