2023-07-07 08:55:59 +00:00
|
|
|
use std::sync::Arc;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
use poise::serenity_prelude::GuildChannel;
|
2023-07-05 09:06:04 +00:00
|
|
|
use serenity::async_trait;
|
2023-07-07 10:16:25 +00:00
|
|
|
use serenity::http::{self, Http};
|
2023-07-05 09:06:04 +00:00
|
|
|
use serenity::model::channel::Message;
|
|
|
|
use serenity::model::gateway::Ready;
|
2023-07-07 08:55:59 +00:00
|
|
|
use serenity::model::id::ChannelId;
|
2023-07-05 09:06:04 +00:00
|
|
|
use serenity::prelude::*;
|
2023-07-07 08:55:59 +00:00
|
|
|
use util::security::dotenv_var;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
mod util;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
|
|
|
struct Handler;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl EventHandler for Handler {
|
|
|
|
async fn message(&self, ctx: Context, msg: Message) {
|
|
|
|
if msg.content == "!ping" {
|
|
|
|
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
|
|
|
println!("Error sending message: {:?}", why);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
2023-07-05 09:06:04 +00:00
|
|
|
println!("{} is connected!", ready.user.name);
|
2023-07-07 08:55:59 +00:00
|
|
|
// if (ready.user.name != "MOOver Debug") {
|
2023-07-07 10:16:25 +00:00
|
|
|
let messages = [
|
|
|
|
"AAAAAAAAAAAAAAAAAAAA",
|
|
|
|
"Henlooo",
|
|
|
|
"Good day y'all!",
|
|
|
|
"May have crashed...",
|
|
|
|
"MOOOooo",
|
|
|
|
"Heyyyyy!",
|
|
|
|
"I'm baaaaack!",
|
|
|
|
"Whom'st have summoned the ancient one?",
|
|
|
|
];
|
2023-07-07 08:55:59 +00:00
|
|
|
|
2023-07-07 10:16:25 +00:00
|
|
|
// }
|
2023-07-07 08:55:59 +00:00
|
|
|
let channel_result = ctx.http.get_channel(780439236867653635).await;
|
|
|
|
let channel = channel_result.unwrap();
|
|
|
|
// let channel = await http.get_channel(780439236867653635);
|
|
|
|
// GuildChannel::say(&self, http, content)
|
|
|
|
// self.message(ctx, new_message)
|
|
|
|
// C = ;
|
2023-07-07 10:16:25 +00:00
|
|
|
|
|
|
|
// const debug_channel =
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-07 10:16:25 +00:00
|
|
|
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();
|
|
|
|
}
|
2023-07-05 09:06:04 +00:00
|
|
|
#[tokio::main]
|
2023-07-07 10:16:25 +00:00
|
|
|
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..."),
|
|
|
|
}
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|
2023-07-07 10:16:25 +00:00
|
|
|
}
|
2023-07-07 08:55:59 +00:00
|
|
|
|
2023-07-07 10:16:25 +00:00
|
|
|
async fn connect() -> anyhow::Result<()> {
|
|
|
|
use anyhow::Context;
|
|
|
|
let token = dotenv_var("TOKEN").context("No TOKEN in env")?;
|
2023-07-05 09:06:04 +00:00
|
|
|
let intents = GatewayIntents::GUILD_MESSAGES
|
|
|
|
| GatewayIntents::DIRECT_MESSAGES
|
|
|
|
| GatewayIntents::MESSAGE_CONTENT;
|
2023-07-07 10:16:25 +00:00
|
|
|
|
2023-07-07 08:55:59 +00:00
|
|
|
let mut client = Client::builder(&token, intents)
|
2023-07-07 10:16:25 +00:00
|
|
|
.event_handler(Handler)
|
|
|
|
.await
|
|
|
|
.context("Failed to build client")?;
|
2023-07-05 09:06:04 +00:00
|
|
|
|
2023-07-07 10:16:25 +00:00
|
|
|
client.start().await?;
|
|
|
|
Ok(())
|
2023-07-05 09:06:04 +00:00
|
|
|
}
|