From 982010f804a9a6fecce39516b38d0dbd7893d1b8 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 29 Aug 2018 09:41:08 -0400 Subject: [PATCH 1/9] nudepy bug, waiting for merge --- nudity/info..json | 4 +- nudity/nudity.py | 97 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 11 deletions(-) diff --git a/nudity/info..json b/nudity/info..json index 4384930..e3d64e4 100644 --- a/nudity/info..json +++ b/nudity/info..json @@ -10,7 +10,9 @@ "description": "Keep track of when users were last seen online", "hidden": true, "install_msg": "Thank you for installing LastSeen. Get started with `[p]help LastSeen`", - "requirements": ["nudepy"], + "requirements": [ + "nudepy" + ], "short": "Last seen tracker", "tags": [ "bobloy", diff --git a/nudity/nudity.py b/nudity/nudity.py index be30ee4..d7c4fe8 100644 --- a/nudity/nudity.py +++ b/nudity/nudity.py @@ -1,8 +1,8 @@ -from datetime import datetime +from io import BytesIO import discord -import nude -from nude import Nude +from PIL import Image +from nude import is_nude from redbot.core import Config from redbot.core import commands from redbot.core.bot import Red @@ -13,16 +13,13 @@ class Nudity: V3 Cog Template """ - online_status = discord.Status.online - - offline_status = discord.Status.offline - def __init__(self, bot: Red): self.bot = bot self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True) default_guild = { - "enabled": False + "enabled": False, + "channel_id": None } self.config.register_guild(**default_guild) @@ -34,12 +31,92 @@ class Nudity: await self.config.guild(ctx.guild).enabled.set(not is_on) await ctx.send("Nude checking is now set to {}".format(not is_on)) + @commands.command() + async def nsfwchannel(self, ctx: commands.Context, channel: discord.TextChannel = None): + if channel is None: + await self.config.guild(ctx.guild).channel_id.set(None) + await ctx.send("NSFW Channel cleared") + else: + if not channel.is_nsfw(): + await ctx.send("This channel isn't NSFW!") + return + else: + await self.config.guild(ctx.guild).channel_id.set(channel.id) + await ctx.send("NSFW channel has been set to {}".format(channel.mention)) + + async def get_nsfw_channel(self, guild: discord.Guild): + channel_id = self.config.guild(guild).channel_id() + + if channel_id is None: + return None + else: + return await guild.get_channel(channel_id=channel_id) + + async def nsfw(self, message: discord.Message, image: BytesIO): + content = message.content + guild: discord.Guild = message.guild + if not content: + content = "*`None`*" + try: + await message.delete() + except discord.Forbidden: + await message.channel.send("NSFW Image detected!") + return + + embed = discord.Embed(title="NSFW Image Detected") + embed.add_field(name="Original Message", value=content) + + await message.channel.send(embed=embed) + + nsfw_channel = await self.get_nsfw_channel(guild) + + if nsfw_channel is None: + return + else: + await nsfw_channel.send("NSFW Image from {}".format(message.channel.mention), file=image) + async def on_message(self, message: discord.Message): - is_on = await self.config.guild(message.guild).enabled() + if not message.attachments: + return + + if message.guild is None: + return + + try: + is_on = await self.config.guild(message.guild).enabled() + except AttributeError: + return + if not is_on: return - if not message.attachments: + channel: discord.TextChannel = message.channel + + if channel.is_nsfw(): return + attachment = message.attachments[0] + + # async with aiohttp.ClientSession() as session: + # img = await fetch_img(session, attachment.url) + + temp = BytesIO() + print("Pre attachment save") + await attachment.save(temp) + print("Pre Image open") + temp = Image.open(temp) + + print("Pre nude check") + if is_nude(temp): + print("Is nude") + await message.add_reaction("❌") + await self.nsfw(message, temp) + else: + print("Is not nude") + await message.add_reaction("✅") +# async def fetch_img(session, url): +# with aiohttp.Timeout(10): +# async with session.get(url) as response: +# assert response.status == 200 +# return await response.read() From 9a3a62f451c379aa2350d81353a5ca230b477c87 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 9 Oct 2018 10:08:37 -0400 Subject: [PATCH 2/9] updates --- nudity/__init__.py | 3 ++- nudity/info..json | 2 +- nudity/nudity.py | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/nudity/__init__.py b/nudity/__init__.py index 7d32df6..09d9dbf 100644 --- a/nudity/__init__.py +++ b/nudity/__init__.py @@ -2,4 +2,5 @@ from .nudity import Nudity def setup(bot): - bot.add_cog(Nudity(bot)) + n = Nudity(bot) + bot.add_cog(n) diff --git a/nudity/info..json b/nudity/info..json index d5d6e2d..1d66cf7 100644 --- a/nudity/info..json +++ b/nudity/info..json @@ -17,4 +17,4 @@ "utils", "tools" ] -} \ No newline at end of file +} diff --git a/nudity/nudity.py b/nudity/nudity.py index d7c4fe8..a7290a5 100644 --- a/nudity/nudity.py +++ b/nudity/nudity.py @@ -17,14 +17,11 @@ class Nudity: self.bot = bot self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True) - default_guild = { - "enabled": False, - "channel_id": None - } + default_guild = {"enabled": False, "channel_id": None} self.config.register_guild(**default_guild) - @commands.command(aliases=['togglenudity'], name='nudity') + @commands.command(aliases=["togglenudity"], name="nudity") async def nudity(self, ctx: commands.Context): """Toggle nude-checking on or off""" is_on = await self.config.guild(ctx.guild).enabled() @@ -73,7 +70,9 @@ class Nudity: if nsfw_channel is None: return else: - await nsfw_channel.send("NSFW Image from {}".format(message.channel.mention), file=image) + await nsfw_channel.send( + "NSFW Image from {}".format(message.channel.mention), file=image + ) async def on_message(self, message: discord.Message): if not message.attachments: @@ -115,6 +114,7 @@ class Nudity: print("Is not nude") await message.add_reaction("✅") + # async def fetch_img(session, url): # with aiohttp.Timeout(10): # async with session.get(url) as response: From a98eb75c0f5572531eb5b291234d558ad972d248 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 12 Aug 2020 10:40:03 -0400 Subject: [PATCH 3/9] Logger and Ubuntu trainer --- chatter/chat.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index f7e8944..1473ad3 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -1,4 +1,5 @@ import asyncio +import logging import os import pathlib from datetime import datetime, timedelta @@ -7,11 +8,13 @@ import discord from chatterbot import ChatBot from chatterbot.comparisons import JaccardSimilarity, LevenshteinDistance, SpacySimilarity from chatterbot.response_selection import get_random_response -from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer +from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer, UbuntuCorpusTrainer from redbot.core import Config, commands from redbot.core.commands import Cog from redbot.core.data_manager import cog_data_path +log = logging.getLogger("red.fox_v3.chat") + class ENG_LG: # TODO: Add option to use this large model ISO_639_1 = "en_core_web_lg" @@ -50,7 +53,7 @@ class Chatter(Cog): self.loop = asyncio.get_event_loop() def _create_chatbot( - self, data_path, similarity_algorithm, similarity_threshold, tagger_language + self, data_path, similarity_algorithm, similarity_threshold, tagger_language ): return ChatBot( "ChatterBot", @@ -61,6 +64,7 @@ class Chatter(Cog): logic_adapters=["chatterbot.logic.BestMatch"], # maximum_similarity_threshold=similarity_threshold, tagger_language=tagger_language, + logger=log, ) async def _get_conversation(self, ctx, in_channel: discord.TextChannel = None): @@ -99,7 +103,7 @@ class Chatter(Cog): try: async for message in channel.history( - limit=None, after=after, oldest_first=True + limit=None, after=after, oldest_first=True ).filter( predicate=predicate ): # type: discord.Message @@ -130,6 +134,11 @@ class Chatter(Cog): return out + def _train_ubuntu(self): + trainer = UbuntuCorpusTrainer(self.chatbot) + trainer.train() + return True + def _train_english(self): trainer = ChatterBotCorpusTrainer(self.chatbot) # try: @@ -182,7 +191,9 @@ class Chatter(Cog): try: os.remove(self.data_path) except PermissionError: - await ctx.maybe_send_embed("Failed to clear training database. Please wait a bit and try again") + await ctx.maybe_send_embed( + "Failed to clear training database. Please wait a bit and try again" + ) self._create_chatbot(self.data_path, SpacySimilarity, 0.45, ENG_MD) @@ -260,6 +271,19 @@ class Chatter(Cog): else: await ctx.send("Error occurred :(") + @chatter.command(name="trainubuntu") + async def chatter_train_ubuntu(self, ctx: commands.Context): + """ + WARNING: Large Download! Trains the bot using Ubuntu Dialog Corpus data. + """ + async with ctx.typing(): + future = await self.loop.run_in_executor(None, self._train_ubuntu) + + if future: + await ctx.send("Training successful!") + else: + await ctx.send("Error occurred :(") + @chatter.command(name="trainenglish") async def chatter_train_english(self, ctx: commands.Context): """ From e8eb3f76e42059efa51b34aa32e88cda658ce862 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 12 Aug 2020 10:57:47 -0400 Subject: [PATCH 4/9] confirmation --- chatter/chat.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chatter/chat.py b/chatter/chat.py index 1473ad3..886efc3 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -272,10 +272,16 @@ class Chatter(Cog): await ctx.send("Error occurred :(") @chatter.command(name="trainubuntu") - async def chatter_train_ubuntu(self, ctx: commands.Context): + async def chatter_train_ubuntu(self, ctx: commands.Context, confirmation: bool = False): """ WARNING: Large Download! Trains the bot using Ubuntu Dialog Corpus data. """ + + if not confirmation: + await ctx.maybe_send_embed("Warning: This command downloads ~500MB then eats your CPU for training\n" + "If you're sure you want to continue, run `[p]chatter trainubuntu True`") + return + async with ctx.typing(): future = await self.loop.run_in_executor(None, self._train_ubuntu) From 361265b9832f757e6a236f368d320e295990d393 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 12 Aug 2020 14:57:36 -0400 Subject: [PATCH 5/9] Functioning nudity detection --- nudity/info..json | 22 ++++++++----- nudity/nudity.py | 83 ++++++++++++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/nudity/info..json b/nudity/info..json index 1d66cf7..34c4804 100644 --- a/nudity/info..json +++ b/nudity/info..json @@ -2,19 +2,25 @@ "author": [ "Bobloy" ], - "bot_version": [ + "min_bot_version": [ 3, - 0, - 0 + 3, + 11 ], - "description": "Keep track of when users were last seen online", - "hidden": true, + "description": "Monitor images for NSFW content and moves them to a nsfw channel if possible", + "hidden": false, "install_msg": "Thank you for installing Nudity. Get started with `[p]load nudity`, then `[p]help Nudity`", - "requirements": ["nudepy"], - "short": "Last seen tracker", + "requirements": [ + "nudenet", + "tensorflow>=1.14,<2.0", + "keras>=2.4" + ], + "short": "NSFW image tracker and mover", "tags": [ "bobloy", "utils", - "tools" + "tools", + "nude", + "nsfw" ] } diff --git a/nudity/nudity.py b/nudity/nudity.py index a7290a5..6eb4221 100644 --- a/nudity/nudity.py +++ b/nudity/nudity.py @@ -1,19 +1,19 @@ -from io import BytesIO +import pathlib import discord -from PIL import Image -from nude import is_nude -from redbot.core import Config -from redbot.core import commands +from nudenet import NudeClassifier +from redbot.core import Config, commands from redbot.core.bot import Red +from redbot.core.data_manager import cog_data_path -class Nudity: +class Nudity(commands.Cog): """ V3 Cog Template """ def __init__(self, bot: Red): + super().__init__() self.bot = bot self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True) @@ -21,6 +21,17 @@ class Nudity: self.config.register_guild(**default_guild) + # self.detector = NudeDetector() + self.classifier = NudeClassifier() + + self.data_path: pathlib.Path = cog_data_path(self) + + self.current_processes = 0 + + async def red_delete_data_for_user(self, **kwargs): + """Nothing to delete""" + return + @commands.command(aliases=["togglenudity"], name="nudity") async def nudity(self, ctx: commands.Context): """Toggle nude-checking on or off""" @@ -42,14 +53,14 @@ class Nudity: await ctx.send("NSFW channel has been set to {}".format(channel.mention)) async def get_nsfw_channel(self, guild: discord.Guild): - channel_id = self.config.guild(guild).channel_id() + channel_id = await self.config.guild(guild).channel_id() if channel_id is None: return None else: - return await guild.get_channel(channel_id=channel_id) + return guild.get_channel(channel_id=channel_id) - async def nsfw(self, message: discord.Message, image: BytesIO): + async def nsfw(self, message: discord.Message, images: dict): content = message.content guild: discord.Guild = message.guild if not content: @@ -62,7 +73,7 @@ class Nudity: embed = discord.Embed(title="NSFW Image Detected") embed.add_field(name="Original Message", value=content) - + embed.set_author(name=message.author.name, icon_url=message.author.avatar_url) await message.channel.send(embed=embed) nsfw_channel = await self.get_nsfw_channel(guild) @@ -70,15 +81,19 @@ class Nudity: if nsfw_channel is None: return else: - await nsfw_channel.send( - "NSFW Image from {}".format(message.channel.mention), file=image - ) - + for image, r in images.items(): + if r["unsafe"] > 0.7: + await nsfw_channel.send( + "NSFW Image from {}".format(message.channel.mention), + file=discord.File(image,), + ) + + @commands.Cog.listener() async def on_message(self, message: discord.Message): - if not message.attachments: - return + is_private = isinstance(message.channel, discord.abc.PrivateChannel) - if message.guild is None: + if not message.attachments or is_private or message.author.bot: + # print("did not qualify") return try: @@ -87,31 +102,41 @@ class Nudity: return if not is_on: + print("Not on") return channel: discord.TextChannel = message.channel if channel.is_nsfw(): + print("nsfw channel is okay") return - attachment = message.attachments[0] + check_list = [] + for attachment in message.attachments: + # async with aiohttp.ClientSession() as session: + # img = await fetch_img(session, attachment.url) + + ext = attachment.filename - # async with aiohttp.ClientSession() as session: - # img = await fetch_img(session, attachment.url) + temp_name = self.data_path / f"nudecheck{self.current_processes}_{ext}" - temp = BytesIO() - print("Pre attachment save") - await attachment.save(temp) - print("Pre Image open") - temp = Image.open(temp) + self.current_processes += 1 + + print("Pre attachment save") + await attachment.save(temp_name) + check_list.append(temp_name) print("Pre nude check") - if is_nude(temp): - print("Is nude") + # nude_results = self.detector.detect(temp_name) + nude_results = self.classifier.classify([str(n) for n in check_list]) + # print(nude_results) + + if True in [r["unsafe"] > 0.7 for r in nude_results.values()]: + # print("Is nude") await message.add_reaction("❌") - await self.nsfw(message, temp) + await self.nsfw(message, nude_results) else: - print("Is not nude") + # print("Is not nude") await message.add_reaction("✅") From a7878359154b51642d13fdfc67ea56d433ff04a5 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 12 Aug 2020 15:00:03 -0400 Subject: [PATCH 6/9] Add Nudity to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 980e762..c37f84f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Cog Function | infochannel | **Beta** |
Create a channel to display server infoJust released, please report bugs
| | lovecalculator | **Alpha** |
Calculate the love between two users[Snap-Ons] Just updated to V3
| | lseen | **Alpha** |
Track when a member was last onlineAlpha release, please report bugs
| -| nudity | **Incomplete** |
Checks for NSFW images posted in non-NSFW channelsLibrary this is based on has a bug, waiting for author to merge my PR
| +| nudity | **Alpha** |
Checks for NSFW images posted in non-NSFW channelsSwitched libraries, now functional
| | planttycoon | **Alpha** |
Grow your own plants![Snap-Ons] Updated to V3, likely to contain bugs
| | qrinvite | **Alpha** |
Create a QR code invite for the serverAlpha release, please report any bugs
| | reactrestrict | **Alpha** |
Removes reactions by role per channelA bit clunky, but functional
| From f55bc4d5834ab8e8a9c688cbbc08e58cc13ad433 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 13 Aug 2020 09:57:50 -0400 Subject: [PATCH 7/9] Update README.md Add notes about `trainubuntu` --- chatter/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chatter/README.md b/chatter/README.md index 933162a..2de5843 100644 --- a/chatter/README.md +++ b/chatter/README.md @@ -162,6 +162,16 @@ This command trains Chatter on the specified channel based on the configured settings. This can take a long time to process. +### Train Ubuntu + +``` +[p]chatter trainubuntu +``` +*WARNING:* This will trigger a large download and use a lot of processing power + +This command trains Chatter on the publicly available Ubuntu Dialogue Corpus. (It'll talk like a geek) + + ## Switching Algorithms ``` From 4fcc12a2d8a04f4d9da7c87497417c0fb56fe474 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 13 Aug 2020 12:02:54 -0400 Subject: [PATCH 8/9] Allow specifying algorithm and model --- chatter/README.md | 31 ++++++++++++++ chatter/chat.py | 100 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 111 insertions(+), 20 deletions(-) diff --git a/chatter/README.md b/chatter/README.md index 933162a..5d5446f 100644 --- a/chatter/README.md +++ b/chatter/README.md @@ -167,7 +167,38 @@ settings. This can take a long time to process. ``` [p]chatter algorithm X ``` +or +``` +[p]chatter algo X 0.95 +``` Chatter can be configured to use one of three different Similarity algorithms. Changing this can help if the response speed is too slow, but can reduce the accuracy of results. + +The second argument is the minimum similarity threshold, +raising this will make the bot me more selective with the responses it finds. + +Default minimum similarity threshold is 0.90 + + +## Switching Pretrained Models + +``` +[p]chatter model X +``` + +Chatter can be configured to use one of three pretrained statistical models for English. + +I have not noticed any advantage to changing this, +but supposedly it would help by splitting the search term into more useful parts. + +See [here](https://spacy.io/models) for more info on spaCy models. + +Before you're able to use the *large* model (option 3), you must install it through pip. + +*Warning:* This is ~800MB download. + +``` +[p]pipinstall https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-2.3.1/en_core_web_lg-2.3.1.tar.gz#egg=en_core_web_lg +``` diff --git a/chatter/chat.py b/chatter/chat.py index 886efc3..76ee56c 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -12,11 +12,12 @@ from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer, UbuntuCorp from redbot.core import Config, commands from redbot.core.commands import Cog from redbot.core.data_manager import cog_data_path +from redbot.core.utils.predicates import MessagePredicate log = logging.getLogger("red.fox_v3.chat") -class ENG_LG: # TODO: Add option to use this large model +class ENG_LG: ISO_639_1 = "en_core_web_lg" ISO_639 = "eng" ENGLISH_NAME = "English" @@ -28,6 +29,12 @@ class ENG_MD: ENGLISH_NAME = "English" +class ENG_SM: + ISO_639_1 = "en_core_web_sm" + ISO_639 = "eng" + ENGLISH_NAME = "English" + + class Chatter(Cog): """ This cog trains a chatbot that will talk like members of your Guild @@ -42,7 +49,13 @@ class Chatter(Cog): path: pathlib.Path = cog_data_path(self) self.data_path = path / "database.sqlite3" - self.chatbot = self._create_chatbot(self.data_path, SpacySimilarity, 0.45, ENG_MD) + # TODO: Move training_model and similarity_algo to config + # TODO: Add an option to see current settings + + self.tagger_language = ENG_MD + self.similarity_algo = SpacySimilarity + self.similarity_threshold = 0.90 + self.chatbot = self._create_chatbot() # self.chatbot.set_trainer(ListTrainer) # self.trainer = ListTrainer(self.chatbot) @@ -52,18 +65,17 @@ class Chatter(Cog): self.loop = asyncio.get_event_loop() - def _create_chatbot( - self, data_path, similarity_algorithm, similarity_threshold, tagger_language - ): + def _create_chatbot(self): + return ChatBot( "ChatterBot", storage_adapter="chatterbot.storage.SQLStorageAdapter", - database_uri="sqlite:///" + str(data_path), - statement_comparison_function=similarity_algorithm, + database_uri="sqlite:///" + str(self.data_path), + statement_comparison_function=self.similarity_algo, response_selection_method=get_random_response, logic_adapters=["chatterbot.logic.BestMatch"], - # maximum_similarity_threshold=similarity_threshold, - tagger_language=tagger_language, + maximum_similarity_threshold=self.similarity_threshold, + tagger_language=self.tagger_language, logger=log, ) @@ -103,7 +115,7 @@ class Chatter(Cog): try: async for message in channel.history( - limit=None, after=after, oldest_first=True + limit=None, after=after, oldest_first=True ).filter( predicate=predicate ): # type: discord.Message @@ -195,12 +207,14 @@ class Chatter(Cog): "Failed to clear training database. Please wait a bit and try again" ) - self._create_chatbot(self.data_path, SpacySimilarity, 0.45, ENG_MD) + self._create_chatbot() await ctx.tick() - @chatter.command(name="algorithm") - async def chatter_algorithm(self, ctx: commands.Context, algo_number: int): + @chatter.command(name="algorithm", aliases=["algo"]) + async def chatter_algorithm( + self, ctx: commands.Context, algo_number: int, threshold: float = None + ): """ Switch the active logic algorithm to one of the three. Default after reload is Spacy @@ -209,17 +223,61 @@ class Chatter(Cog): 2: Levenshtein """ - algos = [(SpacySimilarity, 0.45), (JaccardSimilarity, 0.75), (LevenshteinDistance, 0.75)] + algos = [SpacySimilarity, JaccardSimilarity, LevenshteinDistance] if algo_number < 0 or algo_number > 2: await ctx.send_help() return - self.chatbot = self._create_chatbot( - self.data_path, algos[algo_number][0], algos[algo_number][1], ENG_MD - ) + if threshold is not None: + if threshold >= 1 or threshold <= 0: + await ctx.maybe_send_embed( + "Threshold must be a number between 0 and 1 (exclusive)" + ) + return + else: + self.similarity_algo = threshold - await ctx.tick() + self.similarity_algo = algos[algo_number] + async with ctx.typing(): + self.chatbot = self._create_chatbot() + + await ctx.tick() + + @chatter.command(name="model") + async def chatter_model(self, ctx: commands.Context, model_number: int): + """ + Switch the active model to one of the three. Default after reload is Medium + + 0: Small + 1: Medium + 2: Large (Requires additional setup) + """ + + models = [ENG_SM, ENG_MD, ENG_LG] + + if model_number < 0 or model_number > 2: + await ctx.send_help() + return + + if model_number == 2: + await ctx.maybe_send_embed( + "Additional requirements needed. See guide before continuing.\n" "Continue?" + ) + pred = MessagePredicate.yes_or_no(ctx) + try: + await self.bot.wait_for("message", check=pred, timeout=30) + except TimeoutError: + await ctx.send("Response timed out, please try again later.") + return + if not pred.result: + return + + self.tagger_language = models[model_number] + async with ctx.typing(): + self.chatbot = self._create_chatbot() + + await ctx.maybe_send_embed(f"Model has been switched to {self.tagger_language.ISO_639_1}") @chatter.command(name="minutes") async def minutes(self, ctx: commands.Context, minutes: int): @@ -278,8 +336,10 @@ class Chatter(Cog): """ if not confirmation: - await ctx.maybe_send_embed("Warning: This command downloads ~500MB then eats your CPU for training\n" - "If you're sure you want to continue, run `[p]chatter trainubuntu True`") + await ctx.maybe_send_embed( + "Warning: This command downloads ~500MB then eats your CPU for training\n" + "If you're sure you want to continue, run `[p]chatter trainubuntu True`" + ) return async with ctx.typing(): From f9ae2d6f7edc171237068c6443c4573c60dbce2a Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 13 Aug 2020 12:06:27 -0400 Subject: [PATCH 9/9] It's actually a maximum --- chatter/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chatter/README.md b/chatter/README.md index 5d5446f..17074a0 100644 --- a/chatter/README.md +++ b/chatter/README.md @@ -176,10 +176,10 @@ Chatter can be configured to use one of three different Similarity algorithms. Changing this can help if the response speed is too slow, but can reduce the accuracy of results. -The second argument is the minimum similarity threshold, -raising this will make the bot me more selective with the responses it finds. +The second argument is the maximum similarity threshold, +lowering that will make the bot stop searching sooner. -Default minimum similarity threshold is 0.90 +Default maximum similarity threshold is 0.90 ## Switching Pretrained Models