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) "1615556948"
  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) || [string equal -nocase $nick "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. return
  2473. }
  2474. set online [expr [unixtime] - ${server-online}]
  2475. set read_uptime [expr [unixtime] - $uptime]
  2476. set file [open $black(uptime_file) "r"]
  2477. set data [read -nonewline $file]
  2478. close $file
  2479. set get_uptime 0
  2480. set get_online 0
  2481. set get_uptime [lindex $data 0]
  2482. set get_online [lindex $data 1]
  2483. if {$read_uptime > $get_uptime} {
  2484. set add_uptime $read_uptime
  2485. } else {
  2486. set add_uptime $get_uptime
  2487. }
  2488. if {${server-online} != "0"} {
  2489. if {$online > $get_online} {
  2490. set add_online $online
  2491. } else {
  2492. set add_online $get_online
  2493. }
  2494. } else {
  2495. set add_online $get_online
  2496. }
  2497. set file [open $black(uptime_file) "w"]
  2498. puts $file "$add_uptime $add_online"
  2499. close $file
  2500. }
  2501. ############################## VERSION ################################
  2502. proc blackreply {nick host hand dest key text} {
  2503. global ctcp-version black
  2504. if {[string equal -nocase $key "version"]} {
  2505. set {ctcp-version} "Using \002$black(name) $black(vers)\002 coded by \002$black(author)\002 ($black(site))"
  2506. }
  2507. }
  2508. ########################### Return Mask ##############################
  2509. proc return_mask {type uhost user} {
  2510. global black
  2511. set ident [lindex [split $uhost "@"] 0]
  2512. set host [lindex [split $uhost @] 1]
  2513. switch $type {
  2514. 1 {
  2515. return "*!*@$host"
  2516. }
  2517. 2 {
  2518. return "*!$ident@$host"
  2519. }
  2520. 3 {
  2521. return "$user!$ident@$host"
  2522. }
  2523. 4 {
  2524. return "$user!*@*"
  2525. }
  2526. 5 {
  2527. return "*!$ident@*"
  2528. }
  2529. }
  2530. }
  2531. ########################### Return USERHOST Mask ####################
  2532. proc ub:get:host {from keyword arguments} {
  2533. global black
  2534. set hosts [lindex [split $arguments] 1]
  2535. set hostname [lindex [split $hosts "="] 1]
  2536. regsub {^[-+]} $hostname "" mask
  2537. set nickname [lindex [split $hosts "="] 0]
  2538. regsub {^:} $nickname "" nick
  2539. set fullmask "$nick!$mask"
  2540. set user $::uuser
  2541. set mask $fullmask
  2542. set nick $::unick
  2543. set hand $::uhand
  2544. set host $::uhost
  2545. set chan $::uchan
  2546. set chan1 $::uchan1
  2547. set type $::utype
  2548. set gl $::ugl
  2549. set cmd $::ucmd
  2550. set link $::ulink
  2551. set prv $::prv
  2552. if {$hosts == ":"} {
  2553. set mask $user
  2554. }
  2555. set vhost [lindex [split $mask @] 1]
  2556. if {[string equal -nocase $gl "1"] && [matchattr $hand nm]} {
  2557. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "1" $cmd "1" "" "" $prv
  2558. } elseif {[string equal -nocase $link "1"] && [matchattr $hand nm]} {
  2559. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "" "ub" "1" "1" "" $prv
  2560. } else {
  2561. blacktools:dns:ub $user $mask $nick $hand $host $vhost $chan $chan1 $type "" $cmd "1" "" "" $prv
  2562. }
  2563. check:if:bind "ub:get:host" "302"
  2564. }
  2565. proc sb:get:host {from keyword arguments} {
  2566. global black
  2567. set hosts [lindex [split $arguments] 1]
  2568. set hostname [lindex [split $hosts "="] 1]
  2569. regsub {^[-+]} $hostname "" mask
  2570. set nickname [lindex [split $hosts "="] 0]
  2571. regsub {^:} $nickname "" nick
  2572. set fullmask "$nick!$mask"
  2573. set what $::swhat
  2574. set bhost $fullmask
  2575. set nick $::snick
  2576. set hand $::shand
  2577. set host $::shost
  2578. set chan $::schan
  2579. set chan1 $::schan1
  2580. set type $::stype
  2581. set cmd $::scmd
  2582. if {$hosts == ":"} {
  2583. set bhost "-"
  2584. }
  2585. sb:process $bhost $what $nick $hand $host $chan $chan1 $type "sb" "1"
  2586. check:if:bind "sb:get:host" "302"
  2587. }
  2588. proc userhost:get:host {from keyword arguments} {
  2589. global black
  2590. set hosts [lindex [split $arguments] 1]
  2591. set hostname [lindex [split $hosts "="] 1]
  2592. regsub {^[-+]} $hostname "" mask
  2593. set nick $::bnick
  2594. set txt $::getnick
  2595. set hand $::userhand
  2596. set host $::userhost
  2597. set chan $::userchan
  2598. set chan1 $::userchan1
  2599. set type $::usertype
  2600. set bantime $::userbantime
  2601. set cmd $::usercmd
  2602. set rs $::userrs
  2603. set gl $::usergl
  2604. if {$hosts == ":"} {
  2605. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotexist $txt
  2606. } else {
  2607. bancmds:process $txt $mask $nick $hand $host $chan $chan1 $type $bantime $cmd $rs $gl
  2608. }
  2609. check:if:bind "userhost:get:host" "302"
  2610. }
  2611. proc userhost:act {why nick hand host chan chan1 type bantime cmd rs gl} {
  2612. global black
  2613. set split_hand [split $hand ":"]
  2614. set rcmd [lindex $cmd 0]
  2615. set regex [lindex $cmd 1]
  2616. set gethand [lindex $split_hand 0]
  2617. set cmd_status [btcmd:status $chan $gethand $rcmd 0]
  2618. set yes_whois 0
  2619. set why [strip:all $why]
  2620. if {$cmd_status == "1"} {
  2621. return
  2622. }
  2623. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  2624. return
  2625. }
  2626. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  2627. return
  2628. }
  2629. if {$why == ""} {
  2630. switch $type {
  2631. 0 {
  2632. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $rcmd
  2633. }
  2634. 1 {
  2635. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $rcmd
  2636. }
  2637. 2 {
  2638. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $rcmd
  2639. }
  2640. }
  2641. return 0
  2642. }
  2643. if {[validchan $chan] && ![onchan $why $chan] && $gl != "1"} {
  2644. set yes_whois 1
  2645. }
  2646. if {$gl == "1"} {
  2647. set yes_whois 1
  2648. }
  2649. if {$regex != "REGEX"} {
  2650. if {$rcmd != "troll"} {
  2651. if {(![regexp {\*} $why]) && $yes_whois == "1"} {
  2652. putserv "USERHOST :$why"
  2653. bind RAW - 302 userhost:get:host
  2654. set ::bnick $nick
  2655. set ::getnick $why
  2656. set ::userhand $hand
  2657. set ::userhost $host
  2658. set ::userchan $chan
  2659. set ::userchan1 $chan1
  2660. set ::usertype $type
  2661. set ::userbantime $bantime
  2662. set ::usercmd $cmd
  2663. set ::userrs $rs
  2664. set ::usergl $gl
  2665. return
  2666. }
  2667. }
  2668. }
  2669. bancmds:process $why $why $nick $hand $host $chan $chan1 $type $bantime $cmd $rs $gl
  2670. }
  2671. ########################### bancmds return host #######################
  2672. proc return_host_num {cmd chan host} {
  2673. global black
  2674. if {$cmd == "b:gl"} {
  2675. return [get:banmask "$cmd" $chan]
  2676. }
  2677. switch [string tolower $cmd] {
  2678. topwords {
  2679. set mask [get:mask "topwords" $chan]
  2680. set check_webchat [check:webchat $host]
  2681. if {$mask == "1" && $check_webchat == "1"} {
  2682. return "5"
  2683. } else {
  2684. return $mask
  2685. }
  2686. }
  2687. hello {
  2688. set mask [get:mask "hello" $chan]
  2689. set check_webchat [check:webchat $host]
  2690. if {$mask == "1" && $check_webchat == "1"} {
  2691. return "5"
  2692. } else {
  2693. return $mask
  2694. }
  2695. }
  2696. mb {
  2697. return "5"
  2698. }
  2699. clonescan {
  2700. return 1
  2701. }
  2702. default {
  2703. set mask [get:banmask $cmd $chan]
  2704. set check_webchat [check:webchat $host]
  2705. if {$mask == "1" && $check_webchat == "1"} {
  2706. return "5"
  2707. } else {
  2708. return $mask
  2709. }
  2710. }
  2711. }
  2712. }
  2713. proc check:webchat {host} {
  2714. global black
  2715. set webchat_found 0
  2716. set host "*!$host"
  2717. foreach h $black(webchat_hosts) {
  2718. if {[string match -nocase $h $host]} {
  2719. set webchat_found 1
  2720. break
  2721. }
  2722. }
  2723. return $webchat_found
  2724. }
  2725. ########################## bancmds process ###########################
  2726. proc bancmds:process {user mask nick hand host chan chan1 type bantime cmd rs gl} {
  2727. global black botnick
  2728. set rcmd [lindex $cmd 0]
  2729. set regex [lindex $cmd 1]
  2730. set split_hand [split $hand ":"]
  2731. set gethand [lindex $split_hand 0]
  2732. set comment ""
  2733. set cmd_status [btcmd:status $chan $gethand $rcmd 0]
  2734. if {$cmd_status == "1"} {
  2735. return
  2736. }
  2737. set getlang [string tolower [setting:get $chan lang]]
  2738. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  2739. set show_user $user
  2740. set handle [nick2hand $user]
  2741. if {[matchattr $gethand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  2742. return
  2743. }
  2744. if {[matchattr $gethand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  2745. return
  2746. }
  2747. if {![validchan $chan] && $gl == "0"} {
  2748. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  2749. return
  2750. }
  2751. if {$gl != "1"} {
  2752. set massban [check:massban $mask $chan]
  2753. if {$massban == "1"} {
  2754. blacktools:tell $nick $host $hand $chan $chan1 b.9 none
  2755. return
  2756. }
  2757. }
  2758. if {[isbotnick $user]} {
  2759. return
  2760. }
  2761. if {$gl != "1"} {
  2762. if {![onchan $botnick $chan]} {
  2763. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  2764. return
  2765. }
  2766. }
  2767. if {$gl != "1"} {
  2768. if {[matchattr $handle $black(exceptflags) $chan]} {
  2769. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2770. return
  2771. }
  2772. } else {
  2773. if {[matchattr $handle $black(glflags)]} {
  2774. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2775. return
  2776. }
  2777. }
  2778. set reason_cmds "b stick black mb"
  2779. if {$rs != "" && [lsearch -exact $reason_cmds $rcmd] > -1} {
  2780. set getreason $rs
  2781. } else {
  2782. if {$rs != ""} {
  2783. if {[regexp {(-comment)} $rs]} {
  2784. set split_it [wsplit $rs "-comment"]
  2785. } elseif {[regexp {(-com)} $rs]} {
  2786. set split_it [wsplit $rs "-com"]
  2787. } elseif {[regexp {(-c)} $rs]} {
  2788. set split_it [wsplit $rs "-c"]
  2789. }
  2790. set comment [concat [lindex $split_it 1]]
  2791. }
  2792. set getreason [setting:get $chan $rcmd-reason]
  2793. }
  2794. if {$getreason == ""} {
  2795. set getreason $black(say.$getlang.$rcmd.5)
  2796. if {$rcmd == "b"} {
  2797. set len [llength $getreason]
  2798. set random [expr int(rand()*$len)]
  2799. set getreason [lindex $getreason $random]
  2800. }
  2801. }
  2802. if {$comment != ""} {
  2803. set getreason "$getreason -c $comment"
  2804. }
  2805. if {![string equal -nocase "$rcmd" "black"] && ![string equal -nocase "$rcmd" "bl"] && ![string equal -nocase "$rcmd" "troll"] && ![string equal -nocase "$rcmd" "b"]} {
  2806. set getbantime [setting:get $chan $rcmd-bantime]
  2807. } else { set getbantime 0 }
  2808. if {[string equal -nocase "$rcmd" "b"] || [string equal -nocase "$rcmd" "stick"]} {
  2809. if {[time_return_minute $bantime] == [time_return_minute $black($rcmd:bantime)]} {
  2810. set setbantime [time_return_minute [setting:get $chan $rcmd-bantime]]
  2811. if {$setbantime == "-1"} {
  2812. set getbantime $bantime
  2813. } else {
  2814. set getbantime $setbantime
  2815. }
  2816. } else { set getbantime "" }
  2817. }
  2818. if {$getbantime == ""} {
  2819. set getbantime $bantime
  2820. }
  2821. if {$rcmd == "troll"} {
  2822. set getbantime $bantime
  2823. }
  2824. if {$gl != "1"} {
  2825. if {![onchan $user $chan] && $rcmd == "troll"} {
  2826. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $show_user
  2827. return
  2828. }
  2829. if {[regexp {\*} $mask] && $rcmd == "mb"} {
  2830. switch $type {
  2831. 0 {
  2832. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $rcmd
  2833. }
  2834. 1 {
  2835. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $rcmd
  2836. }
  2837. 2 {
  2838. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $rcmd
  2839. }
  2840. }
  2841. return
  2842. }
  2843. }
  2844. if {$gl != "1"} {
  2845. if {[onchan $user $chan]} {
  2846. set mask [return_mask [return_host_num $rcmd $chan [getchanhost $user $chan]] [getchanhost $user $chan] $user]
  2847. } elseif {![regexp {\*} $mask] && $regex != "REGEX"} {
  2848. set mask [return_mask [return_host_num $rcmd $chan $mask] $mask $user]
  2849. }
  2850. } else {
  2851. if {![regexp {\*} $mask] && $regex != "REGEX"} {
  2852. set mask [return_mask [return_host_num "$rcmd:gl" $chan $mask] $mask $user]
  2853. }
  2854. }
  2855. if {$gl != "1"} {
  2856. set list [userlist $black(exceptflags) $chan]
  2857. foreach u $list {
  2858. set hosts [getuser $u hosts]
  2859. foreach h $hosts {
  2860. if {[string match -nocase "$mask" $h]} {
  2861. blacktools:tell $nick $host $hand $chan $chan1 gl.noban none
  2862. return
  2863. }
  2864. }
  2865. }
  2866. if {$rcmd == "stick"} {
  2867. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "1" $cmd $nick $user $host
  2868. return
  2869. }
  2870. if {$rcmd == "troll"} {
  2871. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "2" $cmd $nick $user $host
  2872. return
  2873. }
  2874. if {$rcmd == "bot" && [onchan $user $chan]} {
  2875. set getreason "$getreason - $black(say.$getlang.$rcmd.8)"
  2876. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "3" $cmd $nick $user $host
  2877. return
  2878. }
  2879. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime BANS($chan) "" $cmd $nick $user $host
  2880. } elseif {$gl == "2"} {
  2881. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime "link" "" $cmd $nick $user $host
  2882. } elseif {$gl == "1"} {
  2883. blacktools:banner:3 $mask $hand $chan $chan1 $getreason $getbantime "gl" "" $cmd $nick $user $host
  2884. }
  2885. }
  2886. proc check:massban {host chan} {
  2887. global black
  2888. set totuser [llength [chanlist $chan]]
  2889. set counter 0
  2890. foreach user [chanlist $chan] {
  2891. set gethost "$user![getchanhost $user $chan]"
  2892. if {[string match -nocase $host $gethost]} {
  2893. set counter [expr $counter + 1]
  2894. }
  2895. }
  2896. if {[expr 100 * $counter / $totuser] > $black(chanserv:percent_ban)} {
  2897. return 1
  2898. }
  2899. return 0
  2900. }
  2901. ################################## Join Auto Ban #############################
  2902. proc reason:details:module {nick host hand chan} {
  2903. global botnick black
  2904. if {![validchan $chan]} {
  2905. return
  2906. }
  2907. who:nick $nick $chan
  2908. }
  2909. proc blacktools:ban:chanexempt {mask dns chan} {
  2910. global black
  2911. set check_it [matchexempt $mask $chan]
  2912. if {$check_it == "1"} {
  2913. return $check_it
  2914. } else {
  2915. set check_it [matchexempt $mask]
  2916. }
  2917. if {$check_it == "1"} {
  2918. return $check_it
  2919. }
  2920. set check_it [matchexempt $dns $chan]
  2921. if {$check_it == "1"} {
  2922. return $check_it
  2923. } else {
  2924. set check_it [matchexempt $dns]
  2925. }
  2926. if {$check_it == "1"} {
  2927. return $check_it
  2928. }
  2929. return $check_it
  2930. }
  2931. proc blacktools:ban:exempt {mask} {
  2932. global black
  2933. set check_it [matchexempt $mask]
  2934. return $check_it
  2935. }
  2936. ############################ Ban Procedure #########################
  2937. proc blacktools:link_ban {chanlink first b nick hand char chan chan1 type return_time cmd reason num} {
  2938. global black
  2939. set first_chan [lindex $chanlink $first]
  2940. set counter [expr $first + 1]
  2941. if {$first_chan != ""} {
  2942. userhost:act $b $nick "$hand" $char $first_chan $chan1 $type $return_time $cmd $reason "2"
  2943. }
  2944. if {[lindex $chanlink $counter] != ""} {
  2945. utimer 5 [list blacktools:link_ban [link:chan:get $chan] $counter $b $nick $hand $char $chan $chan1 $type $return_time $cmd $reason 2]
  2946. }
  2947. }
  2948. proc blacktools:link_ban2 {chanlink first} {
  2949. global black
  2950. set first_chan [lindex $chanlink $first]
  2951. set counter [expr $first + 1]
  2952. if {$first_chan != ""} {
  2953. who:chan $first_chan
  2954. }
  2955. if {[lindex $chanlink $counter] != ""} {
  2956. utimer 5 [list blacktools:link_ban2 $chanlink $counter]
  2957. }
  2958. }
  2959. #http://wiki.tcl.tk/989
  2960. proc wsplit {string sep} {
  2961. set first [string first $sep $string]
  2962. if {$first == -1} {
  2963. return [list $string]
  2964. } else {
  2965. set l [string length $sep]
  2966. set left [string range $string 0 [expr {$first-1}]]
  2967. set right [string range $string [expr {$first+$l}] end]
  2968. return [concat [list $left] [wsplit $right $sep]]
  2969. }
  2970. }
  2971. ###
  2972. proc blacktools:regex_escape {text} {
  2973. global black
  2974. regsub -all {\W} $text {\\&} text
  2975. return "$text"
  2976. }
  2977. ###
  2978. proc who:nick {nick chan} {
  2979. global black
  2980. putquick "WHO :$nick"
  2981. set ::who_nick $nick
  2982. set ::who_nick_chan $chan
  2983. bind RAW - 352 get:nicklist
  2984. bind RAW - 315 end:nicklist
  2985. }
  2986. proc get:nicklist {from keyword arguments} {
  2987. global black
  2988. set who_nick $::who_nick
  2989. set chan $::who_nick_chan
  2990. set ident [lindex [split $arguments] 2]
  2991. set host [lindex [split $arguments] 3]
  2992. set nick [lindex [split $arguments] 5]
  2993. set realname [strip:all [lrange [split $arguments] 8 end]]
  2994. set uhost "$nick!$ident@$host"
  2995. if {[string equal -nocase $who_nick $nick]} {
  2996. set vhost [lindex [split $uhost @] 1]
  2997. blacktools:dns:join $nick $uhost $vhost "" $chan $realname
  2998. }
  2999. }
  3000. proc end:nicklist {from keyword arguments} {
  3001. global black
  3002. if {[info exists ::who_nick_chan]} {
  3003. unset ::who_nick_chan
  3004. }
  3005. if {[info exists ::who_nick]} {
  3006. unset ::who_nick
  3007. }
  3008. unbind RAW - 352 get:nicklist
  3009. unbind RAW - 315 end:nicklist
  3010. }
  3011. proc who:chan {chan} {
  3012. global black
  3013. if {![botisop $chan] && ![setting:get $chan xonly]} {
  3014. return
  3015. }
  3016. putquick "WHO :$chan"
  3017. set ::thechan $chan
  3018. bind RAW - 352 get:chanlist
  3019. bind RAW - 315 end:chanlist
  3020. }
  3021. proc mode:who:chan {chan} {
  3022. global black
  3023. putquick "WHO :$chan"
  3024. set ::thechan $chan
  3025. bind RAW - 352 get:chanlist
  3026. bind RAW - 315 end:chanlist
  3027. }
  3028. proc get:chanlist {from keyword arguments} {
  3029. global black
  3030. set chan [lindex [split $arguments] 1]
  3031. set ident [lindex [split $arguments] 2]
  3032. set host [lindex [split $arguments] 3]
  3033. set nick [lindex [split $arguments] 5]
  3034. set realname [lrange [split $arguments] 8 end]
  3035. set thechan $::thechan
  3036. set uhost "$nick!$ident@$host"
  3037. if {[string equal -nocase $thechan $chan]} {
  3038. blacktools:auto:ban $nick $uhost $thechan $realname
  3039. }
  3040. }
  3041. proc end:chanlist {from keyword arguments} {
  3042. global black
  3043. unbind RAW - 352 get:chanlist
  3044. unbind RAW - 315 end:chanlist
  3045. if {[info exists ::thechan]} {
  3046. unset ::thechan
  3047. }
  3048. }
  3049. proc blacktools:auto:ban {nick uhost chan realname} {
  3050. global black
  3051. set vhost [lindex [split $uhost @] 1]
  3052. blacktools:dns:auto_ban $nick $uhost $vhost $chan $realname
  3053. }
  3054. proc blacktools:rem_comment {reason} {
  3055. global black
  3056. if {[regexp {(%C%)} $reason]} {
  3057. set is_comment 1
  3058. set split_it [wsplit $reason "%C%"]
  3059. set comment [concat [lindex $split_it 1]]
  3060. set reason [concat [lindex $split_it 0]]
  3061. }
  3062. return $reason
  3063. }
  3064. proc blacktools:rem_comment_ban {reason} {
  3065. global black
  3066. set split_it ""
  3067. if {[regexp {(-comment)} $reason]} {
  3068. set split_it [wsplit $reason "-comment"]
  3069. } elseif {[regexp {(-com)} $reason]} {
  3070. set split_it [wsplit $reason "-com"]
  3071. } elseif {[regexp {(-c)} $reason]} {
  3072. set split_it [wsplit $reason "-c"]
  3073. }
  3074. if {$split_it != ""} {
  3075. set comment [concat [lindex $split_it 1]]
  3076. set reason [concat [lindex $split_it 0]]
  3077. }
  3078. return $reason
  3079. }
  3080. proc blacktools:get_comment {reason} {
  3081. global black
  3082. set comment ""
  3083. if {[regexp {(%C%)} $reason]} {
  3084. set is_comment 1
  3085. set split_it [wsplit $reason "%C%"]
  3086. set comment [concat [lindex $split_it 1]]
  3087. }
  3088. if {$comment != ""} {
  3089. return $comment
  3090. } else { return -1 }
  3091. }
  3092. proc decr { int { n 1 } } {
  3093. if { [ catch {
  3094. uplevel incr $int -$n
  3095. } err ] } {
  3096. return -code error "decr: $err"
  3097. }
  3098. return [ uplevel set $int ]
  3099. }
  3100. proc blacktools:bl:setreason {chan reason bywho expire kcount gl id} {
  3101. global black
  3102. set split_hand [split $bywho ":"]
  3103. set cmd [lindex $split_hand 1]
  3104. set reason [blacktools:rem_comment $reason]
  3105. if {$expire != "0"} {
  3106. set expire [return_reason_time [expr $expire - [unixtime]]]
  3107. }
  3108. set show_reason "$reason"
  3109. if {$gl == "0"} {
  3110. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3111. set show_reason "$show_reason \[id: $id\]"
  3112. }
  3113. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3114. set show_reason "$show_reason \[bantime: $expire\]"
  3115. }
  3116. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3117. set show_reason "$show_reason - [join [setting:get $chan url]]"
  3118. }
  3119. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3120. set show_reason "$show_reason - $kcount -"
  3121. }
  3122. } elseif {$gl == "1"} {
  3123. if {[setting:get $chan showhandle]} {
  3124. set show_reason "\[$bywho\] (GLOBAL) $reason"
  3125. } else { set show_reason "(GLOBAL) $reason" }
  3126. if {[setting:get $chan showid]} {
  3127. set show_reason "$show_reason \[id: $id\]"
  3128. }
  3129. } else {
  3130. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3131. set show_reason "(REGEX) $show_reason \[id: $id\]"
  3132. }
  3133. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3134. set show_reason "(REGEX) $show_reason \[bantime: $expire\]"
  3135. }
  3136. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3137. set show_reason "(REGEX) $show_reason - [join [setting:get $chan url]]"
  3138. }
  3139. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3140. set show_reason "(REGEX) $show_reason - $kcount -"
  3141. }
  3142. }
  3143. return $show_reason
  3144. }
  3145. proc blacktools:setreason {chan reason bywho expire kcount gl id} {
  3146. global black
  3147. set split_hand [split $bywho ":"]
  3148. set gethand [lindex $split_hand 0]
  3149. set cmd [lindex $split_hand 1]
  3150. set reason [blacktools:rem_comment $reason]
  3151. if {$expire != "0"} {
  3152. set expire [return_reason_time [expr $expire - [unixtime]]]
  3153. }
  3154. if {$gl == "0"} {
  3155. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  3156. if {[setting:get $chan showhandle] && $gethand != ""} {
  3157. set show_reason "\[$gethand\] $reason"
  3158. } else { set show_reason "$reason" }
  3159. } else {
  3160. set show_reason "$reason"
  3161. }
  3162. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3163. set show_reason "$show_reason \[id: $id\]"
  3164. }
  3165. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3166. set show_reason "$show_reason \[bantime: $expire\]"
  3167. }
  3168. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3169. set show_reason "$show_reason - [join [setting:get $chan url]]"
  3170. }
  3171. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3172. set show_reason "$show_reason - $kcount -"
  3173. }
  3174. } elseif {$gl == "1"} {
  3175. if {[setting:get $chan showhandle]} {
  3176. set show_reason "\[$bywho\] (GLOBAL) $reason"
  3177. } else { set show_reason "(GLOBAL) $reason" }
  3178. if {[setting:get $chan showid]} {
  3179. set show_reason "$show_reason \[id: $id\]"
  3180. }
  3181. } elseif {$gl == "3"} {
  3182. if {[setting:get $chan showhandle]} {
  3183. set show_reason "\[$bywho\] (GLOBAL) (REGEX) $reason"
  3184. } else { set show_reason "(GLOBAL) (REGEX) $reason" }
  3185. } else {
  3186. if {![string equal -nocase $gethand "BADCHAN"] && ![string equal -nocase $gethand "badident"] && ![string equal -nocase $gethand "badnick"] && ![string equal -nocase $gethand "antibadquitpart"] && ![string equal -nocase $gethand "antichanflood"] && ![string equal -nocase $gethand "badrealname"] && ![string equal -nocase $gethand "antispam"] && ![string equal -nocase $gethand "badhost"] && ![string equal -nocase $gethand "antipub"] && ![string equal -nocase $gethand "antijoinflood"] && ![string equal -nocase $gethand "antinotice"] && ![string equal -nocase $gethand "antictcp"] && ![string equal -nocase $gethand "antirepeat"] && ![string equal -nocase $gethand "antibold"] && ![string equal -nocase $gethand "anticolor"] && ![string equal -nocase $gethand "antiunderline"] && ![string equal -nocase $gethand "antilongtext"] && ![string equal -nocase $gethand "antibadword"] && ![string equal -nocase $gethand "anticaps"] && ![string equal -nocase $gethand "nickflood"] && ![string equal -nocase $gethand "inviteban"] && ![string equal -nocase $gethand "private"] && ![string equal -nocase $gethand "clonescan"] && ![string equal -nocase $gethand "repetitivechars"] && ![string equal -nocase $gethand "noproxy"]} {
  3187. if {[setting:get $chan showhandle] && $gethand != ""} {
  3188. set show_reason "\[$gethand\] (REGEX) $reason"
  3189. } else { set show_reason "(REGEX) $reason" }
  3190. } else {
  3191. set show_reason "$reason"
  3192. }
  3193. if {[setting:get $chan showid] && ($cmd != "bot")} {
  3194. set show_reason "(REGEX) $show_reason \[id: $id\]"
  3195. }
  3196. if {[setting:get $chan showtime] && ($expire != "0") && ($cmd != "bot")} {
  3197. set show_reason "(REGEX) $show_reason \[bantime: $expire\]"
  3198. }
  3199. if {[setting:get $chan showurl] && ([setting:get $chan url] != "") && ($cmd != "bot")} {
  3200. set show_reason "(REGEX) $show_reason - [join [setting:get $chan url]]"
  3201. }
  3202. if {[setting:get $chan showcount] && ($cmd != "bot")} {
  3203. set show_reason "(REGEX) $show_reason - $kcount -"
  3204. }
  3205. }
  3206. return $show_reason
  3207. }
  3208. proc blacktools:check:levelban {hand chan level} {
  3209. global black
  3210. if {[lsearch -exact -nocase $level "-c"] > -1} {
  3211. return ""
  3212. } elseif {[lsearch -nocase $level "-com"] > -1} {
  3213. return ""
  3214. } elseif {[lsearch -nocase $level "-comment"] > -1} {
  3215. return ""
  3216. }
  3217. set level [string map {"-" ""} $level]
  3218. set levels ""
  3219. if {[matchattr $hand o]} {
  3220. set levels "[string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]] [string tolower [blacktools:getlevelname 8 $hand]]"
  3221. set split_levels [split $levels " "]
  3222. foreach l $split_levels {
  3223. if {[string equal -nocase $l $level]} {
  3224. return $l
  3225. }
  3226. }
  3227. }
  3228. if {[matchattr $hand nm]} {
  3229. set levels "[string tolower [blacktools:getlevelname 2 $hand]] [string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]] [string tolower [blacktools:getlevelname 8 $hand]]"
  3230. set split_levels [split $levels " "]
  3231. foreach l $split_levels {
  3232. if {[string equal -nocase $l $level]} {
  3233. return $l
  3234. }
  3235. }
  3236. }
  3237. if {[matchattr $hand -|M $chan]} {
  3238. set levels "[string tolower [blacktools:getlevelname 3 $hand]] [string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]]"
  3239. set split_levels [split $levels " "]
  3240. foreach l $split_levels {
  3241. if {[string equal -nocase $l $level]} {
  3242. return $l
  3243. }
  3244. }
  3245. }
  3246. if {[matchattr $hand -|A $chan]} {
  3247. set levels "[string tolower [blacktools:getlevelname 4 $hand]] [string tolower [blacktools:getlevelname 5 $hand]]"
  3248. set split_levels [split $levels " "]
  3249. foreach l $split_levels {
  3250. if {[string equal -nocase $l $level]} {
  3251. return $l
  3252. }
  3253. }
  3254. }
  3255. if {[matchattr $hand -|O $chan]} {
  3256. set levels "[string tolower [blacktools:getlevelname 5 $hand]]"
  3257. set split_levels [split $levels " "]
  3258. foreach l $split_levels {
  3259. if {[string equal -nocase $l $level]} {
  3260. return $l
  3261. }
  3262. }
  3263. }
  3264. return "0 [join [string toupper $levels] ", "]"
  3265. }
  3266. proc blacktools:check:levelub {hand chan level} {
  3267. global black
  3268. set getlevel ""
  3269. if {[string equal -nocase $level [blacktools:getlevelname 2 $hand]] || [string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3270. if {[matchattr $hand nm]} {
  3271. set getlevel [blacktools:getlevelname 2 $hand]
  3272. } elseif {[matchattr $hand o]} {
  3273. set getlevel [blacktools:getlevelname 8 $hand]
  3274. } elseif {[matchattr $hand -|M $chan]} {
  3275. set getlevel [blacktools:getlevelname 3 $hand]
  3276. } elseif {[matchattr $hand -|A $chan]} {
  3277. set getlevel [blacktools:getlevelname 4 $hand]
  3278. } elseif {[matchattr $hand -|O $chan]} {
  3279. set getlevel [blacktools:getlevelname 5 $hand]
  3280. }
  3281. if {[string equal -nocase $getlevel [blacktools:getlevelname 2 $hand]]} {
  3282. if {[string equal -nocase $level [blacktools:getlevelname 2 $hand]] || [string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3283. return 1
  3284. }
  3285. }
  3286. if {[string equal -nocase $getlevel [blacktools:getlevelname 8 $hand]]} {
  3287. if {[string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]] || [string equal -nocase $level [blacktools:getlevelname 8 $hand]]} {
  3288. return 1
  3289. }
  3290. }
  3291. if {[string equal -nocase $getlevel [blacktools:getlevelname 3 $hand]]} {
  3292. if {[string equal -nocase $level [blacktools:getlevelname 3 $hand]] || [string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3293. return 1
  3294. }
  3295. }
  3296. if {[string equal -nocase $getlevel [blacktools:getlevelname 4 $hand]]} {
  3297. if {[string equal -nocase $level [blacktools:getlevelname 4 $hand]] || [string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3298. return 1
  3299. }
  3300. }
  3301. if {[string equal -nocase $getlevel [blacktools:getlevelname 5 $hand]]} {
  3302. if {[string equal -nocase $level [blacktools:getlevelname 5 $hand]]} {
  3303. return 1
  3304. }
  3305. }
  3306. } else { return 0 }
  3307. return -1
  3308. }
  3309. ################################### Login ###############################
  3310. proc loginpublic:start {} {
  3311. global black botnick
  3312. if {$black(autologin) == "0"} {
  3313. return
  3314. }
  3315. if {[info exists black(logged)]} {
  3316. putlog "\002\[BT\]\002 Still logged.."
  3317. return
  3318. }
  3319. chanserv:ignore_remove
  3320. if {[info exists black(notlogged:invalid)]} {
  3321. unset black(notlogged:invalid)
  3322. }
  3323. if {[info exists black(notlogged:failed)]} {
  3324. unset black(notlogged:failed)
  3325. }
  3326. if {[info exists black(notlogged)]} {
  3327. unset black(notlogged)
  3328. }
  3329. putserv "PRIVMSG $black(hostchanserv) :login $black(username) $black(password)"
  3330. putserv "PRIVMSG $black(hostchanserv) :set lang EN"
  3331. putserv "MODE $botnick :$black(xmod)"
  3332. bind RAW - 401 check:chanserv
  3333. }
  3334. proc loginpublic {my} {
  3335. global botnick black
  3336. if {$black(autologin) == "0"} {
  3337. return
  3338. }
  3339. chanserv:ignore_remove
  3340. if {[info exists black(logged)]} {
  3341. unset black(logged)
  3342. }
  3343. if {[info exists black(notlogged)]} {
  3344. unset black(notlogged)
  3345. }
  3346. putserv "PRIVMSG $black(hostchanserv) :login $black(username) $black(password)"
  3347. putserv "MODE $botnick :$black(xmod)"
  3348. bind RAW - 401 check:chanserv
  3349. }
  3350. ########################## show line output ##########################
  3351. proc module:getinfo {nick host hand chan chan1 type text modul gl next} {
  3352. global black
  3353. set remain 0
  3354. set top ""
  3355. set split_modul [split $modul ":"]
  3356. set themodul [lindex $split_modul 0]
  3357. if {$themodul == "topwords" || $themodul == "topbans"} {
  3358. set maxentries "10"
  3359. } else {
  3360. set maxentries $black(modul:nr:entries)
  3361. }
  3362. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3363. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3364. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  3365. if {$getmethod == ""} { set getmethod $black(default_output) }
  3366. if {[string equal -nocase $next "-next"]} {
  3367. if {[info exists black($modul:more:$chan:$hand)]} {
  3368. if {$black($modul:more:$chan:$hand) >= $maxentries} {
  3369. for {set i $black($modul:show:$chan:$hand)} { $i < [expr $black($modul:show:$chan:$hand) + $maxentries] } { incr i } {
  3370. set current_text [lindex $text $i]
  3371. if {$themodul == "topwords" || $themodul == "topbans"} {
  3372. if {$current_text != ""} {
  3373. set nr_text [lindex [split $current_text] 0]
  3374. set read_nick [lindex [split $current_text] 1]
  3375. set counter [lindex [split $current_text] 2]
  3376. lappend top $read_nick:$nr_text:$counter
  3377. }
  3378. } else {
  3379. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3380. }
  3381. }
  3382. if {$themodul == "topwords" || $themodul == "topbans"} {
  3383. if {$black($modul:more:$chan:$hand) > 0} {
  3384. set remain 1
  3385. }
  3386. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3387. }
  3388. set black($modul:more:$chan:$hand) [expr $black($modul:more:$chan:$hand) - $maxentries]
  3389. if {$host == "prv"} {
  3390. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "1"
  3391. } else {
  3392. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "0"
  3393. }
  3394. set black($modul:show:$chan:$hand) [expr $black($modul:show:$chan:$hand) + $maxentries]
  3395. } else {
  3396. if {$black($modul:more:$chan:$hand) < 1} {
  3397. return
  3398. }
  3399. for {set i $black($modul:show:$chan:$hand)} { $i <= [expr $black($modul:show:$chan:$hand) + $black($modul:more:$chan:$hand)]} { incr i } {
  3400. set current_text [lindex $text $i]
  3401. if {$themodul == "topwords" || $themodul == "topbans"} {
  3402. if {$current_text != ""} {
  3403. set nr_text [lindex [split $current_text] 0]
  3404. set read_nick [lindex [split $current_text] 1]
  3405. set counter [lindex [split $current_text] 2]
  3406. lappend top $read_nick:$nr_text:$counter
  3407. }
  3408. } else {
  3409. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3410. }
  3411. }
  3412. if {$themodul == "topwords" || $themodul == "topbans"} {
  3413. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3414. }
  3415. set black($modul:more:$chan:$hand) [expr $black($modul:more:$chan:$hand) - $black($modul:show:$chan:$hand)]
  3416. }
  3417. foreach tmr [utimers] {
  3418. if {[string match -nocase "*module:getinfo:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  3419. killutimer [lindex $tmr 2]
  3420. }
  3421. }
  3422. utimer 30 [list module:getinfo:unset:more $chan $hand $modul]
  3423. if {$black($modul:more:$chan:$hand) < 1} {
  3424. switch $themodul {
  3425. badchan {
  3426. blacktools:tell $nick $host $hand $chan $chan1 $modul.4 none
  3427. }
  3428. notesinbox {
  3429. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3430. }
  3431. noteslist {
  3432. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3433. }
  3434. anunt {
  3435. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3436. }
  3437. tcl {
  3438. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3439. }
  3440. quote {
  3441. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3442. }
  3443. guestnick {
  3444. blacktools:tell $nick $host $hand $chan $chan1 $modul.9 none
  3445. }
  3446. autobroadcast {
  3447. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3448. }
  3449. topwords {
  3450. }
  3451. topbans {
  3452. }
  3453. badword {
  3454. blacktools:tell $nick $host $hand $chan $chan1 antibadword.3 none
  3455. }
  3456. badquitpart {
  3457. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.3 none
  3458. }
  3459. default {
  3460. blacktools:tell $nick $host $hand $chan $chan1 $themodul.3 none
  3461. }
  3462. }
  3463. }
  3464. }
  3465. return
  3466. }
  3467. switch $themodul {
  3468. badchan {
  3469. if {$gl == "1"} {
  3470. blacktools:tell $nick $host $hand $chan $chan1 $modul.15 none
  3471. } else {
  3472. blacktools:tell $nick $host $hand $chan $chan1 $modul.14 none
  3473. }
  3474. }
  3475. anunt {
  3476. blacktools:tell $nick $host $hand $chan $chan1 $modul.8 none
  3477. }
  3478. tcl {
  3479. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3480. }
  3481. notesinbox {
  3482. }
  3483. noteslist {
  3484. }
  3485. quote {
  3486. blacktools:tell $nick $host $hand $chan $chan1 $modul.8 none
  3487. }
  3488. guestnick {
  3489. blacktools:tell $nick $host $hand $chan $chan1 $modul.7 none
  3490. }
  3491. autobroadcast {
  3492. blacktools:tell $nick $host $hand $chan $chan1 $modul.9 none
  3493. }
  3494. topwords {
  3495. }
  3496. topbans {
  3497. }
  3498. badword {
  3499. blacktools:tell $nick $host $hand $chan $chan1 antibadword.7 none
  3500. }
  3501. badquitpart {
  3502. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.7 none
  3503. }
  3504. default {
  3505. blacktools:tell $nick $host $hand $chan $chan1 $themodul.7 none
  3506. }
  3507. }
  3508. set black($modul:ltext:$chan:$hand) [llength $text]
  3509. set black($modul:show:$chan:$hand) 0
  3510. if {$black($modul:ltext:$chan:$hand) > $maxentries} {
  3511. set black($modul:more:$chan:$hand) [expr $black($modul:ltext:$chan:$hand) - $maxentries]
  3512. for {set i 0} { $i < $maxentries } { incr i } {
  3513. set current_text [lindex $text $i]
  3514. if {$themodul == "topwords" || $themodul == "topbans"} {
  3515. if {$current_text != ""} {
  3516. set nr_text [lindex [split $current_text] 0]
  3517. set read_nick [lindex [split $current_text] 1]
  3518. set counter [lindex [split $current_text] 2]
  3519. lappend top $read_nick:$nr_text:$counter
  3520. }
  3521. } else {
  3522. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3523. }
  3524. }
  3525. if {$themodul == "topwords" || $themodul == "topbans"} {
  3526. if {$black($modul:more:$chan:$hand) > 0} {
  3527. set remain 1
  3528. }
  3529. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3530. }
  3531. set black($modul:show:$chan:$hand) [expr $black($modul:show:$chan:$hand) + $maxentries]
  3532. if {$black($modul:more:$chan:$hand) > 0} {
  3533. if {$host == "prv"} {
  3534. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "1"
  3535. } else {
  3536. modul:remain $nick $host $hand $black($modul:more:$chan:$hand) $chan $chan1 $getmethod $modul $gl "0"
  3537. }
  3538. }
  3539. foreach tmr [utimers] {
  3540. if {[string match -nocase "*module:getinfo:unset:more $chan $hand*" [join [lindex $tmr 1]]]} {
  3541. killutimer [lindex $tmr 2]
  3542. }
  3543. }
  3544. utimer 60 [list module:getinfo:unset:more $chan $hand $modul]
  3545. } else {
  3546. for {set i 0} { $i < $maxentries } { incr i } {
  3547. set current_text [lindex $text $i]
  3548. if {$themodul == "topwords" || $themodul == "topbans"} {
  3549. if {$current_text != ""} {
  3550. set nr_text [lindex [split $current_text] 0]
  3551. set read_nick [lindex [split $current_text] 1]
  3552. set counter [lindex [split $current_text] 2]
  3553. lappend top $read_nick:$nr_text:$counter
  3554. }
  3555. } else {
  3556. show:modul:info $nick $host $hand $chan $chan1 $current_text $modul $remain
  3557. }
  3558. }
  3559. if {$themodul == "topwords" || $themodul == "topbans"} {
  3560. show:modul:info $nick $host $hand $chan $chan1 $top $modul $remain
  3561. }
  3562. switch $themodul {
  3563. badchan {
  3564. blacktools:tell $nick $host $hand $chan $chan1 $modul.4 none
  3565. }
  3566. anunt {
  3567. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3568. }
  3569. tcl {
  3570. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3571. }
  3572. notesinbox {
  3573. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3574. }
  3575. noteslist {
  3576. blacktools:tell $nick $host $hand $chan $chan1 $modul.13 none
  3577. }
  3578. quote {
  3579. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3580. }
  3581. guestnick {
  3582. blacktools:tell $nick $host $hand $chan $chan1 $modul.9 none
  3583. }
  3584. autobroadcast {
  3585. blacktools:tell $nick $host $hand $chan $chan1 $modul.10 none
  3586. }
  3587. topwords {
  3588. }
  3589. topbans {
  3590. }
  3591. badword {
  3592. blacktools:tell $nick $host $hand $chan $chan1 antibadword.3 none
  3593. }
  3594. badquitpart {
  3595. blacktools:tell $nick $host $hand $chan $chan1 antibadquitpart.3 none
  3596. }
  3597. default {
  3598. blacktools:tell $nick $host $hand $chan $chan1 $themodul.3 none
  3599. }
  3600. }
  3601. }
  3602. }
  3603. proc module:getinfo:unset:more {chan hand modul} {
  3604. global black
  3605. if {[info exists black($modul:more:$chan:$hand)]} {
  3606. unset black($modul:more:$chan:$hand)
  3607. }
  3608. if {[info exists black($modul:ltext:$chan:$hand)]} {
  3609. unset black($modul:ltext:$chan:$hand)
  3610. }
  3611. if {[info exists black($modul:show:$chan:$hand)]} {
  3612. unset black($modul:show:$chan:$hand)
  3613. }
  3614. }
  3615. proc show:modul:info {nick host hand chan chan1 text modul remain} {
  3616. global black lastbind
  3617. set split_modul [split $modul ":"]
  3618. set themodul [lindex $split_modul 0]
  3619. set total [lindex $split_modul 1]
  3620. set otherchan 0
  3621. set top ""
  3622. if {$chan != $chan1} {
  3623. set otherchan 1
  3624. }
  3625. if {$text == ""} { return }
  3626. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3627. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3628. if {$themodul == "topwords" || $themodul == "topbans"} {
  3629. foreach entry $text {
  3630. set split_entry [split $entry ":"]
  3631. set nickname [lindex $split_entry 1]
  3632. set word_count [lindex $split_entry 0]
  3633. set place [lindex $split_entry 2]
  3634. lappend top "\002#$place\002. $nickname ($word_count)"
  3635. }
  3636. if {$remain == "1"} {
  3637. set split_lastbind [split $lastbind ""]
  3638. set charbind [lindex $split_lastbind 0]
  3639. if {[lsearch -exact $black(cmdchar) $charbind] < 0} {
  3640. set charbind ""
  3641. }
  3642. set replace(%char%) $charbind
  3643. set replace(%chan%) $chan
  3644. if {[string equal -nocase $total "total"]} {
  3645. if {$otherchan == "1"} {
  3646. set others [string map [array get replace] $black(say.$getlang.$themodul.12)]
  3647. } else {
  3648. set others [string map [array get replace] $black(say.$getlang.$themodul.11)]
  3649. }
  3650. } elseif {[string equal -nocase $total "week"]} {
  3651. if {$otherchan == "1"} {
  3652. set others [string map [array get replace] $black(say.$getlang.$themodul.25)]
  3653. } else {
  3654. set others [string map [array get replace] $black(say.$getlang.$themodul.26)]
  3655. }
  3656. } else {
  3657. if {$otherchan == "1"} {
  3658. set others [string map [array get replace] $black(say.$getlang.$themodul.13)]
  3659. } else {
  3660. set others [string map [array get replace] $black(say.$getlang.$themodul.9)]
  3661. }
  3662. }
  3663. if {[string equal -nocase $total "total"]} {
  3664. blacktools:tell $nick $host $hand $chan $chan1 $themodul.1 "[join $top] $others"
  3665. } elseif {[string equal -nocase $total "week"]} {
  3666. blacktools:tell $nick $host $hand $chan $chan1 $themodul.24 "[join $top] $others"
  3667. } else {
  3668. blacktools:tell $nick $host $hand $chan $chan1 $themodul.2 "[join $top] $others"
  3669. }
  3670. } else {
  3671. if {[string equal -nocase $total "total"]} {
  3672. blacktools:tell $nick $host $hand $chan $chan1 $themodul.1 "[join $top]"
  3673. } elseif {[string equal -nocase $total "week"]} {
  3674. blacktools:tell $nick $host $hand $chan $chan1 $themodul.24 "[join $top]"
  3675. } else {
  3676. blacktools:tell $nick $host $hand $chan $chan1 $themodul.2 "[join $top]"
  3677. }
  3678. }
  3679. return
  3680. }
  3681. set num [lindex [split $text] 0]
  3682. set gettext [join [lrange [split $text] 1 end]]
  3683. set encoded [encoding convertfrom utf-8 $gettext]
  3684. set gettext [lindex [split $text] 0]
  3685. blacktools:tell $nick $host $hand $chan $chan1 gl.showline "$num [join $encoded]"
  3686. }
  3687. proc modul:remain {nick host hand count chan chan1 type modul gl prv} {
  3688. global black lastbind botnick
  3689. set otherchan 0
  3690. set charbind ""
  3691. if {$chan != $chan1} {
  3692. set otherchan 1
  3693. }
  3694. if {$count == "0"} { return }
  3695. set split_modul [split $modul ":"]
  3696. set themodul [lindex $split_modul 0]
  3697. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  3698. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  3699. set firstchar [lindex $black(cmdchar) 0]
  3700. if {[string equal $lastbind "*"]} {
  3701. set charbind "prv" } elseif {[string equal -nocase "**" $lastbind]} { set charbind "$botnick "
  3702. } elseif {[string equal -nocase "***" $lastbind]} {
  3703. set split_host [split $host ":"]
  3704. if {[lindex $split_host 1] == "chan"} {
  3705. set host [lindex $split_host 1]
  3706. set charbind [lindex $split_host 0]
  3707. } else {
  3708. set charbind "$host"
  3709. }
  3710. }
  3711. if {$charbind == ""} {
  3712. set charbind $firstchar
  3713. if {[validuser $hand]} {
  3714. set getchar [getuser $hand XTRA MYCHAR]
  3715. if {$getchar != ""} {
  3716. set charbind $getchar
  3717. }
  3718. }
  3719. }
  3720. if {$charbind == "prv"} { set charbind "" }
  3721. set replace(%char%) $charbind
  3722. set replace(%counter%) $count
  3723. set replace(%chan%) $chan
  3724. switch [string tolower $themodul] {
  3725. badchan {
  3726. if {$otherchan == "1" || $prv == "1"} {
  3727. set msg $black(say.$getlang.$modul.41)
  3728. } else {
  3729. set msg $black(say.$getlang.$modul.3)
  3730. }
  3731. if {$gl == "1"} {
  3732. set msg $black(say.$getlang.$modul.2)
  3733. }
  3734. }
  3735. anunt {
  3736. if {$otherchan == "1" || $prv == "1"} {
  3737. set msg $black(say.$getlang.$modul.14)
  3738. } else {
  3739. set msg $black(say.$getlang.$modul.9)
  3740. }
  3741. }
  3742. tcl {
  3743. set msg $black(say.$getlang.$modul.9)
  3744. }
  3745. notesinbox {
  3746. if {$otherchan == "1" || $prv == "1"} {
  3747. set msg $black(say.$getlang.$modul.16)
  3748. } else {
  3749. set msg $black(say.$getlang.$modul.15)
  3750. }
  3751. }
  3752. noteslist {
  3753. if {$otherchan == "1" || $prv == "1"} {
  3754. set msg $black(say.$getlang.$modul.16)
  3755. } else {
  3756. set msg $black(say.$getlang.$modul.15)
  3757. }
  3758. }
  3759. quote {
  3760. if {$otherchan == "1" || $prv == "1"} {
  3761. set msg $black(say.$getlang.$modul.14)
  3762. } else {
  3763. set msg $black(say.$getlang.$modul.9)
  3764. }
  3765. }
  3766. topwords {
  3767. set msg ""
  3768. }
  3769. topbans {
  3770. set msg ""
  3771. }
  3772. guestnick {
  3773. if {$otherchan == "1" || $prv == "1"} {
  3774. set msg $black(say.$getlang.$modul.11)
  3775. } else {
  3776. set msg $black(say.$getlang.$modul.8)
  3777. }
  3778. }
  3779. autobroadcast {
  3780. set msg $black(say.$getlang.$modul.12)
  3781. }
  3782. badword {
  3783. if {$otherchan == "1" || $prv == "1"} {
  3784. set msg $black(say.$getlang.antibadword.9)
  3785. } else {
  3786. set msg $black(say.$getlang.antibadword.8)
  3787. }
  3788. }
  3789. badquitpart {
  3790. if {$otherchan == "1" || $prv == "1"} {
  3791. set msg $black(say.$getlang.antibadquitpart.9)
  3792. } else {
  3793. set msg $black(say.$getlang.antibadquitpart.8)
  3794. }
  3795. }
  3796. default {
  3797. if {$otherchan == "1" || $prv == "1"} {
  3798. set msg $black(say.$getlang.$themodul.9)
  3799. } else {
  3800. set msg $black(say.$getlang.$themodul.8)
  3801. }
  3802. }
  3803. }
  3804. if {$msg == ""} {
  3805. return
  3806. }
  3807. blacktools:tell:cmd $nick $host $hand $chan $chan1 $prv $type [string map [array get replace] $msg]
  3808. }
  3809. ########################## Other Module Process ######################
  3810. proc othermodule:process {nick host hand chan chan1 who msg type modul} {
  3811. global black botnick
  3812. set cmd_status [btcmd:status $chan $hand $modul 0]
  3813. if {$cmd_status == "1"} {
  3814. return
  3815. }
  3816. if {[matchattr $hand q]} {
  3817. blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  3818. return
  3819. }
  3820. if {[matchattr $hand -|q $chan]} {
  3821. blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  3822. return
  3823. }
  3824. if {![validchan $chan]} {
  3825. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3826. return
  3827. }
  3828. if {![onchan $botnick $chan]} {
  3829. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  3830. return
  3831. }
  3832. switch $who {
  3833. on {
  3834. if {[string equal -nocase $modul "topic"]} {
  3835. return
  3836. }
  3837. blacktools:tell $nick $host $hand $chan $chan1 $modul.2 none
  3838. setting:set $chan +$modul ""
  3839. }
  3840. off {
  3841. if {[string equal -nocase $modul "topic"]} {
  3842. return
  3843. }
  3844. blacktools:tell $nick $host $hand $chan $chan1 $modul.3 none
  3845. setting:set $chan -$modul ""
  3846. }
  3847. unset {
  3848. if {[string equal -nocase $modul "topic"]} {
  3849. putserv "TOPIC $chan :"
  3850. msg:del $chan $modul
  3851. blacktools:tell $nick $host $hand $chan $chan1 topic.4 none
  3852. }
  3853. }
  3854. set {
  3855. if {![string equal -nocase $modul "topic"]} {
  3856. if {$msg == ""} {
  3857. switch $type {
  3858. 0 {
  3859. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3860. }
  3861. 1 {
  3862. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $modul
  3863. }
  3864. 2 {
  3865. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $modul
  3866. }
  3867. }
  3868. return
  3869. }
  3870. }
  3871. if {[string equal -nocase $modul "topic"]} {
  3872. set thetopic [topic $chan]
  3873. set url [join [setting:get $chan url]]
  3874. if {$msg == ""} {
  3875. if {$url != ""} {
  3876. set gettopic [string map [list "([color:filter $url])" ""] [color:filter $thetopic]]
  3877. } else { set gettopic $thetopic }
  3878. set msg $gettopic
  3879. }
  3880. if {$msg == ""} {
  3881. blacktools:tell $nick $host $hand $chan $chan1 topic.2 none
  3882. return
  3883. }
  3884. if {$thetopic != $msg} {
  3885. blacktools:tell $nick $host $hand $chan $chan1 topic.1 $msg
  3886. if {$url != ""} {
  3887. putserv "TOPIC $chan :$msg ($url)"
  3888. } else { putserv "TOPIC $chan :$msg" }
  3889. } else {
  3890. blacktools:tell $nick $host $hand $chan $chan1 topic.3 $msg
  3891. }
  3892. msg:add $msg $chan $modul
  3893. return
  3894. }
  3895. msg:add $msg $chan $modul
  3896. blacktools:tell $nick $host $hand $chan $chan1 $modul.1 $msg
  3897. }
  3898. show {
  3899. set getline ""
  3900. set file [open $black(join_file) r]
  3901. while {[gets $file line] != -1} {
  3902. set read_modul [lindex [split $line] 0]
  3903. set read_chan [lindex [split $line] 1]
  3904. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $read_chan]} {
  3905. set read_msg [lrange [split $line] 2 end]
  3906. set getline [encoding convertfrom utf-8 $read_msg]
  3907. continue
  3908. }
  3909. }
  3910. close $file
  3911. blacktools:tell $nick $host $hand $chan $chan1 show.6 "$modul $getline"
  3912. }
  3913. default {
  3914. switch $type {
  3915. 0 {
  3916. blacktools:tell $nick $host $hand $chan $chan1 gl.instr $modul
  3917. }
  3918. 1 {
  3919. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick $modul
  3920. }
  3921. 2 {
  3922. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv $modul
  3923. }
  3924. }
  3925. }
  3926. }
  3927. }
  3928. proc msg:del {chan modul} {
  3929. global black
  3930. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  3931. set temp "$black(tempdir)/othermodule_temp.$timestamp"
  3932. set file [open $black(join_file) r]
  3933. set tempwrite [open $temp w]
  3934. while {[gets $file line] != -1} {
  3935. set read_modul [lindex [split $line] 0]
  3936. set read_chan [lindex [split $line] 1]
  3937. set enc_chan [encoding convertfrom utf-8 $read_chan]
  3938. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $enc_chan]} {
  3939. continue
  3940. } else {
  3941. puts $tempwrite $line
  3942. }
  3943. }
  3944. close $tempwrite
  3945. close $file
  3946. file rename -force $temp $black(join_file)
  3947. }
  3948. proc msg:add {msg chan modul} {
  3949. global black
  3950. set msg [encoding convertto utf-8 $msg]
  3951. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  3952. set temp "$black(tempdir)/othermodule_temp.$timestamp"
  3953. set file [open $black(join_file) r]
  3954. set tempwrite [open $temp w]
  3955. while {[gets $file line] != -1} {
  3956. set read_modul [lindex [split $line] 0]
  3957. set read_chan [lindex [split $line] 1]
  3958. set enc_chan [encoding convertfrom utf-8 $read_chan]
  3959. if {[string equal -nocase $read_modul $modul] && [string equal -nocase $chan $enc_chan]} {
  3960. continue
  3961. } else {
  3962. puts $tempwrite $line
  3963. }
  3964. }
  3965. close $tempwrite
  3966. close $file
  3967. file rename -force $temp $black(join_file)
  3968. set file [open $black(join_file) a]
  3969. set enc_chan [encoding convertto utf-8 $chan]
  3970. puts $file "[string toupper $modul] $enc_chan $msg"
  3971. close $file
  3972. }
  3973. ######################### Channel Remove Data ####################
  3974. proc delchan:all {chan} {
  3975. global black
  3976. if {$black(chanremove_all) == "0"} {
  3977. return
  3978. }
  3979. set files "$black(s_file) $black(seen_file) $black(bans_file) $black(join_file) $black(extra_file) $black(add_file) $black(quote_file)"
  3980. set split_files [split $files " "]
  3981. remove:chan:now $split_files 0 $chan
  3982. topwords:delete $chan
  3983. }
  3984. proc remove:chan:timer {minute hour day month year} {
  3985. global black
  3986. if {$black(chanremove_all) == "0"} {
  3987. return
  3988. }
  3989. set files "$black(s_file) $black(seen_file) $black(bans_file) $black(join_file) $black(extra_file) $black(add_file) $black(quote_file)"
  3990. set split_files [split $files " "]
  3991. remove:chan:now_timer $split_files 0
  3992. }
  3993. proc remove:chan:now_timer {files num} {
  3994. global black
  3995. set f [lindex $files $num]
  3996. if {[string match -nocase "*seen*" $f] || [string match -nocase *othermodule* $f]} {
  3997. set pos 1
  3998. } elseif {[string match -nocase "*bans*" $f]} {
  3999. set pos 2
  4000. } else {
  4001. set pos 0
  4002. }
  4003. set inc [expr $num + 1]
  4004. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4005. set temp "$black(tempdir)/removechan_temp.$timestamp"
  4006. set file [open $f r]
  4007. set tempwrite [open $temp w]
  4008. while {[gets $file line] != -1} {
  4009. if {$line != ""} {
  4010. set chan [lindex [split $line] $pos]
  4011. set encoded [encoding convertfrom utf-8 $chan]
  4012. if {[regexp {^[&#]} $encoded] && ![validchan $encoded]} {
  4013. continue
  4014. } else {
  4015. puts $tempwrite $line
  4016. }
  4017. }
  4018. }
  4019. close $tempwrite
  4020. close $file
  4021. file rename -force $temp $f
  4022. if {[lindex $files $inc] != ""} {
  4023. utimer 3 [list remove:chan:now_timer $files $inc]
  4024. }
  4025. }
  4026. proc remove:chan:now {files num c} {
  4027. global black
  4028. set f [lindex $files $num]
  4029. if {[string match -nocase "*seen*" $f] || [string match -nocase *othermodule* $f]} {
  4030. set pos 1
  4031. } elseif {[string match -nocase "*bans*" $f]} {
  4032. set pos 2
  4033. } else {
  4034. set pos 0
  4035. }
  4036. set inc [expr $num + 1]
  4037. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4038. set temp "$black(tempdir)/removechan_temp.$timestamp"
  4039. set file [open $f r]
  4040. set tempwrite [open $temp w]
  4041. while {[gets $file line] != -1} {
  4042. if {$line != ""} {
  4043. set chan [lindex [split $line] $pos]
  4044. set encoded [encoding convertfrom utf-8 $chan]
  4045. if {[string equal -nocase $c $encoded]} {
  4046. continue
  4047. } else {
  4048. puts $tempwrite $line
  4049. }
  4050. }
  4051. }
  4052. close $tempwrite
  4053. close $file
  4054. file rename -force $temp $f
  4055. if {[lindex $files $inc] != ""} {
  4056. utimer 3 [list remove:chan:now $files $inc $c]
  4057. }
  4058. }
  4059. ########################### Extra settings ########################
  4060. proc btcmd:global:set {hand cmd type} {
  4061. global black
  4062. if {[lsearch -exact $black(validcmds) $cmd] < 0} {
  4063. return 2
  4064. }
  4065. if {[string equal -nocase "enable" $cmd]} {
  4066. return 3
  4067. }
  4068. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4069. set temp "$black(tempdir)/add_file_temp.$timestamp"
  4070. set file [open $black(add_file) r]
  4071. set tempwrite [open $temp w]
  4072. set cmd_found 0
  4073. set disable_type 0
  4074. while {[gets $file line] != -1} {
  4075. set c [lindex [split $line] 0]
  4076. set gettype [lindex [split $line] 1]
  4077. set comp [lindex [split $line] 2]
  4078. if {[string equal -nocase $c "disable"] && [string equal -nocase $gettype "global"] && [string equal -nocase $comp $cmd]} {
  4079. set cmd_found 1
  4080. continue
  4081. } else {
  4082. puts $tempwrite $line
  4083. }
  4084. }
  4085. close $tempwrite
  4086. close $file
  4087. file rename -force $temp $black(add_file)
  4088. if {$type == "1"} {
  4089. set file [open $black(add_file) a]
  4090. puts $file "DISABLE GLOBAL [string toupper $cmd] $type"
  4091. close $file
  4092. }
  4093. return $cmd_found
  4094. }
  4095. proc btcmd:gl:status {cmd} {
  4096. global black
  4097. set file [open $black(add_file) r]
  4098. set cmd_found 0
  4099. while {[gets $file line] != -1} {
  4100. set disable [lindex [split $line] 0]
  4101. set c [lindex [split $line] 1]
  4102. set gettype [lindex [split $line] 2]
  4103. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4104. set cmd_found 1
  4105. continue
  4106. }
  4107. }
  4108. close $file
  4109. return $cmd_found
  4110. }
  4111. proc btcmd:status {chan hand cmd menureply} {
  4112. global black
  4113. set cmd_found 0
  4114. set access ""
  4115. set split_hand [split $hand ":"]
  4116. set hand [lindex $split_hand 0]
  4117. if {[matchattr $hand -|M $chan]} {
  4118. set access "MANAGER"
  4119. } elseif {[matchattr $hand n]} {
  4120. set access "BOSS"
  4121. } elseif {[matchattr $hand m]} {
  4122. set access "OWNER"
  4123. } elseif {[matchattr $hand o]} {
  4124. set access "MASTER"
  4125. }
  4126. if {$menureply == "1"} {
  4127. set file [open $black(add_file) r]
  4128. while {[gets $file line] != -1} {
  4129. set disable [lindex [split $line] 0]
  4130. set c [lindex [split $line] 1]
  4131. set gettype [lindex [split $line] 2]
  4132. set disable_level [lindex [split $line] 3]
  4133. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4134. set cmd_found 1
  4135. continue
  4136. }
  4137. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4138. switch $access {
  4139. MANAGER {
  4140. if {$disable_level == "OWNER"} {
  4141. set cmd_found 1
  4142. }
  4143. if {$disable_level == "BOSS"} {
  4144. set cmd_found 1
  4145. }
  4146. if {$disable_level == "MANAGER"} {
  4147. set cmd_found 1
  4148. }
  4149. if {$disable_level == "MASTER"} {
  4150. set cmd_found 1
  4151. }
  4152. }
  4153. OWNER {
  4154. if {$disable_level == "BOSS"} {
  4155. set cmd_found 1
  4156. }
  4157. if {$disable_level == "OWNER"} {
  4158. set cmd_found 1
  4159. }
  4160. }
  4161. MASTER {
  4162. if {$disable_level == "BOSS"} {
  4163. set cmd_found 1
  4164. }
  4165. if {$disable_level == "OWNER"} {
  4166. set cmd_found 1
  4167. }
  4168. if {$disable_level == "MASTER"} {
  4169. set cmd_found 1
  4170. }
  4171. }
  4172. BOSS {
  4173. if {$disable_level == "BOSS"} {
  4174. set cmd_found 1
  4175. }
  4176. }
  4177. default {
  4178. set cmd_found 1
  4179. }
  4180. }
  4181. }
  4182. }
  4183. close $file
  4184. return $cmd_found
  4185. }
  4186. set file [open $black(add_file) r]
  4187. while {[gets $file line] != -1} {
  4188. set disable [lindex [split $line] 0]
  4189. set c [lindex [split $line] 1]
  4190. set gettype [lindex [split $line] 2]
  4191. set disable_level [lindex [split $line] 3]
  4192. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c "global"] && [string equal -nocase $gettype $cmd]} {
  4193. set cmd_found 1
  4194. continue
  4195. }
  4196. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4197. switch $access {
  4198. MANAGER {
  4199. if {$disable_level == "OWNER"} {
  4200. set cmd_found 1
  4201. }
  4202. if {$disable_level == "BOSS"} {
  4203. set cmd_found 1
  4204. }
  4205. if {$disable_level == "MANAGER"} {
  4206. set cmd_found 1
  4207. }
  4208. if {$disable_level == "MASTER"} {
  4209. set cmd_found 1
  4210. }
  4211. }
  4212. OWNER {
  4213. if {$disable_level == "BOSS"} {
  4214. set cmd_found 1
  4215. }
  4216. if {$disable_level == "OWNER"} {
  4217. set cmd_found 1
  4218. }
  4219. }
  4220. MASTER {
  4221. if {$disable_level == "BOSS"} {
  4222. set cmd_found 1
  4223. }
  4224. if {$disable_level == "OWNER"} {
  4225. set cmd_found 1
  4226. }
  4227. if {$disable_level == "MASTER"} {
  4228. set cmd_found 1
  4229. }
  4230. }
  4231. BOSS {
  4232. if {$disable_level == "BOSS"} {
  4233. set cmd_found 1
  4234. }
  4235. }
  4236. default {
  4237. set cmd_found 1
  4238. }
  4239. }
  4240. }
  4241. }
  4242. if {$cmd_found == "0"} {
  4243. set user_cmd_status [getuser $hand XTRA $cmd\($chan\)]
  4244. if {$user_cmd_status == "OFF"} {
  4245. set cmd_found 1
  4246. }
  4247. }
  4248. close $file
  4249. return $cmd_found
  4250. }
  4251. proc btcmd:set:user {nick host hand chan chan1 user cmd type} {
  4252. global black
  4253. if {[lsearch -exact $black(validcmds) $cmd] < 0} {
  4254. return 2
  4255. }
  4256. set show_user $user
  4257. if {![validuser $user]} {
  4258. if {[onchan $user $chan]} {
  4259. set handle [nick2hand $user]
  4260. if {![validuser $handle]} {
  4261. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  4262. return
  4263. }
  4264. }
  4265. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  4266. return
  4267. }
  4268. set status [getuser $user XTRA $cmd\($chan\)]
  4269. switch $type {
  4270. 1 {
  4271. if {$status == "OFF"} {
  4272. blacktools:tell $nick $host $hand $chan $chan1 disable.5 "$cmd $show_user"
  4273. return
  4274. }
  4275. setuser $user XTRA $cmd\($chan\) OFF
  4276. blacktools:tell $nick $host $hand $chan $chan1 disable.4 "$cmd $show_user"
  4277. }
  4278. 0 {
  4279. if {$status == "OFF"} {
  4280. setuser $user XTRA $cmd\($chan\)
  4281. blacktools:tell $nick $host $hand $chan $chan1 enable.4 "$cmd $show_user"
  4282. return
  4283. }
  4284. blacktools:tell $nick $host $hand $chan $chan1 enable.5 "$cmd $show_user"
  4285. }
  4286. }
  4287. }
  4288. proc btcmd:getlevel {chan cmd} {
  4289. global black
  4290. set file [open $black(add_file) r]
  4291. set found_level ""
  4292. while {[gets $file line] != -1} {
  4293. set disable [lindex [split $line] 0]
  4294. set c [lindex [split $line] 1]
  4295. set gettype [lindex [split $line] 2]
  4296. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4297. set comp [lindex [split $line] 3]
  4298. set found_level $comp
  4299. }
  4300. }
  4301. close $file
  4302. return $found_level
  4303. }
  4304. proc btcmd:set {chan hand cmd type} {
  4305. global black
  4306. if {[lsearch -exact -nocase $black(validcmds) $cmd] < 0} {
  4307. return 2
  4308. }
  4309. if {[string equal -nocase "enable" $cmd]} {
  4310. return 3
  4311. }
  4312. if {[matchattr $hand -|M $chan]} {
  4313. set access "MANAGER"
  4314. } elseif {[matchattr $hand n]} {
  4315. set access "BOSS"
  4316. } elseif {[matchattr $hand m]} {
  4317. set access "OWNER"
  4318. } elseif {[matchattr $hand o]} {
  4319. set access "MASTER"
  4320. }
  4321. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4322. set temp "$black(tempdir)/add_file_temp.$timestamp"
  4323. set file [open $black(add_file) r]
  4324. set tempwrite [open $temp w]
  4325. set cmd_found 0
  4326. set disable_type 0
  4327. while {[gets $file line] != -1} {
  4328. set disable [lindex [split $line] 0]
  4329. set c [lindex [split $line] 1]
  4330. set gettype [lindex [split $line] 2]
  4331. set comp [lindex [split $line] 3]
  4332. if {[string equal -nocase $disable "disable"] && [string equal -nocase $c $chan] && [string equal -nocase $gettype $cmd]} {
  4333. set cmd_found 1
  4334. continue
  4335. } else {
  4336. puts $tempwrite $line
  4337. }
  4338. }
  4339. close $tempwrite
  4340. close $file
  4341. file rename -force $temp $black(add_file)
  4342. if {$type == "1"} {
  4343. set file [open $black(add_file) a]
  4344. puts $file "DISABLE $chan [string toupper $cmd] $access"
  4345. close $file
  4346. }
  4347. return $cmd_found
  4348. }
  4349. proc setting:set {chan setting msg} {
  4350. global black
  4351. set getsetting [string map {
  4352. "+" ""
  4353. "-" ""} $setting]
  4354. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  4355. set temp "$black(tempdir)/extra_temp.$timestamp"
  4356. set file [open $black(extra_file) r]
  4357. set tempwrite [open $temp w]
  4358. while {[gets $file line] != -1} {
  4359. set c [lindex [split $line] 0]
  4360. set gettype [lindex [split $line] 1]
  4361. set comp [lindex [split $line] 2]
  4362. set comp [string map {
  4363. "+" ""
  4364. "-" ""} $comp]
  4365. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp $getsetting]} {
  4366. continue
  4367. } else {
  4368. puts $tempwrite $line
  4369. }
  4370. }
  4371. close $tempwrite
  4372. close $file
  4373. file rename -force $temp $black(extra_file)
  4374. if {[regexp {^[-]} $setting]} {
  4375. return
  4376. }
  4377. set file [open $black(extra_file) a]
  4378. if {[regexp {^[+]} $setting]} {
  4379. puts $file "$chan XTRA [string toupper $setting]"
  4380. } else {
  4381. puts $file "$chan XTRA [string toupper $setting] $msg"
  4382. }
  4383. close $file
  4384. }
  4385. proc setting:exists {setting} {
  4386. global black
  4387. set found_it 0
  4388. if {[regexp {^[+-]} $setting]} {
  4389. set setting [string map {
  4390. "+" ""
  4391. "-" ""} $setting]
  4392. }
  4393. if {[lsearch -exact [string tolower $black(extra_flag)] [string tolower $setting]] > -1} {
  4394. set found_it 1
  4395. } elseif {[lsearch -exact [string tolower $black(extra_str)] [string tolower $setting]] > -1} {
  4396. set found_it 2
  4397. }
  4398. return $found_it
  4399. }
  4400. proc setting:status {chan setting msg} {
  4401. global black
  4402. set status 0
  4403. if {[regexp {^[+-]} $setting]} {
  4404. set file [open $black(extra_file) r]
  4405. while {[gets $file line] != -1} {
  4406. set c [lindex [split $line] 0]
  4407. set gettype [lindex [split $line] 1]
  4408. set comp [lindex [split $line] 2]
  4409. set comp_map [string map {
  4410. "+" ""
  4411. "-" ""} $comp]
  4412. set setting [string map {
  4413. "+" ""
  4414. "-" ""} $setting]
  4415. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp_map $setting]} {
  4416. if {[regexp {^[+]} $comp]} {
  4417. set status 1
  4418. }
  4419. }
  4420. }
  4421. close $file
  4422. return $status
  4423. }
  4424. set file [open $black(extra_file) r]
  4425. while {[gets $file line] != -1} {
  4426. set c [lindex [split $line] 0]
  4427. set gettype [lindex [split $line] 1]
  4428. set comp [lindex [split $line] 2]
  4429. set getmsg [lrange [split $line] 3 end]
  4430. if {![regexp {^[+-]} $comp]} {
  4431. if {[string equal -nocase $c $chan] && [string equal -nocase $gettype "XTRA"] && [string equal -nocase $comp $setting] && [string equal -nocase $msg $getmsg]} {
  4432. set status 1
  4433. }
  4434. }
  4435. }
  4436. close $file
  4437. return $status
  4438. }
  4439. proc setting:get {chan setting} {
  4440. global black
  4441. if {![file exists $black(extra_file)]} {return 0}
  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. ###########################################################################