Put scrape behind owner privliages

I don't want normies tyring to scrape the whole server
This commit is contained in:
Oliver Atkinson 2024-07-25 14:42:15 -06:00
parent 77c0c7af74
commit 8dbc7ee863
2 changed files with 17 additions and 9 deletions

View File

@ -205,8 +205,8 @@ impl Server {
} }
#[poise::command(slash_command, rename = "scrape_all", guild_only)] #[poise::command(slash_command, rename = "scrape_all", guild_only, owners_only)]
pub async fn scrape_all(ctx: Context<'_>) -> Result<(), Error> { pub async fn scrape_all(ctx: Context<'_>, pretty_print: bool) -> Result<(), Error> {
let guild = ctx.guild_id().unwrap().to_partial_guild(ctx.serenity_context()).await.unwrap(); let guild = ctx.guild_id().unwrap().to_partial_guild(ctx.serenity_context()).await.unwrap();
let invoker = ctx.author().name.clone(); let invoker = ctx.author().name.clone();
@ -225,7 +225,13 @@ pub async fn scrape_all(ctx: Context<'_>) -> Result<(), Error> {
let end = start.elapsed().as_millis(); let end = start.elapsed().as_millis();
let msg_count = server.message_count(); let msg_count = server.message_count();
match serde_json::to_string(&server) { let print = if pretty_print {
serde_json::to_string_pretty(&server)
} else {
serde_json::to_string(&server)
};
match print {
Ok(ok) => { Ok(ok) => {
if let Err(e) = fs::write("server.json", ok) { if let Err(e) = fs::write("server.json", ok) {
error!("Problem writing server to disk: {e}"); error!("Problem writing server to disk: {e}");

View File

@ -1,5 +1,7 @@
use std::collections::HashSet;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use poise::serenity_prelude::{self as serenity, GatewayIntents}; use poise::serenity_prelude::{self as serenity, GatewayIntents, UserId};
use tracing::{debug, error, info, warn, Level}; use tracing::{debug, error, info, warn, Level};
use tracing_subscriber::EnvFilter; use tracing_subscriber::EnvFilter;
mod command; mod command;
@ -30,14 +32,13 @@ async fn main() {
// Generate sick text like this: // Generate sick text like this:
// http://www.patorjk.com/software/taag/#p=testall&f=Graffiti&t=hello%20world // http://www.patorjk.com/software/taag/#p=testall&f=Graffiti&t=hello%20world
info!(r#" info!("Invite with: https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
Invite this bot with:
"#);
info!("https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
ENV.id, ENV.id,
ENV.intents.bits(), ENV.intents.bits(),
); );
info!("\n");
let mut owners = HashSet::new();
owners.insert(UserId::new(423970006334832650));
// Setup framework // Setup framework
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
@ -46,6 +47,7 @@ async fn main() {
command::index_cmd(), command::index_cmd(),
command::scrape_all(), command::scrape_all(),
], ],
owners,
..Default::default() ..Default::default()
}) })
.setup(|ctx, _ready, framework| { .setup(|ctx, _ready, framework| {