@ file : Suppress (" unused ") Ċ Ċ package Ġdev . k ord . rest . request Ċ Ċ import Ġdev . k ord . rest . rate limit . Bucket Key Ċ import Ġio . ktor . client . statement .* Ċ import Ġkotlinx . datetime . Clock Ċ import Ġkotlinx . datetime . Instant Ċ import Ġkotlin . time . Duration . Companion . seconds Ċ Ċ private Ġconst Ġval Ġrate Limit Global Header Ġ= Ġ" X - RateLimit - Global " Ċ private Ġconst Ġval Ġretry After Header Ġ= Ġ" Retry - After " Ċ private Ġconst Ġval Ġrate Limit Remaining Header Ġ= Ġ" X - RateLimit - Remaining " Ċ private Ġconst Ġval Ġreset Time Header Ġ= Ġ" X - RateLimit - Reset " Ċ private Ġconst Ġval Ġbucket RateLimit Key Ġ= Ġ" X - RateLimit - Bucket " Ċ private Ġconst Ġval Ġrate Limit Ġ= Ġ" X - RateLimit - Limit " Ċ private Ġconst Ġval Ġrate Limit Reset After Ġ= Ġ" X - RateLimit - Reset - After " Ċ private Ġconst Ġval Ġaudit Log Reason Ġ= Ġ" X - Audit - Log - Reason " Ċ Ċ /** Ċ Ġ* ĠSets Ġthe Ġreason Ġthat Ġwill Ġshow Ġup Ġin Ġthe Ġ[ Discord ĠAudit ĠLog ]() Ġto Ġ[ reason ] Ġfor Ġthis Ġrequest . Ċ Ġ*/ Ċ fun Ġ< T > ĠRequest Builder < T >. audit Log Reason ( reason : ĠString ?) Ġ= Ġreason ?. let Ġ{ Ġurl Encoded Header ( audit Log Reason , Ġreason ) Ġ} Ċ Ċ val ĠHttpResponse . channel Reset Point : ĠInstant ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġunix Seconds Ġ= Ġheaders [ reset Time Header ]?. toDouble () Ġ?: Ġreturn ĠClock . System . now () ĊĠĠĠĠĠĠĠ Ġreturn ĠInstant . from Epoch Milliseconds ( unix Seconds . times ( 1 0 0 0 ). to Long ()) ĊĠĠĠ Ġ} Ċ Ċ fun ĠHttpResponse . channel Reset Point ( clock : ĠClock ): ĠInstant Ġ{ ĊĠĠĠ Ġval Ġseconds Ġ= Ġheaders [ rate Limit Reset After ]?. toDouble () Ġ?: Ġreturn Ġclock . now () ĊĠĠĠ Ġreturn Ġclock . now (). plus ( seconds . seconds ) Ċ } Ċ Ċ val ĠHttpResponse . is RateLimit Ġget () Ġ= Ġstatus . value Ġ== Ġ 4 2 9 Ċ val ĠHttpResponse . isError Ġget () Ġ= Ġstatus . value Ġin Ġ 4 0 0 Ġuntil Ġ 6 0 0 Ċ val ĠHttpResponse . isError With RateLimit Ġget () Ġ= Ġstatus . value Ġ== Ġ 4 0 3 Ġ|| Ġstatus . value Ġ== Ġ 4 0 1 Ċ val ĠHttpResponse . is Global RateLimit Ġget () Ġ= Ġheaders [ rate Limit Global Header ] Ġ!= Ġnull Ċ val ĠHttpResponse . rate Limit Total Ġget () Ġ= Ġheaders [ rate Limit ]?. to Long OrNull () Ċ val ĠHttpResponse . rate Limit Remaining Ġget () Ġ= Ġheaders [ rate Limit Remaining Header ]?. to Long OrNull () Ċ val ĠHttpResponse . is Channel RateLimit Ġget () Ġ= Ġheaders [ rate Limit Remaining Header ]?. toInt OrNull () Ġ== Ġ 0 Ċ val ĠHttpResponse . bucket : ĠBucket Key ? Ġget () Ġ= Ġheaders [ bucket RateLimit Key ]?. let Ġ{ ĠBucket Key ( it ) Ġ} Ċ Ċ /** Ċ Ġ* ĠThe Ġunix Ġtime Ġ( in Ġms ) Ġwhen Ġthe Ġglobal Ġrate Ġlimit Ġgets Ġreset . Ċ Ġ*/ Ċ fun ĠHttpResponse . global Sus pension Point ( clock : ĠClock ): ĠLong Ġ{ ĊĠĠĠ Ġval Ġseconds Wait Ġ= Ġheaders [ retry After Header ]?. to Long () Ġ?: Ġreturn Ġclock . now (). to Epoch Milliseconds () ĊĠĠĠ Ġreturn Ġ( seconds Wait Ġ* Ġ 1 0 0 0 ) Ġ+ Ġclock . now (). to Epoch Milliseconds () Ċ } Ċ Ċ fun ĠHttpResponse . log String ( body : ĠString ) Ġ= ĊĠĠĠ Ġ"[ RESPONSE ]: ${ status . value }:${ call . request . method . value }:${ call . request . url } Ġbody :$ body " Ċ Ċ suspend Ġfun ĠHttpResponse . error String (): ĠString Ġ{ ĊĠĠĠ Ġval Ġmessage Ġ= ĠString ( this . read Bytes ()) ĊĠĠĠ Ġreturn Ġlog String ( message ) Ċ } Ċ Ċ fun ĠRequest < *, Ġ* >. log String ( body : ĠString ): ĠString Ġ{ ĊĠĠĠ Ġval Ġmethod Ġ= Ġroute . method . value ĊĠĠĠ Ġval Ġpath Ġ= Ġroute . path ĊĠĠĠ Ġval Ġparams Ġ= Ġroute Params . entries ĊĠĠĠĠĠĠĠ Ġ. join ToString (",", Ġ"[", Ġ"] ") Ġ{ Ġ( key , Ġvalue ) Ġ-> Ġ"$ key =$ value " Ġ} ĊĊĠĠĠ Ġreturn Ġ"[ REQUEST ]: $ method :$ path Ġparams :$ params Ġbody :$ body " Ċ } Ċ