diff --git a/README.md b/README.md index 82195cf..04d8784 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,11 @@ match the key words and the tags in any way you like! ## Commands -E621Bot comes with a number of commands. These commands must be used in a direct chat with the bot. As this bot is mostly an inline bot, you mostly interact with it by typing `@e621bot your query here` while in another chat to interact with it. To use commands open a direct message chat with the bot, and from there you can use slash commands (`/command`). e621Bot currently has 6 commands. +E621Bot comes with a number of commands. These commands must be used in a direct +chat with the bot. As this bot is mostly an inline bot, you mostly interact with +it by typing `@e621bot your query here` while in another chat to interact with +it. To use commands open a direct message chat with the bot, and from there you +can use slash commands (`/command`). e621Bot currently has 6 commands. - `/start` Starts the bot - `/help` Show a help message @@ -56,11 +60,19 @@ E621Bot comes with a number of commands. These commands must be used in a direc ## Blacklist -e621 has a **LOT** of tags, you may not be comfortable with all of them. That's where your blacklist comes in! You can use the blacklist to filter posts out with tags that you don't want to see. e621 itself [has default blacklist settings](https://e621.net/help/blacklist) in place for all guest users, this is the same default blacklist the bot will start you out with when you first use the bot. +e621 has a **LOT** of tags, you may not be comfortable with all of them. That's +where your blacklist comes in! You can use the blacklist to filter posts out +with tags that you don't want to see. e621 itself +[has default blacklist settings](https://e621.net/help/blacklist) in place for +all guest users, this is the same default blacklist the bot will start you out +with when you first use the bot. ## Editing your blacklist -You can edit this default list by using `/edit_blacklist`, you will be sent your current blacklist which you can copy and paste into the chat. From there you can edit it, and send it back to the bot. The bot will save your blacklist, and display the updated blacklist so you can verify the changes. +You can edit this default list by using `/edit_blacklist`, you will be sent your +current blacklist which you can copy and paste into the chat. From there you can +edit it, and send it back to the bot. The bot will save your blacklist, and +display the updated blacklist so you can verify the changes. ## How do I setup the bot? @@ -69,10 +81,13 @@ If you want to run you own version of the bot you can download the source code. ### Make sure you have all dependencies #### Dependencies: + - Deno 2.X - Sqlite3 -Once you download the source code and you have [Deno](https://deno.com/) installed you should get sqlite3 +Once you download the source code and you have [Deno](https://deno.com/) +installed you should get sqlite3 + - Ubuntu: `sudo apt install sqlite3` - Arch: `` diff --git a/classes/E621Bot.ts b/classes/E621Bot.ts index 32d232d..e5e49be 100644 --- a/classes/E621Bot.ts +++ b/classes/E621Bot.ts @@ -85,11 +85,6 @@ export class E621Bot extends Bot { continue; } - if (/(safe|questionable|explicit)/.test(queryTags[tag])) { - urlBuilder.rating = encodeURIComponent(`rating:${queryTags[tag]}`); - continue; - } - if (/(score|favcount|random|hot)/.test(queryTags[tag])) { urlBuilder.order = encodeURIComponent(`order:${queryTags[tag]}`); continue; @@ -245,7 +240,7 @@ export class E621Bot extends Bot { }); const tags = tagMatrix.flat(); - console.log(this.buildBlacklistRegex(blacklistedTags)); + // console.log(this.buildBlacklistRegex(blacklistedTags)); // Check for blacklisted tags for (const tag in tags) { diff --git a/classes/E621UrlBuilderPosts.ts b/classes/E621UrlBuilderPosts.ts index 6d591b5..408d24d 100644 --- a/classes/E621UrlBuilderPosts.ts +++ b/classes/E621UrlBuilderPosts.ts @@ -71,8 +71,8 @@ export class E621UrlBuilderPosts implements E621UrlBuilder { * Returns a URL built fromt he current state of the builder itself and a base URL * @returns string URL built from the current state of the builder */ - buildUrl() { - return `${this.baseUrl}${this.endpoint}${this.tagString()}&page=${this.page}&limit=${this.limit}`; + buildUrl(rating: string) { + return `${this.baseUrl}${this.endpoint}${this.tagString()}+${rating}&page=${this.page}&limit=${this.limit}`; } /** diff --git a/db/migration.ts b/db/migration.ts index d2ef88b..95a547a 100644 --- a/db/migration.ts +++ b/db/migration.ts @@ -1,14 +1,14 @@ import { PathLike } from "node:fs"; import { DatabaseSync } from "node:sqlite"; -export function createBlacklistDb(dbFile: PathLike) { +export function createUserDb(dbFile: PathLike) { try { const db = new DatabaseSync(dbFile); - db.prepare(` CREATE TABLE IF NOT EXISTS user_db ( id INTEGER PRIMARY KEY AUTOINCREMENT, telegram_id BIGINT NOT NULL UNIQUE, + rating TEXT DEFAULT 's', -- Default rating for the bot for now will be s (safe) blacklist TEXT DEFAULT 'gore,scat,watersports,young,loli,shota' -- Default blacklist for every user on e621 ); `).run(); diff --git a/db/utils/createDb.ts b/db/utils/createDb.ts index 0b7ad71..b683a95 100644 --- a/db/utils/createDb.ts +++ b/db/utils/createDb.ts @@ -1,9 +1,9 @@ import { PathLike } from "node:fs"; -import { createBlacklistDb } from "../migration.ts"; +import { createUserDb } from "../migration.ts"; export function createDatabase(dbFile: PathLike): boolean { try { - createBlacklistDb(dbFile); + createUserDb(dbFile); return true; } catch (err) { console.error(`Failed to create Database: ${dbFile}: ${err}`); diff --git a/deno.json b/deno.json index c4db627..ea33ad2 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,5 @@ { - "version": "0.1.0", + "version": "0.2.0", "tasks": { "dev": "deno run --allow-write --allow-net --allow-env --allow-read --watch main.ts", "test": "deno test --allow-write --allow-net --allow-env --allow-read ./tests/*", diff --git a/handlers/edit_blacklist.ts b/handlers/edit_blacklist.ts index 668d3f3..a07adaf 100644 --- a/handlers/edit_blacklist.ts +++ b/handlers/edit_blacklist.ts @@ -1,7 +1,7 @@ import { Conversation } from "@grammyjs/conversations"; import { Context } from "grammy"; import { User } from "../types/Blacklist.ts"; -import { getUserByTelegramId, updateUser } from "../models/user.ts"; +import { getUserByTelegramId, updateBlacklist } from "../models/user.ts"; import { DB_FILE } from "../constants/strings.ts"; /** @@ -30,11 +30,12 @@ export async function edit_blacklist(conversation: Conversation, ctx: Context) { const newUserData: User = { telegramId: ctx.from?.id!, + rating: "", blacklist: blacklist, }; try { - updateUser(newUserData, DB_FILE); + updateBlacklist(newUserData, DB_FILE); } catch (err) { console.error( `Failed to save blacklist for ${ctx.from?.first_name} id ${ctx.from?.id}: ${err}`, diff --git a/interfaces.ts b/interfaces.ts index 74c407f..a7a28c6 100644 --- a/interfaces.ts +++ b/interfaces.ts @@ -3,7 +3,7 @@ export interface E621UrlBuilder { limit?: number; page?: number; endpoint: string; - buildUrl(): string; + buildUrl(rating?: string): string; } export interface Pool { diff --git a/main.ts b/main.ts index 147ea6a..5230ae1 100644 --- a/main.ts +++ b/main.ts @@ -11,8 +11,10 @@ import { createDatabase } from "./db/utils/createDb.ts"; import { getUserByTelegramId as getUserByTelegramId, insertUser as insertUser, + updateRating, userExists as userExists, } from "./models/user.ts"; +import { DB_FILE } from "./constants/strings.ts"; if (import.meta.main) { try { @@ -73,6 +75,41 @@ if (import.meta.main) { await ctx.conversation.enter("edit_blacklist"); }); + yiffBot.command("rating", async (ctx) => { + switch (ctx.match) { + case "s": + case "q": + case "e": + case "safe": + case "questionable": + case "explicit": { + try { + updateRating( + ctx.from?.id!, + encodeURIComponent(`rating:${ctx.match}`), + DB_FILE, + ); + await ctx.reply(`Updated your rating to ${ctx.match}.`, { + parse_mode: "HTML", + }); + } catch (err) { + console.error( + `Failed to update rating setting for user ${ctx.from?.id}: ${err}`, + ); + } + + break; + } + default: { + await ctx.reply( + `Invalid rating: ${ctx.match}! The rating must be s (safe), q (questionable), or e (explicit).`, + { parse_mode: "HTML" }, + ); + break; + } + } + }); + yiffBot.command("help", async (ctx) => { await ctx.reply(strings.helpString, { parse_mode: "HTML" }); }); @@ -188,7 +225,10 @@ if (import.meta.main) { yiffBot.on("inline_query", async (ctx) => { // Create new user if not exists if (!userExists(ctx.from.id, strings.DB_FILE)) { - insertUser({ telegramId: ctx.from.id, blacklist: [] }, strings.DB_FILE); + insertUser( + { telegramId: ctx.from.id, blacklist: [], rating: "" }, + strings.DB_FILE, + ); } const user = getUserByTelegramId(ctx.from.id, strings.DB_FILE); @@ -219,10 +259,12 @@ if (import.meta.main) { urlBuilder.page = page; - console.log(`Current URL: ${urlBuilder.buildUrl()}`); + console.log(`Current URL: ${urlBuilder.buildUrl(user?.rating!)}`); // Grab our data - const request = await yiffBot.sendRequest(urlBuilder.buildUrl()); + const request = await yiffBot.sendRequest( + urlBuilder.buildUrl(user?.rating!), + ); const requestJson = await request.json(); const postsJson = requestJson.posts; // An array of 50 posts diff --git a/models/user.ts b/models/user.ts index 8b728a6..b25cfa2 100644 --- a/models/user.ts +++ b/models/user.ts @@ -31,7 +31,7 @@ export function insertUser(user: User, dbFile: PathLike) { * @param dbFile * @returns StatementResultingChanges */ -export function updateUser(user: User, dbFile: PathLike) { +export function updateBlacklist(user: User, dbFile: PathLike) { try { const db = new DatabaseSync(dbFile); const queryResult = db.prepare( @@ -47,6 +47,31 @@ export function updateUser(user: User, dbFile: PathLike) { } } +/** + * @param rating Rating the user picked + * @param id Telegram Id of user + * @param dbFile Path to DB file + * @returns StatementResultingChanges + */ +export function updateRating(id: number, rating: string, dbFile: PathLike) { + try { + const db = new DatabaseSync(dbFile); + const queryResult = db.prepare( + `UPDATE OR FAIL user_db SET rating = ? WHERE telegram_id = ?;`, + ).run( + rating, + id, + ); + db.close(); + return queryResult; + } catch (err) { + console.error( + `Failed to update rating for user ${id}: ${err}`, + ); + throw err; + } +} + /** * Delete a user from the db * @param telegramId Id attatched to blacklist @@ -90,6 +115,7 @@ export function getUserByTelegramId( return { id: Number(queryResult.id), telegramId: Number(queryResult.telegram_id), + rating: String(queryResult.rating), blacklist: String(queryResult.blacklist).split(",") || defaultBlacklist.split(","), }; diff --git a/tests/migration_tests.ts b/tests/migration_tests.ts index dab9f54..ddc640d 100644 --- a/tests/migration_tests.ts +++ b/tests/migration_tests.ts @@ -1,6 +1,6 @@ import { assertEquals } from "@std/assert/equals"; import { DatabaseSync } from "node:sqlite"; -import { createBlacklistDb } from "../db/migration.ts"; +import { createUserDb } from "../db/migration.ts"; import { assertNotEquals } from "@std/assert/not-equals"; import { TEST_DB_FILE } from "../constants/strings.ts"; import { existsSync } from "node:fs"; @@ -10,7 +10,7 @@ if (!existsSync("db/test_db")) { } Deno.test(function testCreateBlacklistDb() { - createBlacklistDb(TEST_DB_FILE); + createUserDb(TEST_DB_FILE); // Get table const db = new DatabaseSync(TEST_DB_FILE); diff --git a/tests/parse_inline_query_tests.ts b/tests/parse_inline_query_tests.ts index b8557f4..f438a21 100644 --- a/tests/parse_inline_query_tests.ts +++ b/tests/parse_inline_query_tests.ts @@ -10,8 +10,8 @@ import * as numbers from "../constants/numbers.ts"; */ Deno.test(function parseInlineQueryTest() { const testBot = new E621Bot( - Deno.env.get("TELEGRAM_BOT_KEY") || "", - Deno.env.get("E621_API_KEY") || "", + "TELEGRAM_BOT_KEY", + "E621_API_KEY", ); // Create our test queries @@ -21,9 +21,9 @@ Deno.test(function parseInlineQueryTest() { const dateQuery = "dragons 2024-10-10"; // Rating query - const safeQuery = "dragons safe"; - const questionableQuery = "dragons questionable"; - const explicitQuery = "dragons explicit"; // e621 is Explicit by default + const safeQuery = "dragons"; + const questionableQuery = "dragons"; + const explicitQuery = "dragons"; // e621 is Explicit by default // Order query const scoreQuery = "dragons score"; @@ -41,7 +41,7 @@ Deno.test(function parseInlineQueryTest() { // Mixed search queries const mixedSearchQuery1 = "dragons today mp4"; const mixedSearchQuery2 = "dragons random gif"; - const mixedSearchQuery3 = "dragons questionable favcount"; + const mixedSearchQuery3 = "dragons favcount"; // Create test URL builders with processPosts() // Date Urlbuilders @@ -131,11 +131,11 @@ Deno.test(function parseInlineQueryTest() { // Date urls const todayUrl = - `${postsUrl}dragons+${urls.date.today}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.date.today}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const yesterdayUrl = - `${postsUrl}dragons+${urls.date.yesterday}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.date.yesterday}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const dateUrl = - `${postsUrl}dragons+${urls.date.byDate}2024-10-10&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.date.byDate}2024-10-10+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; // Rating urls const safeUrl = @@ -147,61 +147,73 @@ Deno.test(function parseInlineQueryTest() { // Order urls const scoreUrl = - `${postsUrl}dragons+${urls.order.score}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.order.score}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const favcountUrl = - `${postsUrl}dragons+${urls.order.favcount}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.order.favcount}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const randomUrl = - `${postsUrl}dragons+${urls.order.random}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.order.random}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const hotUrl = - `${postsUrl}dragons+${urls.order.hot}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.order.hot}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; // File urls const jpgUrl = - `${postsUrl}dragons+${urls.fileType.jpg}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.jpg}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const pngUrl = - `${postsUrl}dragons+${urls.fileType.png}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.png}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const gifUrl = - `${postsUrl}dragons+${urls.fileType.gif}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.gif}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const mp4Url = - `${postsUrl}dragons+${urls.fileType.mp4}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.mp4}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const webmUrl = - `${postsUrl}dragons+${urls.fileType.webm}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.webm}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; // Mixed search urls const mixedSearchUrl1 = - `${postsUrl}dragons+${urls.date.today}+${urls.fileType.mp4}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.date.today}+${urls.fileType.mp4}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const mixedSearchUrl2 = - `${postsUrl}dragons+${urls.fileType.gif}+${urls.order.random}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.fileType.gif}+${urls.order.random}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; const mixedSearchUrl3 = - `${postsUrl}dragons+${urls.rating.questionable}+${urls.order.favcount}&page=1&limit=${numbers.API_PAGE_SIZE}`; + `${postsUrl}dragons+${urls.order.favcount}+${urls.rating.safe}&page=1&limit=${numbers.API_PAGE_SIZE}`; // Date asserts - assertEquals(todayUrlBuilder.buildUrl(), todayUrl); - assertEquals(yesterdayUrlBuilder.buildUrl(), yesterdayUrl); - assertEquals(dateUrlBuilder.buildUrl(), dateUrl); + assertEquals(todayUrlBuilder.buildUrl(urls.rating.safe), todayUrl); + assertEquals(yesterdayUrlBuilder.buildUrl(urls.rating.safe), yesterdayUrl); + assertEquals(dateUrlBuilder.buildUrl(urls.rating.safe), dateUrl); // Rating asserts - assertEquals(safeUrlBuilder.buildUrl(), safeUrl); - assertEquals(questionableUrlBuilder.buildUrl(), questionableUrl); - assertEquals(explicitUrlBuilder.buildUrl(), explicitUrl); + assertEquals(safeUrlBuilder.buildUrl(urls.rating.safe), safeUrl); + assertEquals( + questionableUrlBuilder.buildUrl(urls.rating.questionable), + questionableUrl, + ); + assertEquals(explicitUrlBuilder.buildUrl(urls.rating.explicit), explicitUrl); // Order asserts - assertEquals(scoreUrlBuilder.buildUrl(), scoreUrl); - assertEquals(favcountUrlBuilder.buildUrl(), favcountUrl); - assertEquals(randomUrlBuilder.buildUrl(), randomUrl); - assertEquals(hotUrlBuilder.buildUrl(), hotUrl); + assertEquals(scoreUrlBuilder.buildUrl(urls.rating.safe), scoreUrl); + assertEquals(favcountUrlBuilder.buildUrl(urls.rating.safe), favcountUrl); + assertEquals(randomUrlBuilder.buildUrl(urls.rating.safe), randomUrl); + assertEquals(hotUrlBuilder.buildUrl(urls.rating.safe), hotUrl); // Filetype asserts - assertEquals(jpgUrlBuilder.buildUrl(), jpgUrl); - assertEquals(pngUrlBuilder.buildUrl(), pngUrl); - assertEquals(gifUrlBuilder.buildUrl(), gifUrl); - assertEquals(mp4UrlBuilder.buildUrl(), mp4Url); - assertEquals(webmUrlBuilder.buildUrl(), webmUrl); + assertEquals(jpgUrlBuilder.buildUrl(urls.rating.safe), jpgUrl); + assertEquals(pngUrlBuilder.buildUrl(urls.rating.safe), pngUrl); + assertEquals(gifUrlBuilder.buildUrl(urls.rating.safe), gifUrl); + assertEquals(mp4UrlBuilder.buildUrl(urls.rating.safe), mp4Url); + assertEquals(webmUrlBuilder.buildUrl(urls.rating.safe), webmUrl); // Mixed search asserts - assertEquals(mixedSearchUrlBuilder1.buildUrl(), mixedSearchUrl1); - assertEquals(mixedSearchUrlBuilder2.buildUrl(), mixedSearchUrl2); - assertEquals(mixedSearchUrlBuilder3.buildUrl(), mixedSearchUrl3); + assertEquals( + mixedSearchUrlBuilder1.buildUrl(urls.rating.safe), + mixedSearchUrl1, + ); + assertEquals( + mixedSearchUrlBuilder2.buildUrl(urls.rating.safe), + mixedSearchUrl2, + ); + assertEquals( + mixedSearchUrlBuilder3.buildUrl(urls.rating.safe), + mixedSearchUrl3, + ); }); /** diff --git a/tests/url_builder_tests.ts b/tests/url_builder_tests.ts index d0bb695..2c0e1fe 100644 --- a/tests/url_builder_tests.ts +++ b/tests/url_builder_tests.ts @@ -7,8 +7,7 @@ Deno.test(function buildUrlPostsTest() { `https://e621.net/posts.json?tags=dragon+rating:safe&page=1&limit=${API_PAGE_SIZE}`; const testUrlBuilder = new E621UrlBuilderPosts(); testUrlBuilder.tags = ["dragon"]; - testUrlBuilder.rating = "rating:safe"; - assertEquals(testUrlBuilder.buildUrl(), testUrl); + assertEquals(testUrlBuilder.buildUrl("rating:safe"), testUrl); }); Deno.test(function buildUrlPoolsTest() { diff --git a/tests/user_tests.ts b/tests/user_tests.ts index a72d0ca..000e445 100644 --- a/tests/user_tests.ts +++ b/tests/user_tests.ts @@ -1,20 +1,22 @@ import { existsSync } from "node:fs"; import { TEST_DB_FILE } from "../constants/strings.ts"; -import { createBlacklistDb } from "../db/migration.ts"; +import { createUserDb } from "../db/migration.ts"; import { deleteUser, getUserByTelegramId as getUserByTelegramId, insertUser, - updateUser, + updateBlacklist, + updateRating, userExists, } from "../models/user.ts"; import { User } from "../types/Blacklist.ts"; import { assertEquals } from "@std/assert/equals"; import { assertObjectMatch } from "@std/assert/object-match"; -const testBlacklist: User = { +const testUser: User = { id: 1, telegramId: 12345, + rating: "s", blacklist: [ "gore", "scat", @@ -30,35 +32,46 @@ if (!existsSync("db/test_db")) { } Deno.test(function testInsertBlacklist() { - createBlacklistDb(TEST_DB_FILE); + createUserDb(TEST_DB_FILE); - const queryResult = insertUser(testBlacklist, TEST_DB_FILE); + const queryResult = insertUser(testUser, TEST_DB_FILE); assertEquals(queryResult?.changes, 1); assertEquals(queryResult?.lastInsertRowid, 1); Deno.removeSync(TEST_DB_FILE); }); Deno.test(function testGetUserByTelegramId() { - createBlacklistDb(TEST_DB_FILE); - insertUser(testBlacklist, TEST_DB_FILE); + createUserDb(TEST_DB_FILE); + insertUser(testUser, TEST_DB_FILE); const user = getUserByTelegramId(12345, TEST_DB_FILE); - console.log(user); + assertObjectMatch(user!, testUser); + Deno.removeSync(TEST_DB_FILE); +}); + +Deno.test(function testUpdateRating() { + createUserDb(TEST_DB_FILE); + insertUser(testUser, TEST_DB_FILE); + + const updatedUser = testUser; + updatedUser.rating = "e"; - assertObjectMatch(user!, testBlacklist); + const queryResults = updateRating(12345, "e", TEST_DB_FILE); + assertEquals(queryResults.changes, 1); + assertEquals(queryResults.lastInsertRowid, 0); Deno.removeSync(TEST_DB_FILE); }); Deno.test(function testUpdateUser() { - createBlacklistDb(TEST_DB_FILE); - insertUser(testBlacklist, TEST_DB_FILE); + createUserDb(TEST_DB_FILE); + insertUser(testUser, TEST_DB_FILE); - const updatedBlacklist = testBlacklist; + const updatedBlacklist = testUser; updatedBlacklist.blacklist.push("test", "tags"); - const queryResult = updateUser(updatedBlacklist, TEST_DB_FILE); + const queryResult = updateBlacklist(updatedBlacklist, TEST_DB_FILE); assertEquals(queryResult?.changes, 1); assertEquals(queryResult?.lastInsertRowid, 0); @@ -66,18 +79,18 @@ Deno.test(function testUpdateUser() { }); Deno.test(function testDeleteUser() { - createBlacklistDb(TEST_DB_FILE); - insertUser(testBlacklist, TEST_DB_FILE); + createUserDb(TEST_DB_FILE); + insertUser(testUser, TEST_DB_FILE); - const queryResult = deleteUser(testBlacklist.telegramId, TEST_DB_FILE); + const queryResult = deleteUser(testUser.telegramId, TEST_DB_FILE); assertEquals(queryResult?.changes, 1); assertEquals(queryResult?.lastInsertRowid, 0); Deno.removeSync(TEST_DB_FILE); }); Deno.test(function testUserExist() { - createBlacklistDb(TEST_DB_FILE); - insertUser(testBlacklist, TEST_DB_FILE); + createUserDb(TEST_DB_FILE); + insertUser(testUser, TEST_DB_FILE); const result1 = userExists(12345, TEST_DB_FILE); assertEquals(result1, true); diff --git a/types/Blacklist.ts b/types/Blacklist.ts index e529c33..a6a8c4a 100644 --- a/types/Blacklist.ts +++ b/types/Blacklist.ts @@ -1,5 +1,6 @@ export type User = { id?: number; telegramId: number; + rating: string; blacklist: string[]; };