BT.Core.tcl 206 KB

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