Skip to content

Commit 09e5e5f

Browse files
committed
bot => discord
1 parent 756ee4a commit 09e5e5f

4 files changed

Lines changed: 99 additions & 100 deletions

File tree

src/Discord/Voice/Client.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class Client extends EventEmitter
286286
/**
287287
* Constructs the Voice client instance.
288288
*
289-
* @param Discord $bot The Discord instance.
289+
* @param Discord $discord The Discord instance.
290290
* @param Channel $channel
291291
* @param string[] $voice_sessions
292292
* @param array $data
@@ -296,7 +296,7 @@ class Client extends EventEmitter
296296
* @param Manager|null $manager
297297
*/
298298
public function __construct(
299-
public Discord $bot,
299+
public Discord $discord,
300300
public Channel $channel,
301301
public array &$voice_sessions,
302302
public array $data = [],
@@ -309,7 +309,7 @@ public function __construct(
309309
$this->deaf = $this->data['deaf'] ?? false;
310310
$this->mute = $this->data['mute'] ?? false;
311311

312-
$this->data['user_id'] = $this->bot->id;
312+
$this->data['user_id'] = $this->discord->id;
313313
$this->data['deaf'] = $this->deaf;
314314
$this->data['mute'] = $this->mute;
315315
$this->data['session'] = $this->data['session'] ?? null;
@@ -330,7 +330,7 @@ public function start(): bool
330330
return false;
331331
}
332332

333-
WS::make($this, $this->bot, $this->data);
333+
WS::make($this, $this->discord, $this->data);
334334

335335
return true;
336336
}
@@ -370,7 +370,7 @@ public function playFile(string $file, int $channels = 2): PromiseInterface
370370
}
371371

372372
$process = Ffmpeg::encode($file, volume: $this->getDbVolume());
373-
$process->start($this->bot->getLoop());
373+
$process->start($this->discord->getLoop());
374374

375375
return $this->playOggStream($process);
376376
}
@@ -410,15 +410,15 @@ public function playRawStream($stream, int $channels = 2, int $audioRate = 48000
410410
}
411411

412412
if (is_resource($stream)) {
413-
$stream = new Stream($stream, $this->bot->getLoop());
413+
$stream = new Stream($stream, $this->discord->getLoop());
414414
}
415415

416416
$process = Ffmpeg::encode(volume: $this->getDbVolume(), preArgs: [
417417
'-f', 's16le',
418418
'-ac', $channels,
419419
'-ar', $audioRate,
420420
]);
421-
$process->start($this->bot->getLoop());
421+
$process->start($this->discord->getLoop());
422422
$stream->pipe($process->stdin);
423423

424424
return $this->playOggStream($process);
@@ -463,7 +463,7 @@ public function playOggStream($stream): PromiseInterface
463463
}
464464

465465
if (is_resource($stream)) {
466-
$stream = new Stream($stream, $this->bot->getLoop());
466+
$stream = new Stream($stream, $this->discord->getLoop());
467467
}
468468

469469
if (! ($stream instanceof ReadableStreamInterface)) {
@@ -472,7 +472,7 @@ public function playOggStream($stream): PromiseInterface
472472
return $deferred->promise();
473473
}
474474

475-
$this->buffer = new RealBuffer($this->bot->getLoop());
475+
$this->buffer = new RealBuffer($this->discord->getLoop());
476476
$stream->on('data', function ($d) {
477477
$this->buffer->write($d);
478478
});
@@ -487,7 +487,7 @@ public function playOggStream($stream): PromiseInterface
487487
OggStream::fromBuffer($this->buffer)->then(function (OggStream $os) use ($deferred, &$ogg, &$loops) {
488488
$ogg = $os;
489489
$this->startTime = microtime(true) + 0.5;
490-
$this->readOpusTimer = $this->bot->getLoop()->addTimer(0.5, fn () => $this->readOggOpus($deferred, $ogg, $loops));
490+
$this->readOpusTimer = $this->discord->getLoop()->addTimer(0.5, fn () => $this->readOggOpus($deferred, $ogg, $loops));
491491
});
492492

493493
return $deferred->promise();
@@ -509,7 +509,7 @@ protected function readOggOpus(Deferred $deferred, OggStream &$ogg, int &$loops)
509509
// If the client is paused, delay by frame size and check again.
510510
if ($this->paused) {
511511
$this->udp->insertSilence();
512-
$this->readOpusTimer = $this->bot->getLoop()->addTimer($this->frameSize / 1000, fn () => $this->readOggOpus($deferred, $ogg, $loops));
512+
$this->readOpusTimer = $this->discord->getLoop()->addTimer($this->frameSize / 1000, fn () => $this->readOggOpus($deferred, $ogg, $loops));
513513

514514
return;
515515
}
@@ -540,7 +540,7 @@ protected function readOggOpus(Deferred $deferred, OggStream &$ogg, int &$loops)
540540
$nextTime = $this->startTime + (20.0 / 1000.0) * $loops;
541541
$delay = $nextTime - microtime(true);
542542

