BT.Core.tcl 182 KB

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