BT.Core.tcl 182 KB

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