BT.Core.tcl 169 KB

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