BT.Core.tcl 179 KB

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