file description module import type { HibikiClient } from "../../classes/Client" ; import { convertHex } from "../../utils/embed" ; import express from "express" ; import rateLimit from "express-rate-limit" ; const router = express . Router ( ) ; const votingRateLimit = rateLimit ( { windowMs : 1 * 60 * 1000 , max : 30 , message : "Too many voting requests in a short period of time." , } ) ; export function votingRoutes ( bot ) { router . post ( "/get/" , votingRateLimit , async ( req , res ) => { if ( req . headers . authorization !== bot . config . keys . botlists . voting . auth ) { if ( req . headers . authorization ?. length || ! req . headers . authorization ) { bot . log . warn ( `${ req . socket . remoteAddress } tried to make a request with the wrong auth key.` ) ; return res . sendStatus ( 401 ) ; } } const user = bot . users . get ( req . body . user ) ; let cookies = await bot . db . getUserCookies ( req . body . user ) ; if ( ! cookies ) { await bot . db . insertBlankUserCookies ( req . body . user ) ; cookies = { id : req . body . user , amount : 0 , lastclaim : null } ; } let amount = cookies . amount + 150 ; if ( req . body . isWeekend ) amount += 150 ; cookies = { id : req . body . user , amount : amount , lastclaim : cookies . lastclaim } ; await bot . db . updateUserCookies ( req . body . user , cookies ) ; if ( user ) { const dmChannel = await user . getDMChannel ( ) . catch ( ( ) => { } ) ; if ( ! dmChannel ) return ; const userLocale = await bot . localeSystem . getUserLocale ( `${ user }` , bot ) ; const string = bot . localeSystem . getLocaleFunction ( userLocale ) ; await dmChannel . createMessage ( { embed : { title : `✨ ${ string ( "global.THANKS_FOR_VOTING" ) }` , description : string ( "global.VOTING_COOKIES_ADDED" , { amount : req . body . isWeekend ? "300" : "150" } ) , color : convertHex ( "general" ) , } , } ) . catch ( ( ) => { } ) ; } await bot . createMessage ( bot . config . logchannel , { embed : { title : "🗳 User Voted" , description : `**${ user ? user . username : req . body . user }** has voted.` , color : convertHex ( "general" ) , } , } ) ; bot . log . info ( `${ user ? user . username : req . body . user } has voted.` ) ; res . sendStatus ( 200 ) ; } ) ; return router ; }