pincer.utils.shards.calculate_shard_id()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from typing import TYPE_CHECKING
7
8
if TYPE_CHECKING:
9
    from typing import Union
10
    from .snowflake import Snowflake
11
12
13
def calculate_shard_id(guild_id: Union[Snowflake, int], num_shards: int) -> int:
14
    """Calculates the shard receiving the events for a specified guild
15
16
    Parameters
17
    ----------
18
    guild_id : Optional[~pincer.utils.snowflake.Snowflake]
19
        The guild_id of the shard to look for
20
    num_shards : Optional[int]
21
        The number of shards.
22
    """
23
    return (guild_id >> 22) % num_shards
24