commit 3971a76d0295af28c1349e9a52bf133193f71a34 Author: Zastian Pretorius Date: Thu Aug 28 00:21:50 2025 +0100 first commit diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..f719b0f --- /dev/null +++ b/bot.py @@ -0,0 +1,39 @@ +import discord +from discord.ext import commands +import re +import os + +# Set up intents explicitly +intents = discord.Intents.default() +intents.message_content = True # Enable message content access + +# Set up the bot +bot = commands.Bot(command_prefix='!', intents=intents) + +# Event: Bot is ready and connected to Discord +@bot.event +async def on_ready(): + print(f'Logged in as {bot.user.name}') + +# Event: Triggered when a message is sent in a channel the bot can see +@bot.event +async def on_message(message): + # Ignore messages sent by the bot itself to prevent loops + if message.author == bot.user: + return + # Check if the message contains "nixos" (case-insensitive, as a whole word) + if re.search(r'\bnixos\b', message.content, re.IGNORECASE): + # Replace "nixos" with "fagos" (preserving case of the first letter) + new_content = re.sub( + r'\b(nixos)\b', + lambda m: 'Fagos' if m.group(1)[0].isupper() else 'fagos', + message.content, + flags=re.IGNORECASE + ) + # Send the modified message + await message.channel.send(f'{new_content}') + # Allow other commands to process (if any) + await bot.process_commands(message) + +# Run the bot using the token from the environment variable +bot.run(os.getenv('FAGOS_TOKEN')) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9464e76 --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1746904237, + "narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=", + "rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956", + "revCount": 797896, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.797896%2Brev-d89fc19e405cb2d55ce7cc114356846a0ee5e956/0196c1a7-7ad3-74a9-9d50-1b854aca6d6c/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1d7f872 --- /dev/null +++ b/flake.nix @@ -0,0 +1,96 @@ +{ + description = "A Nix-flake-based Python development environment for the Fagos Discord bot"; + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; + outputs = inputs: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import inputs.nixpkgs { inherit system; }; + }); + version = "3.13"; + in + { + # Development shell for `nix develop` + devShells = forEachSupportedSystem ({ pkgs }: + let + concatMajorMinor = v: + pkgs.lib.pipe v [ + pkgs.lib.versions.splitVersion + (pkgs.lib.sublist 0 2) + pkgs.lib.concatStrings + ]; + python = pkgs."python${concatMajorMinor version}"; + in + { + default = pkgs.mkShell { + venvDir = ".venv"; + postShellHook = '' + venvVersionWarn() { + local venvVersion + venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')" + [[ "$venvVersion" == "${python.version}" ]] && return + cat <=2.0.0" +] diff --git a/result b/result new file mode 120000 index 0000000..82182bf --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/3afn3mm8r72bwgni7hlgfx39bqb7scj7-python3.13-fagos-0.1.0 \ No newline at end of file