BT.Core.tcl 182 KB

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