use actix::Actor;
use actor_discord::discord::ExampleDiscordActor;
use actor_discord::types::events::{ChannelType, GuildChannelCreate};
use actor_discord::DiscordAPI;
use actor_discord::DiscordBot;
use actor_discord::GatewayIntents;
use anyhow::Result;
use dotenv::dotenv;
use std::env;
#[actix_rt::main]
async fn main() -> Result<()> {
dotenv().ok();
env_logger::init();
log::info!("Starting");
let token = env::var("DISCORD_TOKEN")?;
let url = env::var("DISCORD_URL")?;
let intents: GatewayIntents = GatewayIntents::GUILDS
| GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILD_MESSAGE_REACTIONS
| GatewayIntents::DIRECT_MESSAGE_REACTIONS;
log::info!("** Intents = {}", intents.bits);
log::info!("attempting to create websocket");
let discord_api = DiscordAPI::create(&token, &url)?;
log::info!("attempting to create actor");
log::info!("attempting to start actor");
log::info!("creating threads");
let channels = discord_api.channels("839604684573638696".into()).await?;
let foo = channels
.iter()
.filter(|c| c.parent_id.is_none() && c.u_type == ChannelType::GuildText)
.collect::<Vec<_>>();
let bb = futures::future::join_all(foo.iter().map(|c| discord_api.delete_channel(c.id))).await;
bb.iter().for_each(|cr| match cr {
Ok(gc) => {
log::info!("{}", gc.id.to_string())
}
Err(e) => {
log::error!("{}", e)
}
});
log::info!("{}", channels.len());
log::info!("done");
Ok(())
}