Skip to content

Commit 0b0779f

Browse files
committed
clean up
1 parent 9dfc3b2 commit 0b0779f

32 files changed

+137
-181
lines changed

Cargo.lock

+2-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ eyre = "0.6.11"
2323
log = "0.4.20"
2424
poise = "0.6.1"
2525
octocrab = "0.37.0"
26-
owo-colors = "4.0.0"
2726
redis = { version = "0.25.2", features = ["tokio-comp", "tokio-rustls-comp"] }
2827
regex = "1.10.3"
2928
reqwest = { version = "0.12.2", default-features = false, features = [
@@ -37,7 +36,17 @@ tokio = { version = "1.35.1", features = [
3736
"rt-multi-thread",
3837
"signal",
3938
] }
40-
url = { version = "2.5.0", features = ["serde"] }
39+
40+
[lints.rust]
41+
unsafe_code = "forbid"
42+
43+
[lints.clippy]
44+
complexity = "warn"
45+
correctness = "deny"
46+
pedantic = "warn"
47+
perf = "warn"
48+
style = "warn"
49+
suspicious = "deny"
4150

4251
[profile.release]
4352
codegen-units = 1

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use gray_matter::{engine, Matter};
66

77
include!("src/tags.rs");
88

9-
/// generate the ChoiceParameter enum and tag data we will use in the `tag` command
9+
/// generate the `ChoiceParameter` enum and tag data we will use in the `tag` command
1010
#[allow(dead_code)]
1111
fn main() {
1212
let out_dir = env::var_os("OUT_DIR").unwrap();

src/api/github.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::sync::{Arc, OnceLock};
1+
use std::sync::OnceLock;
22

33
use eyre::{Context, OptionExt, Result};
44
use log::debug;
55
use octocrab::Octocrab;
66

7-
fn octocrab() -> &'static Arc<Octocrab> {
8-
static OCTOCRAB: OnceLock<Arc<Octocrab>> = OnceLock::new();
9-
OCTOCRAB.get_or_init(octocrab::instance)
7+
fn octocrab() -> &'static Octocrab {
8+
static OCTOCRAB: OnceLock<Octocrab> = OnceLock::new();
9+
OCTOCRAB.get_or_init(Octocrab::default)
1010
}
1111

1212
pub async fn get_latest_prism_version() -> Result<String> {

src/api/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::OnceLock;
33
use eyre::Result;
44
use log::debug;
55
use reqwest::{Client, Response};
6+
use serde::de::DeserializeOwned;
67

78
pub mod dadjoke;
89
pub mod github;
@@ -44,3 +45,10 @@ pub async fn bytes_from_url(url: &str) -> Result<Vec<u8>> {
4445
let bytes = resp.bytes().await?;
4546
Ok(bytes.to_vec())
4647
}
48+
49+
pub async fn json_from_url<T: DeserializeOwned>(url: &str) -> Result<T> {
50+
let resp = get_url(url).await?;
51+
52+
let json = resp.json().await?;
53+
Ok(json)
54+
}

src/api/paste_gg.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const PASTE_GG: &str = "https://api.paste.gg/v1";
66
const PASTES: &str = "/pastes";
77

88
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize)]
9-
enum Status {
9+
pub enum Status {
1010
#[serde(rename = "success")]
1111
Success,
1212
#[serde(rename = "error")]
@@ -15,10 +15,10 @@ enum Status {
1515

1616
#[derive(Clone, Debug, Deserialize, Serialize)]
1717
pub struct Response<T> {
18-
status: Status,
18+
pub status: Status,
1919
pub result: Option<Vec<T>>,
20-
error: Option<String>,
21-
message: Option<String>,
20+
pub error: Option<String>,
21+
pub message: Option<String>,
2222
}
2323

2424
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -27,12 +27,11 @@ pub struct Files {
2727
pub name: Option<String>,
2828
}
2929

30-
pub async fn get_files(id: &str) -> Result<Response<Files>> {
30+
pub async fn files_from(id: &str) -> Result<Response<Files>> {
3131
let url = format!("{PASTE_GG}{PASTES}/{id}/files");
3232
debug!("Making request to {url}");
33-
let resp = super::client().get(url).send().await?;
34-
resp.error_for_status_ref()?;
35-
let resp: Response<Files> = resp.json().await?;
33+
34+
let resp: Response<Files> = super::json_from_url(&url).await?;
3635

3736
if resp.status == Status::Error {
3837
let message = resp

src/api/pluralkit.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ pub struct Message {
1111
const PLURAL_KIT: &str = "https://api.pluralkit.me/v2";
1212
const MESSAGES: &str = "/messages";
1313

14-
pub async fn get_sender(message_id: MessageId) -> Result<UserId> {
14+
pub async fn sender_from(message_id: MessageId) -> Result<UserId> {
1515
let url = format!("{PLURAL_KIT}{MESSAGES}/{message_id}");
16-
1716
debug!("Making request to {url}");
18-
let resp = super::client().get(url).send().await?;
19-
resp.error_for_status_ref()?;
2017

21-
let data: Message = resp.json().await?;
18+
let resp: Message = super::json_from_url(&url).await?;
19+
2220
let id: u64 =
23-
data.sender.parse().wrap_err_with(|| {
24-
format!("Couldn't parse response from PluralKit as a UserId! Here's the response:\n{data:#?}")
21+
resp.sender.parse().wrap_err_with(|| {
22+
format!("Couldn't parse response from PluralKit as a UserId! Here's the response:\n{resp:#?}")
2523
})?;
2624
let sender = UserId::from(id);
2725

src/api/prism_meta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct MinecraftPackageJson {
1414
const META: &str = "https://meta.prismlauncher.org/v1";
1515
const MINECRAFT_PACKAGEJSON: &str = "/net.minecraft/package.json";
1616

17-
pub async fn get_latest_minecraft_version() -> Result<String> {
17+
pub async fn latest_minecraft_version() -> Result<String> {
1818
let url = format!("{META}{MINECRAFT_PACKAGEJSON}");
1919

2020
debug!("Making request to {url}");

src/commands/general/help.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::Context;
1+
use crate::{Context, Error};
22

3-
use eyre::Result;
43
use log::trace;
54
use poise::samples::HelpConfiguration;
65

@@ -9,7 +8,7 @@ use poise::samples::HelpConfiguration;
98
pub async fn help(
109
ctx: Context<'_>,
1110
#[description = "Provide information about a specific command"] command: Option<String>,
12-
) -> Result<()> {
11+
) -> Result<(), Error> {
1312
trace!("Running help command");
1413

1514
let configuration = HelpConfiguration {

src/commands/general/joke.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use crate::api::dadjoke;
2-
use crate::Context;
1+
use crate::{api::dadjoke, Context, Error};
32

43
use eyre::Result;
54
use log::trace;
65

76
/// It's a joke
87
#[poise::command(slash_command, prefix_command, track_edits = true)]
9-
pub async fn joke(ctx: Context<'_>) -> Result<()> {
8+
pub async fn joke(ctx: Context<'_>) -> Result<(), Error> {
109
trace!("Running joke command");
1110

1211
ctx.defer().await?;

src/commands/general/members.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use crate::{consts::Colors, Context};
1+
use crate::{consts::Colors, Context, Error};
22

3-
use eyre::{eyre, Context as _, OptionExt, Result};
3+
use eyre::{eyre, Context as _, OptionExt};
44
use log::trace;
55
use poise::serenity_prelude::CreateEmbed;
66
use poise::CreateReply;
77

88
/// Returns the number of members in the server
99
#[poise::command(slash_command, prefix_command, guild_only = true, track_edits = true)]
10-
pub async fn members(ctx: Context<'_>) -> Result<()> {
10+
pub async fn members(ctx: Context<'_>) -> Result<(), Error> {
1111
trace!("Running members command");
1212

1313
ctx.defer().await?;
@@ -29,7 +29,7 @@ pub async fn members(ctx: Context<'_>) -> Result<()> {
2929
let embed = CreateEmbed::new()
3030
.title(format!("{member_count} total members!",))
3131
.description(format!("{online_count} online members",))
32-
.color(Colors::BLUE);
32+
.color(Colors::Blue);
3333
let reply = CreateReply::default().embed(embed);
3434

3535
ctx.send(reply).await?;

src/commands/general/ping.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::Context;
1+
use crate::{Context, Error};
22

3-
use eyre::Result;
43
use log::trace;
54

65
/// Replies with pong!
76
#[poise::command(slash_command, prefix_command, track_edits = true, ephemeral)]
8-
pub async fn ping(ctx: Context<'_>) -> Result<()> {
7+
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
98
trace!("Running ping command!");
109
ctx.say("Pong!").await?;
1110
Ok(())

src/commands/general/rory.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use crate::api::rory;
2-
use crate::Context;
1+
use crate::{api::rory, Context, Error};
32

4-
use eyre::Result;
53
use log::trace;
64
use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
75
use poise::CreateReply;
@@ -11,7 +9,7 @@ use poise::CreateReply;
119
pub async fn rory(
1210
ctx: Context<'_>,
1311
#[description = "specify a Rory ID"] id: Option<u64>,
14-
) -> Result<()> {
12+
) -> Result<(), Error> {
1513
trace!("Running rory command");
1614

1715
ctx.defer().await?;

src/commands/general/say.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::{utils, Context};
1+
use crate::{utils, Context, Error};
22

3-
use eyre::Result;
43
use log::trace;
54
use poise::serenity_prelude::{CreateEmbed, CreateMessage};
65

@@ -15,18 +14,12 @@ use poise::serenity_prelude::{CreateEmbed, CreateMessage};
1514
pub async fn say(
1615
ctx: Context<'_>,
1716
#[description = "the message content"] content: String,
18-
) -> Result<()> {
17+
) -> Result<(), Error> {
1918
let channel = ctx.channel_id();
2019
channel.say(ctx, &content).await?;
2120
ctx.say("I said what you said!").await?;
2221

23-
if let Some(channel_id) = ctx
24-
.data()
25-
.config
26-
.discord_config()
27-
.channels()
28-
.log_channel_id()
29-
{
22+
if let Some(channel_id) = ctx.data().config.discord.channels.log_channel_id {
3023
let author = utils::embed_author_from_user(ctx.author());
3124

3225
let embed = CreateEmbed::default()

src/commands/general/stars.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::{api, consts::Colors, Context};
1+
use crate::{api, consts::Colors, Context, Error};
22

3-
use eyre::Result;
43
use log::trace;
54
use poise::serenity_prelude::CreateEmbed;
65
use poise::CreateReply;
76

87
/// Returns GitHub stargazer count
98
#[poise::command(slash_command, prefix_command, track_edits = true)]
10-
pub async fn stars(ctx: Context<'_>) -> Result<()> {
9+
pub async fn stars(ctx: Context<'_>) -> Result<(), Error> {
1110
trace!("Running stars command");
1211

1312
ctx.defer().await?;
@@ -27,7 +26,7 @@ pub async fn stars(ctx: Context<'_>) -> Result<()> {
2726

2827
let embed = CreateEmbed::new()
2928
.title(format!("⭐ {count} total stars!"))
30-
.color(Colors::YELLOW);
29+
.color(Colors::Yellow);
3130
let reply = CreateReply::default().embed(embed);
3231

3332
ctx.send(reply).await?;

src/commands/general/tag.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(non_camel_case_types, clippy::upper_case_acronyms)]
2-
use crate::{consts::Colors, tags::Tag, Context};
2+
use crate::{consts::Colors, tags::Tag, Context, Error};
33
use std::env;
44
use std::str::FromStr;
55
use std::sync::OnceLock;
66

7-
use eyre::{eyre, Result};
7+
use eyre::eyre;
88
use log::trace;
99
use poise::serenity_prelude::{Color, CreateEmbed, User};
1010
use poise::CreateReply;
@@ -26,7 +26,7 @@ pub async fn tag(
2626
ctx: Context<'_>,
2727
#[description = "the tag to send"] name: Choice,
2828
#[description = "a user to mention"] user: Option<User>,
29-
) -> Result<()> {
29+
) -> Result<(), Error> {
3030
trace!("Running tag command");
3131

3232
let tag_id = name.as_str();

src/commands/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::Data;
2-
3-
use eyre::Report;
1+
use crate::{Data, Error};
42

53
mod general;
64
mod moderation;
@@ -32,7 +30,7 @@ macro_rules! module_macro {
3230
module_macro!(general);
3331
module_macro!(moderation);
3432

35-
pub type Command = poise::Command<Data, Report>;
33+
pub type Command = poise::Command<Data, Error>;
3634

3735
pub fn get() -> Vec<Command> {
3836
vec![

0 commit comments

Comments
 (0)