An API to interact with the popular messaging app Discord
PHP Discord Interface
Discord Helper PHP
Bot to monitor stability of Fenrir
.env processor
a thing for backups
Bread
Discord bot that sends a cat
push eventtnapf/Config
commit sha 53785c237c3b2eaa563fcb62ef038c247790b2c1
Rename function
push time in 8 hours
Pull request review commenttnapf/Config
feature/cached-config-provider
public function testItThrowsAnErrorIfAConfigProviderReturnsNonArrayForMultiLevel */ public function testItReturnsDefault(string $key, mixed $providerReturn) {- /** @var ConfigProvider&MockInterface */+ /** @var ConfigProvider&MockInterface $configProvider */
https://discord.com/channels/1040758519323971624/1103456136671268884/1113826503038353478
comment created time in 9 hours
push eventdc-Ragnarok/Fenrir
commit sha df49d77f07d8a9c69f947345222cbb26af976e48
Add binding
push time in a day
push eventdc-Ragnarok/Fenrir
commit sha ec37405fbaeee9329843b86eb45ccc11fbe5f57b
Api updates
commit sha 14067258e84f41774c3bac204490ed13f4a7abb0
Merge pull request #42 from dc-Ragnarok/chore/api-updates-may-2023 Api updates
push time in a day
PR merged dc-Ragnarok/Fenrir
-
Add Auto Moderation custom_message Action Metadata Field https://discord.com/developers/docs/change-log#add-auto-moderation-custommessage-action-metadata-field
-
Interaction Channel Data https://discord.com/developers/docs/change-log#interaction-channel-data
-
Add Join Raid and Mention Raid fields https://discord.com/developers/docs/change-log#add-join-raid-and-mention-raid-fields
pr closed time in a day
push eventdc-Ragnarok/Fenrir
commit sha ddd780d6e219c44fddb6ead8a8073f465e4ae515
Add bindings
push time in 2 days
push eventExanlv/tnapf-JsonMapper
commit sha a586f54ea055fa1554333a14b60d3f5decf9b58c
cs
push time in 2 days
push eventdc-Ragnarok/Fenrir
commit sha f1fe64cbe33bac936832588d768295e7f9d12fff
More guild bindings
push time in 2 days
PR opened dc-Ragnarok/Fenrir
-
Add Auto Moderation custom_message Action Metadata Field https://discord.com/developers/docs/change-log#add-auto-moderation-custommessage-action-metadata-field
-
Interaction Channel Data https://discord.com/developers/docs/change-log#interaction-channel-data
-
Add Join Raid and Mention Raid fields https://discord.com/developers/docs/change-log#add-join-raid-and-mention-raid-fields
pr created time in 3 days
push eventdc-Ragnarok/Fenrir
commit sha ec37405fbaeee9329843b86eb45ccc11fbe5f57b
Api updates
push time in 3 days
push eventdc-Ragnarok/Fenrir
commit sha 5f5e186ea9641b9be8011adfcc70f2621278e820
Add more bindings
push time in 3 days
Pull request review commenttnapf/Config
feature/cached-config-provider
+<?php++namespace Tnapf\Config\Cache;++use DateInterval;+use Psr\SimpleCache\CacheInterface;+use Psr\SimpleCache\InvalidArgumentException;+use Tnapf\Config\Exceptions\InvalidCacheKeyException;++class InMemoryDriver implements CacheInterface+{+ private array $storage = [];++ /**+ * @throws InvalidArgumentException+ */+ public function get(string $key, mixed $default = null): mixed+ {+ return $this->has($key) ? $this->storage[$key] : $default;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool+ {+ $this->validateKey($key);+ $this->storage[$key] = $value;++ return true;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function delete(string $key): bool+ {+ $this->validateKey($key);+ unset($this->storage[$key]);++ return true;+ }++ public function clear(): bool+ {+ $this->storage = [];++ return true;+ }++ /**+ * @param string[] $keys+ *+ * @throws InvalidArgumentException+ *+ * @return iterable<string, mixed>+ */+ public function getMultiple(iterable $keys, mixed $default = null): iterable+ {+ $items = [];+ foreach ($keys as $key) {+ $items[$key] = $this->get($key, $default);+ }++ return $items;+ }++ /**+ * @throws InvalidArgumentException+ */+ public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool+ {+ foreach ($values as $key => $value) {
It's ever so slightly faster to do it with my suggestion and a separate loop for validating keys. But its ~0.01 to 0.03 seconds faster for every million uses so not worth it
comment created time in 3 days
Pull request review commenttnapf/Config
feature/cached-config-provider
+<?php++namespace Tnapf\Config\Test\Cache;++use PHPUnit\Framework\TestCase;+use Tnapf\Config\Cache\InMemoryDriver;+use Tnapf\Config\Exceptions\InvalidCacheKeyException;++class InMemoryDriverTest extends TestCase+{+ public function testItCachesValues(): void+ {+ $driver = new InMemoryDriver();+ $driver->set('host', 'localhost');++ $this->assertTrue($driver->has('host'));+ $this->assertSame('localhost', $driver->get('host'));+ }++ public function testItDeletesCache(): void+ {+ $driver = new InMemoryDriver();+ $driver->set('key', 'value');++ $driver->delete('key');++ $this->assertFalse($driver->has('key'));+ $this->assertNull($driver->get('key'));+ }++ public function testItClearsCache(): void+ {+ $driver = new InMemoryDriver();+ $driver->setMultiple(['host' => 'localhost', 'user' => 'root']);++ $driver->clear();++ $this->assertFalse($driver->has('host'));+ $this->assertNull($driver->get('host'));++ $this->assertFalse($driver->has('user'));+ $this->assertNull($driver->get('user'));+ }++ public function testItRetrievesDefaultValueOnMissingCache(): void+ {+ $driver = new InMemoryDriver();++ $this->assertFalse($driver->has('non-existent-key'));++ $result = $driver->get('non-existent-key', 'defaultValue');+ $this->assertSame('defaultValue', $result);+ }++ public function testItFillsDefaultValueForMultipleKeys(): void+ {+ $driver = new InMemoryDriver();++ $driver->set('host', 'localhost');+ $expected = ['host' => 'localhost', 'user' => 'empty', 'driver' => 'empty'];++ $this->assertSame($expected, $driver->getMultiple(['host', 'user', 'driver'], 'empty'));+ }++ public function testItDeletesMultipleKeys(): void+ {+ $driver = new InMemoryDriver();++ $driver->setMultiple(['host' => 'localhost', 'user' => 'root', 'driver' => 'pdo']);++ $driver->deleteMultiple(['host', 'user']);++ $this->assertFalse($driver->has('host'));+ $this->assertNull($driver->get('host'));++ $this->assertFalse($driver->has('user'));+ $this->assertNull($driver->get('user'));++ $this->assertTrue($driver->has('driver'));+ $this->assertSame('pdo', $driver->get('driver'));+ }++ public function testItThrowsWhenCacheKeyIsInvalid(): void+ {+ $this->expectException(InvalidCacheKeyException::class);++ $driver = new InMemoryDriver();+ $driver->get('{invalid}');
Since there's a lot of characters that are not allowed, how about a dataprovider that provides every one of those chars separately which is then prepended to some string to be tested?
comment created time in 3 days
Pull request review commenttnapf/Config
feature/cached-config-provider
+<?php++namespace Tnapf\Config\Cache;++use DateInterval;+use Psr\SimpleCache\CacheInterface;+use Psr\SimpleCache\InvalidArgumentException;+use Tnapf\Config\Exceptions\InvalidCacheKeyException;++class InMemoryDriver implements CacheInterface+{+ private array $storage = [];++ /**+ * @throws InvalidArgumentException+ */+ public function get(string $key, mixed $default = null): mixed+ {+ return $this->has($key) ? $this->storage[$key] : $default;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool+ {+ $this->validateKey($key);+ $this->storage[$key] = $value;++ return true;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function delete(string $key): bool+ {+ $this->validateKey($key);+ unset($this->storage[$key]);++ return true;+ }++ public function clear(): bool+ {+ $this->storage = [];++ return true;+ }++ /**+ * @param string[] $keys+ *+ * @throws InvalidArgumentException+ *+ * @return iterable<string, mixed>+ */+ public function getMultiple(iterable $keys, mixed $default = null): iterable+ {+ $items = [];+ foreach ($keys as $key) {+ $items[$key] = $this->get($key, $default);+ }++ return $items;+ }++ /**+ * @throws InvalidArgumentException+ */+ public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool+ {+ foreach ($values as $key => $value) {
Maybe a bit jank, but would this work?
$this->storage = [...$this->storage, ...$values];
Guessing no, cuz of iterable instead of array
comment created time in 3 days
Pull request review commenttnapf/Config
feature/cached-config-provider
+<?php++namespace Tnapf\Config\Cache;++use DateInterval;+use Psr\SimpleCache\CacheInterface;+use Psr\SimpleCache\InvalidArgumentException;+use Tnapf\Config\Exceptions\InvalidCacheKeyException;++class InMemoryDriver implements CacheInterface+{+ private array $storage = [];++ /**+ * @throws InvalidArgumentException+ */+ public function get(string $key, mixed $default = null): mixed+ {+ return $this->has($key) ? $this->storage[$key] : $default;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool+ {+ $this->validateKey($key);+ $this->storage[$key] = $value;++ return true;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function delete(string $key): bool+ {+ $this->validateKey($key);+ unset($this->storage[$key]);++ return true;+ }++ public function clear(): bool+ {+ $this->storage = [];++ return true;+ }++ /**+ * @param string[] $keys+ *+ * @throws InvalidArgumentException+ *+ * @return iterable<string, mixed>+ */+ public function getMultiple(iterable $keys, mixed $default = null): iterable+ {+ $items = [];+ foreach ($keys as $key) {+ $items[$key] = $this->get($key, $default);+ }++ return $items;+ }++ /**+ * @throws InvalidArgumentException+ */+ public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool+ {+ foreach ($values as $key => $value) {+ $this->set($key, $value, $ttl);+ }++ return true;+ }++ /**+ * @throws InvalidArgumentException
* @throws InvalidCacheKeyException
comment created time in 3 days
Pull request review commenttnapf/Config
feature/cached-config-provider
+<?php++namespace Tnapf\Config\Cache;++use DateInterval;+use Psr\SimpleCache\CacheInterface;+use Psr\SimpleCache\InvalidArgumentException;+use Tnapf\Config\Exceptions\InvalidCacheKeyException;++class InMemoryDriver implements CacheInterface+{+ private array $storage = [];++ /**+ * @throws InvalidArgumentException+ */+ public function get(string $key, mixed $default = null): mixed+ {+ return $this->has($key) ? $this->storage[$key] : $default;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool+ {+ $this->validateKey($key);+ $this->storage[$key] = $value;++ return true;+ }++ /**+ * @throws InvalidCacheKeyException+ */+ public function delete(string $key): bool+ {+ $this->validateKey($key);+ unset($this->storage[$key]);++ return true;+ }++ public function clear(): bool+ {+ $this->storage = [];++ return true;+ }++ /**+ * @param string[] $keys+ *+ * @throws InvalidArgumentException+ *+ * @return iterable<string, mixed>+ */+ public function getMultiple(iterable $keys, mixed $default = null): iterable+ {+ $items = [];+ foreach ($keys as $key) {+ $items[$key] = $this->get($key, $default);+ }++ return $items;+ }++ /**+ * @throws InvalidArgumentException
* @throws InvalidCacheKeyException
comment created time in 3 days