Update and fix some warnings

Mainly just changing old deprecated functions to their newer counterparts
This commit is contained in:
BuyMyMojo 2024-07-03 17:11:05 +10:00
parent bbe1ee264b
commit f3811ac712
No known key found for this signature in database
GPG key ID: 119F86561BCE6522
5 changed files with 23 additions and 21 deletions

View file

@ -187,6 +187,7 @@ pub async fn search(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Member to search for. This must be a user ID."] user_id: String, #[description = "Member to search for. This must be a user ID."] user_id: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
use chrono::DateTime;
use pastemyst::paste::*; use pastemyst::paste::*;
use pastemyst::str; use pastemyst::str;
use poise::serenity_prelude::User; use poise::serenity_prelude::User;
@ -381,12 +382,11 @@ pub async fn search(
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
// this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN // this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN
let date_time_stamp = chrono::NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0) let date_time_stamp = DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
.unwrap_or(chrono::NaiveDateTime::MIN);
let age = chrono::Utc::now() let age = chrono::Utc::now()
.naive_utc() .naive_utc()
.signed_duration_since(date_time_stamp) .signed_duration_since(date_time_stamp.naive_local())
.num_days(); .num_days();
let is_user_in_db: Option<String> = check_username_against_db(ctx.author().id.0).await.unwrap(); let is_user_in_db: Option<String> = check_username_against_db(ctx.author().id.0).await.unwrap();
@ -626,6 +626,8 @@ pub async fn footprint_lookup(
BlacklistOutput, BlacklistOutput,
>, >,
) -> Result<(), Error> { ) -> Result<(), Error> {
use chrono::DateTime;
ctx.defer().await?; ctx.defer().await?;
let mut con = open_redis_connection().await?; let mut con = open_redis_connection().await?;
@ -929,12 +931,11 @@ pub async fn footprint_lookup(
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
// this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN // this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN
let date_time_stamp = chrono::NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0) let date_time_stamp = DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
.unwrap_or(chrono::NaiveDateTime::MIN);
let age = chrono::Utc::now() let age = chrono::Utc::now()
.naive_utc() .naive_utc()
.signed_duration_since(date_time_stamp) .signed_duration_since(date_time_stamp.naive_local())
.num_days(); .num_days();
let is_user_in_db: Option<String> = let is_user_in_db: Option<String> =

View file

@ -1,4 +1,4 @@
use chrono::NaiveDateTime; use chrono::DateTime;
use poise::serenity_prelude::{self as serenity, AttachmentType, RichInvite}; use poise::serenity_prelude::{self as serenity, AttachmentType, RichInvite};
use rusted_fbt_lib::{ use rusted_fbt_lib::{
checks::guild_auth_check, checks::guild_auth_check,
@ -26,11 +26,11 @@ pub async fn account_age(
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
// this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN // this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN
let date_time_stamp = let date_time_stamp =
NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0).unwrap_or(NaiveDateTime::MIN); DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
let age = chrono::Utc::now() let age = chrono::Utc::now()
.naive_utc() .naive_utc()
.signed_duration_since(date_time_stamp) .signed_duration_since(date_time_stamp.naive_local())
.num_days(); .num_days();
ctx.say(format!( ctx.say(format!(
@ -56,7 +56,7 @@ pub async fn creation_date(
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
// this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN // this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN
let date_time_stamp = let date_time_stamp =
NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0).unwrap_or(NaiveDateTime::MIN); DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
ctx.say(format!("Created/Joined on {date_time_stamp}")) ctx.say(format!("Created/Joined on {date_time_stamp}"))
.await?; .await?;
@ -277,11 +277,11 @@ pub async fn invite_info(
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
// this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN // this shouldn't be able to break but just in case I'm making the `unwrap_or` output NaiveDateTime::MIN
let date_time_stamp = let date_time_stamp =
NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0).unwrap_or(NaiveDateTime::MIN); DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
let age = chrono::Utc::now() let age = chrono::Utc::now()
.naive_utc() .naive_utc()
.signed_duration_since(date_time_stamp) .signed_duration_since(date_time_stamp.naive_local())
.num_days(); .num_days();
let is_user_in_db: Option<String> = let is_user_in_db: Option<String> =

View file

@ -1,7 +1,7 @@
use crate::structs::{GuildSettings, UserInfo, WaybackResponse, WaybackStatus}; use crate::structs::{GuildSettings, UserInfo, WaybackResponse, WaybackStatus};
use crate::utils::snowflake_to_unix; use crate::utils::snowflake_to_unix;
use crate::vars::FBT_GUILD_ID; use crate::vars::FBT_GUILD_ID;
use chrono::NaiveDateTime; // use chrono::NaiveDateTime;
use chrono::Utc; use chrono::Utc;
use chrono_tz::Australia::Melbourne; use chrono_tz::Australia::Melbourne;
use colored::Colorize; use colored::Colorize;
@ -90,6 +90,8 @@ pub async fn alt_kicker(
ctx: &serenity::Context, ctx: &serenity::Context,
member: &serenity::Member, member: &serenity::Member,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
use chrono::DateTime;
use crate::utils::open_redis_connection; use crate::utils::open_redis_connection;
use std::collections::HashSet; use std::collections::HashSet;
@ -133,12 +135,11 @@ pub async fn alt_kicker(
#[allow(clippy::pedantic)] #[allow(clippy::pedantic)]
// it literally only take's i64, no need to warn about truncation here. // it literally only take's i64, no need to warn about truncation here.
let date_time_stamp = NaiveDateTime::from_timestamp_opt(unix_timecode as i64, 0) let date_time_stamp = DateTime::from_timestamp(unix_timecode as i64, 0).unwrap_or(DateTime::UNIX_EPOCH);
.unwrap_or(NaiveDateTime::MIN);
let age = chrono::Utc::now() let age = chrono::Utc::now()
.naive_utc() .naive_utc()
.signed_duration_since(date_time_stamp) .signed_duration_since(date_time_stamp.naive_local())
.num_days(); .num_days();
// Compare user age // Compare user age

View file

@ -36,7 +36,7 @@ pub async fn pog_be_gone(
let mut hits: Vec<&str> = Vec::new(); let mut hits: Vec<&str> = Vec::new();
for word in words { for word in words {
POG_RE.find(word).map_or((), |pog| { let _ = POG_RE.find(word).map_or((), |pog| {
hits.push(pog.as_str()); hits.push(pog.as_str());
}); });
} }

View file

@ -25,9 +25,9 @@ pub fn verbose_mode() -> bool {
/// Open a tokio redis connection /// Open a tokio redis connection
#[cfg(feature = "database")] #[cfg(feature = "database")]
#[instrument()] #[instrument()]
pub async fn open_redis_connection() -> Result<redis::aio::Connection, anyhow::Error> { pub async fn open_redis_connection() -> Result<redis::aio::MultiplexedConnection, anyhow::Error> {
let redis_connection = redis::Client::open(REDIS_ADDR)? let redis_connection = redis::Client::open(REDIS_ADDR)?
.get_tokio_connection() .get_multiplexed_tokio_connection()
.await?; .await?;
Ok(redis_connection) Ok(redis_connection)
@ -38,7 +38,7 @@ pub async fn open_redis_connection() -> Result<redis::aio::Connection, anyhow::E
#[instrument(skip(con))] #[instrument(skip(con))]
pub async fn set_guild_settings( pub async fn set_guild_settings(
ctx: Context<'_>, ctx: Context<'_>,
con: &mut redis::aio::Connection, con: &mut redis::aio::MultiplexedConnection,
settings: GuildSettings, settings: GuildSettings,
) -> Result<(), Error> { ) -> Result<(), Error> {
let json = serde_json::to_string(&settings).unwrap(); let json = serde_json::to_string(&settings).unwrap();
@ -64,7 +64,7 @@ pub async fn set_guild_settings(
#[instrument(skip(con))] #[instrument(skip(con))]
pub async fn auth( pub async fn auth(
ctx: Context<'_>, ctx: Context<'_>,
con: &mut redis::aio::Connection, con: &mut redis::aio::MultiplexedConnection,
uid: String, uid: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
redis::cmd("SADD") redis::cmd("SADD")