Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Забыл добавить бродкаст для клиентов. Исправляюсь #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DMBotNetwork/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .side import Client, Server
from .units import ClientUnit
from .utils import ServerDB

__all__ = ["Client", "Server", "ServerDB"]
__version__ = "0.1.2"
__all__ = ["Client", "Server", "ClientUnit", "ServerDB"]
__version__ = "0.1.3"
18 changes: 18 additions & 0 deletions DMBotNetwork/side/side_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ async def _main_client_handler(
await cl_unit.close()
del cls._connections[cl_unit.login]

@classmethod
async def broadcast(cls, func_name: str, *args, **kwargs) -> None:
if not cls._connections:
logger.warning("No active connections to broadcast")
return

tasks = []
for cl_unit in cls._connections.values():
func = getattr(cl_unit, func_name, None)
if callable(func):
tasks.append(func(*args, **kwargs))

else:
logger.error(f"{func_name} is not a callable method of {cl_unit}")

if tasks:
await asyncio.gather(*tasks)

# Auth
@classmethod
async def _auth(cls, cl_unit: ClientUnit) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="DMBotNetwork",
version="0.1.2",
version="0.1.3",
packages=find_packages(),
install_requires=["aiosqlite", "bcrypt", "msgpack"],
author="Angels And Demons dev team",
Expand Down
Loading