diff --git a/.envrc b/.envrc deleted file mode 100644 index 3550a30..0000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fe24b2e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2023-2024 George Kusayko [L-Nafaryus] + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7eeb49a --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Oscuro - Discord Bot (Nim) + +# License + + +**oscuro** is licensed under the [MIT License](LICENSE). diff --git a/discord_bot b/discord_bot deleted file mode 100755 index 0ad61c5..0000000 Binary files a/discord_bot and /dev/null differ diff --git a/discord_bot.nimble b/discord_bot.nimble index d339c17..eded58c 100644 --- a/discord_bot.nimble +++ b/discord_bot.nimble @@ -5,10 +5,11 @@ author = "L-Nafaryus" description = "Discord bot with nim" license = "MIT" srcDir = "src" -bin = @["discord_bot"] +bin = @["dicord_bot"] # Dependencies requires "nim >= 1.6.8" requires "dimscord" +requires "dimscmd" diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 6e48398..0000000 --- a/flake.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ - description = "my project description"; - - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; -}; - - outputs = { self, nixpkgs, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem - (system: - let - pkgs = import nixpkgs { inherit system overlays }; - in - { - devShells.default = import ./shell.nix { inherit pkgs; }; - } - ); -} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index a2a38da..0000000 --- a/shell.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ pkgs ? import { } }: -with pkgs; -mkShell { - buildInputs = [ - nixpkgs-fmt - ]; - - shellHook = '' - # ... - ''; -} diff --git a/src/discord_bot.nim b/src/discord_bot.nim index 862d40c..2978782 100644 --- a/src/discord_bot.nim +++ b/src/discord_bot.nim @@ -1,5 +1,74 @@ -# This is just an example to get you started. A typical binary package -# uses this file as the main entry point of the application. +{.define: ssl.} -when isMainModule: - echo("Hello, World!") +import os, httpclient, asyncdispatch +import times, options, strutils, options +import dimscord, dimscmd + +let discord = newDiscordClient(getEnv("BOT_TOKEN")) +var cmd = discord.newHandler() + +proc reply(msg: Message, text: string): Future[Message] {.async.} = + result = await discord.api.sendMessage(msg.channelId, text) + +proc reply(i: Interaction, text: string) {.async.} = + let response = InteractionResponse( + kind: irtChannelMessageWithSource, + data: some InteractionApplicationCommandCallbackData(content: text) + ) + await discord.api.createInteractionResponse(i.id, i.token, response) + +cmd.addChat("hi") do (): + discard await msg.reply("hello") + +cmd.addChat("notacat") do (): + ## asd + let client = newHttpClient() + try: + let res = client.get("https://cataas.com/cat") + echo "Fetching a cat: ", res.status, ", ", res.headers["content-type"].string + echo "cat." & res.headers["content-type"].split("/")[1] + + ## Invalid JSON (50109) + #[let attach = Attachment( + filename: "cat." & res.headers["content-type"].split("/")[1], + content_type: some res.headers["content-type"].string, + file: res.body, + ) + echo attach + + let response = InteractionResponse( + kind: irtChannelMessageWithSource, + data: some InteractionApplicationCommandCallbackData(content: "asd", attachments: @[ attach ]) + ) + await discord.api.createInteractionResponse(i.id, i.token, response)]# + + discard await discord.api.sendMessage(msg.channelId, files = @[DiscordFile( + name: "cat." & res.headers["content-type"].split("/")[1], + body: res.body + )]) + + except: + var error = getCurrentException() + echo "Exception occurred: ", error.msg + + + #[discard await discord.api.sendMessage(msg.channelId, "smh", + files = @[DiscordFile(body: res.body)] + )]# + +# Handle event for on_ready. +proc onReady(s: Shard, r: Ready) {.event(discord).} = + await cmd.registerCommands() + echo "Ready as " & $r.user + +proc interactionCreate(s: Shard, i: Interaction) {.event(discord).} = + discard await cmd.handleInteraction(s, i) + +# Handle event for message_create. +proc messageCreate(s: Shard, msg: Message) {.event(discord).} = + if msg.author.bot: return + + discard await cmd.handleMessage("./", s, msg) + +# Connect to Discord and run the bot. +waitFor discord.startSession()