Initial Commit for Dolly:
Dolly is a simple Discord Bot that *right now* only does TODO lists. She does not handle anything else.
This commit is contained in:
33
database.py
Normal file
33
database.py
Normal file
@ -0,0 +1,33 @@
|
||||
import sqlite3
|
||||
|
||||
def setup_database():
|
||||
conn = sqlite3.connect('todos.db')
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS todos (content TEXT)''')
|
||||
conn.commit()
|
||||
return conn
|
||||
|
||||
def add_todo(conn, todo_item):
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("INSERT INTO todos (content) VALUES (?)", (todo_item,))
|
||||
conn.commit()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error adding to-do: {e}")
|
||||
return False
|
||||
|
||||
def list_todos(conn):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT rowid, content FROM todos")
|
||||
return cursor.fetchall()
|
||||
|
||||
def remove_todo(conn, todo_id):
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("DELETE FROM todos WHERE rowid = ?", (todo_id,))
|
||||
conn.commit()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error removing to-do: {e}")
|
||||
return False
|
Reference in New Issue
Block a user