@@ -81,6 +81,43 @@ class Utils {
8181 }
8282 }
8383
84+ /**
85+ * Fetches HLTV rating for a user by Steam ID.
86+ * @param steamId - The user's Steam ID
87+ * @returns HLTV rating or null if not found
88+ */
89+ static async getRatingFromSteamId ( steamId : string ) : Promise < number | null > {
90+ let playerStatSql =
91+ `SELECT steam_id, name, sum(kills) as kills,
92+ sum(deaths) as deaths, sum(assists) as assists, sum(k1) as k1,
93+ sum(k2) as k2, sum(k3) as k3,
94+ sum(k4) as k4, sum(k5) as k5, sum(v1) as v1,
95+ sum(v2) as v2, sum(v3) as v3, sum(v4) as v4,
96+ sum(v5) as v5, sum(roundsplayed) as trp, sum(flashbang_assists) as fba,
97+ sum(damage) as dmg, sum(headshot_kills) as hsk, count(id) as totalMaps,
98+ sum(knife_kills) as knifekills, sum(friendlies_flashed) as fflash,
99+ sum(enemies_flashed) as eflash, sum(util_damage) as utildmg
100+ FROM player_stats
101+ WHERE steam_id = ?
102+ AND match_id IN (
103+ SELECT id
104+ FROM \`match\`
105+ WHERE cancelled = 0)` ;
106+ const user : RowDataPacket [ ] = await db . query ( playerStatSql , [ steamId ] ) ; ;
107+
108+ if ( ! user . length ) return null ;
109+
110+ return this . getRating ( parseFloat ( user [ 0 ] . kills ) ,
111+ parseFloat ( user [ 0 ] . trp ) ,
112+ parseFloat ( user [ 0 ] . deaths ) ,
113+ parseFloat ( user [ 0 ] . k1 ) ,
114+ parseFloat ( user [ 0 ] . k2 ) ,
115+ parseFloat ( user [ 0 ] . k3 ) ,
116+ parseFloat ( user [ 0 ] . k4 ) ,
117+ parseFloat ( user [ 0 ] . k5 ) ) ;
118+ }
119+
120+
84121 /** Inner function - Supports encryption and decryption for the database keys to get server RCON passwords.
85122 * @name decrypt
86123 * @function
@@ -591,6 +628,40 @@ class Utils {
591628 }
592629 }
593630
631+ /**
632+ * Generates a Counter-Strike-style slug using themed adjectives and nouns,
633+ * including weapon skins and knife types.
634+ * Example: "clutch-karambit" or "dusty-dragonlore"
635+ */
636+ public static generateSlug ( ) : string {
637+ const adjectives = [
638+ 'dusty' , 'silent' , 'brutal' , 'clutch' , 'smoky' , 'tactical' , 'deadly' , 'stealthy' ,
639+ 'eco' , 'forceful' , 'aggressive' , 'defensive' , 'sneaky' , 'explosive' , 'fraggy' , 'nasty' ,
640+ 'quick' , 'slow' , 'noisy' , 'clean' , 'dirty' , 'sharp' , 'blind' , 'lucky' ,
641+ 'fiery' , 'cold' , 'ghostly' , 'venomous' , 'royal'
642+ ] ;
643+
644+ const nouns = [
645+ // Weapons & gameplay
646+ 'ak47' , 'deagle' , 'bombsite' , 'flashbang' , 'knife' , 'smoke' , 'molotov' , 'awp' ,
647+ 'nade' , 'scout' , 'pistol' , 'rifle' , 'mid' , 'long' , 'short' , 'connector' ,
648+ 'ramp' , 'hegrenade' , 'tunnel' , 'palace' , 'apps' , 'boost' , 'peek' , 'spray' ,
649+
650+ // Skins
651+ 'dragonlore' , 'fireserpent' , 'hyperbeast' , 'fade' , 'casehardened' , 'redline' ,
652+ 'vulcan' , 'asiimov' , 'howl' , 'bloodsport' , 'phantomdisruptor' , 'neonrider' ,
653+
654+ // Knives
655+ 'karambit' , 'bayonet' , 'butterfly' , 'gutknife' , 'falchion' , 'shadowdaggers' ,
656+ 'huntsman' , 'talon' , 'ursus' , 'paracord' , 'nomad'
657+ ] ;
658+
659+ const adj = adjectives [ Math . floor ( Math . random ( ) * adjectives . length ) ] ;
660+ const noun = nouns [ Math . floor ( Math . random ( ) * nouns . length ) ] ;
661+
662+ return `${ adj } -${ noun } ` ;
663+ }
664+
594665 public static addChallongeTeamAuthsToArray : ( teamId : number , custom_field_response : { key : string ; value : string ; } ) => Promise < void > = async ( teamId : number , custom_field_response : { key : string , value : string } ) => {
595666 let teamAuthArray : Array < Array < any > > = [ ] ;
596667 let key : keyof typeof custom_field_response ;
@@ -608,6 +679,7 @@ class Utils {
608679 await db . query ( sqlString , [ teamAuthArray ] ) ;
609680 }
610681 }
682+
611683}
612684
613685
0 commit comments