Added branches system, updated database, v0.8.0
- Updated to v0.8.0 - Added note about rate limitting to README - Updated examples to work with new callback system - Updated README to describe new callback system correctly - Added branch_bot.py example - Updated database so internal functions are prefixed with underscore now - Replaced MatrixBot.add_room_event_callback with MatrixBot.add_callback - Database schema version is 4 now - Added room state to database to simplify user code - Added RoomStateFilter
This commit is contained in:
@@ -16,10 +16,10 @@ from _environment import check_environment
|
||||
async def bump_count(bot: MatrixBot) -> int:
|
||||
"""Bump count of reactions processed and return new value. Uses bot's
|
||||
database for storage."""
|
||||
val = await bot.load_value("reactions_processed")
|
||||
val = await bot.database.custom_get("reactions_processed")
|
||||
val = 0 if val is None else int.from_bytes(val)
|
||||
val += 1
|
||||
await bot.save_value("reactions_processed", val.to_bytes(8))
|
||||
await bot.database.custom_set("reactions_processed", val.to_bytes(8))
|
||||
return val
|
||||
|
||||
async def on_specific_reaction(ctx: EventContext, vars: ContextVars) -> None:
|
||||
@@ -61,15 +61,9 @@ async def main() -> None:
|
||||
storage_directory="session_storage"
|
||||
)
|
||||
bot = MatrixBot(config)
|
||||
bot.add_callback(
|
||||
~SenderIsBotFilter() & MessageReactionFilter(reaction=["❤️", "👍"]),
|
||||
on_specific_reaction)
|
||||
bot.add_callback(
|
||||
~SenderIsBotFilter() & MessageReactionFilter(),
|
||||
on_reaction)
|
||||
bot.add_callback(
|
||||
~SenderIsBotFilter() & NewMessageFilter(),
|
||||
on_message)
|
||||
bot.callbacks.add_callback(MessageReactionFilter(reaction=["❤️", "👍"]), on_specific_reaction)
|
||||
bot.callbacks.add_callback(MessageReactionFilter(), on_reaction)
|
||||
bot.callbacks.add_callback(NewMessageFilter(), on_message)
|
||||
|
||||
# run until Ctrl+C
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user