Skip to content

Commit

Permalink
Adding ChatEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Dec 31, 2021
1 parent e45692b commit 6a201ac
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rustplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from .api import RustSocket
from .commands import CommandOptions, Command
from .exceptions import *
from .api.structures import EntityEvent, TeamEvent
from .api.structures import EntityEvent, TeamEvent, ChatEvent
from .utils import entity_type_to_string

__name__ = "rustplus"
__author__ = "olijefferson"
__version__ = "5.1.1"
__version__ = "5.1.2"
__support__ = "Discord: https://discord.gg/nQqJe8qvP8"
7 changes: 7 additions & 0 deletions rustplus/api/base_rust_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def team_event(self, coro) -> None:

self.remote.event_handler.register_event("team_changed", (coro, asyncio.get_event_loop()))

def chat_event(self, coro) -> None:
"""
A Decorator to register an event listener for chat messages
"""

self.remote.event_handler.register_event("chat_message", (coro, asyncio.get_event_loop()))

async def hang(self) -> None:
"""This Will permanently put your script into a state of 'hanging' Cannot be Undone. Only do this in scripts using commands"""

Expand Down
8 changes: 7 additions & 1 deletion rustplus/api/remote/event_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from ..structures import EntityEvent, TeamEvent
from ..structures import EntityEvent, TeamEvent, ChatEvent

class EventHandler:

Expand Down Expand Up @@ -29,3 +29,9 @@ def run_team_event(self, app_message) -> None:
if hasattr(self, "team_changed"):
coro, loop = getattr(self, "team_changed")
self._schedule_event(loop, coro, TeamEvent(app_message))

def run_chat_event(self, app_message) -> None:

if hasattr(self, "chat_message"):
coro, loop = getattr(self, "chat_message")
self._schedule_event(loop, coro, ChatEvent(app_message))
2 changes: 1 addition & 1 deletion rustplus/api/remote/rustws.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def received_message(self, message):
self.remote.event_handler.run_team_event(app_message)

elif self.is_message(app_message):
return
self.remote.event_handler.run_chat_event(app_message)

else:
self.responses[app_message.response.seq] = app_message
Expand Down
2 changes: 1 addition & 1 deletion rustplus/api/structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .rust_entity_info import RustEntityInfo
from .rust_contents import RustContents
from .rust_item import RustItem
from .event import EntityEvent, TeamEvent
from .event import EntityEvent, TeamEvent, ChatEvent
7 changes: 7 additions & 0 deletions rustplus/api/structures/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List
from .rust_team_info import RustTeamInfo
from .rust_chat_message import RustChatMessage

class EntityEvent:

Expand Down Expand Up @@ -28,3 +29,9 @@ def __init__(self, app_message) -> None:

self.playerId : int = app_message.broadcast.teamChanged.playerId
self.teamInfo = RustTeamInfo(app_message.broadcast.teamChanged.teamInfo)

class ChatEvent:

def __init__(self, app_message) -> None:

self.message = RustChatMessage(app_message.broadcast.teamMessage.message)

0 comments on commit 6a201ac

Please sign in to comment.