Not working so far
This commit is contained in:
parent
1088a1356a
commit
6bd5da9c3a
7 changed files with 130 additions and 28 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -28,6 +28,15 @@ dependencies = [
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android-tzdata"
|
name = "android-tzdata"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -967,6 +976,8 @@ dependencies = [
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"mongodb",
|
"mongodb",
|
||||||
"poise",
|
"poise",
|
||||||
|
"rand",
|
||||||
|
"regex",
|
||||||
"serenity",
|
"serenity",
|
||||||
"serenity_utils",
|
"serenity_utils",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -1183,18 +1194,32 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.8.4"
|
version = "1.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
|
checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
|
checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
|
|
|
@ -14,3 +14,5 @@ poise = "0.5.5"
|
||||||
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http"] }
|
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "http"] }
|
||||||
serenity_utils = "0.7.0"
|
serenity_utils = "0.7.0"
|
||||||
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
rand = "0.8.4"
|
||||||
|
regex = "1.9.0"
|
47
src/main.rs
47
src/main.rs
|
@ -1,14 +1,11 @@
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use poise::serenity_prelude::GuildChannel;
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::http::{self, Http};
|
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::gateway::Ready;
|
use serenity::model::gateway::Ready;
|
||||||
use serenity::model::id::ChannelId;
|
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use util::security::dotenv_var;
|
use util::security::dotenv_var;
|
||||||
|
use rand::random;
|
||||||
|
|
||||||
|
mod moove;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
@ -25,22 +22,29 @@ impl EventHandler for Handler {
|
||||||
|
|
||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
// if (ready.user.name != "MOOver Debug") {
|
let debug = match dotenv_var("DEBUG") {
|
||||||
let messages = [
|
Some(v) => v,
|
||||||
"AAAAAAAAAAAAAAAAAAAA",
|
None => "OFF".to_string()
|
||||||
"Henlooo",
|
};
|
||||||
"Good day y'all!",
|
if debug == "ON" {
|
||||||
"May have crashed...",
|
let messages = [
|
||||||
"MOOOooo",
|
"AAAAAAAAAAAAAAAAAAAA",
|
||||||
"Heyyyyy!",
|
"Henlooo",
|
||||||
"I'm baaaaack!",
|
"Good day y'all!",
|
||||||
"Whom'st have summoned the ancient one?",
|
"May have crashed...",
|
||||||
];
|
"MOOOooo",
|
||||||
|
"Heyyyyy!",
|
||||||
// }
|
"I'm baaaaack!",
|
||||||
|
"Whom'st have summoned the ancient one?",
|
||||||
let channel = ctx.http.get_channel(780439236867653635).await.unwrap();
|
];
|
||||||
|
|
||||||
|
let rand_num = random::<usize>() % messages.len();
|
||||||
|
let channel = ctx.http.get_channel(780439236867653635).await.unwrap().id();
|
||||||
|
match channel.say(&ctx.http, messages[rand_num]).await {
|
||||||
|
Err(e) => println!("Something went wrong: {e}"),
|
||||||
|
Ok(_) => return
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +53,6 @@ async fn main() -> 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::MESSAGE_CONTENT;
|
| GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
|
||||||
let mut client = Client::builder(&token, intents)
|
let mut client = Client::builder(&token, intents)
|
||||||
|
|
73
src/moove.rs
Normal file
73
src/moove.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
use serenity::builder::{CreateEmbed, CreateMessage};
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
use serenity::http::Http;
|
||||||
|
use serenity::model::channel::Attachment;
|
||||||
|
use anyhow;
|
||||||
|
use serenity::model::mention;
|
||||||
|
|
||||||
|
// use regex::Regex;
|
||||||
|
|
||||||
|
// Checks if the message should be mooved, if not returns Ok(0)
|
||||||
|
// If the message should be mooved, try to move it and return Ok(1) if mooved succesfully
|
||||||
|
// else returns Err()
|
||||||
|
pub async fn moove(http: Http, msg: Message) -> Result<u8, String>{
|
||||||
|
let channel_mentions = msg.mention_channels;
|
||||||
|
let words = msg.content.trim().split_whitespace().count();
|
||||||
|
|
||||||
|
// let re = Regex::new(r"<#[0-9]*>$").unwrap();
|
||||||
|
// if re.captures(content)
|
||||||
|
|
||||||
|
if channel_mentions.len() != 1 || words != 1 {
|
||||||
|
return Ok(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut msg_to_moove = match msg.referenced_message {
|
||||||
|
Some(m) => m,
|
||||||
|
None => return Ok(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mentioned_channel = channel_mentions[0].id;
|
||||||
|
|
||||||
|
let attachments = msg_to_moove.attachments;
|
||||||
|
let embeds = msg_to_moove.embeds;
|
||||||
|
|
||||||
|
let sent_by = format!("Sent by {}\n mooved {}\n", msg_to_moove.author, msg.author);
|
||||||
|
|
||||||
|
let mut embeds_copy : Vec<CreateEmbed> = Vec::new();
|
||||||
|
for embed in msg_to_moove.embeds {
|
||||||
|
embeds_copy.push(CreateEmbed::from(embed));
|
||||||
|
}
|
||||||
|
|
||||||
|
// let mut attachment_links : Vec<String> = Vec::new();
|
||||||
|
let attachment_link = msg_to_moove.attachments.pop();
|
||||||
|
// for attachment in msg_to_moove.attachments {
|
||||||
|
// attachment_links.push(attachment.url);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if embeds_copy.len() > 0 || attachment_links.len() > 0 {
|
||||||
|
if embeds_copy.len() > 0 {
|
||||||
|
let mut new_content = "".to_string();
|
||||||
|
if !msg_to_moove.content.is_empty() {
|
||||||
|
new_content = format!("Message:\n{}", msg_to_moove.content);
|
||||||
|
}
|
||||||
|
sent_by.push_str(&new_content);
|
||||||
|
match mentioned_channel.send_message(http, |m| {
|
||||||
|
m.content(sent_by).add_embeds(embeds_copy).add_file(attachment_link)
|
||||||
|
}).await {
|
||||||
|
Ok(_) => return Ok(0),
|
||||||
|
Err(e) => return Err(e.to_string())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if !msg_to_moove.content.is_empty() {
|
||||||
|
match mentioned_channel.send_message(http, |m| {
|
||||||
|
m.add_embed(|e| {
|
||||||
|
e.title("MOO").field(sent_by, " ", false).field("Message:\n", msg_to_moove.content, false)
|
||||||
|
})
|
||||||
|
}).await {
|
||||||
|
Ok(_) => return Ok(0),
|
||||||
|
Err(e) => return Err(e.to_string())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Err("Something went wrong while mooving the message".to_string())
|
||||||
|
}
|
0
src/util/embeds.rs
Normal file
0
src/util/embeds.rs
Normal file
|
@ -3,10 +3,9 @@ use std::env;
|
||||||
|
|
||||||
pub fn dotenv_var(key: &str) -> Option<String> {
|
pub fn dotenv_var(key: &str) -> Option<String> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let key = "TOKEN";
|
|
||||||
|
|
||||||
match env::var(key) {
|
match env::var(key) {
|
||||||
Ok(val) => return Some(val),
|
Ok(val) => return Some(val),
|
||||||
Err(_) => None,
|
Err(_) => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
0
src/util/utilities.rs
Normal file
0
src/util/utilities.rs
Normal file
Loading…
Reference in a new issue