BT.Core.tcl 180 KB

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