Skip to content

Commit

Permalink
fix: quotee via commands are case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
dlg1206 committed Apr 24, 2024
1 parent f4163e7 commit ced8f27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ A docker image is available to host the bot

### Building the Image
```bash
docker build -t quotebot:2.5.0 .
docker build -t quotebot:2.5.1 .
```

### Running the Container
#### Quick Start
( If running in the root directory )
```bash
docker run --rm -it -d -e TOKEN=<your token here> quotebot:2.5.0
docker run --rm -it -d -e TOKEN=<your token here> quotebot:2.5.1
```
To reattach, run `docker attach quotebot`

#### Explanation
```bash
# Just using token
docker run --rm -it -d -e TOKEN=<your token here> -v <absolute path to db directory>:/app/data/db --name quotebot quotebot:2.5.0
docker run --rm -it -d -e TOKEN=<your token here> -v <absolute path to db directory>:/app/data/db --name quotebot quotebot:2.5.1
# or using env file
docker run --rm -it -d --env-file <path to env file> -v <absolute path to db directory>:/app/data/db --name quotebot quotebot:2.5.0
docker run --rm -it -d --env-file <path to env file> -v <absolute path to db directory>:/app/data/db --name quotebot quotebot:2.5.1
```
- `--rm`: Remove container when finished
- `-it`: Open interactive shell to allow for `docker attach`
Expand All @@ -121,7 +121,7 @@ docker run --rm -it -d --env-file <path to env file> -v <absolute path to db dir
- `-v`: Mount db directory to container's db directory. This allows for the container to stopped and started without
loosing quote info. Also allows for SQLite db to be accessed outside the container
- `--name`: Name of the container
- `<image>`: Name of image to use, in this case `quotebot:2.5.0`
- `<image>`: Name of image to use, in this case `quotebot:2.5.1`

## Debug
QuoteBot has an additional command, `qkill`, which will kill the bot process from inside Discord. This can only be used
Expand Down
2 changes: 1 addition & 1 deletion src/quotebot/bot/QuoteBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from log.Logger import Logger, Status
from quote.Quote import format_quotee, is_quote, parse_quote

VERSION = "2.5"
VERSION = "2.5.1"
SOURCE_CODE = "github.com/dlg1206/Discord-Quote-Bot"
COMMANDS_REGEX = re.compile("!qadd|!q|!qall|!qrand|!qsearch|!qstat|!qhelp|!qkill") # list of commands

Expand Down
10 changes: 5 additions & 5 deletions src/quotebot/db/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def add_quote(self, quote: Quote, contributor: str) -> int:
with self.get_cursor(conn) as cur:
# Add new quotee if does not exist
try:
cur.execute("INSERT INTO quotee VALUES (?);", (quote.quotee,))
cur.execute("INSERT INTO quotee VALUES (?);", (quote.quotee.lower(),))
conn.commit()
except sqlite3.IntegrityError as ie:
conn.commit()
Expand All @@ -98,7 +98,7 @@ def add_quote(self, quote: Quote, contributor: str) -> int:
# Upload quote
cur.execute(
"INSERT INTO quote (pre_context, quote, post_context, quotee, contributor) VALUES (?, ?, ?, ?, ?);",
(quote.pre_context, quote.quote, quote.post_context, quote.quotee, contributor)
(quote.pre_context, quote.quote, quote.post_context, quote.quotee.lower(), contributor)
)
conn.commit()

Expand All @@ -116,7 +116,7 @@ def find_similar_quotee(self, quotee: str) -> list[str]:
with self.open_connection() as conn:
with self.get_cursor(conn) as cur:
# Find similar quotees
cur.execute("SELECT name FROM quotee WHERE name LIKE ?;", (f"%{quotee}%",))
cur.execute("SELECT name FROM quotee WHERE name LIKE ?;", (f"%{quotee.lower()}%",))
data = cur.fetchall()
conn.commit()
return [q[0] for q in data] # convert list of tuples for list of strings
Expand Down Expand Up @@ -152,7 +152,7 @@ def get_all_quotes(self, quotee: str = None) -> list[Quote]:
else:
cur.execute(
"SELECT quote, quotee, pre_context, post_context FROM quote WHERE quotee = ?;",
(quotee,)
(quotee.lower(),)
)
data = cur.fetchall()
return [Quote(q[0], q[1], q[2], q[3]) for q in data] # convert list of tuples for list of Quotes
Expand Down Expand Up @@ -185,7 +185,7 @@ def get_quote_total(self, quotee: str = None) -> int:
cur.execute("SELECT COUNT(ROWID) FROM quote;")
# Else get count for specific quotee
else:
cur.execute("SELECT COUNT(ROWID) FROM quote WHERE quotee = ?;", (quotee,))
cur.execute("SELECT COUNT(ROWID) FROM quote WHERE quotee = ?;", (quotee.lower(),))
count = cur.fetchall()[0][0]
return count

Expand Down

0 comments on commit ced8f27

Please sign in to comment.