update serenity, use debug_say

This commit is contained in:
Edward Shen 2020-05-02 14:37:34 -04:00
parent 8c8b6a5400
commit 6090db30bc
Signed by: edward
GPG key ID: 19182661E818369F
8 changed files with 118 additions and 80 deletions

115
Cargo.lock generated
View file

@ -186,9 +186,9 @@ checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
[[package]]
name = "cc"
version = "1.0.50"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
[[package]]
name = "cfg-if"
@ -226,7 +226,7 @@ dependencies = [
[[package]]
name = "command_attr"
version = "0.2.0"
source = "git+https://github.com/Lakelezz/serenity?branch=await#0fad30bdf491b5cdc003ebb12bf33d3ea4233df5"
source = "git+https://github.com/Lakelezz/serenity?branch=await#c34014b6bc3b0e7fd883cb106099d3c710f2d257"
dependencies = [
"futures",
"proc-macro2",
@ -537,9 +537,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
version = "0.1.11"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0d737e0f947a1864e93d33fdef4af8445a00d1ed8dc0c8ddb73139ea6abf15"
checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
dependencies = [
"libc",
]
@ -674,9 +674,9 @@ checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
[[package]]
name = "js-sys"
version = "0.3.38"
version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b823ebafcee1632403f2782d28728aab353f7881547a700043ef455c078326f"
checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7"
dependencies = [
"wasm-bindgen",
]
@ -762,9 +762,9 @@ dependencies = [
[[package]]
name = "mio"
version = "0.6.21"
version = "0.6.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f"
checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430"
dependencies = [
"cfg-if",
"fuchsia-zircon",
@ -793,9 +793,9 @@ dependencies = [
[[package]]
name = "mio-uds"
version = "0.6.7"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
dependencies = [
"iovec",
"libc",
@ -844,9 +844,9 @@ dependencies = [
[[package]]
name = "net2"
version = "0.2.33"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"
checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
dependencies = [
"cfg-if",
"libc",
@ -882,6 +882,12 @@ dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"
[[package]]
name = "opaque-debug"
version = "0.2.3"
@ -955,9 +961,9 @@ checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae"
[[package]]
name = "pin-utils"
version = "0.1.0-alpha.4"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
@ -985,9 +991,9 @@ checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694"
[[package]]
name = "proc-macro2"
version = "1.0.10"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319"
dependencies = [
"unicode-xid",
]
@ -1000,9 +1006,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7"
dependencies = [
"proc-macro2",
]
@ -1120,13 +1126,13 @@ dependencies = [
[[package]]
name = "ring"
version = "0.16.12"
version = "0.16.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c"
checksum = "703516ae74571f24b465b4a1431e81e2ad51336cb0ded733a55a1aa3eccac196"
dependencies = [
"cc",
"lazy_static",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
@ -1173,9 +1179,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76"
checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1"
[[package]]
name = "schannel"
@ -1199,9 +1205,9 @@ dependencies = [
[[package]]
name = "security-framework"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "572dfa3a0785509e7a44b5b4bebcf94d41ba34e9ed9eb9df722545c3b3c4144a"
checksum = "3f331b9025654145cd425b9ded0caf8f5ae0df80d418b326e2dc1c3dc5eb0620"
dependencies = [
"bitflags",
"core-foundation",
@ -1212,9 +1218,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ddb15a5fec93b7021b8a9e96009c5d8d51c15673569f7c0f6b7204e5b7b404f"
checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
dependencies = [
"core-foundation-sys",
"libc",
@ -1242,9 +1248,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.51"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9"
checksum = "a7894c8ed05b7a3a279aeb79025fdec1d3158080b75b98a08faf2806bb799edd"
dependencies = [
"itoa",
"ryu",
@ -1265,8 +1271,8 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.8.4"
source = "git+https://github.com/Lakelezz/serenity?branch=await#0fad30bdf491b5cdc003ebb12bf33d3ea4233df5"
version = "0.8.6"
source = "git+https://github.com/Lakelezz/serenity?branch=await#c34014b6bc3b0e7fd883cb106099d3c710f2d257"
dependencies = [
"async-tls",
"async-trait",
@ -1321,9 +1327,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05720e22615919e4734f6a99ceae50d00226c3c5aca406e102ebc33298214e0a"
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
[[package]]
name = "socket2"
@ -1409,9 +1415,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.17"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213"
dependencies = [
"proc-macro2",
"quote",
@ -1481,20 +1487,19 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.42"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]]
name = "tokio"
version = "0.2.18"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ef16d072d2b6dc8b4a56c70f5c5ced1a37752116f8e7c1e80c659aa7cb6713"
checksum = "05c1d570eb1a36f0345a5ce9c6c6e665b70b73d11236912c0b477616aeec47b1"
dependencies = [
"bytes",
"fnv",
@ -1698,9 +1703,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasm-bindgen"
version = "0.2.61"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f56e97dbea16d5f56549d6c8ea7f36efb6be98507308650c1a5970574b3941b9"
checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551"
dependencies = [
"cfg-if",
"serde",
@ -1710,9 +1715,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.61"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75d4f3f9b81dfc7d66b955876b325b20e8affd4ce8d93e51162626fc5faadb"
checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94"
dependencies = [
"bumpalo",
"lazy_static",
@ -1725,9 +1730,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.11"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "736dcd8f8455458c82614f12116aabd0209d440c1a28d8824bcaed755ac3e058"
checksum = "8a369c5e1dfb7569e14d62af4da642a3cbc2f9a3652fe586e26ac22222aa4b04"
dependencies = [
"cfg-if",
"js-sys",
@ -1737,9 +1742,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.61"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcde4b19e863521c1e78ecf100935132396291b09ae0ae2e155ff84ccbe9736"
checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1747,9 +1752,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.61"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13d87d2b117af2b86472402d70f7eb173bbe166beb5e727f3c0bebecdf356504"
checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a"
dependencies = [
"proc-macro2",
"quote",
@ -1760,15 +1765,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.61"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71f77b681efd0bca6f8ea356cdc2e497538b41d3e2a02afed18ce8f022231d29"
checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad"
[[package]]
name = "web-sys"
version = "0.3.38"
version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07c5819dc39222a788ca169a81aef7d02739019256300534f493b5747d5469c2"
checksum = "8bc359e5dd3b46cb9687a051d50a2fdd228e4ba7cf6fcf861a5365c3d671a642"
dependencies = [
"js-sys",
"wasm-bindgen",

View file

@ -4,8 +4,6 @@ version = "0.1.0"
authors = ["Edward Shen <code@eddie.sh>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "2"
serenity = { git = "https://github.com/Lakelezz/serenity", branch = "await"}

View file

@ -1,14 +1,15 @@
use crate::util::debug_say;
use log::error;
use serenity::framework::standard::{macros::command, Args, CommandResult};
use serenity::model::channel::Message;
use serenity::prelude::Context;
#[command]
async fn clap(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
async fn clap(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let resp = match args
.iter()
.map(|arg: Result<String, _>| match arg {
Ok(arg) => arg,
Ok(arg) => arg.trim().to_string(),
Err(e) => {
error!(
"Failed to cast clap arg to String; returning empty string instead: {:?}",
@ -28,6 +29,7 @@ async fn clap(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult
args => args.join(" :clap: "),
};
msg.channel_id.say(ctx, resp).await?;
debug_say(msg, ctx, resp).await?;
Ok(())
}

View file

@ -1,3 +1,4 @@
use crate::util::debug_say;
/// This was directly ported from the Java version. I make no quality assurances.
use serenity::framework::standard::{macros::command, Args, CommandResult};
use serenity::model::channel::Message;
@ -5,7 +6,7 @@ use serenity::prelude::Context;
use unicode_segmentation::UnicodeSegmentation;
#[command]
pub(crate) async fn cube(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
pub(crate) async fn cube(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let resp = match args
.iter()
.map(|e: Result<String, _>| e.unwrap())
@ -37,7 +38,7 @@ pub(crate) async fn cube(ctx: &mut Context, msg: &Message, mut args: Args) -> Co
}
};
msg.channel_id.say(ctx, resp).await?;
debug_say(msg, ctx, resp).await?;
Ok(())
}

View file

@ -1,18 +1,19 @@
use crate::DbConnPool;
use crate::{util::debug_say, DbConnPool};
use serenity::framework::standard::{macros::command, CommandResult};
use serenity::model::channel::Message;
use serenity::prelude::Context;
#[command]
async fn heck(ctx: &mut Context, msg: &Message) -> CommandResult {
async fn heck(ctx: &Context, msg: &Message) -> CommandResult {
let db_pool = ctx.data.clone();
let mut db_pool = db_pool.write().await;
let db_pool = db_pool
.get_mut::<DbConnPool>()
.expect("No db pool in context?!");
let value = db_pool.get_heck().await;
msg.channel_id
.say(
debug_say(
msg,
ctx,
format!("This command has been hecked {} times", value?),
)

View file

@ -1,11 +1,10 @@
use crate::util::debug_say;
use serenity::framework::standard::{macros::command, CommandResult};
use serenity::model::channel::Message;
use serenity::prelude::Context;
#[command]
async fn source(ctx: &mut Context, msg: &Message) -> CommandResult {
msg.channel_id
.say(ctx, "https://git.eddie.sh/edward/discord-kurante")
.await?;
async fn source(ctx: &Context, msg: &Message) -> CommandResult {
debug_say(msg, ctx, "https://git.eddie.sh/edward/discord-kurante").await?;
Ok(())
}

View file

@ -45,11 +45,9 @@ async fn run() -> Result<(), KuranteError> {
}
};
let mut client = Client::new_with_extras(token, |extras| {
extras
let mut client = Client::new(token)
.event_handler(Handler::default())
.framework(framework)
})
.await?;
{

View file

@ -1,2 +1,36 @@
use lazy_static::lazy_static;
use serenity::{http::Http, model::channel::Message};
use std::env::var;
pub mod db;
pub mod error;
lazy_static! {
static ref BOT_OWNER_ID: u64 = var("BOT_OWNER_ID")
.unwrap_or_else(|_| {
log::warn!("`BOT_OWNER_ID` env var missing, bot will never respond in debug mode!");
String::new()
})
.parse()
.unwrap_or_else(|_| {
log::error!(
"`BOT_OWNER_ID` env var is not a valid u64! Bot will never respond in debug mode!"
);
0
});
}
pub async fn debug_say(
msg: &Message,
ctx: impl AsRef<Http>,
resp: impl std::fmt::Display,
) -> Result<Option<Message>, serenity::Error> {
if cfg!(debug_assertions) && *msg.author.id.as_u64() == *BOT_OWNER_ID {
Ok(Some(
msg.channel_id.say(ctx, format!("DEBUG: {}", resp)).await?,
))
} else if !cfg!(debug_assertions) {
Ok(Some(msg.channel_id.say(ctx, resp).await?))
} else {
Ok(None)
}
}