From 1d6fdd94ac01b31d101431a42420ad4247aec213 Mon Sep 17 00:00:00 2001 From: ZeldaFan0225 <78901316+ZeldaFan0225@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:23:58 +0200 Subject: [PATCH] replacement filter implementation and documentation --- changelog.md | 10 ++++++++++ config.md | 11 ++++------- package-lock.json | 2 +- package.json | 2 +- src/commands/advanced_generate.ts | 12 +----------- src/commands/generate.ts | 12 +----------- src/index.ts | 1 - src/types.ts | 6 ++---- template.config.json | 8 +++----- template.env | 3 +-- 10 files changed, 24 insertions(+), 43 deletions(-) diff --git a/changelog.md b/changelog.md index f1f744f..15884bf 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Changelog +## V3.0.1 + +- add loras to generate and advanced_generate +- implement replacement filter +- add userinfo for horde ids + +## V3.0.0 + +- update dependencies and require node 18 or above + ## V2.4.1 - fixes to the kudos transfer by reacting diff --git a/config.md b/config.md index d366447..1c002d6 100644 --- a/config.md +++ b/config.md @@ -11,10 +11,6 @@ Here you can see an explanation of what which option does "advanced": { "dev": Whether this instance is for development or not (BOOLEAN) *4, "encrypt_token": Encrypt the users token before saving in the database (BOOLEAN) *9 - "pre_check_prompts_for_suspicion": { - "enabled": Check if the prompt the user gave is suspicious and would get your IP banned (BOOLEAN) *10, - "timeout_duration": The duration to put the user into timeout for - } }, "filter_actions": { "mode": The mode on how the guilds list should act ('whitelist' or 'blacklist'), @@ -68,6 +64,7 @@ Here you can see an explanation of what which option does "require_login": Set to true if you want the user to log in with their ai horde token (BOOLEAN), "trusted_workers": Whether to only use trusted workers (BOOLEAN) *1, "censor_nsfw": Whether to censor NSFW images if they were generated by accident (BOOLEAN) *1, + "replacement_filter": If enabled, suspicious prompts are sanitized through a string replacement filter instead. *1, "blacklisted_models": A list of blacklisted models which users are not allowed to use (ARRAY OF STRING), "blacklisted_words": A list of blacklisted words which users are not allowed to use (ARRAY OF STRING), "update_generation_status_interval_seconds": The interval at which the embed in Discord gets updated (INTEGER), @@ -150,12 +147,13 @@ Here you can see an explanation of what which option does "require_login": Set to true if you want the user to log in with their ai horde token (BOOLEAN), "trusted_workers": Whether to only use trusted workers (BOOLEAN) *1, "censor_nsfw": Whether to censor NSFW images if they were generated by accident (BOOLEAN) *1, + "replacement_filter": If enabled, suspicious prompts are sanitized through a string replacement filter instead. *1, "blacklisted_styles": A list of blacklisted styles which users are not allowed to use (ARRAY OF STRING), "blacklisted_words": A list of blacklisted words which users are not allowed to use (ARRAY OF STRING), "update_generation_status_interval_seconds": The interval at which the embed in Discord gets updated (INTEGER), "convert_a1111_weight_to_horde_weight": Whether to convert a1111 to weighted prompt required by the api (BOOLEAN) *7 *8, "improve_loading_time": Try to improve the displaying time between generation finished and generation displayed in discord (BOOLEAN) *7 - "styles_source": The default source where to fetch the styles from (STRING) *11, + "styles_source": The default source where to fetch the styles from (STRING) *10, "default": { "tiling": Whether the result should be tileable if nothing is specified (BOOLEAN) *1, "share:" The default for sharing the result (BOOLEAN) *1, @@ -225,5 +223,4 @@ Here you can see an explanation of what which option does `*7` EXPERIMENTAL OPTION, ENABLE AT YOUR OWN RISK `*8` For example (((test))) will be automatically converted to (test:1.3) `*9` Uses an encryption key only known to you to encrypt the users tokens. This is recommended to increase security. Enabling this option may have an impact on speed. -`*10` This Option requires a `OPERATOR_API_KEY` to be set in the `.env` -`*11` Must follow the scheme of https://github.com/db0/Stable-Horde-Styles/blob/main/styles.json \ No newline at end of file +`*10` Must follow the scheme of https://github.com/db0/Stable-Horde-Styles/blob/main/styles.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8e06b30..6052b8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zeldafan_discord_bot", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index ce19880..9f1b557 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zeldafan_discord_bot", - "version": "3.0.0", + "version": "3.0.1", "description": "", "main": "dist/index.js", "scripts": { diff --git a/src/commands/advanced_generate.ts b/src/commands/advanced_generate.ts index 1144d77..8530192 100644 --- a/src/commands/advanced_generate.ts +++ b/src/commands/advanced_generate.ts @@ -333,17 +333,6 @@ export default class extends Command { } } - if(ctx.client.config.advanced?.pre_check_prompts_for_suspicion?.enabled) { - if(ctx.client.timeout_users.has(ctx.interaction.user.id)) return ctx.error({error: "Your previous prompt has been marked as suspicious.\nYou have been timed out, try again later."}) - const filter_result = await ctx.ai_horde_manager.postFilters({ - prompt - }, {token: process.env["OPERATOR_API_KEY"]}).catch(console.error) - if(filter_result && Number(filter_result.suspicion) >= 2) { - ctx.client.timeout_users.set(ctx.interaction.user.id, ctx.interaction.user.id, (ctx.client.config.advanced.pre_check_prompts_for_suspicion.timeout_duration ?? 1000 * 60 * 60)) - } - if(ctx.client.timeout_users.has(ctx.interaction.user.id)) return ctx.error({error: "Your prompt has been marked as suspicious.\nTherefore you have been timed out!"}) - } - const post_processing = [] as (typeof ModelGenerationInputPostProcessingTypes[keyof typeof ModelGenerationInputPostProcessingTypes])[] if(gfpgan) post_processing.push(ModelGenerationInputPostProcessingTypes.GFPGAN) @@ -366,6 +355,7 @@ export default class extends Command { karras, loras: lora_id ? [{name: lora_id}] : undefined }, + replacement_filter: ctx.client.config.advanced_generate.replacement_filter, nsfw: ctx.client.config.advanced_generate?.user_restrictions?.allow_nsfw, censor_nsfw: ctx.client.config.advanced_generate?.censor_nsfw, trusted_workers: ctx.client.config.advanced_generate?.trusted_workers, diff --git a/src/commands/generate.ts b/src/commands/generate.ts index d6a7e9c..e0e5b35 100644 --- a/src/commands/generate.ts +++ b/src/commands/generate.ts @@ -200,17 +200,6 @@ export default class extends Command { } } - if(ctx.client.config.advanced?.pre_check_prompts_for_suspicion?.enabled) { - if(ctx.client.timeout_users.has(ctx.interaction.user.id)) return ctx.error({error: "Your previous prompt has been marked as suspicious.\nYou have been timed out, try again later."}) - const filter_result = await ctx.ai_horde_manager.postFilters({ - prompt - }, {token: process.env["OPERATOR_API_KEY"]}).catch(console.error) - if(filter_result && Number(filter_result.suspicion) >= 2) { - ctx.client.timeout_users.set(ctx.interaction.user.id, ctx.interaction.user.id, (ctx.client.config.advanced.pre_check_prompts_for_suspicion.timeout_duration ?? 1000 * 60 * 60)) - } - if(ctx.client.timeout_users.has(ctx.interaction.user.id)) return ctx.error({error: "Your prompt has been marked as suspicious.\nTherefore you have been timed out!"}) - } - const generation_data: ImageGenerationInput = { prompt, @@ -225,6 +214,7 @@ export default class extends Command { loras: style.loras, steps: style.steps }, + replacement_filter: ctx.client.config.generate.replacement_filter, nsfw: ctx.client.config.generate?.user_restrictions?.allow_nsfw, censor_nsfw: ctx.client.config.generate?.censor_nsfw, trusted_workers: ctx.client.config.generate?.trusted_workers, diff --git a/src/index.ts b/src/index.ts index 0a24b84..3bb41a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,7 +83,6 @@ client.on("ready", async () => { await client.application?.commands.set([...client.commands.createPostBody(), ...client.contexts.createPostBody()]).catch(console.error) if((client.config.advanced_generate?.user_restrictions?.amount?.max ?? 4) > 10) throw new Error("More than 10 images are not supported in the bot") if(client.config.filter_actions?.guilds?.length && (client.config.filter_actions?.mode !== "whitelist" && client.config.filter_actions?.mode !== "blacklist")) throw new Error("The actions filter mode must be set to either whitelist, blacklist.") - if(client.config.advanced?.pre_check_prompts_for_suspicion?.enabled && !process.env["OPERATOR_API_KEY"]) throw new Error("The OPERATOR_API_KEY in the .env is required when pre checking prompts for being suspicious") if(client.config.party?.enabled && !client.config.generate?.enabled) throw new Error("When party is enabled the /generate command also needs to be enabled") if(client.config.party?.enabled && connection) { diff --git a/src/types.ts b/src/types.ts index a904e60..f985156 100644 --- a/src/types.ts +++ b/src/types.ts @@ -181,10 +181,6 @@ export interface Config { advanced?: { dev?: boolean, encrypt_token?: boolean - pre_check_prompts_for_suspicion?: { - enabled: boolean, - timeout_duration?: number - } }, filter_actions?: { mode?: "whitelist" | "blacklist", @@ -235,6 +231,7 @@ export interface Config { require_login?: boolean, trusted_workers?: boolean, censor_nsfw?: boolean, + replacement_filter?: boolean, workers?: string[], blacklisted_words?: string[], blacklisted_models?: string[], @@ -323,6 +320,7 @@ export interface Config { require_login?: boolean, trusted_workers?: boolean, censor_nsfw?: boolean, + replacement_filter?: boolean, blacklisted_words?: string[], blacklisted_styles?: string[], update_generation_status_interval_seconds?: number, diff --git a/template.config.json b/template.config.json index ab577d7..c1b8384 100644 --- a/template.config.json +++ b/template.config.json @@ -9,11 +9,7 @@ ], "advanced": { "dev": false, - "encrypt_token": true, - "pre_check_prompts_for_suspicion": { - "enabled": false, - "timeout_duration": 3600000 - } + "encrypt_token": true }, "filter_actions": { "mode": "whitelist", @@ -68,6 +64,7 @@ "require_login": true, "trusted_workers": true, "censor_nsfw": true, + "replacement_filter": true, "blacklisted_models": [], "blacklisted_words": [], "update_generation_status_interval_seconds": 5, @@ -155,6 +152,7 @@ "require_login": true, "trusted_workers": true, "censor_nsfw": true, + "replacement_filter": true, "blacklisted_styles": [], "blacklisted_words": [], "update_generation_status_interval_seconds": 5, diff --git a/template.env b/template.env index a280673..ab8086a 100644 --- a/template.env +++ b/template.env @@ -4,5 +4,4 @@ DB_USERNAME= The Database user DB_PASSWORD= The Database password DB_IP= The database IP DB_PORT= The database Port -ENCRYPTION_KEY= The key to encrypt user tokens with -OPERATOR_API_KEY= The API key of the user who operates the bot (optional, read config.md for more information) \ No newline at end of file +ENCRYPTION_KEY= The key to encrypt user tokens with \ No newline at end of file