idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
41,200 | protected function findReplacements ( $ pattern ) { if ( 0 !== strpos ( $ pattern , '@' ) ) { return $ pattern ; } $ replace = [ '@yearly' => '0 0 1 1 * *' , '@annually' => '0 0 1 1 * *' , '@monthly' => '0 0 1 * *' , '@weekly' => '0 0 * * 0' , '@daily' => '0 0 * * *' , '@hourly' => '0 * * * *' , ] ; if ( isset ( $ repl... | Translate known shorthands to basic cron syntax . |
41,201 | public function setCommand ( $ command , $ cwd = null , array $ env = null , $ input = null , $ timeout = 60 , array $ options = array ( ) ) { if ( method_exists ( Process :: class , 'fromShellCommandline' ) ) { $ this -> process = Process :: fromShellCommandline ( $ command , $ cwd , $ env , $ input , $ timeout , $ op... | Set the command to execute as if you would run it in the shell . |
41,202 | public function valid ( \ DateTime $ now ) { if ( false === $ this -> checkMinute ( $ now ) ) { return false ; } if ( false === $ this -> checkHour ( $ now ) ) { return false ; } if ( false === $ this -> checkDay ( $ now ) ) { return false ; } if ( false === $ this -> checkMonth ( $ now ) ) { return false ; } if ( fals... | Validate if this pattern can run on the given date . |
41,203 | protected function checkMinute ( \ DateTime $ now ) { if ( $ this -> parts [ 'min' ] != '*' ) { foreach ( $ this -> parseRule ( $ this -> parts [ 'min' ] , 0 , 59 ) as $ value ) { if ( $ now -> format ( 'i' ) == $ value ) { return true ; } } return false ; } return true ; } | Check if the minute matches . |
41,204 | protected function parsePattern ( $ pattern ) { $ parts = [ 'min' => '[0-5]?\d' , 'hour' => '[01]?\d|2[0-3]' , 'day' => '0?[1-9]|[12]\d|3[01]' , 'month' => '[1-9]|1[012]' , 'dow' => '[0-7]' , 'year' => '20([0-9]{2})' , ] ; $ regex = [ ] ; foreach ( array_slice ( $ parts , 0 , 5 ) as $ name => $ number ) { $ range = '('... | Parse the pattern into a rule for every property . |
41,205 | protected function parseRule ( $ rule , $ min , $ max ) { $ result = [ ] ; foreach ( explode ( ',' , $ rule ) as $ value ) { if ( preg_match ( '/^([0-9]+)-([0-9]+)$/' , $ value , $ r ) ) { $ result = array_merge ( $ result , range ( $ r [ 1 ] , $ r [ 2 ] ) ) ; } elseif ( preg_match ( '/^\*\/([0-9]+)$/' , $ value , $ r ... | Convert a rule to an array of all its values . |
41,206 | public function valid ( \ DateTime $ now ) { return parent :: valid ( $ now ) && $ this -> getProcess ( ) && ! $ this -> isRunning ( ) ; } | Validate the job . |
41,207 | public function isRunning ( ) { $ running = $ this -> isProcessRunning ( ) ; if ( ! $ running && $ this -> getProcess ( ) -> isStarted ( ) ) { $ this -> registerEnd ( ) ; $ this -> registerSuccessful ( ) ; } return $ running ; } | Validate if the process is running . |
41,208 | protected function registerEnd ( ) { if ( is_null ( $ this -> report -> getEndTime ( ) ) ) { $ this -> report -> setEndTime ( microtime ( true ) ) ; } } | Register the end of a job to the report . |
41,209 | public function checkForMutator ( $ key , $ type ) { $ str = $ type . Str :: studly ( $ key ) . 'Attribute' ; if ( is_callable ( [ $ this , $ str ] ) ) { return $ str ; } return false ; } | Checks if there is a mutator present . |
41,210 | public function uriReplace ( $ key , $ params ) { $ string = $ this -> uris [ $ key ] ; $ matches = null ; $ matcher = preg_match_all ( $ this -> regex , $ string , $ matches ) ; $ original = $ matches [ 0 ] ; $ vars = $ matches [ 1 ] ; foreach ( $ vars as $ key => $ variable ) { if ( $ attribute = $ params [ $ variabl... | Replaces variables in one of the URIs . |
41,211 | public function getAttribute ( $ key ) { if ( isset ( $ this -> repositories [ $ key ] ) ) { $ className = str_replace ( '\\' , '' , $ this -> repositories [ $ key ] ) ; if ( $ repository = $ this -> cache -> get ( "repositories.{$className}.{$this->id}.{$key}" ) ) { return $ repository ; } $ class = $ this -> reposito... | Gets an attribute on the part . |
41,212 | public function setAttribute ( $ key , $ value ) { if ( isset ( $ this -> repositories [ $ key ] ) ) { if ( ! ( $ value instanceof $ this -> repositories [ $ key ] ) ) { return ; } $ className = str_replace ( '\\' , '' , $ this -> repositories [ $ key ] ) ; $ this -> cache -> set ( "repositories.{$className}.{$this->id... | Sets an attribute on the part . |
41,213 | public function getPublicAttributes ( ) { $ data = [ ] ; foreach ( $ this -> fillable as $ key ) { if ( in_array ( $ key , $ this -> hidden ) ) { continue ; } $ value = $ this -> getAttribute ( $ key ) ; if ( $ value instanceof Carbon ) { $ value = $ value -> format ( 'Y-m-d\TH:i:s\Z' ) ; } $ data [ $ key ] = $ value ;... | Returns an array of public attributes . |
41,214 | public function afterConstruct ( ) { $ this -> user = $ this -> factory -> create ( User :: class , [ 'id' => $ this -> id , 'username' => $ this -> username , 'avatar' => $ this -> attributes [ 'avatar' ] , 'discriminator' => $ this -> discriminator , ] , true ) ; $ this -> application = $ this -> factory -> create ( ... | Runs any extra construction tasks . |
41,215 | public function setAvatar ( $ filepath ) { if ( ! file_exists ( $ filepath ) ) { throw new FileNotFoundException ( "File does not exist at path {$filepath}." ) ; } $ extension = pathinfo ( $ filepath , PATHINFO_EXTENSION ) ; $ file = file_get_contents ( $ filepath ) ; $ base64 = base64_encode ( $ file ) ; $ this -> att... | Sets the users avatar . |
41,216 | public function save ( ) { $ deferred = new Deferred ( ) ; $ this -> http -> patch ( 'users/@me' , $ this -> getUpdatableAttributes ( ) ) -> then ( \ React \ Partial \ bind_right ( $ this -> resolve , $ deferred ) , \ React \ Partial \ bind_right ( $ this -> reject , $ deferred ) ) ; return $ deferred -> promise ( ) ; ... | Saves the client instance . |
41,217 | public function get ( $ key , $ value = null ) { if ( $ key == $ this -> discrim && array_key_exists ( $ value , $ this -> items ) ) { return $ this -> items [ $ value ] ; } foreach ( $ this -> items as $ item ) { if ( is_array ( $ item ) ) { if ( $ item [ $ key ] == $ value ) { return $ item ; } } elseif ( is_object (... | Get an item from the collection with a key and value . |
41,218 | public function getAll ( $ key , $ value = null ) { $ collection = new self ( ) ; foreach ( $ this -> items as $ item ) { if ( $ item -> { $ key } == $ value ) { $ collection -> push ( $ item ) ; } } return $ collection ; } | Gets a collection of items from the repository with a key and value . |
41,219 | public function accept ( ) { $ deferred = new Deferred ( ) ; if ( $ this -> revoked ) { $ deferred -> reject ( new \ Exception ( 'This invite has been revoked.' ) ) ; return $ deferred -> promise ( ) ; } if ( $ this -> uses >= $ this -> max_uses ) { $ deferred -> reject ( new \ Exception ( 'This invite has been used th... | Accepts the invite . |
41,220 | final public function setEnhanceSigchildCompatibility ( $ enhance ) { if ( $ this -> isRunning ( ) ) { throw new \ RuntimeException ( 'Process is already running' ) ; } $ this -> enhanceSigchildCompatibility = ( bool ) $ enhance ; return $ this ; } | Enable or disable sigchild compatibility mode . |
41,221 | public function isRunning ( ) { if ( $ this -> process === null ) { return false ; } $ status = $ this -> getFreshStatus ( ) ; return $ status !== null ? $ status [ 'running' ] : false ; } | Return whether the process is still running . |
41,222 | private function pollExitCodePipe ( ) { if ( ! isset ( $ this -> pipes [ 3 ] ) ) { return ; } $ r = [ $ this -> pipes [ 3 ] ] ; $ w = $ e = null ; $ n = @ stream_select ( $ r , $ w , $ e , 0 ) ; if ( 1 !== $ n ) { return ; } $ data = fread ( $ r [ 0 ] , 8192 ) ; if ( strlen ( $ data ) > 0 ) { $ this -> fallbackExitCode... | Check the fourth pipe for an exit code . |
41,223 | public function writePCM ( $ pcm ) { if ( $ this -> isClosed ) { return ; } if ( $ this -> isPaused ) { $ this -> pcmPauseBuffer [ ] = $ pcm ; return ; } $ this -> pcmData .= $ pcm ; $ this -> emit ( 'pcm' , [ $ pcm ] ) ; } | Writes PCM audio data . |
41,224 | public function writeOpus ( $ opus ) { if ( $ this -> isClosed ) { return ; } if ( $ this -> isPaused ) { $ this -> opusPauseBuffer [ ] = $ opus ; return ; } $ this -> opusData .= $ opus ; $ this -> emit ( 'opus' , [ $ opus ] ) ; } | Writes Opus audio data . |
41,225 | public function pipePCM ( WritableStreamInterface $ dest , array $ options = [ ] ) { if ( $ this -> isClosed ) { return ; } $ this -> on ( 'pcm' , function ( $ data ) use ( $ dest ) { $ feedmore = $ dest -> write ( $ data ) ; if ( false === $ feedmore ) { $ this -> pause ( ) ; } } ) ; $ dest -> on ( 'drain' , function ... | Pipes PCM to a destination stream . |
41,226 | public function getChannelAttribute ( ) { foreach ( $ this -> discord -> guilds as $ guild ) { if ( $ guild -> channels -> has ( $ this -> channel_id ) ) { return $ guild -> channels -> get ( 'id' , $ this -> channel_id ) ; } } if ( $ this -> cache -> has ( "pm_channels.{$this->channel_id}" ) ) { return $ this -> cache... | Returns the channel attribute . |
41,227 | public function getMentionRolesAttribute ( ) { $ roles = new Collection ( [ ] , 'id' ) ; foreach ( $ this -> channel -> guild -> roles as $ role ) { if ( array_search ( $ role -> id , $ this -> attributes [ 'mention_roles' ] ) !== false ) { $ roles -> push ( $ role ) ; } } return $ roles ; } | Returns the mention_roles attribute . |
41,228 | public function getMentionsAttribute ( ) { $ users = new Collection ( [ ] , 'id' ) ; foreach ( $ this -> attributes [ 'mentions' ] as $ mention ) { $ users -> push ( $ this -> factory -> create ( User :: class , $ mention , true ) ) ; } return $ users ; } | Returns the mention attribute . |
41,229 | public function getAuthorAttribute ( ) { if ( $ this -> channel -> type != Channel :: TYPE_TEXT ) { return $ this -> factory -> create ( User :: class , $ this -> attributes [ 'author' ] , true ) ; } return $ this -> channel -> guild -> members -> get ( 'id' , $ this -> attributes [ 'author' ] -> id ) ; } | Returns the author attribute . |
41,230 | public function getEmbedsAttribute ( ) { $ embeds = new Collection ( ) ; foreach ( $ this -> attributes [ 'embeds' ] as $ embed ) { $ embeds -> push ( $ this -> factory -> create ( Embed :: class , $ embed , true ) ) ; } return $ embeds ; } | Returns the embed attribute . |
41,231 | public function decodeBitwise ( $ bitwise ) { $ result = [ ] ; foreach ( $ this -> bitwise as $ key => $ value ) { $ result [ $ key ] = ( ( ( $ bitwise >> $ value ) & 1 ) == 1 ) ; } $ this -> fill ( $ result ) ; return $ this ; } | Decodes a bitwise integer . |
41,232 | public function getBitwiseAttribute ( ) { $ bitwise = 0 ; foreach ( $ this -> attributes as $ key => $ value ) { if ( $ value ) { $ bitwise |= ( 1 << $ this -> bitwise [ $ key ] ) ; } else { $ bitwise &= ~ ( 1 << $ this -> bitwise [ $ key ] ) ; } } return $ bitwise ; } | Retrieves the bitwise integer . |
41,233 | public function afterConstruct ( ) { if ( ! isset ( $ this -> attributes [ 'permissions' ] ) ) { $ this -> permissions = $ this -> factory -> create ( RolePermission :: class ) ; } } | Runs extra construction tasks . |
41,234 | public function setColor ( $ red = null , $ green = null , $ blue = null ) { $ deferred = new Deferred ( ) ; if ( is_null ( $ red ) ) { $ this -> setAttribute ( 'color' , 0 ) ; $ deferred -> resolve ( ) ; return $ deferred -> promise ( ) ; } $ this -> setAttribute ( 'color' , $ red * 16 ** 4 + $ green * 16 ** 2 + $ blu... | Sets the color for a role . RGB . |
41,235 | public function getTimestampAttribute ( ) { if ( ! array_key_exists ( 'timestamp' , $ this -> attributes ) ) { return Carbon :: now ( ) ; } return Carbon :: parse ( $ this -> attributes [ 'timestamp' ] ) ; } | Gets the timestamp attribute . |
41,236 | public function getFieldsAttribute ( ) { $ fields = new Collection ( ) ; foreach ( $ this -> attributes [ 'fields' ] as $ field ) { if ( ! ( $ field instanceof Field ) ) { $ field = $ this -> discord -> factory ( Field :: class , $ field , true ) ; } $ fields -> push ( $ field ) ; } return $ fields ; } | Gets the fields attribute . |
41,237 | protected function attributeHelper ( $ key , $ class ) { if ( $ this -> attributes [ $ key ] instanceof $ class ) { return $ this -> attributes [ $ key ] ; } return $ this -> discord -> factory ( $ class , $ this -> attributes [ $ key ] , true ) ; } | Helps with getting embed attributes . |
41,238 | public function getChannelAttribute ( ) { foreach ( $ this -> discord -> guilds as $ guild ) { if ( $ guild -> channels -> has ( $ this -> channel_id ) ) { return $ guild -> channels -> get ( 'id' , $ this -> channel_id ) ; } } } | Gets the channel attribute . |
41,239 | public function transferOwnership ( $ member ) { $ deferred = new Deferred ( ) ; if ( $ member instanceof Member ) { $ member = $ member -> id ; } $ this -> http -> patch ( $ this -> replaceWithVariables ( 'guilds/:id' ) , [ 'owner_id' => $ member , ] ) -> then ( function ( $ response ) use ( $ member , $ deferred ) { ... | Transfers ownership of the guild to another member . |
41,240 | public function validateRegion ( ) { if ( ! in_array ( $ this -> region , $ this -> regions ) ) { return self :: REGION_DEFUALT ; } return $ this -> region ; } | Validates the specified region . |
41,241 | protected function initBufferNoEncryption ( $ data ) { $ data = ( binary ) $ data ; $ header = $ this -> buildHeader ( ) ; $ buffer = new Buffer ( strlen ( ( string ) $ header ) + strlen ( $ data ) ) ; $ buffer -> write ( ( string ) $ header , 0 ) ; $ buffer -> write ( $ data , 12 ) ; $ this -> buffer = $ buffer ; } | Initilizes the buffer with no encryption . |
41,242 | protected function initBufferEncryption ( $ data , $ key ) { $ data = ( binary ) $ data ; $ header = $ this -> buildHeader ( ) ; $ nonce = new Buffer ( 24 ) ; $ nonce -> write ( ( string ) $ header , 0 ) ; $ data = \ Sodium \ crypto_secretbox ( $ data , ( string ) $ nonce , $ key ) ; $ this -> buffer = new Buffer ( str... | Initilizes the buffer with encryption . |
41,243 | protected function buildHeader ( ) { $ header = new Buffer ( self :: RTP_HEADER_BYTE_LENGTH ) ; $ header [ self :: RTP_VERSION_PAD_EXTEND_INDEX ] = pack ( 'c' , self :: RTP_VERSION_PAD_EXTEND ) ; $ header [ self :: RTP_PAYLOAD_INDEX ] = pack ( 'c' , self :: RTP_PAYLOAD_TYPE ) ; $ header -> writeShort ( $ this -> seq , ... | Builds the header . |
41,244 | public static function make ( $ data ) { $ n = new self ( '' , 0 , 0 , 0 ) ; $ buff = new Buffer ( $ data ) ; $ n -> setBuffer ( $ buff ) ; return $ n ; } | Creates a voice packet from data sent from Discord . |
41,245 | public function setBuffer ( $ buffer ) { $ this -> buffer = $ buffer ; $ this -> seq = $ this -> buffer -> readShort ( self :: SEQ_INDEX ) ; $ this -> timestamp = $ this -> buffer -> readInt ( self :: TIMESTAMP_INDEX ) ; $ this -> ssrc = $ this -> buffer -> readInt ( self :: SSRC_INDEX ) ; return $ this ; } | Sets the buffer . |
41,246 | public function freshen ( ) { if ( ! isset ( $ this -> endpoints [ 'all' ] ) ) { return \ React \ Promise \ reject ( new \ Exception ( 'You cannot freshen this repository.' ) ) ; } $ deferred = new Deferred ( ) ; $ this -> http -> get ( $ this -> replaceWithVariables ( $ this -> endpoints [ 'all' ] ) ) -> then ( functi... | Freshens the repository collection . |
41,247 | private function runRequest ( $ method , $ url , $ content , $ extraHeaders , $ cache , $ blocking , $ options ) { $ deferred = new Deferred ( ) ; $ key = 'guzzle.' . sha1 ( $ url ) ; if ( $ method === 'get' && $ this -> cache -> has ( $ key ) ) { $ deferred -> resolve ( $ this -> cache -> get ( $ key ) ) ; return $ de... | Runs http calls . |
41,248 | public function sendFile ( Channel $ channel , $ filepath , $ filename , $ content , $ tts ) { $ multipart = [ [ 'name' => 'file' , 'contents' => fopen ( $ filepath , 'r' ) , 'filename' => $ filename , ] , [ 'name' => 'tts' , 'contents' => ( $ tts ? 'true' : 'false' ) , ] , [ 'name' => 'content' , 'contents' => ( strin... | Uploads a file to a channel . |
41,249 | public function handleError ( $ errorCode , $ message , $ content , $ url ) { if ( ! is_string ( $ message ) ) { $ message = $ message -> getReasonPhrase ( ) ; } $ message .= " - {$content} - {$url}" ; switch ( $ errorCode ) { case 400 : return new DiscordRequestFailedException ( "Error code 400: We sent a bad request.... | Handles an error code . |
41,250 | public function start ( ) { if ( ! $ this -> checkForFFmpeg ( ) || ! $ this -> checkForDCA ( ) || ! $ this -> checkForLibsodium ( ) ) { return false ; } if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' ) { $ this -> emit ( 'error' , [ new \ Exception ( 'The voice client does not work on Windows operating systems... | Starts the voice client . |
41,251 | public function handleWebSocketError ( $ e ) { $ this -> logger -> error ( 'error with voice websocket' , [ 'e' => $ e -> getMessage ( ) ] ) ; $ this -> emit ( 'error' , [ $ e ] ) ; } | Handles a WebSocket error . |
41,252 | public function handleVoiceServerChange ( array $ data = [ ] ) { $ this -> logger -> debug ( 'voice server has changed, dynamically changing servers in the background' , [ 'data' => $ data ] ) ; $ this -> reconnecting = true ; $ this -> sentLoginFrame = false ; $ this -> pause ( ) ; $ this -> client -> close ( ) ; $ th... | Handles a voice server change . |
41,253 | public function playFile ( $ file , $ channels = 2 ) { $ deferred = new Deferred ( ) ; if ( ! file_exists ( $ file ) ) { $ deferred -> reject ( new FileNotFoundException ( "Could not find the file \"{$file}\"." ) ) ; return $ deferred -> promise ( ) ; } if ( ! $ this -> ready ) { $ deferred -> reject ( new \ Exception ... | Plays a file on the voice stream . |
41,254 | public function playRawStream ( $ stream , $ channels = 2 ) { $ deferred = new Deferred ( ) ; if ( ! $ this -> ready ) { $ deferred -> reject ( new \ Exception ( 'Voice Client is not ready.' ) ) ; return $ deferred -> promise ( ) ; } if ( ! is_resource ( $ stream ) && ! $ stream instanceof Stream ) { $ deferred -> reje... | Plays a raw PCM16 stream . |
41,255 | public function sendBuffer ( $ data ) { if ( ! $ this -> ready ) { return ; } $ packet = new VoicePacket ( $ data , $ this -> ssrc , $ this -> seq , $ this -> timestamp , true , $ this -> secret_key ) ; $ this -> client -> send ( ( string ) $ packet ) ; $ this -> streamTime = microtime ( true ) ; $ this -> emit ( 'pack... | Sends a buffer to the UDP socket . |
41,256 | public function setSpeaking ( $ speaking = true ) { $ deferred = new Deferred ( ) ; if ( $ this -> speaking == $ speaking ) { $ deferred -> resolve ( ) ; return $ deferred -> promise ( ) ; } if ( ! $ this -> ready ) { $ deferred -> reject ( new \ Exception ( 'Voice Client is not ready.' ) ) ; return $ deferred -> promi... | Sets the speaking value of the client . |
41,257 | public function switchChannel ( Channel $ channel ) { $ deferred = new Deferred ( ) ; if ( $ channel -> type != Channel :: TYPE_VOICE ) { $ deferred -> reject ( new \ InvalidArgumentException ( 'Channel must be a voice chnanel to be able to switch' ) ) ; return $ deferred -> promise ( ) ; } $ this -> mainSend ( [ 'op' ... | Switches voice channels . |
41,258 | public function setFrameSize ( $ fs ) { $ deferred = new Deferred ( ) ; $ legal = [ 20 , 40 , 60 ] ; if ( false === array_search ( $ fs , $ legal ) ) { $ deferred -> reject ( new \ InvalidArgumentException ( "{$fs} is not a valid option. Valid options are: " . trim ( implode ( ', ' , $ legal ) , ', ' ) ) ) ; return $ d... | Sets the frame size . |
41,259 | public function setBitrate ( $ bitrate ) { $ deferred = new Deferred ( ) ; if ( $ bitrate > 128000 || $ bitrate < 8000 ) { $ deferred -> reject ( new \ InvalidArgumentException ( "{$bitrate} is not a valid option. The bitrate must be between 8,000bpm and 128,000bpm." ) ) ; return $ deferred -> promise ( ) ; } if ( $ th... | Sets the bitrate . |
41,260 | public function setVolume ( $ volume ) { $ deferred = new Deferred ( ) ; if ( $ volume > 100 || $ volume < 0 ) { $ deferred -> reject ( new \ InvalidArgumentException ( "{$volume}% is not a valid option. The bitrate must be between 0% and 100%." ) ) ; return $ deferred -> promise ( ) ; } if ( $ this -> speaking ) { $ d... | Sets the volume . |
41,261 | public function setAudioApplication ( $ app ) { $ deferred = new Deferred ( ) ; $ legal = [ 'voip' , 'audio' , 'lowdelay' ] ; if ( false === array_search ( $ app , $ legal ) ) { $ deferred -> reject ( new \ InvalidArgumentException ( "{$app} is not a valid option. Valid options are: " . trim ( implode ( ', ' , $ legal ... | Sets the audio application . |
41,262 | public function setMuteDeaf ( $ mute , $ deaf ) { $ deferred = new Deferred ( ) ; if ( ! $ this -> ready ) { $ deferred -> reject ( new \ Exception ( 'The voice client must be ready before you can set mute or deaf.' ) ) ; return $ deferred -> promise ( ) ; } $ this -> mute = $ mute ; $ this -> deaf = $ deaf ; $ this ->... | Changes your mute and deaf value . |
41,263 | public function pause ( ) { $ deferred = new Deferred ( ) ; if ( ! $ this -> speaking ) { $ deferred -> reject ( new \ Exception ( 'Audio must be playing to pause it.' ) ) ; return $ deferred -> promise ( ) ; } $ this -> isPaused = true ; $ deferred -> resolve ( ) ; return $ deferred -> promise ( ) ; } | Pauses the current sound . |
41,264 | public function unpause ( ) { $ deferred = new Deferred ( ) ; if ( ! $ this -> speaking ) { $ deferred -> reject ( new \ Exception ( 'Audio must be playing to unpause it.' ) ) ; return $ deferred -> promise ( ) ; } $ this -> isPaused = false ; $ this -> timestamp = microtime ( true ) * 1000 ; $ deferred -> resolve ( ) ... | Unpauses the current sound . |
41,265 | public function stop ( ) { $ deferred = new Deferred ( ) ; if ( $ this -> stopAudio ) { $ deferred -> reject ( new \ Exception ( 'Audio is already being stopped.' ) ) ; return $ deferred -> promise ( ) ; } if ( ! $ this -> speaking ) { $ deferred -> reject ( new \ Exception ( 'Audio must be playing to stop it.' ) ) ; r... | Stops the current sound . |
41,266 | public function close ( ) { $ deferred = new Deferred ( ) ; if ( ! $ this -> ready ) { $ deferred -> reject ( new \ Exception ( 'Voice Client is not connected.' ) ) ; return $ deferred -> promise ( ) ; } $ this -> stop ( ) ; $ this -> setSpeaking ( false ) ; $ this -> ready = false ; $ this -> mainSend ( [ 'op' => Op :... | Closes the voice client . |
41,267 | public function isSpeaking ( $ id ) { $ ssrc = @ $ this -> speakingStatus [ $ id ] ; $ user = $ this -> speakingStatus -> get ( 'user_id' , $ id ) ; if ( is_null ( $ ssrc ) && ! is_null ( $ user ) ) { return $ user -> speaking ; } elseif ( is_null ( $ user ) && ! is_null ( $ ssrc ) ) { return $ user -> speaking ; } els... | Checks if the user is speaking . |
41,268 | public function handleVoiceStateUpdate ( $ data ) { $ removeDecoder = function ( $ ss ) { $ decoder = @ $ this -> voiceDecoders [ $ ss -> ssrc ] ; if ( is_null ( $ decoder ) ) { return ; } $ decoder -> close ( ) ; unset ( $ this -> voiceDecoders [ $ ss -> ssrc ] ) ; unset ( $ this -> speakingStatus [ $ ss -> ssrc ] ) ;... | Handles a voice state update . |
41,269 | public function getRecieveStream ( $ id ) { $ deferred = new Deferred ( ) ; if ( isset ( $ this -> recieveStreams [ $ id ] ) ) { $ deferred -> resolve ( $ this -> recieveStreams [ $ id ] ) ; return $ deferred -> promise ( ) ; } foreach ( $ this -> speakingStatus as $ status ) { if ( $ status -> user_id == $ id ) { $ de... | Gets a recieve voice stream . |
41,270 | public function checkForFFmpeg ( ) { $ binaries = [ 'ffmpeg' , ] ; foreach ( $ binaries as $ binary ) { $ output = shell_exec ( "which {$binary}" ) ; if ( ! empty ( $ output ) ) { return true ; } } $ this -> emit ( 'error' , [ new FFmpegNotFoundException ( 'No FFmpeg binary was found.' ) ] ) ; return false ; } | Checks if FFmpeg is installed . |
41,271 | public function checkForDCA ( ) { $ binaries = [ 'Darwin' => [ 32 => 'dca-v0.1.0-darwin-10.6-386' , 64 => 'dca-v0.1.0-darwin-10.6-amd64' , ] , 'Linux' => [ 32 => 'dca-v0.1.0-linux-386' , 64 => 'dca-v0.1.0-linux-amd64' , ] , ] ; if ( array_key_exists ( PHP_OS , $ binaries ) ) { $ binary = realpath ( __DIR__ . '/../../..... | Checks if DCA is installed . |
41,272 | public function dcaEncode ( $ filename = '' , $ channels = 2 ) { $ flags = [ '-ac' , $ channels , '-aa' , $ this -> audioApplication , '-ab' , round ( $ this -> bitrate / 1000 ) , '-as' , round ( $ this -> frameSize * 48 ) , '-vol' , round ( $ this -> volume * 2.56 ) , '-i' , ( empty ( $ filename ) ) ? 'pipe:0' : "\"{$... | Encodes a file to Opus with DCA . |
41,273 | public function dcaDecode ( $ channels = 2 , $ frameSize = null ) { if ( is_null ( $ frameSize ) ) { $ frameSize = round ( $ this -> frameSize * 48 ) ; } $ flags = [ '-ac' , $ channels , '-ab' , round ( $ this -> bitrate / 1000 ) , '-as' , $ frameSize , '-mode' , 'decode' , ] ; $ flags = implode ( ' ' , $ flags ) ; ret... | Decodes a file from Opus with DCA . |
41,274 | protected function handleVoiceServerUpdate ( $ data ) { if ( isset ( $ this -> voiceClients [ $ data -> d -> guild_id ] ) ) { $ this -> logger -> debug ( 'voice server update received' , [ 'guild' => $ data -> d -> guild_id , 'data' => $ data -> d ] ) ; $ this -> voiceClients [ $ data -> d -> guild_id ] -> handleVoiceS... | Handles VOICE_SERVER_UPDATE packets . |
41,275 | protected function handleGuildMembersChunk ( $ data ) { $ guild = $ this -> guilds -> get ( 'id' , $ data -> d -> guild_id ) ; $ members = $ data -> d -> members ; $ this -> logger -> debug ( 'received guild member chunk' , [ 'guild_id' => $ guild -> id , 'guild_name' => $ guild -> name , 'member_count' => count ( $ me... | Handles GUILD_MEMBERS_CHUNK packets . |
41,276 | protected function handleVoiceStateUpdate ( $ data ) { if ( isset ( $ this -> voiceClients [ $ data -> d -> guild_id ] ) ) { $ this -> logger -> debug ( 'voice state update received' , [ 'guild' => $ data -> d -> guild_id , 'data' => $ data -> d ] ) ; $ this -> voiceClients [ $ data -> d -> guild_id ] -> handleVoiceSta... | Handles VOICE_STATE_UPDATE packets . |
41,277 | public function handleWsConnection ( WebSocket $ ws ) { $ this -> ws = $ ws ; $ this -> connected = true ; $ this -> logger -> info ( 'websocket connection has been created' ) ; $ ws -> on ( 'message' , [ $ this , 'handleWsMessage' ] ) ; $ ws -> on ( 'close' , [ $ this , 'handleWsClose' ] ) ; $ ws -> on ( 'error' , [ $... | Handles WebSocket connections received by the client . |
41,278 | public function handleWsMessage ( $ message ) { if ( $ message -> isBinary ( ) ) { $ data = zlib_decode ( $ message -> getPayload ( ) ) ; } else { $ data = $ message -> getPayload ( ) ; } $ data = json_decode ( $ data ) ; $ this -> emit ( 'raw' , [ $ data , $ this ] ) ; if ( isset ( $ data -> s ) ) { $ this -> seq = $ ... | Handles WebSocket messages received by the client . |
41,279 | public function handleWsClose ( $ op , $ reason ) { $ this -> connected = false ; if ( ! is_null ( $ this -> heartbeatTimer ) ) { $ this -> heartbeatTimer -> cancel ( ) ; $ this -> heartbeatTimer = null ; } if ( ! is_null ( $ this -> heartbeatAckTimer ) ) { $ this -> heartbeatAckTimer -> cancel ( ) ; $ this -> heartbea... | Handles WebSocket closes received by the client . |
41,280 | public function handleWsError ( $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'Tried to write to closed stream' ) !== false ) { return ; } $ this -> logger -> error ( 'websocket error' , [ 'e' => $ e -> getMessage ( ) ] ) ; $ this -> emit ( 'error' , [ $ e , $ this ] ) ; $ this -> handleWsClose ( 0 , 'websocket error' ... | Handles WebSocket errors received by the client . |
41,281 | protected function handleDispatch ( $ data ) { if ( ! is_null ( $ hData = $ this -> handlers -> getHandler ( $ data -> t ) ) ) { $ handler = new $ hData [ 'class' ] ( $ this -> http , $ this -> factory , $ this -> cache , $ this ) ; $ deferred = new Deferred ( ) ; $ deferred -> promise ( ) -> then ( function ( $ d ) us... | Handles dispatch events received by the WebSocket . |
41,282 | protected function handleHeartbeat ( $ data ) { $ this -> logger -> debug ( 'received heartbeat' , [ 'seq' => $ data -> d ] ) ; $ payload = [ 'op' => Op :: OP_HEARTBEAT , 'd' => $ data -> d , ] ; $ this -> send ( $ payload ) ; } | Handles heartbeat packets received by the client . |
41,283 | protected function handleHeartbeatAck ( $ data ) { $ received = microtime ( true ) ; $ diff = $ received - $ this -> heartbeatTime ; $ time = $ diff * 1000 ; $ this -> heartbeatAckTimer -> cancel ( ) ; $ this -> emit ( 'heartbeat-ack' , [ $ time , $ this ] ) ; $ this -> logger -> debug ( 'received heartbeat ack' , [ 'r... | Handles heartbeat ACK packets received by the client . |
41,284 | protected function handleReconnect ( $ data ) { $ this -> logger -> warning ( 'received opcode 7 for reconnect' ) ; $ this -> ws -> close ( Op :: CLOSE_NORMAL , 'gateway redirecting - opcode 7' ) ; } | Handles reconnect packets received by the client . |
41,285 | protected function handleHello ( $ data ) { $ this -> logger -> info ( 'received hello' ) ; $ resume = $ this -> identify ( ) ; if ( ! $ resume ) { $ this -> setupHeartbeat ( $ data -> d -> heartbeat_interval ) ; } } | Handles HELLO packets received by the websocket . |
41,286 | protected function identify ( $ resume = true ) { if ( $ resume && $ this -> reconnecting && ! is_null ( $ this -> sessionId ) ) { $ payload = [ 'op' => Op :: OP_RESUME , 'd' => [ 'session_id' => $ this -> sessionId , 'seq' => $ this -> seq , 'token' => $ this -> token , ] , ] ; $ this -> logger -> info ( 'resuming con... | Identifies with the Discord gateway with IDENTIFY or RESUME packets . |
41,287 | public function heartbeat ( ) { $ this -> logger -> debug ( 'sending heartbeat' , [ 'seq' => $ this -> seq ] ) ; $ payload = [ 'op' => Op :: OP_HEARTBEAT , 'd' => $ this -> seq , ] ; $ this -> send ( $ payload ) ; $ this -> heartbeatTime = microtime ( true ) ; $ this -> emit ( 'heartbeat' , [ $ this -> seq , $ this ] )... | Sends a heartbeat packet to the Discord gateway . |
41,288 | protected function setupChunking ( ) { if ( ! $ this -> options [ 'loadAllMembers' ] ) { $ this -> logger -> info ( 'loadAllMembers option is disabled, not setting chunking up' ) ; return $ this -> ready ( ) ; } $ checkForChunks = function ( ) { if ( ( count ( $ this -> largeGuilds ) < 1 ) && ( count ( $ this -> largeS... | Sets guild member chunking up . |
41,289 | protected function setupHeartbeat ( $ interval ) { $ this -> heartbeatInterval = $ interval ; if ( isset ( $ this -> heartbeatTimer ) ) { $ this -> heartbeatTimer -> cancel ( ) ; } $ interval = $ interval / 1000 ; $ this -> heartbeatTimer = $ this -> loop -> addPeriodicTimer ( $ interval , [ $ this , 'heartbeat' ] ) ; ... | Sets the heartbeat timer up . |
41,290 | protected function connectWs ( ) { $ this -> logger -> info ( 'starting connection to websocket' , [ 'gateway' => $ this -> gateway ] ) ; $ this -> wsFactory -> __invoke ( $ this -> gateway ) -> then ( [ $ this , 'handleWsConnection' ] , [ $ this , 'handleWsError' ] ) ; } | Initilizes the connection with the Discord gateway . |
41,291 | protected function ready ( ) { if ( $ this -> emittedReady ) { return false ; } $ this -> logger -> info ( 'client is ready' ) ; $ this -> emit ( 'ready' , [ $ this ] ) ; foreach ( $ this -> unparsedPackets as $ parser ) { $ parser ( ) ; } } | Emits ready if it has not been emitted already . |
41,292 | public function updatePresence ( Game $ game = null , $ idle = false ) { $ idle = ( $ idle ) ? $ idle : null ; if ( ! is_null ( $ game ) ) { $ game = $ game -> getPublicAttributes ( ) ; } $ payload = [ 'op' => Op :: OP_PRESENCE_UPDATE , 'd' => [ 'game' => $ game , 'idle_since' => $ idle , ] , ] ; $ this -> send ( $ pay... | Updates the clients presence . |
41,293 | public function getVoiceClient ( $ id ) { if ( isset ( $ this -> voiceClients [ $ id ] ) ) { return \ React \ Promise \ resolve ( $ this -> voiceClients [ $ id ] ) ; } return \ React \ Promise \ reject ( new \ Exception ( 'Could not find the voice client.' ) ) ; } | Gets a voice client from a guild ID . |
41,294 | protected function setGateway ( $ gateway = null ) { $ deferred = new Deferred ( ) ; $ buildParams = function ( $ gateway ) use ( $ deferred ) { $ params = [ 'v' => self :: GATEWAY_VERSION , 'encoding' => $ this -> encoding , ] ; $ query = http_build_query ( $ params ) ; $ this -> gateway = trim ( $ gateway , '/' ) . '... | Retrieves and sets the gateway URL for the client . |
41,295 | public function close ( ) { $ this -> closing = true ; $ this -> ws -> close ( 1000 , 'discordphp closing...' ) ; $ this -> emit ( 'closed' , [ $ this ] ) ; } | Closes the Discord client . |
41,296 | public function getRepository ( $ class , $ id , $ key , $ vars = [ ] ) { $ classKey = str_replace ( '\\' , '' , $ class ) ; $ cacheKey = "repositories.{$classKey}.{$id}.{$key}" ; if ( $ object = $ this -> cache -> get ( $ cacheKey ) ) { return $ object ; } $ repository = new $ class ( $ this -> http , $ this -> cache ... | Attempts to get a repository from the cache . |
41,297 | public function getMemberAttribute ( ) { $ guild = $ this -> discord -> guilds -> get ( 'id' , $ this -> guild_id ) ; return $ guild -> members -> get ( 'id' , $ this -> user_id ) ; } | Gets the member attribute . |
41,298 | public function getRecipientsAttribute ( ) { $ recipients = new Collection ( ) ; if ( array_key_exists ( 'recipients' , $ this -> attributes ) ) { foreach ( ( array ) $ this -> attributes [ 'recipients' ] as $ recipient ) { $ recipients -> push ( $ this -> factory -> create ( User :: class , $ recipient , true ) ) ; } ... | Gets the recipients attribute . |
41,299 | public function setPermissions ( Part $ part , ChannelPermission $ permissions = null ) { $ deferred = new Deferred ( ) ; if ( $ part instanceof Member ) { $ type = 'member' ; } elseif ( $ part instanceof Role ) { $ type = 'role' ; } else { return false ; } if ( is_null ( $ permissions ) ) { $ permissions = $ this -> f... | Sets a permission value to the channel . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.