diff options
| author | Nakidai <nakidai@disroot.org> | 2024-11-05 16:22:44 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-11-05 16:22:44 +0300 |
| commit | 09fe2c1160cf87d31ebe381d1622d5889c8a333d (patch) | |
| tree | 1a8c4a324f836dc5e8db67b8145ea15e94d9b8c7 | |
| parent | 8311ace9df72d57ee6026de57b0063cf198d1ae5 (diff) | |
| download | petthecord-09fe2c1160cf87d31ebe381d1622d5889c8a333d.tar.gz petthecord-09fe2c1160cf87d31ebe381d1622d5889c8a333d.zip | |
Add shard support, fix #2
Shards are way to fix the problem with 429
| -rw-r--r-- | src/petthecord/main.py | 10 | ||||
| -rw-r--r-- | src/petthecord/runner.py | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/petthecord/main.py b/src/petthecord/main.py index c164685..9177926 100644 --- a/src/petthecord/main.py +++ b/src/petthecord/main.py @@ -55,6 +55,13 @@ def main() -> None: metavar="TIME", help="Delay between cache's garbage collector runs in seconds" ) + parser.add_argument( + "-c", "--shards", + default=1, + type=int, + metavar="COUNT", + help="Amount of shards to create" + ) args = parser.parse_args() bot = PetTheCord( @@ -64,7 +71,8 @@ def main() -> None: not args.no_cache, args.cache_dir, args.cache_lifetime, - args.cache_gc_delay + args.cache_gc_delay, + args.shards, ) if (token := getenv("PETTHECORD_TOKEN")) is not None: bot.run(token, root_logger=True) diff --git a/src/petthecord/runner.py b/src/petthecord/runner.py index f40577c..75ed6ca 100644 --- a/src/petthecord/runner.py +++ b/src/petthecord/runner.py @@ -9,7 +9,7 @@ from .cache import CachedPet from .server import Server -class PetTheCord(commands.Bot): +class PetTheCord(commands.AutoShardedBot): def __init__( self, @@ -20,10 +20,12 @@ class PetTheCord(commands.Bot): cache_path: str = "/var/cache/petthecord", cache_lifetime: int = 86400, cache_gc_delay: int = 14400, + shard_count: int = 1, ) -> None: super().__init__( command_prefix="!", - intents=Intents.default() + intents=Intents.default(), + shard_count=shard_count, ) self._host = host self._port = port |