Skip to content

Commit

Permalink
ok final fixes for the new bot client
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Nov 26, 2024
1 parent bf16a05 commit cc4e238
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions nextgen_bot.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (c) 2024 iiPython

# Modules
from nightwatch.bot import Client
from nightwatch.bot import Client, Context

# Create client
class NextgenerationBot(Client):
def __init__(self) -> None:
super().__init__()

# Handle events
async def on_message(self, ctx) -> None:
async def on_connect(self, ctx: Context) -> None:
print(f"Connected to '{ctx.rics.name}'!")

async def on_message(self, ctx: Context) -> None:
print(f"{ctx.user.name} sent '{ctx.message.message}'")

NextgenerationBot().run(
username = "Next-gen Bot",
hex = "ff0000",
Expand Down
4 changes: 2 additions & 2 deletions nightwatch/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .client import Client # noqa: F401
from .types import Message # noqa: F401
from .client import Client, Context # noqa: F401
from .types import User, Message, RicsInfo # noqa: F401
10 changes: 5 additions & 5 deletions nightwatch/bot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ def __init__(self) -> None:
self.__session = requests.Session()

# Events (for overwriting)
async def on_connect(self, _) -> None:
async def on_connect(self, ctx: Context) -> None:
pass

async def on_message(self, _) -> None:
async def on_message(self, ctx: Context) -> None:
pass

async def on_join(self, _) -> None:
async def on_join(self, ctx: Context) -> None:
pass

async def on_leave(self, _) -> None:
async def on_leave(self, ctx: Context) -> None:
pass

# Handle running
Expand Down Expand Up @@ -114,7 +114,7 @@ async def __match_event(self, event: dict[str, typing.Any]) -> None:
message = from_dict(Message, payload)

# Propagate
await self.on_message(Context(self.__state, message))
await self.on_message(Context(self.__state, message = message, user = message.user))
self.__state.chat_logs.append(message)

case {"type": "join", "data": payload}:
Expand Down

0 comments on commit cc4e238

Please sign in to comment.