Compare commits

...

3 Commits

Author SHA1 Message Date
Oliver Atkinson
2fbdeeef06 Add better logging + Clippy warnings fix 2024-07-25 13:57:49 -06:00
Oliver Atkinson
4e9a70d60c add time to logging
makes looking at a lot of the same message output easier
2024-07-25 13:57:25 -06:00
Oliver Atkinson
430d6b76c4 use custom poise version
There are errors in the poise dependency serenity, they aren't yet in the newest version of poise, so we are using a git version
2024-07-25 13:56:54 -06:00
5 changed files with 51 additions and 16 deletions

15
Cargo.lock generated
View File

@ -933,25 +933,23 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]] [[package]]
name = "poise" name = "poise"
version = "0.6.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1819d5a45e3590ef33754abce46432570c54a120798bdbf893112b4211fa09a6"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"derivative", "derivative",
"futures-util", "futures-util",
"indexmap",
"parking_lot", "parking_lot",
"poise_macros", "poise_macros",
"regex", "regex",
"serenity", "serenity",
"tokio", "tokio",
"tracing", "tracing",
"trim-in-place",
] ]
[[package]] [[package]]
name = "poise_macros" name = "poise_macros"
version = "0.6.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fa2c123c961e78315cd3deac7663177f12be4460f5440dbf62a7ed37b1effea"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -1328,8 +1326,7 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.12.2" version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/serenity-rs/serenity.git?rev=e34f4491ee3a0b20ea8dc30cbc77b257f402f692#e34f4491ee3a0b20ea8dc30cbc77b257f402f692"
checksum = "880a04106592d0a8f5bdacb1d935889bfbccb4a14f7074984d9cd857235d34ac"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"async-trait", "async-trait",
@ -1725,6 +1722,12 @@ dependencies = [
"tracing-log", "tracing-log",
] ]
[[package]]
name = "trim-in-place"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "343e926fc669bc8cde4fa3129ab681c63671bae288b1f1081ceee6d9d37904fc"
[[package]] [[package]]
name = "triomphe" name = "triomphe"
version = "0.1.13" version = "0.1.13"

View File

@ -11,7 +11,7 @@ edition = "2021"
[dependencies] [dependencies]
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
# songbird = { version = "0.3.2", features = ["yt-dlp"] } # songbird = { version = "0.3.2", features = ["yt-dlp"] }
poise = { version = "0.6", features = ["cache"] } poise = { version = "0.6", features = ["cache"], path="../poise" }
dotenv = "0.15.0" dotenv = "0.15.0"
anyhow = "1.0.75" anyhow = "1.0.75"
once_cell = "1.19.0" once_cell = "1.19.0"

View File

@ -2,6 +2,26 @@
egress a discord server egress a discord server
### NOTE:
Using custom version of poise (the discord library) because I need to use a specific version of serenity (the discord library for poise). Here's how to set it up:
1) Clone Poise next to this repo:
```shell
git clone https://github.com/serenity-rs/poise.git
```
2) Change the version of serenity that poise uses:
```diff
[dependencies.serenity]
- version = "x.xx.x"
+ git = "https://github.com/serenity-rs/serenity.git"
+ rev = "e34f4491ee3a0b20ea8dc30cbc77b257f402f692"
```
> Just make sure that the rev is a sha1 commit hash sometime after 7/25/24
## Getting started ## Getting started
* goto: [Discord applicatoins](https://discord.com/developers/applications) and * goto: [Discord applicatoins](https://discord.com/developers/applications) and
create an application. create an application.

View File

@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Display, sync::Arc};
use crate::Context; use crate::Context;
use anyhow::Error; use anyhow::Error;
use poise::{serenity_prelude::{Cache, CacheHttp, ChannelId, ChannelType, GetMessages, GuildChannel, Http, Message}, CreateReply}; use poise::{serenity_prelude::{Cache, CacheHttp, ChannelId, ChannelType, GetMessages, GuildChannel, Http, Message}, CreateReply};
use tokio::time::Instant;
use tracing::{debug, error, trace}; use tracing::{debug, error, trace};
struct Server { struct Server {
@ -86,11 +87,10 @@ impl Server {
if child.this.id == *find { if child.this.id == *find {
return Some(child); return Some(child);
} }
match Self::search_by_id(&mut child.children, find) { if let Some(x) = Self::search_by_id(&mut child.children, find) {
Some(x) => return Some(x), return Some(x);
None => {},
} }
} }
None None
} }
@ -99,7 +99,7 @@ impl Server {
if let Some(parent_id) = &insert.parent_id { if let Some(parent_id) = &insert.parent_id {
// find the parent (needs to go thru all nodes) // find the parent (needs to go thru all nodes)
match Self::search_by_id(&mut self.channels, &parent_id) { match Self::search_by_id(&mut self.channels, parent_id) {
Some(parent_node) => { Some(parent_node) => {
parent_node.children.push(Channel::new(insert)); parent_node.children.push(Channel::new(insert));
}, },
@ -141,7 +141,10 @@ impl Server {
/// Recursive walk thru the channels /// Recursive walk thru the channels
async fn walk_channels(all: &mut Vec<Channel>, cache: impl CacheHttp + Clone) { async fn walk_channels(all: &mut Vec<Channel>, cache: impl CacheHttp + Clone) {
let settings = GetMessages::default().limit(5); // Qty of messages to take at a time, max=100
let batch_size = 100;
let settings = GetMessages::default().limit(batch_size);
for channel in all { for channel in all {
// Clone *should* be cheap - it's Arc under the hood // Clone *should* be cheap - it's Arc under the hood
// get the messages // get the messages
@ -169,7 +172,11 @@ impl Server {
} }
} }
}, },
Err(e) => error!("Error while trying to get messages - {e}"), Err(e) => {
error!("While reading messages in \"{}\" before `{}` - {e}", channel.this.name, last);
// Stop reading this channel on an error.
last_id = None;
},
} }
} }
// Then recurse into children channels // Then recurse into children channels
@ -200,8 +207,14 @@ pub async fn scrape_all(ctx: Context<'_>) -> Result<(), Error> {
let mut server = index(map).await; let mut server = index(map).await;
match ctx.reply("Starting scrape...").await { match ctx.reply("Starting scrape...").await {
Ok(ok) => { Ok(ok) => {
let start = Instant::now();
server.scrape_all().await; server.scrape_all().await;
let _ = ok.edit(ctx, CreateReply::default().content(&format!("Scraped {} messages", server.message_count()))).await; let end = start.elapsed().as_millis();
let msg_count = server.message_count();
let _ = ok.edit(ctx, CreateReply::default().content(
&format!("Done. Stats: \n```toml\nMessages: {msg_count}\nElapsed time: {end}ms\n```")
)).await;
debug!("Scraped server in {}ms", end);
}, },
Err(e) => error!("{e} - While trying to reply to scrape command"), Err(e) => error!("{e} - While trying to reply to scrape command"),
} }

View File

@ -26,7 +26,6 @@ async fn main() {
.with_env_filter(filter) .with_env_filter(filter)
.with_thread_ids(false) .with_thread_ids(false)
.with_file(false) .with_file(false)
.without_time()
.init(); .init();
// Generate sick text like this: // Generate sick text like this: