From 960b66a5b88e6ca162a1df09a21c281538106274 Mon Sep 17 00:00:00 2001 From: BogdanWDK Date: Wed, 30 Sep 2020 06:54:18 +0100 Subject: [PATCH 01/24] Language Support Added Supports Language as [p]tts --- tts/tts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index 235d585..8584f5a 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -28,12 +28,12 @@ class TTS(Cog): return @commands.command(aliases=["t2s", "text2"]) - async def tts(self, ctx: commands.Context, *, text: str): - """ - Send Text to speech messages as an mp3 + async def tts(self, ctx: commands.Context, *, lang: str, text: str): """ + Send Text to speech messages as an mp3 + """ mp3_fp = io.BytesIO() - tts = gTTS(text, lang="en") + tts = gTTS(text, lang=lang) tts.write_to_fp(mp3_fp) mp3_fp.seek(0) await ctx.send(file=discord.File(mp3_fp, "text.mp3")) From 10ed1f9b9f34315fecf406aff8666676d7a68bca Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 14 Apr 2021 09:40:34 -0400 Subject: [PATCH 02/24] pagify lots of stolen emojis --- stealemoji/stealemoji.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index be9903c..b456616 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -6,6 +6,7 @@ import discord from redbot.core import Config, checks, commands from redbot.core.bot import Red from redbot.core.commands import Cog +from redbot.core.utils.chat_formatting import pagify log = logging.getLogger("red.fox_v3.stealemoji") # Replaced with discord.Asset.read() @@ -99,7 +100,8 @@ class StealEmoji(Cog): await ctx.maybe_send_embed("No stolen emojis yet") return - await ctx.maybe_send_embed(emoj) + for page in pagify(emoj): + await ctx.maybe_send_embed(page) @checks.is_owner() @stealemoji.command(name="notify") From 28edcc1fddae07a17d91973efb51edfc5ba95280 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 14 Apr 2021 09:44:28 -0400 Subject: [PATCH 03/24] deliminate on space not newline --- stealemoji/stealemoji.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index b456616..fb83f3b 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -100,7 +100,7 @@ class StealEmoji(Cog): await ctx.maybe_send_embed("No stolen emojis yet") return - for page in pagify(emoj): + for page in pagify(emoj, delims=[" "]): await ctx.maybe_send_embed(page) @checks.is_owner() From f04ff6886b2382a59ea19d187611b6ae25768abe Mon Sep 17 00:00:00 2001 From: Kreusada <67752638+Kreusada@users.noreply.github.com> Date: Thu, 15 Apr 2021 13:59:19 +0100 Subject: [PATCH 04/24] [SCP] Remove double setup --- scp/scp.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scp/scp.py b/scp/scp.py index 3b4176c..d564d4c 100644 --- a/scp/scp.py +++ b/scp/scp.py @@ -177,7 +177,3 @@ class SCP(Cog): msg = "http://www.scp-wiki.net/log-of-unexplained-locations" await ctx.maybe_send_embed(msg) - - -def setup(bot): - bot.add_cog(SCP(bot)) From 1ddcd980789c819f6a1db5ac08423376b1b5be6f Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 15 Apr 2021 11:12:47 -0400 Subject: [PATCH 05/24] Implement languages --- tts/tts.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index 8584f5a..fe86407 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -1,11 +1,40 @@ import io +import logging +from typing import Optional, TYPE_CHECKING import discord +import pycountry +from discord.ext.commands import BadArgument, Converter from gtts import gTTS +from gtts.lang import _fallback_deprecated_lang, tts_langs from redbot.core import Config, commands from redbot.core.bot import Red from redbot.core.commands import Cog +log = logging.getLogger("red.fox_v3.tts") + +langs = [lang.iso639_1_code for lang in pycountry.languages if hasattr(lang, "iso639_1_code")] + +print(langs) + +if TYPE_CHECKING: + ISO639Converter = str +else: + + class ISO639Converter(Converter): + async def convert(self, ctx, argument) -> str: + lang = _fallback_deprecated_lang(argument) + + try: + langs = tts_langs() + if lang not in langs: + raise BadArgument("Language not supported: %s" % lang) + except RuntimeError as e: + log.debug(str(e), exc_info=True) + log.warning(str(e)) + + return lang + class TTS(Cog): """ @@ -18,7 +47,7 @@ class TTS(Cog): self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True) default_global = {} - default_guild = {} + default_guild = {"language": "en"} self.config.register_global(**default_global) self.config.register_guild(**default_guild) @@ -27,11 +56,27 @@ class TTS(Cog): """Nothing to delete""" return + @commands.mod() + @commands.command() + async def ttslang(self, ctx: commands.Context, lang: ISO639Converter): + """ + Sets the default language for TTS in this guild. + + Default is `en` for English + """ + await self.config.guild(ctx.guild).language.set(lang) + await ctx.send(f"Default tts language set to {lang}") + @commands.command(aliases=["t2s", "text2"]) - async def tts(self, ctx: commands.Context, *, lang: str, text: str): + async def tts( + self, ctx: commands.Context, lang: Optional[ISO639Converter] = None, *, text: str + ): + """ + Send Text to speech messages as an mp3 """ - Send Text to speech messages as an mp3 - """ + if lang is None: + lang = await self.config.guild(ctx.guild).language() + mp3_fp = io.BytesIO() tts = gTTS(text, lang=lang) tts.write_to_fp(mp3_fp) From 506a79c6d6294c0353173e04f6b9c7bcb7d54bae Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 15 Apr 2021 11:14:00 -0400 Subject: [PATCH 06/24] Removing debugging print --- tts/tts.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index fe86407..02d7267 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -15,8 +15,6 @@ log = logging.getLogger("red.fox_v3.tts") langs = [lang.iso639_1_code for lang in pycountry.languages if hasattr(lang, "iso639_1_code")] -print(langs) - if TYPE_CHECKING: ISO639Converter = str else: From ed6cc433c8891cac1e0f1353088bbe10b6fcb146 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 15 Apr 2021 11:38:36 -0400 Subject: [PATCH 07/24] Remove pycountry --- tts/tts.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index 02d7267..c69522a 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -3,7 +3,6 @@ import logging from typing import Optional, TYPE_CHECKING import discord -import pycountry from discord.ext.commands import BadArgument, Converter from gtts import gTTS from gtts.lang import _fallback_deprecated_lang, tts_langs @@ -13,8 +12,6 @@ from redbot.core.commands import Cog log = logging.getLogger("red.fox_v3.tts") -langs = [lang.iso639_1_code for lang in pycountry.languages if hasattr(lang, "iso639_1_code")] - if TYPE_CHECKING: ISO639Converter = str else: From 2f21de6a972a6e55b9f6e85616ea462ee3774490 Mon Sep 17 00:00:00 2001 From: PhenoM4n4n Date: Thu, 15 Apr 2021 17:39:49 -0700 Subject: [PATCH 08/24] lovecalc attributeerror --- lovecalculator/lovecalculator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lovecalculator/lovecalculator.py b/lovecalculator/lovecalculator.py index 20504bd..a706ea0 100644 --- a/lovecalculator/lovecalculator.py +++ b/lovecalculator/lovecalculator.py @@ -49,7 +49,11 @@ class LoveCalculator(Cog): result_image = soup_object.find("img", class_="result__image").get("src") - result_text = soup_object.find("div", class_="result-text").get_text() + result_text = soup_object.find("div", class_="result-text") + if result_text is None: + result_text = f"{x} and {y} aren't compatible 😔" + else: + result_text.get_text() result_text = " ".join(result_text.split()) try: From 2937b6ac923d7c16c79d907d88b143408b3dac08 Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 3 May 2021 13:58:35 -0400 Subject: [PATCH 09/24] List of dicts --- fifo/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fifo/task.py b/fifo/task.py index e1b7207..34df8e2 100644 --- a/fifo/task.py +++ b/fifo/task.py @@ -142,7 +142,7 @@ class FakeMessage(discord.Message): self._update( { "mention_roles": self.raw_role_mentions, - "mentions": self.raw_mentions, + "mentions": [{"id": _id} for _id in self.raw_mentions], } ) From 52ca2f6a4541a1d4b1ee8029175dfb61781b5ebb Mon Sep 17 00:00:00 2001 From: aleclol <50505980+aleclol@users.noreply.github.com> Date: Tue, 18 May 2021 15:27:55 -0400 Subject: [PATCH 10/24] Update lovecalculator.py --- lovecalculator/lovecalculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lovecalculator/lovecalculator.py b/lovecalculator/lovecalculator.py index a706ea0..d6ae4fe 100644 --- a/lovecalculator/lovecalculator.py +++ b/lovecalculator/lovecalculator.py @@ -53,7 +53,7 @@ class LoveCalculator(Cog): if result_text is None: result_text = f"{x} and {y} aren't compatible 😔" else: - result_text.get_text() + result_text = result_text.get_text() result_text = " ".join(result_text.split()) try: From bc12aa866e6d7f39304945217407405abc42a9fe Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 25 May 2021 10:12:51 -0400 Subject: [PATCH 11/24] Fix formatting --- timerole/timerole.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/timerole/timerole.py b/timerole/timerole.py index b3fe843..0d62cf0 100644 --- a/timerole/timerole.py +++ b/timerole/timerole.py @@ -295,8 +295,11 @@ class Timerole(Cog): log.exception("Failed Adding Roles") add_results += f"{member.display_name} : **(Failed Adding Roles)**\n" else: - add_results += " \n".join( - f"{member.display_name} : {role.name}" for role in add_roles + add_results += ( + " \n".join( + f"{member.display_name} : {role.name}" for role in add_roles + ) + + "\n" ) for role_id in addlist: await self.config.custom( @@ -310,8 +313,11 @@ class Timerole(Cog): log.exception("Failed Removing Roles") remove_results += f"{member.display_name} : **(Failed Removing Roles)**\n" else: - remove_results += " \n".join( - f"{member.display_name} : {role.name}" for role in remove_roles + remove_results += ( + " \n".join( + f"{member.display_name} : {role.name}" for role in remove_roles + ) + + "\n" ) for role_id in removelist: await self.config.custom( From a55ae8a51126099a3418ce7f9b6889e5f233bdf9 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 30 Jun 2021 17:29:00 -0400 Subject: [PATCH 12/24] Use Bobloy's chatterbot fork --- chatter/README.md | 66 +++++++------------------------------ chatter/chat.py | 8 ++++- chatter/info.json | 12 +------ chatter/requirements.txt | 24 +++++++------- chatter/storage_adapters.py | 2 +- 5 files changed, 33 insertions(+), 79 deletions(-) diff --git a/chatter/README.md b/chatter/README.md index 06331b2..bcd6cbc 100644 --- a/chatter/README.md +++ b/chatter/README.md @@ -74,77 +74,35 @@ If you get an error at this step, stop and skip to one of the manual methods bel #### Step 2: Install additional dependencies -Assuming the previous commands had no error, you can now use `pipinstall` to add the remaining dependencies. +Here you need to decide which training models you want to have available to you. -NOTE: This method is not the intended use case for `pipinstall` and may stop working in the future. +Shutdown the bot and run any number of these in the console: ``` -[p]pipinstall --no-deps chatterbot>=1.1 -``` - -#### Step 3: Load the cog and get started - -``` -[p]load chatter -``` +python -m spacy download en_core_web_sm # ~15 MB -### Windows - Manually -#### Step 1: Built-in Downloader +python -m spacy download en_core_web_md # ~50 MB -You need to get a copy of the requirements.txt provided with chatter, I recommend this method. +python -m spacy download en_core_web_lg # ~750 MB (CPU Optimized) -``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 +python -m spacy download en_core_web_trf # ~500 MB (GPU Optimized) ``` -#### Step 2: Install Requirements - -Make sure you have your virtual environment that you installed Red on activated before starting this step. See the Red Docs for details on how. - -In a terminal running as an admin, navigate to the directory containing this repo. - -I've used my install directory as an example. - -``` -cd C:\Users\Bobloy\AppData\Local\Red-DiscordBot\Red-DiscordBot\data\bobbot\cogs\RepoManager\repos\Fox\chatter -pip install -r requirements.txt -pip install --no-deps "chatterbot>=1.1" -``` - -#### Step 3: Load Chatter +#### Step 3: Load the cog and get started ``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 # If you didn't already do this in step 1 -[p]cog install Fox chatter [p]load chatter ``` -### Linux - Manually - -#### Step 1: Built-in Downloader - -``` -[p]repo add Fox https://github.com/bobloy/Fox-V3 -[p]cog install Fox chatter -``` - -#### Step 2: Install Requirements - -In your console with your virtual environment activated: - -``` -pip install --no-deps "chatterbot>=1.1" -``` - -### Step 3: Load Chatter +### Windows - Manually +Deprecated -``` -[p]load chatter -``` +### Linux - Manually +Deprecated # Configuration -Chatter works out the the box without any training by learning as it goes, +Chatter works out the box without any training by learning as it goes, but will have very poor and repetitive responses at first. Initial training is recommended to speed up its learning. diff --git a/chatter/chat.py b/chatter/chat.py index 5ad3efb..b8cf75d 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -29,6 +29,12 @@ def my_local_get_prefix(prefixes, content): return None +class ENG_TRF: + ISO_639_1 = "en_core_web_trf" + ISO_639 = "eng" + ENGLISH_NAME = "English" + + class ENG_LG: ISO_639_1 = "en_core_web_lg" ISO_639 = "eng" @@ -70,7 +76,7 @@ class Chatter(Cog): # TODO: Move training_model and similarity_algo to config # TODO: Add an option to see current settings - self.tagger_language = ENG_MD + self.tagger_language = ENG_TRF self.similarity_algo = SpacySimilarity self.similarity_threshold = 0.90 self.chatbot = self._create_chatbot() diff --git a/chatter/info.json b/chatter/info.json index fc31e7c..a9bb96b 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -7,17 +7,7 @@ "hidden": false, "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", "requirements": [ - "git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus", - "mathparse>=0.1,<0.2", - "nltk>=3.2,<4.0", - "pint>=0.8.1", - "python-dateutil>=2.8,<2.9", - "pyyaml>=5.3,<5.4", - "sqlalchemy>=1.3,<1.4", - "pytz", - "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm", - "https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md", - "spacy>=2.3,<2.4", + "git+git://github.com/bobloy/ChatterBot@fox#egg=ChatterBot", "kaggle" ], "short": "Local Chatbot run on machine learning", diff --git a/chatter/requirements.txt b/chatter/requirements.txt index 88cd662..bbcfcf9 100644 --- a/chatter/requirements.txt +++ b/chatter/requirements.txt @@ -1,12 +1,12 @@ -git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus -mathparse>=0.1,<0.2 -nltk>=3.2,<4.0 -pint>=0.8.1 -python-dateutil>=2.8,<2.9 -pyyaml>=5.3,<5.4 -sqlalchemy>=1.3,<1.4 -pytz -spacy>=2.3,<2.4 -https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm -https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md -# 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 \ No newline at end of file +# git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus +# mathparse>=0.1,<0.2 +# nltk>=3.2,<4.0 +# pint>=0.8.1 +# python-dateutil>=2.8,<2.9 +# # pyyaml>=5.3,<5.4 +# sqlalchemy>=1.3,<1.4 +# pytz +# spacy>=2.3,<2.4 +# https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm +# https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md +# # 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 \ No newline at end of file diff --git a/chatter/storage_adapters.py b/chatter/storage_adapters.py index 4de2f00..6f11601 100644 --- a/chatter/storage_adapters.py +++ b/chatter/storage_adapters.py @@ -19,7 +19,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): self.database_uri = "sqlite:///db.sqlite3" self.engine = create_engine( - self.database_uri, convert_unicode=True, connect_args={"check_same_thread": False} + self.database_uri, connect_args={"check_same_thread": False} ) if self.database_uri.startswith("sqlite://"): From 9c63c126563153e3c5290bc5d6c2dde06c1a4c37 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 30 Jun 2021 17:29:31 -0400 Subject: [PATCH 13/24] Don't need requirements file --- chatter/requirements.txt | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 chatter/requirements.txt diff --git a/chatter/requirements.txt b/chatter/requirements.txt deleted file mode 100644 index bbcfcf9..0000000 --- a/chatter/requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -# git+git://github.com/gunthercox/chatterbot-corpus@master#egg=chatterbot_corpus -# mathparse>=0.1,<0.2 -# nltk>=3.2,<4.0 -# pint>=0.8.1 -# python-dateutil>=2.8,<2.9 -# # pyyaml>=5.3,<5.4 -# sqlalchemy>=1.3,<1.4 -# pytz -# spacy>=2.3,<2.4 -# https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz#egg=en_core_web_sm -# https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.3.1/en_core_web_md-2.3.1.tar.gz#egg=en_core_web_md -# # 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 \ No newline at end of file From c165313031644c4480aedff848859a7a1c36da8b Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 1 Jul 2021 15:25:38 -0400 Subject: [PATCH 14/24] no reply errors in cache --- chatter/chat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index b8cf75d..2deb082 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -63,7 +63,7 @@ class Chatter(Cog): self.bot = bot self.config = Config.get_conf(self, identifier=6710497116116101114) default_global = {"learning": True} - default_guild = { + self.default_guild = { "whitelist": None, "days": 1, "convo_delta": 15, @@ -711,7 +711,9 @@ class Chatter(Cog): ) replying = None - if self._guild_cache[guild.id]["reply"]: + if ( + "reply" not in self._guild_cache[guild.id] and self.default_guild["reply"] + ) or self._guild_cache[guild.id]["reply"]: if message != ctx.channel.last_message: replying = message From 6f0c88b1ac31b424de5af46cade5b6f1fb816879 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 1 Jul 2021 17:19:29 -0400 Subject: [PATCH 15/24] change default models, fix requirements --- chatter/chat.py | 9 +++++---- chatter/info.json | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index 2deb082..e3f14cc 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -76,7 +76,7 @@ class Chatter(Cog): # TODO: Move training_model and similarity_algo to config # TODO: Add an option to see current settings - self.tagger_language = ENG_TRF + self.tagger_language = ENG_SM self.similarity_algo = SpacySimilarity self.similarity_threshold = 0.90 self.chatbot = self._create_chatbot() @@ -85,7 +85,7 @@ class Chatter(Cog): # self.trainer = ListTrainer(self.chatbot) self.config.register_global(**default_global) - self.config.register_guild(**default_guild) + self.config.register_guild(**self.default_guild) self.loop = asyncio.get_event_loop() @@ -371,11 +371,12 @@ class Chatter(Cog): 0: Small 1: Medium 2: Large (Requires additional setup) + 3. Accurate (Requires additional setup) """ - models = [ENG_SM, ENG_MD, ENG_LG] + models = [ENG_SM, ENG_MD, ENG_LG, ENG_TRF] - if model_number < 0 or model_number > 2: + if model_number < 0 or model_number > 3: await ctx.send_help() return diff --git a/chatter/info.json b/chatter/info.json index a9bb96b..0004709 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -8,6 +8,7 @@ "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", "requirements": [ "git+git://github.com/bobloy/ChatterBot@fox#egg=ChatterBot", + "en_core_web_sm", "kaggle" ], "short": "Local Chatbot run on machine learning", From 86cc1fa35adb5dc6d8539df67b720d55321bcceb Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 5 Jul 2021 14:14:29 -0400 Subject: [PATCH 16/24] Don't specify pyaml --- chatter/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatter/requirements.txt b/chatter/requirements.txt index 88cd662..490c2a1 100644 --- a/chatter/requirements.txt +++ b/chatter/requirements.txt @@ -3,7 +3,7 @@ mathparse>=0.1,<0.2 nltk>=3.2,<4.0 pint>=0.8.1 python-dateutil>=2.8,<2.9 -pyyaml>=5.3,<5.4 +# pyyaml>=5.3,<5.4 sqlalchemy>=1.3,<1.4 pytz spacy>=2.3,<2.4 From e0a361b952586d25ecc042486ade285c75ca3784 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 6 Jul 2021 10:52:25 -0400 Subject: [PATCH 17/24] remove en_core_web_sm as dependency --- chatter/info.json | 1 - 1 file changed, 1 deletion(-) diff --git a/chatter/info.json b/chatter/info.json index 0004709..a9bb96b 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -8,7 +8,6 @@ "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", "requirements": [ "git+git://github.com/bobloy/ChatterBot@fox#egg=ChatterBot", - "en_core_web_sm", "kaggle" ], "short": "Local Chatbot run on machine learning", From 47269ba8f4d8ccd564f73b773fdd35db2ab8e693 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 6 Jul 2021 12:01:27 -0400 Subject: [PATCH 18/24] fix has_table, move age and minutes to trainset --- chatter/chat.py | 10 ++++++++-- chatter/storage_adapters.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index e3f14cc..1b81959 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -402,7 +402,13 @@ class Chatter(Cog): ) @commands.is_owner() - @chatter.command(name="minutes") + @chatter.group(name="trainset") + async def chatter_trainset(self, ctx: commands.Context): + """Commands for configuring training""" + pass + + @commands.is_owner() + @chatter_trainset.command(name="minutes") async def minutes(self, ctx: commands.Context, minutes: int): """ Sets the number of minutes the bot will consider a break in a conversation during training @@ -418,7 +424,7 @@ class Chatter(Cog): await ctx.tick() @commands.is_owner() - @chatter.command(name="age") + @chatter_trainset.command(name="age") async def age(self, ctx: commands.Context, days: int): """ Sets the number of days to look back diff --git a/chatter/storage_adapters.py b/chatter/storage_adapters.py index 6f11601..b2dc02a 100644 --- a/chatter/storage_adapters.py +++ b/chatter/storage_adapters.py @@ -5,7 +5,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): def __init__(self, **kwargs): super(SQLStorageAdapter, self).__init__(**kwargs) - from sqlalchemy import create_engine + from sqlalchemy import create_engine, inspect from sqlalchemy.orm import sessionmaker self.database_uri = kwargs.get("database_uri", False) @@ -31,7 +31,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): dbapi_connection.execute("PRAGMA journal_mode=WAL") dbapi_connection.execute("PRAGMA synchronous=NORMAL") - if not self.engine.dialect.has_table(self.engine, "Statement"): + if not inspect(self.engine).has_table('Statement'): self.create_database() self.Session = sessionmaker(bind=self.engine, expire_on_commit=True) From b752bfd153507ff54ff999c2d5272da15f6c8ec1 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 6 Jul 2021 13:50:15 -0400 Subject: [PATCH 19/24] Stop looking at DMs --- chatter/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatter/chat.py b/chatter/chat.py index 1b81959..66ff116 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -643,7 +643,7 @@ class Chatter(Cog): guild: discord.Guild = getattr(message, "guild", None) - if await self.bot.cog_disabled_in_guild(self, guild): + if guild is None or await self.bot.cog_disabled_in_guild(self, guild): return ctx: commands.Context = await self.bot.get_context(message) From 1d514f80c696e0b7170cbf168a86862747fab540 Mon Sep 17 00:00:00 2001 From: Brad Duncan <51077147+XargsUK@users.noreply.github.com> Date: Thu, 8 Jul 2021 07:37:37 +0100 Subject: [PATCH 20/24] adding no response exit condition Previously, if no response was provided by the user, the function would continuously loop. I've modified the timeout to 20 seconds. When there's no response, +! to timeoutcount variable. When there's been 3 timeouts, break. --- recyclingplant/recyclingplant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index cc7bf57..2bf0753 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -32,6 +32,7 @@ class RecyclingPlant(Cog): x = 0 reward = 0 + timeoutcount = 0 await ctx.send( "{0} has signed up for a shift at the Recycling Plant! Type ``exit`` to terminate it early.".format( ctx.author.display_name @@ -53,7 +54,7 @@ class RecyclingPlant(Cog): return m.author == ctx.author and m.channel == ctx.channel try: - answer = await self.bot.wait_for("message", timeout=120, check=check) + answer = await self.bot.wait_for("message", timeout=20, check=check) except asyncio.TimeoutError: answer = None From 15ecf72c6483fe8e61467f042dc890b66bc2bf61 Mon Sep 17 00:00:00 2001 From: Brad Duncan <51077147+XargsUK@users.noreply.github.com> Date: Thu, 8 Jul 2021 07:37:45 +0100 Subject: [PATCH 21/24] Update recyclingplant.py --- recyclingplant/recyclingplant.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index 2bf0753..74ff6e8 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -59,9 +59,14 @@ class RecyclingPlant(Cog): answer = None if answer is None: - await ctx.send( - "``{}`` fell down the conveyor belt to be sorted again!".format(used["object"]) - ) + if timeoutcount == 2: + await ctx.send( + "{} slacked off at work, so they were sacked with no pay.".format(ctx.author.display_name) + ) + break + else: + await ctx.send("{} is slacking, and if they carry on not working, they'll be fired.".format(ctx.author.display_name)) + timeoutcount += 1 elif answer.content.lower().strip() == used["action"]: await ctx.send( "Congratulations! You put ``{}`` down the correct chute! (**+50**)".format( From 698dafade4cde7c3d691babb37e27430a29be0dd Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 8 Jul 2021 08:29:18 -0400 Subject: [PATCH 22/24] Add chatter initialization --- chatter/__init__.py | 6 ++++-- chatter/chat.py | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/chatter/__init__.py b/chatter/__init__.py index 9447c6a..663dadf 100644 --- a/chatter/__init__.py +++ b/chatter/__init__.py @@ -1,8 +1,10 @@ from .chat import Chatter -def setup(bot): - bot.add_cog(Chatter(bot)) +async def setup(bot): + cog = Chatter(bot) + await cog.initialize() + bot.add_cog(cog) # __all__ = ( diff --git a/chatter/chat.py b/chatter/chat.py index 66ff116..4655da8 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -19,6 +19,7 @@ from redbot.core.utils.predicates import MessagePredicate from chatter.trainers import MovieTrainer, TwitterCorpusTrainer, UbuntuCorpusTrainer2 +chatterbot_log = logging.getLogger("red.fox_v3.chatterbot") log = logging.getLogger("red.fox_v3.chatter") @@ -58,11 +59,14 @@ class Chatter(Cog): This cog trains a chatbot that will talk like members of your Guild """ + models = [ENG_SM, ENG_MD, ENG_LG, ENG_TRF] + algos = [SpacySimilarity, JaccardSimilarity, LevenshteinDistance] + def __init__(self, bot): super().__init__() self.bot = bot self.config = Config.get_conf(self, identifier=6710497116116101114) - default_global = {"learning": True} + default_global = {"learning": True, "model_number": 0, "algo_number": 0, "threshold": 0.90} self.default_guild = { "whitelist": None, "days": 1, @@ -79,7 +83,7 @@ class Chatter(Cog): self.tagger_language = ENG_SM self.similarity_algo = SpacySimilarity self.similarity_threshold = 0.90 - self.chatbot = self._create_chatbot() + self.chatbot = None # self.chatbot.set_trainer(ListTrainer) # self.trainer = ListTrainer(self.chatbot) @@ -98,6 +102,18 @@ class Chatter(Cog): """Nothing to delete""" return + async def initialize(self): + all_config = dict(self.config.defaults["GLOBAL"]) + all_config.update(await self.config.all()) + model_number = all_config["model_number"] + algo_number = all_config["algo_number"] + threshold = all_config["threshold"] + + self.tagger_language = self.models[model_number] + self.similarity_algo = self.algos[algo_number] + self.similarity_threshold = threshold + self.chatbot = self._create_chatbot() + def _create_chatbot(self): return ChatBot( @@ -110,7 +126,7 @@ class Chatter(Cog): logic_adapters=["chatterbot.logic.BestMatch"], maximum_similarity_threshold=self.similarity_threshold, tagger_language=self.tagger_language, - logger=log, + logger=chatterbot_log, ) async def _get_conversation(self, ctx, in_channels: List[discord.TextChannel]): @@ -334,15 +350,12 @@ class Chatter(Cog): 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 + Switch the active logic algorithm to one of the three. Default is Spacy 0: Spacy 1: Jaccard 2: Levenshtein """ - - algos = [SpacySimilarity, JaccardSimilarity, LevenshteinDistance] - if algo_number < 0 or algo_number > 2: await ctx.send_help() return @@ -355,8 +368,11 @@ class Chatter(Cog): return else: self.similarity_threshold = threshold + await self.config.threshold.set(self.similarity_threshold) + + self.similarity_algo = self.algos[algo_number] + await self.config.algo_number.set(algo_number) - self.similarity_algo = algos[algo_number] async with ctx.typing(): self.chatbot = self._create_chatbot() @@ -366,21 +382,18 @@ class Chatter(Cog): @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 + Switch the active model to one of the three. Default is Small 0: Small - 1: Medium + 1: Medium (Requires additional setup) 2: Large (Requires additional setup) 3. Accurate (Requires additional setup) """ - - models = [ENG_SM, ENG_MD, ENG_LG, ENG_TRF] - if model_number < 0 or model_number > 3: await ctx.send_help() return - if model_number == 2: + if model_number >= 0: await ctx.maybe_send_embed( "Additional requirements needed. See guide before continuing.\n" "Continue?" ) @@ -393,7 +406,8 @@ class Chatter(Cog): if not pred.result: return - self.tagger_language = models[model_number] + self.tagger_language = self.models[model_number] + await self.config.model_number.set(model_number) async with ctx.typing(): self.chatbot = self._create_chatbot() From 3eb499bf0e0dd3dbc72553fcef39d992d359592b Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 8 Jul 2021 08:30:21 -0400 Subject: [PATCH 23/24] black reformat --- recyclingplant/recyclingplant.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index 74ff6e8..3751648 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -61,11 +61,17 @@ class RecyclingPlant(Cog): if answer is None: if timeoutcount == 2: await ctx.send( - "{} slacked off at work, so they were sacked with no pay.".format(ctx.author.display_name) + "{} slacked off at work, so they were sacked with no pay.".format( + ctx.author.display_name ) + ) break else: - await ctx.send("{} is slacking, and if they carry on not working, they'll be fired.".format(ctx.author.display_name)) + await ctx.send( + "{} is slacking, and if they carry on not working, they'll be fired.".format( + ctx.author.display_name + ) + ) timeoutcount += 1 elif answer.content.lower().strip() == used["action"]: await ctx.send( From a5ff888f4c19c1297a47f15c04f9891cb4e29c7d Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 8 Jul 2021 08:33:29 -0400 Subject: [PATCH 24/24] black reformat --- chatter/storage_adapters.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/chatter/storage_adapters.py b/chatter/storage_adapters.py index b2dc02a..706f96f 100644 --- a/chatter/storage_adapters.py +++ b/chatter/storage_adapters.py @@ -18,9 +18,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): if not self.database_uri: self.database_uri = "sqlite:///db.sqlite3" - self.engine = create_engine( - self.database_uri, connect_args={"check_same_thread": False} - ) + self.engine = create_engine(self.database_uri, connect_args={"check_same_thread": False}) if self.database_uri.startswith("sqlite://"): from sqlalchemy.engine import Engine @@ -31,7 +29,7 @@ class MyDumbSQLStorageAdapter(SQLStorageAdapter): dbapi_connection.execute("PRAGMA journal_mode=WAL") dbapi_connection.execute("PRAGMA synchronous=NORMAL") - if not inspect(self.engine).has_table('Statement'): + if not inspect(self.engine).has_table("Statement"): self.create_database() self.Session = sessionmaker(bind=self.engine, expire_on_commit=True)