refactor: harden clippy lints
This commit is contained in:
parent
2b3d81cfa4
commit
a4abdd72e4
19 changed files with 39 additions and 37 deletions
4
build.rs
4
build.rs
|
@ -54,7 +54,7 @@ fn main() {
|
|||
r#"
|
||||
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
|
||||
#[derive(Clone, Debug, poise::ChoiceParameter)]
|
||||
pub enum TagChoice {{
|
||||
pub enum Choice {{
|
||||
{}
|
||||
}}"#,
|
||||
formatted_names.join(",\n")
|
||||
|
@ -62,7 +62,7 @@ fn main() {
|
|||
|
||||
let to_str = format!(
|
||||
r#"
|
||||
impl TagChoice {{
|
||||
impl Choice {{
|
||||
fn as_str(&self) -> &str {{
|
||||
match &self {{
|
||||
{}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
const DADJOKE: &str = "https://icanhazdadjoke.com";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Context, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use poise::serenity_prelude::{MessageId, UserId};
|
||||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Context, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Context, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct RoryResponse {
|
||||
pub struct Response {
|
||||
pub id: u64,
|
||||
pub url: String,
|
||||
pub error: Option<String>,
|
||||
|
@ -15,7 +15,7 @@ pub struct RoryResponse {
|
|||
const RORY: &str = "https://rory.cat";
|
||||
const ENDPOINT: &str = "/purr";
|
||||
|
||||
pub async fn get_rory(id: Option<u64>) -> Result<RoryResponse> {
|
||||
pub async fn get(id: Option<u64>) -> Result<Response> {
|
||||
let target = id.map(|id| id.to_string()).unwrap_or_default();
|
||||
|
||||
let req = REQWEST_CLIENT
|
||||
|
@ -33,7 +33,7 @@ pub async fn get_rory(id: Option<u64>) -> Result<RoryResponse> {
|
|||
|
||||
if let StatusCode::OK = status {
|
||||
let data = resp
|
||||
.json::<RoryResponse>()
|
||||
.json::<Response>()
|
||||
.await
|
||||
.wrap_err_with(|| "Couldn't parse the rory response!")?;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::api::rory::get_rory;
|
||||
use crate::api::rory;
|
||||
use crate::Context;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
|
@ -11,7 +11,7 @@ pub async fn rory(
|
|||
ctx: Context<'_>,
|
||||
#[description = "specify a Rory ID"] id: Option<u64>,
|
||||
) -> Result<()> {
|
||||
let rory = get_rory(id).await?;
|
||||
let rory = rory::get(id).await?;
|
||||
|
||||
let embed = {
|
||||
let embed = CreateEmbed::new();
|
||||
|
|
|
@ -15,7 +15,7 @@ static TAGS: Lazy<Vec<Tag>> = Lazy::new(|| serde_json::from_str(env!("TAGS")).un
|
|||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn tag(
|
||||
ctx: Context<'_>,
|
||||
#[description = "the copypasta you want to send"] name: TagChoice,
|
||||
#[description = "the copypasta you want to send"] name: Choice,
|
||||
user: Option<User>,
|
||||
) -> Result<()> {
|
||||
let tag_file = name.as_str();
|
||||
|
|
|
@ -5,7 +5,7 @@ use poise::Command;
|
|||
|
||||
mod general;
|
||||
|
||||
pub fn to_global_commands() -> Vec<Command<Data, Report>> {
|
||||
pub fn get() -> Vec<Command<Data, Report>> {
|
||||
vec![
|
||||
general::joke(),
|
||||
general::members(),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use log::*;
|
||||
use log::{info, warn};
|
||||
use poise::serenity_prelude::ChannelId;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -9,7 +9,7 @@ pub struct RefractionChannels {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct DiscordConfig {
|
||||
pub struct Config {
|
||||
pub channels: RefractionChannels,
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ impl RefractionChannels {
|
|||
}
|
||||
}
|
||||
|
||||
impl DiscordConfig {
|
||||
impl Config {
|
||||
pub fn new_from_env() -> Self {
|
||||
let channels = RefractionChannels::new_from_env();
|
||||
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
mod discord;
|
||||
use discord::DiscordConfig;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub discord: DiscordConfig,
|
||||
pub discord: discord::Config,
|
||||
pub redis_url: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
discord: DiscordConfig::default(),
|
||||
discord: discord::Config::default(),
|
||||
redis_url: "redis://localhost:6379".to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +17,7 @@ impl Default for Config {
|
|||
|
||||
impl Config {
|
||||
pub fn new_from_env() -> Self {
|
||||
let discord = DiscordConfig::new_from_env();
|
||||
let discord = discord::Config::new_from_env();
|
||||
|
||||
Self {
|
||||
discord,
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::consts::COLORS;
|
|||
use crate::Data;
|
||||
|
||||
use color_eyre::eyre::Report;
|
||||
use log::*;
|
||||
use log::error;
|
||||
use poise::serenity_prelude::{CreateEmbed, Timestamp};
|
||||
use poise::{CreateReply, FrameworkError};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use regex::Regex;
|
|||
|
||||
pub type Issue = Option<(String, String)>;
|
||||
|
||||
pub async fn find_issues(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
|
||||
pub async fn find(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
|
||||
let issues = [
|
||||
fabric_internal,
|
||||
flatpak_nvidia,
|
||||
|
@ -24,7 +24,7 @@ pub async fn find_issues(log: &str, data: &Data) -> Result<Vec<(String, String)>
|
|||
let mut res: Vec<(String, String)> = issues.iter().filter_map(|issue| issue(log)).collect();
|
||||
|
||||
if let Some(issues) = outdated_launcher(log, data).await? {
|
||||
res.push(issues)
|
||||
res.push(issues);
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::consts::COLORS;
|
|||
use crate::Data;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use poise::serenity_prelude::{
|
||||
Context, CreateAllowedMentions, CreateEmbed, CreateMessage, Message,
|
||||
};
|
||||
|
@ -10,7 +10,6 @@ use poise::serenity_prelude::{
|
|||
mod issues;
|
||||
mod providers;
|
||||
|
||||
use issues::find_issues;
|
||||
use providers::find_log;
|
||||
|
||||
pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> {
|
||||
|
@ -38,7 +37,7 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()>
|
|||
return Ok(());
|
||||
};
|
||||
|
||||
let issues = find_issues(&log, data).await?;
|
||||
let issues = issues::find(&log, data).await?;
|
||||
|
||||
let embed = {
|
||||
let mut e = CreateEmbed::new().title("Log analysis");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{api, Data};
|
||||
|
||||
use color_eyre::eyre::{Report, Result};
|
||||
use log::*;
|
||||
use log::{debug, info};
|
||||
use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus};
|
||||
use poise::FrameworkContext;
|
||||
|
||||
|
@ -23,7 +23,7 @@ pub async fn handle(
|
|||
info!("Logged in as {}!", data_about_bot.user.name);
|
||||
|
||||
let latest_minecraft_version = api::prism_meta::get_latest_minecraft_version().await?;
|
||||
let activity = ActivityData::playing(format!("Minecraft {}", latest_minecraft_version));
|
||||
let activity = ActivityData::playing(format!("Minecraft {latest_minecraft_version}"));
|
||||
|
||||
info!("Setting presence to activity {activity:#?}");
|
||||
ctx.set_presence(Some(activity), OnlineStatus::Online);
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{api, Data};
|
|||
use std::time::Duration;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use poise::serenity_prelude::{Context, Message};
|
||||
use tokio::time::sleep;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use color_eyre::eyre::{eyre, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use poise::serenity_prelude::{
|
||||
ChannelType, Context, CreateAllowedMentions, CreateMessage, GuildChannel,
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ pub async fn handle(ctx: &Context, thread: &GuildChannel) -> Result<()> {
|
|||
.ok_or_else(|| eyre!("Couldn't get parent ID from thread {}!", thread.name))?
|
||||
.name(ctx)
|
||||
.await
|
||||
.unwrap_or("".to_string())
|
||||
.unwrap_or(String::new())
|
||||
!= "support"
|
||||
{
|
||||
debug!("Not posting onboarding message to threads outside of support");
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,10 +1,14 @@
|
|||
#![warn(clippy::all, clippy::pedantic, clippy::perf)]
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use color_eyre::eyre::{eyre, Context as _, Report, Result};
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
|
||||
use log::*;
|
||||
use log::{info, warn};
|
||||
|
||||
use poise::{
|
||||
serenity_prelude as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions,
|
||||
|
@ -78,7 +82,7 @@ async fn setup(
|
|||
async fn handle_shutdown(shard_manager: Arc<serenity::ShardManager>, reason: &str) {
|
||||
warn!("{reason}! Shutting down bot...");
|
||||
shard_manager.shutdown_all().await;
|
||||
println!("{}", "Everything is shutdown. Goodbye!".green())
|
||||
println!("{}", "Everything is shutdown. Goodbye!".green());
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -94,7 +98,7 @@ async fn main() -> Result<()> {
|
|||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
|
||||
|
||||
let options = FrameworkOptions {
|
||||
commands: commands::to_global_commands(),
|
||||
commands: commands::get(),
|
||||
|
||||
on_error: |error| Box::pin(handlers::handle_error(error)),
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use log::*;
|
||||
use log::{debug, info};
|
||||
use poise::serenity_prelude::UserId;
|
||||
use redis::{AsyncCommands as _, Client, FromRedisValue, ToRedisArgs};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use color_eyre::eyre::{eyre, Context as _, Result};
|
||||
use log::*;
|
||||
use log::debug;
|
||||
use once_cell::sync::Lazy;
|
||||
use poise::serenity_prelude::{
|
||||
ChannelId, ChannelType, Colour, Context, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter,
|
||||
|
@ -19,7 +19,7 @@ pub fn find_first_image(msg: &Message) -> Option<String> {
|
|||
.find(|a| {
|
||||
a.content_type
|
||||
.as_ref()
|
||||
.unwrap_or(&"".to_string())
|
||||
.unwrap_or(&String::new())
|
||||
.starts_with("image/")
|
||||
})
|
||||
.map(|res| res.url.clone())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue