generated from Oliver/discord-bot-template
	Put scrape behind owner privliages
I don't want normies tyring to scrape the whole server
This commit is contained in:
		@@ -205,8 +205,8 @@ impl Server {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[poise::command(slash_command, rename = "scrape_all", guild_only)]
 | 
			
		||||
pub async fn scrape_all(ctx: Context<'_>) -> Result<(), Error> {
 | 
			
		||||
#[poise::command(slash_command, rename = "scrape_all", guild_only, owners_only)]
 | 
			
		||||
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 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 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) => {
 | 
			
		||||
                        if let Err(e) = fs::write("server.json", ok) {
 | 
			
		||||
                            error!("Problem writing server to disk: {e}");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,5 +1,7 @@
 | 
			
		||||
use std::collections::HashSet;
 | 
			
		||||
 | 
			
		||||
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_subscriber::EnvFilter;
 | 
			
		||||
mod command;
 | 
			
		||||
@@ -30,14 +32,13 @@ async fn main() {
 | 
			
		||||
 | 
			
		||||
    // Generate sick text like this: 
 | 
			
		||||
    // http://www.patorjk.com/software/taag/#p=testall&f=Graffiti&t=hello%20world
 | 
			
		||||
    info!(r#"
 | 
			
		||||
    Invite this bot with:
 | 
			
		||||
    "#);
 | 
			
		||||
    info!("https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
 | 
			
		||||
    info!("Invite with: https://discord.com/api/oauth2/authorize?client_id={}&permissions={}&scope=bot",
 | 
			
		||||
        ENV.id,
 | 
			
		||||
        ENV.intents.bits(),
 | 
			
		||||
    );
 | 
			
		||||
    info!("\n");
 | 
			
		||||
 | 
			
		||||
    let mut owners = HashSet::new();
 | 
			
		||||
    owners.insert(UserId::new(423970006334832650));
 | 
			
		||||
 | 
			
		||||
    // Setup framework
 | 
			
		||||
    let framework = poise::Framework::builder()
 | 
			
		||||
@@ -46,6 +47,7 @@ async fn main() {
 | 
			
		||||
                command::index_cmd(),
 | 
			
		||||
                command::scrape_all(),
 | 
			
		||||
            ],
 | 
			
		||||
            owners,
 | 
			
		||||
            ..Default::default()
 | 
			
		||||
        })
 | 
			
		||||
        .setup(|ctx, _ready, framework| {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user