BT.Core.tcl 179 KB

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