commit 3b5652ebb90c262a3ee3c9cd40922f66c1cdf002 Author: Dani Date: Thu Dec 21 14:54:10 2023 -0500 Initial Commit for Dolly: Dolly is a simple Discord Bot that *right now* only does TODO lists. She does not handle anything else. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3cea36f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Dolly", + "type": "python", + "request": "launch", + "program": "main.py", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..65af4f9 --- /dev/null +++ b/config.py @@ -0,0 +1,14 @@ +import os +from dotenv import load_dotenv +import discord + +def load_config(): + load_dotenv() + return { + "discord_token": os.getenv("DISCORD_BOT_TOKEN") + } + +def get_intents(): + intents = discord.Intents.default() + intents.message_content = True + return intents \ No newline at end of file diff --git a/database.py b/database.py new file mode 100644 index 0000000..9abda91 --- /dev/null +++ b/database.py @@ -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 \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..2c1a344 --- /dev/null +++ b/main.py @@ -0,0 +1,36 @@ +import discord +from discord.ext import commands +from config import load_config, get_intents +from database import setup_database, add_todo, list_todos, remove_todo + +config = load_config() +intents = get_intents() +bot = commands.Bot(command_prefix='!', intents=intents) + +conn = setup_database() + +@bot.event +async def on_ready(): + print(f'{bot.user.name} has connected to Discord!') + +@bot.command(name='todo', help='Adds a new to-do item') +async def todo_command(ctx, *, todo_item: str): + if add_todo(conn, todo_item): + await ctx.send(f"Added to-do: {todo_item}") + else: + await ctx.send("Error adding to-do.") + +@bot.command(name='listtodos', help='Lists all to-do items') +async def listtodos_command(ctx): + todos = list_todos(conn) + response = "To-Do List:\n" + "\n".join([f"{id}: {content}" for id, content in todos]) + await ctx.send(response) + +@bot.command(name='removetodo', help='Removes a to-do item by its ID') +async def removetodo_command(ctx, todo_id: int): + if remove_todo(conn, todo_id): + await ctx.send(f"Removed to-do with ID {todo_id}") + else: + await ctx.send("Error removing to-do.") + +bot.run(config["discord_token"]) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..36709eb Binary files /dev/null and b/requirements.txt differ diff --git a/todos.db b/todos.db new file mode 100644 index 0000000..e7bc118 Binary files /dev/null and b/todos.db differ