initial commit
This commit is contained in:
1289
Cargo.lock
generated
Normal file
1289
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
Cargo.toml
Normal file
18
Cargo.toml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
cargo-features = ["edition2021"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "singh4"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = [ "Amneesh Singh <natto@weirdnatto.in>" ]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tracing = "*"
|
||||||
|
|
||||||
|
[dependencies.serenity]
|
||||||
|
version = "0.10.10"
|
||||||
|
features = ["cache", "framework", "standard_framework", "rustls_backend", "unstable_discord_api", "collector"]
|
||||||
|
|
||||||
|
[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
|
||||||
|
}
|
54
flake.nix
Normal file
54
flake.nix
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
description = "singh4 discord bot";
|
||||||
|
|
||||||
|
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
|
||||||
|
rec {
|
||||||
|
devShells = with pkgs; {
|
||||||
|
default = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
rust-analyzer
|
||||||
|
];
|
||||||
|
};
|
||||||
|
bare = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
withLSP = mkShell
|
||||||
|
{
|
||||||
|
buildInputs = [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
rust-analyzer
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
devShell = devShells.default;
|
||||||
|
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "singh4";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
rust-bin.nightly.latest.default
|
||||||
|
];
|
||||||
|
cargoSha256 = "sha256-DhWWUNDpDsao6lOogoM5UfUgrUfEmZvCpY0pxmr4/mI=";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
18
src/handler/mod.rs
Normal file
18
src/handler/mod.rs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
use serenity::{
|
||||||
|
async_trait,
|
||||||
|
model::{event::ResumedEvent, gateway::Ready},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
|
pub struct Handler;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl EventHandler for Handler {
|
||||||
|
async fn ready(&self, _: Context, ready: Ready) {
|
||||||
|
println!("{} connected bhay", ready.user.name);
|
||||||
|
}
|
||||||
|
async fn resume(&self, _: Context, _: ResumedEvent) {
|
||||||
|
info!("how th when the");
|
||||||
|
}
|
||||||
|
}
|
77
src/main.rs
Normal file
77
src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
mod handler;
|
||||||
|
use handler::Handler;
|
||||||
|
use serenity::{
|
||||||
|
client::bridge::gateway::ShardManager,
|
||||||
|
framework::{
|
||||||
|
standard::{
|
||||||
|
help_commands,
|
||||||
|
macros::help,
|
||||||
|
Args, CommandGroup, CommandResult, HelpOptions,
|
||||||
|
},
|
||||||
|
StandardFramework,
|
||||||
|
},
|
||||||
|
http::Http,
|
||||||
|
model::{channel::Message, id::UserId},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
use std::{collections::HashSet, env, sync::Arc};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
|
struct ShardManagerContainer;
|
||||||
|
impl TypeMapKey for ShardManagerContainer {
|
||||||
|
type Value = Arc<Mutex<ShardManager>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[help]
|
||||||
|
#[max_levenshtein_distance(2)]
|
||||||
|
#[indention_prefix = "+"]
|
||||||
|
#[lacking_role = "Nothing"]
|
||||||
|
#[wrong_channel = "Strike"]
|
||||||
|
async fn my_help(
|
||||||
|
context: &Context,
|
||||||
|
msg: &Message,
|
||||||
|
args: Args,
|
||||||
|
help_options: &'static HelpOptions,
|
||||||
|
groups: &[&'static CommandGroup],
|
||||||
|
owners: HashSet<UserId>,
|
||||||
|
) -> CommandResult {
|
||||||
|
let _ = help_commands::with_embeds(context, msg, args, help_options, groups, owners).await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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(","))
|
||||||
|
.help(&MY_HELP);
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(why) = client.start().await {
|
||||||
|
error!("Client error: {:?}", why);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user