Skip to content

Commit cc4e238

Browse files
committed
ok final fixes for the new bot client
1 parent bf16a05 commit cc4e238

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

nextgen_bot.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Copyright (c) 2024 iiPython
22

33
# Modules
4-
from nightwatch.bot import Client
4+
from nightwatch.bot import Client, Context
55

66
# Create client
77
class NextgenerationBot(Client):
8-
def __init__(self) -> None:
9-
super().__init__()
10-
11-
# Handle events
12-
async def on_message(self, ctx) -> None:
8+
async def on_connect(self, ctx: Context) -> None:
139
print(f"Connected to '{ctx.rics.name}'!")
1410

11+
async def on_message(self, ctx: Context) -> None:
12+
print(f"{ctx.user.name} sent '{ctx.message.message}'")
13+
1514
NextgenerationBot().run(
1615
username = "Next-gen Bot",
1716
hex = "ff0000",

nightwatch/bot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .client import Client # noqa: F401
2-
from .types import Message # noqa: F401
1+
from .client import Client, Context # noqa: F401
2+
from .types import User, Message, RicsInfo # noqa: F401

nightwatch/bot/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ def __init__(self) -> None:
5959
self.__session = requests.Session()
6060

6161
# Events (for overwriting)
62-
async def on_connect(self, _) -> None:
62+
async def on_connect(self, ctx: Context) -> None:
6363
pass
6464

65-
async def on_message(self, _) -> None:
65+
async def on_message(self, ctx: Context) -> None:
6666
pass
6767

68-
async def on_join(self, _) -> None:
68+
async def on_join(self, ctx: Context) -> None:
6969
pass
7070

71-
async def on_leave(self, _) -> None:
71+
async def on_leave(self, ctx: Context) -> None:
7272
pass
7373

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

116116
# Propagate
117-
await self.on_message(Context(self.__state, message))
117+
await self.on_message(Context(self.__state, message = message, user = message.user))
118118
self.__state.chat_logs.append(message)
119119

120120
case {"type": "join", "data": payload}:

0 commit comments

Comments
 (0)