BT.Core.tcl 205 KB

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