From e603a932dcbb478d5d08fe0073ea2c90be8e016b Mon Sep 17 00:00:00 2001 From: DavidSiegl Date: Tue, 29 Oct 2024 18:20:33 +0100 Subject: [PATCH 1/9] added event for auto-reply to dms --- src/disco/__main__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/disco/__main__.py b/src/disco/__main__.py index 7a63801..31b7206 100644 --- a/src/disco/__main__.py +++ b/src/disco/__main__.py @@ -30,6 +30,7 @@ # Discord bot setup intents = discord.Intents.default() intents.message_content = True +intents.dm_messages = True bot = commands.Bot(command_prefix="!", intents=intents) @@ -102,6 +103,16 @@ async def on_ready() -> None: # noqa RUF029 synchronize_podcasts.start() +@bot.event +async def on_message(message) -> None: + # Check if the message is a DM and that it is not from the bot itself + if message.guild is None and message.author != bot.user: + # Send an automatic reply + await message.channel.send("Ich bin ein Bot. Meine Inbox wird daher nicht überwacht. Mehr Antworten bekommst du von mir nicht.") + + await bot.process_commands(message) + + def main() -> int: """ Entry point for the Discord bot. From 7a718ec094eeee504e8ceda2292547e9e9c06ed3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:22:43 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/disco/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/disco/__main__.py b/src/disco/__main__.py index 31b7206..da380d9 100644 --- a/src/disco/__main__.py +++ b/src/disco/__main__.py @@ -108,7 +108,9 @@ async def on_message(message) -> None: # Check if the message is a DM and that it is not from the bot itself if message.guild is None and message.author != bot.user: # Send an automatic reply - await message.channel.send("Ich bin ein Bot. Meine Inbox wird daher nicht überwacht. Mehr Antworten bekommst du von mir nicht.") + await message.channel.send( + "Ich bin ein Bot. Meine Inbox wird daher nicht überwacht. Mehr Antworten bekommst du von mir nicht." + ) await bot.process_commands(message) From 235277c552d2d37ef1b7f04b2ed7eb40be84f4fa Mon Sep 17 00:00:00 2001 From: DavidSiegl Date: Tue, 29 Oct 2024 18:26:11 +0100 Subject: [PATCH 3/9] added description to func --- src/disco/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/disco/__main__.py b/src/disco/__main__.py index 31b7206..7aa76d3 100644 --- a/src/disco/__main__.py +++ b/src/disco/__main__.py @@ -105,6 +105,7 @@ async def on_ready() -> None: # noqa RUF029 @bot.event async def on_message(message) -> None: + """Auto response in case of retrieving a DM.""" # Check if the message is a DM and that it is not from the bot itself if message.guild is None and message.author != bot.user: # Send an automatic reply From 921778b6e2c8a87923bf6831001f18920342575f Mon Sep 17 00:00:00 2001 From: "Fabian H. Schneider" <4962476+FlotterCodername@users.noreply.github.com> Date: Sat, 2 Nov 2024 22:46:17 +0100 Subject: [PATCH 4/9] remove old example code --- res/misc/example_autoresponder.py | 65 ------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 res/misc/example_autoresponder.py diff --git a/res/misc/example_autoresponder.py b/res/misc/example_autoresponder.py deleted file mode 100644 index b91d1ec..0000000 --- a/res/misc/example_autoresponder.py +++ /dev/null @@ -1,65 +0,0 @@ -# mypy: ignore-errors -""" -Copyright © 2024 Fabian H. Schneider - -This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -If a copy of the MPL was not distributed with this file, -You can obtain one at https://mozilla.org/MPL/2.0/. -""" - -# based on: https://discordpy.readthedocs.io/en/stable/quickstart.html -import os -import re -import textwrap - -import discord - -# This example requires the 'message_content' intent. -intents = discord.Intents.default() -intents.message_content = True - -client = discord.Client(intents=intents) - -RE_MINDSET = re.compile(r"mindset", re.IGNORECASE) -RE_RESILIENZ = re.compile(r"resilienz", re.IGNORECASE) - - -@client.event -def on_ready() -> None: - """Logged in to Discord, let's log this very important event.""" - print(f"We have logged in as {client.user}") - - -@client.event -async def on_message(message: discord.Message) -> None: - """ - Respond to messages that contain 'mindset' or 'resilienz'. - - :param message: the message to (potentially) respond to - """ - print(message, type(message)) - if message.author == client.user: - return - - is_mindset = RE_MINDSET.search(message.content) - is_resilienz = RE_RESILIENZ.search(message.content) - - if is_mindset and is_resilienz: - await message.channel.send( - "Da versucht wohl jemand, möglichst viele Hasswörter von Wolfgang M. Schmitt zu verwenden." - ) - elif is_mindset: - await message.channel.send( - textwrap.dedent("""\ - "Wer Mindset sagt, hat den Verstand schon lange verloren." - --Wolfgang M. Schmitt""") - ) - elif is_resilienz: - await message.channel.send( - textwrap.dedent("""\ - "Wer Resilienz sagt, will betrügen." - --Wolfgang M. Schmitt""") - ) - - -client.run(os.getenv("DISCORD_TOKEN")) From cace0046daf21f9310ca5a95ce261219559f2aad Mon Sep 17 00:00:00 2001 From: "Fabian H. Schneider" <4962476+FlotterCodername@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:26:33 +0100 Subject: [PATCH 5/9] fix docstring --- src/disco/schemas/docgen.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/disco/schemas/docgen.py b/src/disco/schemas/docgen.py index 1c65391..657529b 100644 --- a/src/disco/schemas/docgen.py +++ b/src/disco/schemas/docgen.py @@ -35,8 +35,7 @@ def generate_markdown(self, schema: dict[str, Any]) -> str: Generate Markdown documentation from a JSONSchema. :param schema: The JSONSchema dictionary - Returns: - str: Generated Markdown documentation + :return: Generated Markdown documentation """ sections: list[str] = [] if schema.get("description"): From 4d2c50ad3c3f42eb7119e410f1c2495354569da7 Mon Sep 17 00:00:00 2001 From: "Fabian H. Schneider" <4962476+FlotterCodername@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:39:04 +0100 Subject: [PATCH 6/9] update doc building run configs --- .../runConfigurations/Docs___Build_locally.xml | 17 +++++++++++++++++ ...y_dirhtml.xml => Docs___Open_in_browser.xml} | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .idea/runConfigurations/Docs___Build_locally.xml rename .idea/runConfigurations/{python___docs_make_py_dirhtml.xml => Docs___Open_in_browser.xml} (73%) diff --git a/.idea/runConfigurations/Docs___Build_locally.xml b/.idea/runConfigurations/Docs___Build_locally.xml new file mode 100644 index 0000000..4b93d1f --- /dev/null +++ b/.idea/runConfigurations/Docs___Build_locally.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/python___docs_make_py_dirhtml.xml b/.idea/runConfigurations/Docs___Open_in_browser.xml similarity index 73% rename from .idea/runConfigurations/python___docs_make_py_dirhtml.xml rename to .idea/runConfigurations/Docs___Open_in_browser.xml index 04c9886..2ac1b3a 100644 --- a/.idea/runConfigurations/python___docs_make_py_dirhtml.xml +++ b/.idea/runConfigurations/Docs___Open_in_browser.xml @@ -1,6 +1,6 @@ - -