Telegram version of schneiderbot. I'll totally do something w/ this, this is never going to be effectively a mirror.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

  1. """DB interface"""
  2. import sqlite3
  3. class Db():
  4. """ Abstract interface for db actions """
  5. def __init__(self):
  6. self.conn = sqlite3.connect("deaths.db")
  7. table_exist = self.conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='death'")
  8. if table_exist.fetchall() == []:
  9. self.conn.execute("CREATE TABLE death(name text, chat integer )")
  10. self.conn.execute("create index chat_idx on death(chat)")
  11. def __del__(self):
  12. self.conn.commit()
  13. def is_dead(self, user, chat):
  14. """Reports whether a user is already dead"""
  15. res = self.conn.execute("select * from death where chat = ? and name = ?", [chat, user])
  16. return res.fetchall() != []
  17. def kill(self, user, chat):
  18. """Kills a user"""
  19. self.conn.execute("insert into death(name, chat) values(?, ?)", [user, chat])
  20. def revive(self, user, chat):
  21. """Revives a user"""
  22. self.conn.execute("delete from death where chat = ? and name = ?", [chat, user])
  23. def get_dead_bodies(self, chat):
  24. """List the dead"""
  25. names = []
  26. for name in self.conn.execute("select * from death where chat = ?", [chat]).fetchall():
  27. names.append(name[0])
  28. return ", ".join(names)