stage changes
This commit is contained in:
parent
4788157455
commit
def12bf247
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2023-2024 George Kusayko [L-Nafaryus] <l.nafaryus@gmail.com>
|
||||
|
||||
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.
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Oscuro - Discord Bot (Nim)
|
||||
|
||||
# License
|
||||
|
||||
|
||||
**oscuro** is licensed under the [MIT License](LICENSE).
|
BIN
discord_bot
BIN
discord_bot
Binary file not shown.
@ -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"
|
||||
|
19
flake.nix
19
flake.nix
@ -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; };
|
||||
}
|
||||
);
|
||||
}
|
11
shell.nix
11
shell.nix
@ -1,11 +0,0 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
with pkgs;
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
nixpkgs-fmt
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
# ...
|
||||
'';
|
||||
}
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user