chore: replace hardcoded API timeout values with configurable constants in snek_core_bot.py

This commit is contained in:
2025-04-24 19:03:12 +00:00
parent c1421d0c22
commit 476041c0ab
4 changed files with 143 additions and 96 deletions
+11 -11
View File
@@ -42,23 +42,19 @@ class ExampleBot(Bot):
async def on_join(self, 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):
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):
print(f"Received my own message: {data.message}")
@@ -80,7 +76,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}")
@@ -98,7 +96,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())
```