-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
use log::{error, info}; | ||
|
||
#[allow(unused_imports)] // They aren't unused | ||
use serenity::all::{FullEvent, HttpBuilder}; | ||
use std::io::Write; | ||
use std::sync::Arc; | ||
|
||
pub async fn test_serenity() { | ||
let debug_mode = std::env::var("DEBUG").unwrap_or_default() == "true"; | ||
let debug_opts = std::env::var("DEBUG_OPTS").unwrap_or_default(); | ||
|
||
let mut env_builder = env_logger::builder(); | ||
|
||
let default_filter = | ||
"serenity=debug,rust_assetgen=info,bot_binutils=info,botox=info,templating=debug,sqlx=error" | ||
.to_string(); | ||
|
||
env_builder | ||
.format(move |buf, record| { | ||
writeln!( | ||
buf, | ||
"({}) {} - {}", | ||
record.target(), | ||
record.level(), | ||
record.args() | ||
) | ||
}) | ||
.parse_filters(&default_filter) | ||
.filter(None, log::LevelFilter::Info); | ||
|
||
// Set custom log levels | ||
for opt in debug_opts.split(',') { | ||
let opt = opt.trim(); | ||
|
||
if opt.is_empty() { | ||
continue; | ||
} | ||
|
||
let (target, level) = if opt.contains('=') { | ||
let mut split = opt.split('='); | ||
let target = split.next().unwrap(); | ||
let level = split.next().unwrap(); | ||
(target, level) | ||
} else { | ||
(opt, "debug") | ||
}; | ||
|
||
let level = match level { | ||
"trace" => log::LevelFilter::Trace, | ||
"debug" => log::LevelFilter::Debug, | ||
"info" => log::LevelFilter::Info, | ||
"warn" => log::LevelFilter::Warn, | ||
"error" => log::LevelFilter::Error, | ||
_ => { | ||
error!("Invalid log level: {}", level); | ||
continue; | ||
} | ||
}; | ||
|
||
env_builder.filter(Some(target), level); | ||
} | ||
|
||
if debug_mode { | ||
env_builder.filter(None, log::LevelFilter::Debug); | ||
} else { | ||
env_builder.filter(None, log::LevelFilter::Error); | ||
} | ||
|
||
env_builder.init(); | ||
|
||
info!("Starting serenity_test"); | ||
|
||
let proxy_url = config::CONFIG.meta.proxy.clone(); | ||
|
||
let http = Arc::new( | ||
HttpBuilder::new(&config::CONFIG.discord_auth.token) | ||
.proxy(proxy_url) | ||
.ratelimiter_disabled(true) | ||
.build(), | ||
); | ||
|
||
info!("HttpBuilder done"); | ||
|
||
let mut intents = serenity::all::GatewayIntents::all(); | ||
|
||
// Remove the really spammy intents | ||
intents.remove(serenity::all::GatewayIntents::GUILD_PRESENCES); // Don't even have the privileged gateway intent for this | ||
intents.remove(serenity::all::GatewayIntents::GUILD_MESSAGE_TYPING); // Don't care about typing | ||
intents.remove(serenity::all::GatewayIntents::DIRECT_MESSAGE_TYPING); // Don't care about typing | ||
intents.remove(serenity::all::GatewayIntents::DIRECT_MESSAGES); // Don't care about DMs | ||
|
||
let client_builder = serenity::all::ClientBuilder::new_with_http(http, intents); | ||
|
||
let framework_opts = poise::FrameworkOptions { | ||
initialize_owners: true, | ||
prefix_options: poise::PrefixFrameworkOptions { | ||
prefix: Some("%".into()), | ||
..poise::PrefixFrameworkOptions::default() | ||
}, | ||
event_handler: |_ctx, event| { | ||
Box::pin(async move { | ||
log::trace!("Event: {:?}", event); | ||
Ok(()) | ||
}) | ||
}, | ||
commands: vec![], | ||
command_check: Some(|ctx| Box::pin(bot_binutils::command_check(ctx))), | ||
pre_command: |ctx| { | ||
Box::pin(async move { | ||
info!( | ||
"Executing command {} for user {} ({})...", | ||
ctx.command().qualified_name, | ||
ctx.author().name, | ||
ctx.author().id | ||
); | ||
}) | ||
}, | ||
post_command: |ctx| { | ||
Box::pin(async move { | ||
info!( | ||
"Done executing command {} for user {} ({})...", | ||
ctx.command().qualified_name, | ||
ctx.author().name, | ||
ctx.author().id | ||
); | ||
}) | ||
}, | ||
on_error: |error| Box::pin(bot_binutils::on_error(error)), | ||
..Default::default() | ||
}; | ||
|
||
let framework = poise::Framework::builder().options(framework_opts).build(); | ||
|
||
info!("DB Connect [start]"); | ||
|
||
let mut client = client_builder | ||
.framework(framework) | ||
.data(Arc::new(())) | ||
.await | ||
.expect("Error creating client"); | ||
|
||
if let Err(why) = client.start_autosharded().await { | ||
panic!("Client error occurred during testing: {:?}", why); | ||
} | ||
} |
Submodule website
updated
2 files
+6 −5 | src/components/common/CommandList.svelte | |
+2 −23 | src/lib/ui/permMap.ts |