/* Ċ Ġ* ĠCopyright Ġ 2 0 1 7 - 2 0 2 2 ĠA very ĠCar roll Ġand ĠLog an ĠDe ve ck a Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . sand r abot . s andra . utils Ċ Ċ import Ġcom . sand r abot . s andra . events . Command Event Ċ import Ġcom . sand r abot . s andra . exceptions . Missing Permission Exception Ċ import Ġcom . sand r abot . s andra . exceptions . Missing Translation Exception Ċ import Ġnet . dv 8 tion . j da . api . Permission Ċ import Ġnet . dv 8 tion . j da . api . entities . Member Ċ Ċ fun Ġmissing Permission ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġ! has Permission ( event , Ġpermission ) Ċ fun Ġhas Permission ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġcheck ( event , Ġpermission , Ġevent . self Member !! ) Ċ Ċ fun Ġmissing User Permission ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġ! has User Permission ( event , Ġpermission ) Ċ fun Ġhas User Permission ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġcheck ( event , Ġpermission , Ġevent . member !! ) Ċ Ċ private Ġfun Ġcheck ( event : ĠCommand Event , Ġpermission : ĠPermission , Ġmember : ĠMember ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġif Ġ( permission . is Channel ) Ġ{ ĊĠĠĠĠĠĠĠ Ġmember . has Permission ( event . text Channel , Ġpermission ) ĊĠĠĠ Ġ} Ġelse Ġmember . has Permission ( permission ) Ċ } Ċ Ċ fun Ġmissing Permissions ( event : ĠCommand Event , Ġvar arg Ġpermissions : ĠPermission ) Ġ= Ġ! has Permissions ( event , Ġ* permissions ) Ċ fun Ġhas Permissions ( event : ĠCommand Event , Ġvar arg Ġpermissions : ĠPermission ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġpermissions . all Ġ{ Ġhas Permission ( event , Ġit ) Ġ} Ċ } Ċ Ċ fun Ġensure Permissions ( event : ĠCommand Event , Ġvar arg Ġpermissions : ĠPermission ) Ġ= ĊĠĠĠ Ġpermissions . forEach Ġ{ Ġensure Permission ( event , Ġit ) Ġ} Ċ Ċ fun Ġensure Permission ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ{ ĊĠĠĠ Ġif Ġ( missing Permission ( event , Ġpermission )) Ġthrow ĠMissing Permission Exception ( event , Ġpermission ) Ċ } Ċ Ċ fun Ġmissing Self Message ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġmissing Message ( event , Ġpermission , Ġtrue ) Ċ fun Ġmissing User Message ( event : ĠCommand Event , Ġpermission : ĠPermission ) Ġ= Ġmissing Message ( event , Ġpermission , Ġfalse ) Ċ private Ġfun Ġmissing Message ( event : ĠCommand Event , Ġpermission : ĠPermission , Ġself : ĠBoolean ): ĠString Ġ{ ĊĠĠĠ Ġval Ġcontext Ġ= Ġif Ġ( permission . is Channel ) Ġ" channel " Ġelse Ġ" server " ĊĠĠĠ Ġreturn Ġevent . translate ( ĊĠĠĠĠĠĠĠ Ġ" general ." Ġ+ Ġif Ġ( self ) Ġ" missing _ permission " Ġelse Ġ" missing _ user _ permission ", Ġfalse , ĊĠĠĠĠĠĠĠ Ġevent . locale Context . get (" permissions .${ find Translation Key ( permission )} ", Ġfalse ), Ġcontext ĊĠĠĠ Ġ) Ċ } Ċ Ċ fun Ġfind Translation Key ( permission : ĠPermission ) Ġ= Ġwhen Ġ( permission ) Ġ{ ĊĠĠĠ ĠPermission . CREATE _ INST ANT _ INV ITE Ġ-> Ġ" create _ invite " ĊĠĠĠ ĠPermission . K ICK _ MEMBER S Ġ-> Ġ" kick " ĊĠĠĠ ĠPermission . BAN _ MEMBER S Ġ-> Ġ" ban " ĊĠĠĠ ĠPermission . ADMIN ISTR ATOR Ġ-> Ġ" administrator " ĊĠĠĠ ĠPermission . MESSAGE _ ADD _ RE ACTION Ġ-> Ġ" add _ reactions " ĊĠĠĠ ĠPermission . VIEW _ AUDIT _ LOG S Ġ-> Ġ" view _ audit _ logs " ĊĠĠĠ ĠPermission . VIEW _ CHANNEL Ġ-> Ġ" view _ channel " ĊĠĠĠ ĠPermission . MESSAGE _ SEND Ġ-> Ġ" send _ messages " ĊĠĠĠ ĠPermission . MESSAGE _ MANAGE Ġ-> Ġ" manage _ messages " ĊĠĠĠ ĠPermission . MESSAGE _ EMB ED _ LIN KS Ġ-> Ġ" embed _ links " ĊĠĠĠ ĠPermission . MESSAGE _ ATTACH _ FILES Ġ-> Ġ" attach _ files " ĊĠĠĠ ĠPermission . MESSAGE _ HISTORY Ġ-> Ġ" read _ history " ĊĠĠĠ ĠPermission . MESSAGE _ EXT _ E MO JI Ġ-> Ġ" external _ emo jis " ĊĠĠĠ ĠPermission . VOICE _ CONNECT Ġ-> Ġ" voice _ connect " ĊĠĠĠ ĠPermission . VOICE _ SPE AK Ġ-> Ġ" voice _ speak " ĊĠĠĠ ĠPermission . VOICE _ USE _ V AD Ġ-> Ġ" voice _ activity " ĊĠĠĠ ĠPermission . N ICK NAME _ CHANGE Ġ-> Ġ" change _ nickname " ĊĠĠĠ ĠPermission . N ICK NAME _ MANAGE Ġ-> Ġ" manage _ nick names " ĊĠĠĠ ĠPermission . MANAGE _ RO LES Ġ-> Ġ" manage _ roles " ĊĠĠĠ ĠPermission . MANAGE _ PERMISSION S Ġ-> Ġ" manage _ permissions " ĊĠĠĠ ĠPermission . MO DER ATE _ MEMBER S Ġ-> Ġ" mod erate _ members " ĊĠĠĠ Ġelse Ġ-> Ġthrow ĠMissing Translation Exception (" Missing Ġtranslation Ġfor Ġpermission Ġ$ permission ") Ċ } Ċ