Update.
This commit is contained in:
parent
5d6a86f8b2
commit
4da3a5ce30
2
Makefile
2
Makefile
@ -5,7 +5,7 @@ APP=./example.py
|
||||
all: install run
|
||||
|
||||
install:
|
||||
python3 -m venv .venv
|
||||
python3.12 -m venv .venv
|
||||
$(PIP) install -e .
|
||||
|
||||
run:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Metadata-Version: 2.2
|
||||
Metadata-Version: 2.4
|
||||
Name: snekbot
|
||||
Version: 1.0.0
|
||||
Summary: Bot API for Snek chat
|
||||
@ -8,6 +8,7 @@ Requires-Python: >=3
|
||||
Description-Content-Type: text/markdown
|
||||
License-File: LICENSE.txt
|
||||
Requires-Dist: aiohttp
|
||||
Dynamic: license-file
|
||||
|
||||
# Snekbot API
|
||||
|
||||
@ -51,27 +52,25 @@ from snekbot.bot import Bot
|
||||
class ExampleBot(Bot):
|
||||
|
||||
async def on_join(self, channel_uid):
|
||||
await super().on_join(channel_uid)
|
||||
print(f"I joined!")
|
||||
await self.send_message(
|
||||
channel_uid,
|
||||
f"Hello, i'm actively part of the conversation in channel {channel_uid} now, you don't have to mention me anymore. "
|
||||
channel_uid,
|
||||
f"Hello, i'm actively part of the conversation in channel {channel_uid} now, you don't have to mention me anymore. ",
|
||||
)
|
||||
|
||||
async def on_leave(self, channel_uid):
|
||||
await super().on_leave(channel_uid)
|
||||
print(f"I left!!")
|
||||
await self.send_message(
|
||||
channel_uid,
|
||||
"I stop actively being part of the conversation now. Bye!"
|
||||
channel_uid, "I stop actively being part of the conversation now. Bye!"
|
||||
)
|
||||
|
||||
async def on_ping(self,username, user_nick, channel_uid, message):
|
||||
async def on_ping(self, username, user_nick, channel_uid, message):
|
||||
print(f"Ping from {user_nick} in channel {channel_uid}: {message}")
|
||||
await self.send_message(
|
||||
channel_uid,
|
||||
"pong " + message
|
||||
)
|
||||
await self.send_message(channel_uid, "pong " + message)
|
||||
|
||||
async def on_own_message(self, data):
|
||||
async def on_own_message(self, channel_uid, data):
|
||||
print(f"Received my own message: {data.message}")
|
||||
|
||||
async def on_mention(self, username, user_nick, channel_uid, message):
|
||||
@ -91,7 +90,9 @@ class ExampleBot(Bot):
|
||||
)
|
||||
await self.send_message(channel_uid, result)
|
||||
else:
|
||||
await self.send_message(channel_uid, f'Hey {user_nick}, Thanks for mentioning me "{message}".')
|
||||
await self.send_message(
|
||||
channel_uid, f'Hey {user_nick}, Thanks for mentioning me "{message}".'
|
||||
)
|
||||
|
||||
async def on_message(self, sender_username, sender_nick, channel_uid, message):
|
||||
print(f"Message from {sender_nick}: {message}")
|
||||
@ -109,7 +110,9 @@ class ExampleBot(Bot):
|
||||
await self.send_message(channel_uid, result)
|
||||
|
||||
|
||||
bot = ExampleBot(url="ws://snek.molodetz.nl/rpc.ws", username="example", password="example")
|
||||
bot = ExampleBot(
|
||||
url="ws://snek.molodetz.nl/rpc.ws", username="example", password="example"
|
||||
)
|
||||
asyncio.run(bot.run())
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user