BT.Core.tcl 169 KB

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