BT.Core.tcl 180 KB

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