Ready to merge

This commit is contained in:
Ladislav Hano 2023-07-07 13:44:07 +02:00
parent 97b1d8e26b
commit f105e5e746
2 changed files with 25 additions and 37 deletions

View file

@ -38,8 +38,9 @@ impl EventHandler for Handler {
]; ];
// } // }
let channel_result = ctx.http.get_channel(780439236867653635).await;
let channel = channel_result.unwrap(); let channel = ctx.http.get_channel(780439236867653635).await.unwrap();
// let channel = await http.get_channel(780439236867653635); // let channel = await http.get_channel(780439236867653635);
// GuildChannel::say(&self, http, content) // GuildChannel::say(&self, http, content)
// self.message(ctx, new_message) // self.message(ctx, new_message)
@ -48,52 +49,20 @@ impl EventHandler for Handler {
// const debug_channel = // const debug_channel =
} }
} }
struct MyStruct {
niečo: String,
}
impl MyStruct {
fn add(&mut self) {
self.niečo.push(char::from_digit(2, 2).unwrap());
}
}
trait Countable {
fn count(&self) -> usize;
}
impl Countable for MyStruct {
fn count(&self) -> usize {
self.niečo.len()
}
}
fn smt(var: Box<dyn Countable>) {
var.count();
}
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
let mut n = MyStruct {
niečo: "aaa".to_string(),
};
n.add();
loop {
//Keeps trying to reconnect, if errors occur print to console and retry
match connect().await {
Ok(r) => return Ok(()),
Err(e) => println!("FAILED TO CONNECT!!! {e}\nRetrying soon..."),
}
}
}
async fn connect() -> anyhow::Result<()> {
use anyhow::Context; use anyhow::Context;
let token = dotenv_var("TOKEN").context("No TOKEN in env")?; let token = dotenv_var("TOKEN").context("No TOKEN in env")?;
let intents = GatewayIntents::GUILD_MESSAGES let intents = GatewayIntents::GUILD_MESSAGES
| GatewayIntents::DIRECT_MESSAGES | GatewayIntents::DIRECT_MESSAGES
| GatewayIntents::MESSAGE_CONTENT; | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(&token, intents) let mut client = Client::builder(&token, intents)
.event_handler(Handler) .event_handler(Handler)
.await .await
.context("Failed to build client")?; .context("Failed to build client")?;
client.start().await?; client.start().await?;
Ok(()) Ok(())
} }

19
src/sample.rs Normal file
View file

@ -0,0 +1,19 @@
struct MyStruct {
niečo: String,
}
impl MyStruct {
fn add(&mut self) {
self.niečo.push(char::from_digit(2, 2).unwrap());
}
}
trait Countable {
fn count(&self) -> usize;
}
impl Countable for MyStruct {
fn count(&self) -> usize {
self.niečo.len()
}
}
fn smt(var: Box<dyn Countable>) {
var.count();
}