chatbot1-6 Exercise 2: Erasure Across Channels ================================================= ex2.py (save in the project root): import asyncio, json from bot.core import Bot from bot.moderation import KeywordModerator, SafetyPolicy from bot.providers import FakeProvider async def main(): bot = Bot(FakeProvider(), moderator=KeywordModerator({"harassment": ("you idiot",)}), safety=SafetyPolicy(disclosure=None)) await bot.handle("web:1", "hello from the website", user_id="ada") await bot.handle("telegram:9", "hello from telegram", user_id="ada") await bot.handle("web:1", "/remember my cat is called Biscuit", user_id="ada") await bot.handle("web:1", "you idiot", user_id="ada") # a strike await bot.handle("web:5", "somebody else's chat", user_id="bob") def snapshot(label): print(f"{label:<8} web:1={len(bot.store.messages('web:1'))} telegram:9={len(bot.store.messages('telegram:9'))} " f"ada's facts={len(bot.store.facts('ada'))} ada's strikes={bot.store.strikes_since('ada', 0)} bob's messages={len(bot.store.messages('web:5'))}") snapshot("before") print("reply :", await bot.handle("telegram:9", "/deleteme", user_id="ada")) snapshot("after") export = json.loads(await bot.handle("web:1", "/export", user_id="ada")) print("/export now shows:", {k: v for k, v in export.items() if k in ("messages", "facts")}) asyncio.run(main()) Run with: py ex2.py Output: before web:1=2 telegram:9=2 ada's facts=1 ada's strikes=1 bob's messages=2 reply : Done. I erased 4 message(s) and 1 note(s) from 2 chat(s) (a short record of rule-breaking warnings, if any, stays until it expires). after web:1=0 telegram:9=0 ada's facts=0 ada's strikes=1 bob's messages=2 /export now shows: {'messages': [], 'facts': []} Why the strike is still there: a record of recent abuse is what makes muting work. If /deleteme removed strikes, a user who had just been muted could clear it by deleting themselves. The privacy notice says warnings are kept until they expire, and the retention purge deletes them with everything else after the retention period. Why the other user's chat is untouched: the store records which user owns which session (the session_users table) and /deleteme deletes only the sessions linked to the user who asked. WHY THIS WORKS AS AN ANSWER --------------------------- Before the command the user had messages in two channels, a note and a strike. The command removed all four messages and the note in one go, from both channels, because the store knew both sessions belonged to the same user id. After it, /export shows empty messages and facts. Bob's two messages remain. The honesty point is the last one: erasing from the database does not erase backups, which is a deployment concern (chapter 12), so a real service needs a policy for them too.