543-
$this->readOpusTimer = $this->bot->getLoop()->addTimer($delay, fn () => $this->readOggOpus($deferred, $ogg, $loops));
543+
$this->readOpusTimer = $this->discord->getLoop()->addTimer($delay, fn () => $this->readOggOpus($deferred, $ogg, $loops));
544544
}, function () use ($deferred) {
545545
$this->reset();
546546
$deferred->resolve(null);
@@ -587,7 +587,7 @@ public function playDCAStream($stream): PromiseInterface
587587
}
588588

589589
if (is_resource($stream)) {
590-
$stream = new Stream($stream, $this->bot->getLoop());
590+
$stream = new Stream($stream, $this->discord->getLoop());
591591
}
592592

593593
if (! ($stream instanceof ReadableStreamInterface)) {
@@ -596,7 +596,7 @@ public function playDCAStream($stream): PromiseInterface
596596
return $deferred->promise();
597597
}
598598

599-
$this->buffer = new RealBuffer($this->bot->getLoop());
599+
$this->buffer = new RealBuffer($this->discord->getLoop());
600600
$stream->on('data', function ($d) {
601601
$this->buffer->write($d);
602602
});
@@ -622,7 +622,7 @@ public function playDCAStream($stream): PromiseInterface
622622
}
623623

624624
$this->startTime = microtime(true) + 0.5;
625-
$this->readOpusTimer = $this->bot->getLoop()->addTimer(0.5, fn () => $this->readDCAOpus($deferred));
625+
$this->readOpusTimer = $this->discord->getLoop()->addTimer(0.5, fn () => $this->readDCAOpus($deferred));
626626
});
627627

628628
return $deferred->promise();
@@ -640,7 +640,7 @@ protected function readDCAOpus(Deferred $deferred): void
640640
// If the client is paused, delay by frame size and check again.
641641
if ($this->paused) {
642642
$this->udp->insertSilence();
643-
$this->readOpusTimer = $this->bot->getLoop()->addTimer($this->frameSize / 1000, fn () => $this->readDCAOpus($deferred));
643+
$this->readOpusTimer = $this->discord->getLoop()->addTimer($this->frameSize / 1000, fn () => $this->readDCAOpus($deferred));
644644

645645
return;
646646
}
@@ -664,7 +664,7 @@ protected function readDCAOpus(Deferred $deferred): void
664664
$this->timestamp = 0;
665665
}
666666

