From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.149]) by gnuweeb.org (Postfix) with ESMTPSA id BD4B180F5A; Sun, 25 Sep 2022 21:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1664140501; bh=64Ro+87dLM9oGJ6td1CpZntEn0zpFYrwDQLGDOJUkOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PR6lAaY4lwT8aoyawtMSxx1Mig0p3wsPfpXm06qTUnUGS7P9Gkm4vDnsiO18nxqGG BqavqIoyWr866+vwHFTLwlLbGmi1tUKRUudkgzIkfBskNdrxqdZ7dVsMpa94BjFFkk 7onSxshKyZBIMSBwjqMGRjlFmqtycUV2wHyXn/ZOQPnRGmlfUFEawokk8zuA1gqdb8 qVb5FdhXIYS6ndb8RusZ+0v8GGWL8v4eRSRMh6TydJk0DXvqtiz6ppcEuv2w8Iqi5l 7vwJPjOS4O5rpsY4ZvyYVG0Cdg9G6Nch2ooiEEXoMvBEhXCNaS1iqvv0T4GkynOqyZ ZngYKDazbNGdA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [RFC PATCH v5 08/18] discord: Initial work for the Discord bot Date: Mon, 26 Sep 2022 04:14:17 +0700 Message-Id: <20220925211427.412-9-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220925211427.412-1-kiizuha@gnuweeb.org> References: <20220925211427.412-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Initialize Discord bot, the feature only has a game activity to tell it that the bot is successfully running. Signed-off-by: Muhammad Rizki --- .gitignore | 1 + daemon/dc.py | 20 ++++++++++++++++ daemon/discord.env.example | 11 +++++++++ daemon/dscord/config.py.example | 13 +++++++++++ daemon/dscord/gnuweeb/__init__.py | 6 +++++ daemon/dscord/gnuweeb/client.py | 28 +++++++++++++++++++++++ daemon/dscord/gnuweeb/plugins/__init__.py | 11 +++++++++ 7 files changed, 90 insertions(+) create mode 100644 daemon/dc.py create mode 100644 daemon/discord.env.example create mode 100644 daemon/dscord/config.py.example create mode 100644 daemon/dscord/gnuweeb/__init__.py create mode 100644 daemon/dscord/gnuweeb/client.py create mode 100644 daemon/dscord/gnuweeb/plugins/__init__.py diff --git a/.gitignore b/.gitignore index e77815f..ad5ade0 100644 --- a/.gitignore +++ b/.gitignore @@ -142,3 +142,4 @@ data.json # configuration file daemon/*.env daemon/telegram/config.py +daemon/dscord/config.py diff --git a/daemon/dc.py b/daemon/dc.py new file mode 100644 index 0000000..ff29abe --- /dev/null +++ b/daemon/dc.py @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +import os +from dotenv import load_dotenv + +from dscord.gnuweeb import GWClient + + +def main(): + load_dotenv("discord.env") + + client = GWClient() + client.run(os.getenv("DISCORD_TOKEN"), log_handler=None) + + +if __name__ == "__main__": + main() diff --git a/daemon/discord.env.example b/daemon/discord.env.example new file mode 100644 index 0000000..60fcfac --- /dev/null +++ b/daemon/discord.env.example @@ -0,0 +1,11 @@ +# Input your Discord bot token below +DISCORD_TOKEN= + +# Input your MySQL connection below +DB_HOST= +DB_USER= +DB_PASS= +DB_NAME= + +# Storage directory to save patch files +STORAGE_DIR= diff --git a/daemon/dscord/config.py.example b/daemon/dscord/config.py.example new file mode 100644 index 0000000..6dd4313 --- /dev/null +++ b/daemon/dscord/config.py.example @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +# Paste the admin role ID below +# to filter only admin who can +# access add/delete lore commands. +ADMIN_ROLE_ID = + +# The activity name like "Playing Genshin Impact" +# you set the value as "Genshin Impact" +ACTIVITY_NAME = diff --git a/daemon/dscord/gnuweeb/__init__.py b/daemon/dscord/gnuweeb/__init__.py new file mode 100644 index 0000000..f3d814a --- /dev/null +++ b/daemon/dscord/gnuweeb/__init__.py @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +from .client import GWClient diff --git a/daemon/dscord/gnuweeb/client.py b/daemon/dscord/gnuweeb/client.py new file mode 100644 index 0000000..fa07fb1 --- /dev/null +++ b/daemon/dscord/gnuweeb/client.py @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + +import discord +from discord.ext import commands +from discord import Intents +from dscord.config import ACTIVITY_NAME + + +class GWClient(commands.Bot): + def __init__(self) -> None: + intents = Intents.default() + intents.message_content = True + super().__init__( + command_prefix=["$", "."], + description="Just a bot for receiving lore emails.", + intents=intents, + activity=discord.Game(ACTIVITY_NAME) + ) + + + async def setup_hook(self): + await self.load_extension( + name=".gnuweeb.plugins", + package="dscord" + ) diff --git a/daemon/dscord/gnuweeb/plugins/__init__.py b/daemon/dscord/gnuweeb/plugins/__init__.py new file mode 100644 index 0000000..b9a7e37 --- /dev/null +++ b/daemon/dscord/gnuweeb/plugins/__init__.py @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 Muhammad Rizki +# + + +from discord.ext import commands + + +async def setup(bot: "commands.Bot"): + pass -- Muhammad Rizki