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:
Dani
2023-12-21 14:54:10 -05:00
commit 3b5652ebb9
7 changed files with 259 additions and 0 deletions

160
.gitignore vendored Normal file
View File

@ -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/

16
.vscode/launch.json vendored Normal file
View File

@ -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
}
]
}

14
config.py Normal file
View File

@ -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

33
database.py Normal file
View 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

36
main.py Normal file
View File

@ -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"])

BIN
requirements.txt Normal file

Binary file not shown.

BIN
todos.db Normal file

Binary file not shown.