667-
$this->readOpusTimer = $this->bot->getLoop()->addTimer(($this->frameSize - 1) / 1000, fn () => $this->readDCAOpus($deferred));
667+
$this->readOpusTimer = $this->discord->getLoop()->addTimer(($this->frameSize - 1) / 1000, fn () => $this->readDCAOpus($deferred));
668668
}, function () use ($deferred) {
669669
$this->reset();
670670
$deferred->resolve(null);
@@ -677,7 +677,7 @@ protected function readDCAOpus(Deferred $deferred): void
677677
protected function reset(): void
678678
{
679679
if ($this->readOpusTimer) {
680-
$this->bot->getLoop()->cancelTimer($this->readOpusTimer);
680+
$this->discord->getLoop()->cancelTimer($this->readOpusTimer);
681681
$this->readOpusTimer = null;
682682
}
683683

@@ -752,7 +752,7 @@ public function switchChannel(?Channel $channel): self
752752
}
753753

754754
/**
755-
* Disconnects the bot from the current voice channel.
755+
* Disconnects the discord from the current voice channel.
756756
*
757757
* @return \Discord\Voice\VoiceClient
758758
*/
@@ -835,7 +835,7 @@ public function setAudioApplication(string $app): void
835835
*/
836836
protected function mainSend($data): void
837837
{
838-
$this->bot->send($data);
838+
$this->discord->send($data);
839839
}
840840

841841
/**
@@ -980,7 +980,7 @@ public function close(): void
980980
$this->heartbeatInterval = null;
981981

982982
if (null !== $this->heartbeat) {
983-
$this->bot->getLoop()->cancelTimer($this->heartbeat);
983+
$this->discord->getLoop()->cancelTimer($this->heartbeat);
984984
$this->heartbeat = null;
985985
}
986986

@@ -997,7 +997,7 @@ public function close(): void
997997
/**
998998
* Checks if the user is speaking.
999999
*
1000-
* @param string|int|null $id Either the User ID or SSRC (if null, return bots speaking status).
1000+
* @param string|int|null $id Either the User ID or SSRC (if null, return discords speaking status).
10011001
*
10021002
* @return bool Whether the user is speaking.
10031003
*/
@@ -1040,19 +1040,19 @@ public function handleVoiceStateUpdate(object $data): void
10401040
*/
10411041
public function handleVoiceServerChange(array $data = []): void
10421042
{
1043-
$this->bot->getLogger()->debug('voice server has changed, dynamically changing servers in the background', ['data' => $data]);
1043+
$this->discord->getLogger()->debug('voice server has changed, dynamically changing servers in the background', ['data' => $data]);
10441044
$this->reconnecting = true;
10451045
$this->sentLoginFrame = false;
10461046
$this->pause();
10471047

10481048
$this->close();
10491049
$this->ws->close();
10501050

1051-
$this->bot->getLoop()->cancelTimer($this->heartbeat);
1052-
$this->bot->getLoop()->cancelTimer($this->udp->heartbeat);
1051+
$this->discord->getLoop()->cancelTimer($this->heartbeat);
1052+
$this->discord->getLoop()->cancelTimer($this->udp->heartbeat);
10531053

10541054
$this->on('resumed', function () {
1055-
$this->bot->getLogger()->debug('voice client resumed');
1055+
$this->discord->getLogger()->debug('voice client resumed');
10561056
$this->unpause();
10571057
$this->speaking = self::NOT_SPEAKING;
10581058
$this->setSpeaking(self::MICROPHONE);
@@ -1062,7 +1062,7 @@ public function handleVoiceServerChange(array $data = []): void
10621062
$this->data['token'] = $data['token']; // set the token if it changed
10631063
$this->endpoint = str_replace([':80', ':443'], '', $data['endpoint']);
10641064

1065-
WS::make($this, $this->bot, $data);
1065+
WS::make($this, $this->discord, $data);
10661066
}
10671067

10681068
/**
@@ -1141,7 +1141,7 @@ public function handleAudioData(Packet $voicePacket): void
11411141
// We don't have a speaking status for this SSRC
11421142
// Probably a "ping" to the udp socket
11431143
// There's no message or the message threw an error inside the decrypt function
1144-
$this->bot->getLogger()->warning('No audio data.', ['voicePacket' => $voicePacket]);
1144+
$this->discord->getLogger()->warning('No audio data.', ['voicePacket' => $voicePacket]);
11451145

11461146
return;
11471147
}
@@ -1153,7 +1153,7 @@ public function handleAudioData(Packet $voicePacket): void
11531153

11541154
if (null === $ss) {
11551155
// for some reason we don't have a speaking status
1156-
$this->bot->getLogger()->warning('Unknown SSRC.', ['ssrc' => $voicePacket->getSSRC(), 't' => $voicePacket->getTimestamp()]);
1156+
$this->discord->getLogger()->warning('Unknown SSRC.', ['ssrc' => $voicePacket->getSSRC(), 't' => $voicePacket->getTimestamp()]);
11571157

11581158
return;
11591159
}
@@ -1177,7 +1177,7 @@ public function handleAudioData(Packet $voicePacket): void
11771177
}
11781178

11791179
if ($decoder->stdin->isWritable() === false) {
1180-
$this->bot->getLogger()->warning('Decoder stdin is not writable.', ['ssrc' => $ss->ssrc]);
1180+
$this->discord->getLogger()->warning('Decoder stdin is not writable.', ['ssrc' => $ss->ssrc]);
11811181

11821182
return; // decoder stdin is not writable, cannot write audio data.
11831183
// This should be either restarted or checked if the decoder is still running.
@@ -1194,7 +1194,7 @@ public function handleAudioData(Packet $voicePacket): void
11941194
$data = OpusFfi::decode($voicePacket->decryptedAudio);
11951195

11961196
if (empty(trim($data))) {
1197-
$this->bot->getLogger()->debug('Received empty audio data.', ['ssrc' => $ss->ssrc]);
1197+
$this->discord->getLogger()->debug('Received empty audio data.', ['ssrc' => $ss->ssrc]);
11981198

11991199
return; // no audio data to write
12001200
}
@@ -1210,7 +1210,7 @@ public function handleAudioData(Packet $voicePacket): void
12101210
protected function createDecoder($ss): void
12111211
{
12121212
$decoder = Ffmpeg::decode((string) $ss->ssrc);
1213-
$decoder->start($this->bot->getLoop());
1213+
$decoder->start($this->discord->getLoop());
12141214

12151215
$decoder->stdout->on('data', function ($data) use ($ss) {
12161216
if (empty($data)) {
@@ -1250,14 +1250,14 @@ protected function monitorProcessExit(Process $process, $ss): void
12501250
// $pid = $process->getPid();
12511251

12521252
// Check every second if the process is still running
1253-
$this->monitorProcessTimer = $this->bot->getLoop()->addPeriodicTimer(1.0, function () use ($process, $ss) {
1253+
$this->monitorProcessTimer = $this->discord->getLoop()->addPeriodicTimer(1.0, function () use ($process, $ss) {
12541254
// Check if the process is still running
12551255
if (! $process->isRunning()) {
12561256
// Get the exit code
12571257
$exitCode = $process->getExitCode();
12581258

12591259
// Clean up the timer
1260-
$this->bot->getLoop()->cancelTimer($this->monitorProcessTimer);
1260+
$this->discord->getLoop()->cancelTimer($this->monitorProcessTimer);
12611261

12621262
// If exit code indicates an error, emit event and recreate decoder
12631263
if ($exitCode > 0) {
@@ -1291,7 +1291,7 @@ public function getDbVolume(): float|int
12911291
/**
12921292
* Creates a new voice client instance statically.
12931293
*
1294-
* @param \Discord\Discord $bot
1294+
* @param \Discord\Discord $discord
12951295
* @param \Discord\Parts\Channel\Channel $channel
12961296
* @param array $data
12971297
* @param bool $deaf
@@ -1315,7 +1315,7 @@ public static function make(): self
13151315
public function boot(): bool
13161316
{
13171317
return $this->once('ready', function () {
1318-
$this->bot->getLogger()->info('voice client is ready');
1318+
$this->discord->getLogger()->info('voice client is ready');
13191319
if (isset($this->manager->clients[$this->channel->guild_id])) {
13201320
$this->disconnect();
13211321
}
@@ -1324,17 +1324,17 @@ public function boot(): bool
13241324

13251325
$this->setBitrate($this->channel->bitrate);
13261326

1327-
$this->bot->getLogger()->info('set voice client bitrate', ['bitrate' => $this->channel->bitrate]);
1327+
$this->discord->getLogger()->info('set voice client bitrate', ['bitrate' => $this->channel->bitrate]);
13281328
$this->deferred->resolve($this);
13291329
})
13301330
->once('error', function ($e) {
13311331
$this->disconnect();
1332-
$this->bot->getLogger()->error('error initializing voice client', ['e' => $e->getMessage()]);
1332+
$this->discord->getLogger()->error('error initializing voice client', ['e' => $e->getMessage()]);
13331333
$this->deferred->reject($e);
13341334
})
13351335
->once('close', function () {
13361336
$this->disconnect();
1337-
$this->bot->getLogger()->warning('voice client closed');
1337+
$this->discord->getLogger()->warning('voice client closed');
13381338
unset($this->manager->clients[$this->channel->guild_id]);
13391339
})
13401340
->start();
@@ -1347,7 +1347,7 @@ public function record(): void
13471347
}
13481348

13491349
$this->shouldRecord = true;
1350-
$this->bot->getLogger()->info('Started recording audio.');
1350+
$this->discord->getLogger()->info('Started recording audio.');
13511351

13521352
$this->udp->on('message', [$this, 'handleAudioData']);
13531353
}
@@ -1359,7 +1359,7 @@ public function stopRecording(): void
13591359
}
13601360

13611361
$this->shouldRecord = false;
1362-
$this->bot->getLogger()->info('Stopped recording audio.');
1362+
$this->discord->getLogger()->info('Stopped recording audio.');
13631363

13641364
$this->udp->removeListener('message', [$this, 'handleAudioData']);
13651365
$this->reset();
@@ -1380,7 +1380,7 @@ public function setData(array $data): self
13801380
if (isset($this->data['token'], $this->data['endpoint'], $this->data['session'], $this->data['dnsConfig'])) {
13811381
$this->endpoint = str_replace([':80', ':443'], '', $this->data['endpoint']);
13821382
$this->dnsConfig = $this->data['dnsConfig'];
1383-
$this->data['user_id'] ??= $this->bot->id;
1383+
$this->data['user_id'] ??= $this->discord->id;
13841384
$this->boot();
13851385
}
13861386

src/Discord/Voice/Client/UDP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ public function refreshSilenceFrames(): void
292292
*/
293293
private function getLogger(): LoggerInterface
294294
{
295-
return $this->ws->vc->bot->getLogger();
295+
return $this->ws->vc->discord->getLogger();
296296
}
297297

298298
/**
299299
* Gets the event loop instance.
300300
*/
301301
private function getLoop(): LoopInterface
302302
{
303-
return $this->ws->vc->bot->getLoop();
303+
return $this->ws->vc->discord->getLoop();
304304
}
305305
}

0 commit comments

Comments
 (0)