BT.Core.tcl 209 KB

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