From de91a303e29598740a2f17e4037dae222f48d0da Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Sat, 13 Sep 2025 17:14:59 +0530 Subject: [PATCH] initial commit Signed-off-by: Amneesh Singh --- .clang-format | 7 ++++ .clang-tidy | 12 +++++++ .clangd | 2 ++ .gitignore | 10 ++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++ flake.nix | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 13 ++++++++ src/main.cc | 29 +++++++++++++++++ src/meson.build | 15 +++++++++ 9 files changed, 234 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .clangd create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 meson.build create mode 100644 src/main.cc create mode 100644 src/meson.build diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4c3aa89 --- /dev/null +++ b/.clang-format @@ -0,0 +1,7 @@ +BasedOnStyle: GNU +IndentWidth: 4 +BreakBeforeBraces: Attach +AlwaysBreakTemplateDeclarations: Yes +AlignConsecutiveAssignments: Consecutive +BreakAfterAttributes: Always +AllowShortEnumsOnASingleLine: False \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..1880e5f --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,12 @@ +Checks: ' + , clang-analyzer-* + , cppcoreguidelines-* + , -cppcoreguidelines-avoid-magic-numbers + , -cppcoreguidelines-pro-bounds-constant-array-index + , -cppcoreguidelines-macro-usage + , -cppcoreguidelines-avoid-const-or-ref-data-members + , -cppcoreguidelines-non-private-member-variables-in-classes + , -cppcoreguidelines-avoid-non-const-global-variables + , -cppcoreguidelines-pro-type-member-init + , -cppcoreguidelines-init-variables +' \ No newline at end of file diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..0a4f13f --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + CompilationDatabase: build/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ccf4988 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Direnv +.envrc +.direnv/ + +# Emacs +*~ +\#*\# + +# Cache +.cache/ \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..96c6cc8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1757686808, + "narHash": "sha256-PL+Z3OrNpFNHddbsBaxeojYkWObYc2NlyhTmsmpt+hc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "098982b6eca9b809cc2f583e733338f5a36b3ad8", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f714e0a --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "singh5 discord bot"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + inputs@{ + self, + nixpkgs, + utils, + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + }; + + src = pkgs.lib.sourceFilesBySuffices ./. [ + ".hh" + ".cc" + ".build" + ".options" + ]; + + llvm = pkgs.llvmPackages_21; + + package = + { stdenv }: + stdenv.mkDerivation { + name = "singh5"; + version = "0.1"; + inherit src; + + outputs = [ "out" ]; + + nativeBuildInputs = with pkgs; [ + meson + ninja + pkg-config + ]; + + buildInputs = with pkgs; [ + (dpp.override { inherit stdenv; }) + (ffmpeg.overrideAttrs (_: { + inherit stdenv; + makeFlags = [ + "HOSTCC=$\{CC}" + "HOSTLD=$\{LD}" + ]; + })) + ]; + }; + + shell = + { stdenv }: + pkgs.mkShell.override { inherit stdenv; } { + name = "singh5"; + inputsFrom = [ (package { inherit stdenv; }) ]; + packages = with pkgs; [ + llvm.clang-tools + ]; + }; + + in + { + packages = rec { + singh5 = package { stdenv = pkgs.gcc15Stdenv; }; + singh5-clang = package { stdenv = llvm.libcxxStdenv; }; + default = singh5-clang; + }; + + devShells = rec { + singh5 = shell { stdenv = pkgs.gcc15Stdenv; }; + singh5-clang = shell { stdenv = llvm.libcxxStdenv; }; + default = singh5-clang; + }; + + formatter = pkgs.nixfmt-tree; + } + ); +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..16ff38c --- /dev/null +++ b/meson.build @@ -0,0 +1,13 @@ +project('singh5', 'cpp', + version : '0.1', + license : 'GPLv3', + default_options : ['warning_level=3', + 'werror=true', + 'optimization=3', + 'cpp_std=c++23']) + +compiler = meson.get_compiler('cpp') + +lib_cpp_args = [] + +subdir('src') \ No newline at end of file diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..9d51a4f --- /dev/null +++ b/src/main.cc @@ -0,0 +1,29 @@ +#include +#include + +const char * +get_bot_token () { + return getenv ("BOT_TOKEN"); +} + +int +main () { + dpp::cluster bot (get_bot_token ()); + + bot.on_log (dpp::utility::cout_logger ()); + + bot.on_slashcommand ([] (const dpp::slashcommand_t &event) { + if (event.command.get_command_name () == "ping") { + event.reply ("Pong!"); + } + }); + + bot.on_ready ([&bot] (const dpp::ready_t &_) { + if (dpp::run_once ()) { + bot.global_command_create ( + dpp::slashcommand ("ping", "Ping pong!", bot.me.id)); + } + }); + + bot.start (dpp::st_wait); +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..ec13605 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,15 @@ +sources = files( + 'main.cc', +) + +dpp = dependency('dpp', version: '>=10.1.2', static: true) +libavformat = dependency('libavformat', version: '>=61.7.100') +libavcodec = dependency('libavcodec', version: '>=61.19.101') + +executable( + 'singh5', + sources, + dependencies: [ dpp, libavformat, libavcodec ], + install : true, + cpp_args: lib_cpp_args +) \ No newline at end of file