Telegram version of schneiderbot
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.1 KiB

"""DB interface"""
import sqlite3
class Db():
""" Abstract interface for db actions """
def __init__(self):
self.conn = sqlite3.connect("deaths.db")
table_exist = self.conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='death'")
if table_exist.fetchall() == []:
self.conn.execute("CREATE TABLE death(name)")
def __del__(self):
self.conn.commit()
def is_dead(self, user):
"""Reports whether a user is already dead"""
print(str(user))
res = self.conn.execute("select * from death where name = ?", [user])
return res.fetchall() != []
def kill(self, user):
"""Kills a user"""
self.conn.execute("insert into death(name) values(?)", [user])
def revive(self, user):
"""Revives a user"""
self.conn.execute("delete from death where name = ?", [user])
def get_dead_bodies(self):
"""List the dead"""
names = []
for name in self.conn.execute("select * from death").fetchall():
names.append(name[0])
return ", ".join(names)