initial commit
This commit is contained in:
21
.github/workflows/main.yml
vendored
Normal file
21
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: main
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
packages:
|
||||
name: test packages
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.3.4
|
||||
- uses: cachix/install-nix-action@v13
|
||||
with:
|
||||
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20210429_d15a196/install
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
- uses: cachix/cachix-action@v10
|
||||
with:
|
||||
name: natto1784
|
||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||
- run: nix build
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
target/
|
||||
result
|
1307
Cargo.lock
generated
Normal file
1307
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "singh3"
|
||||
version = "0.1.0"
|
||||
authors = [ "Amneesh Singh <natto@weirdnatto.in>" ]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1.22"
|
||||
|
||||
[dependencies.serenity]
|
||||
version = "0.10.8"
|
||||
features = ["cache", "framework", "standard_framework", "rustls_backend", "unstable_discord_api"]
|
||||
|
||||
[dependencies.tokio]
|
||||
version = "1.0"
|
||||
features = ["macros", "signal", "rt-multi-thread"]
|
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
93
flake.lock
generated
Normal file
93
flake.lock
generated
Normal file
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1614513358,
|
||||
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1622966049,
|
||||
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fbfb79400a08bf754e32b4d4fc3f7d8f8055cf94",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1617325113,
|
||||
"narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1623034161,
|
||||
"narHash": "sha256-cbw9X+nVFcpIuBga0hkbtzXbW2fyDWBon6oUN/uQmu0=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "0b952cdfa37f8b0fc70fc75fbd4605227cd0b272",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"locked": {
|
||||
"lastModified": 1622445595,
|
||||
"narHash": "sha256-m+JRe6Wc5OZ/mKw2bB3+Tl0ZbtyxxxfnAWln8Q5qs+Y=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "7d706970d94bc5559077eb1a6600afddcd25a7c8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
37
flake.nix
Normal file
37
flake.nix
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
description = "A simple filehost written in rust";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
|
||||
utils.url = github:numtide/flake-utils;
|
||||
rust-overlay.url = github:oxalica/rust-overlay;
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, utils, rust-overlay }:
|
||||
utils.lib.eachDefaultSystem
|
||||
(system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
in
|
||||
{
|
||||
devShell = with pkgs; mkShell {
|
||||
buildInputs = [
|
||||
rust-bin.nightly.latest.default
|
||||
rust-analyzer
|
||||
];
|
||||
};
|
||||
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
|
||||
pname = "singh3";
|
||||
version = "0.1.0";
|
||||
src = ./. ;
|
||||
nativeBuildInputs = with pkgs; [
|
||||
rust-bin.nightly.latest.default
|
||||
];
|
||||
cargoSha256 = "sha256-qpmDIhgHcSoX/wIJlKNULxrEr+KOrCdXOi7HDuCdlFM=";
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
12
src/general.rs
Normal file
12
src/general.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use serenity::prelude::*;
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::framework::standard::{
|
||||
CommandResult,
|
||||
macros::command
|
||||
};
|
||||
|
||||
#[command]
|
||||
pub async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.reply(ctx, "Pong!").await?;
|
||||
Ok(())
|
||||
}
|
104
src/main.rs
Normal file
104
src/main.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
mod general;
|
||||
use serenity::{
|
||||
async_trait,
|
||||
client::bridge::gateway::ShardManager,
|
||||
framework::{standard::macros::group, StandardFramework},
|
||||
http::Http,
|
||||
model::{
|
||||
event::ResumedEvent,
|
||||
gateway::Ready,
|
||||
interactions::{ApplicationCommand, Interaction, InteractionResponseType, InteractionType, InteractionData},
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
use std::{collections::HashSet, env, sync::Arc};
|
||||
use tracing::{error, info};
|
||||
|
||||
pub struct ShardManagerContainer;
|
||||
use general::*;
|
||||
|
||||
impl TypeMapKey for ShardManagerContainer {
|
||||
type Value = Arc<Mutex<ShardManager>>;
|
||||
}
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
if interaction.kind == InteractionType::ApplicationCommand {
|
||||
if let Some(InteractionData::ApplicationCommand(data)) = interaction.data.as_ref() {
|
||||
let content = match data.name.as_str() {
|
||||
"ping" => "Hey, I'm alive!".to_string(),
|
||||
_ => "not implemented :(".to_string(),
|
||||
};
|
||||
|
||||
if let Err(why) = interaction
|
||||
.create_interaction_response(&ctx.http, |response| {
|
||||
response
|
||||
.kind(InteractionResponseType::ChannelMessageWithSource)
|
||||
.interaction_response_data(|message| message.content(content))
|
||||
})
|
||||
.await
|
||||
{
|
||||
println!("Cannot respond to slash command: {}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
info!("{} connected bhay", ready.user.name);
|
||||
}
|
||||
|
||||
async fn resume(&self, _: Context, _: ResumedEvent) {
|
||||
info!("how th when the");
|
||||
}
|
||||
}
|
||||
|
||||
#[group]
|
||||
#[commands(ping)]
|
||||
struct General;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let token = env::var("DISCORD_TOKEN").expect("Token daal madarchod");
|
||||
|
||||
let http = Http::new_with_token(&token);
|
||||
|
||||
let (owners, bot_id) = match http.get_current_application_info().await {
|
||||
Ok(info) => {
|
||||
let mut owners = HashSet::new();
|
||||
owners.insert(info.owner.id);
|
||||
match http.get_current_user().await {
|
||||
Ok(bot_id) => (owners, bot_id.id),
|
||||
Err(why) => panic!("Could not access the bot id: {:?}", why),
|
||||
}
|
||||
}
|
||||
Err(why) => panic!("Could not access application info: {:?}", why),
|
||||
};
|
||||
|
||||
let framework = StandardFramework::new()
|
||||
.configure(|c| c.owners(owners).prefix("xx"))
|
||||
.group(&GENERAL_GROUP);
|
||||
|
||||
let mut client = Client::builder(&token)
|
||||
.framework(framework)
|
||||
.event_handler(Handler)
|
||||
.application_id(*bot_id.as_u64())
|
||||
.await
|
||||
.expect("Client no wokey");
|
||||
|
||||
{
|
||||
let mut data = client.data.write().await;
|
||||
data.insert::<ShardManagerContainer>(client.shard_manager.clone());
|
||||
}
|
||||
let _ = ApplicationCommand::create_global_application_command(&http, |a| {
|
||||
a.name("ping").description("A simple ping command")
|
||||
})
|
||||
.await;
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
error!("Client error: {:?}", why);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user