Fixed some Clippy lints
This commit is contained in:
parent
ebf8bf1cb2
commit
244dfac270
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1514,7 +1514,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shibe-bot"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"build-time",
|
||||
"dotenvy",
|
||||
|
@ -1,6 +1,9 @@
|
||||
[package]
|
||||
name = "shibe-bot"
|
||||
version = "0.3.0"
|
||||
description = "A Discord bot written in Rust, using Poise."
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
version = "0.3.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Shibe Bot 0.3.0
|
||||
# Shibe Bot 0.3.1
|
||||
|
||||
[](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml)
|
||||
[](LICENSE.txt)
|
||||
|
@ -4,10 +4,10 @@ use crate::Error;
|
||||
use poise::serenity_prelude as serenity;
|
||||
|
||||
use rand::prelude::SliceRandom;
|
||||
use rand::*;
|
||||
use rand::Rng;
|
||||
|
||||
use roux::util::*;
|
||||
use roux::*;
|
||||
use roux::util::{FeedOption, TimePeriod};
|
||||
use roux::Subreddit;
|
||||
|
||||
/// mrow
|
||||
#[poise::command(slash_command)]
|
||||
@ -31,11 +31,12 @@ pub async fn meow(ctx: Context<'_>) -> Result<(), Error> {
|
||||
];
|
||||
let response = {
|
||||
let mut rng = rand::thread_rng();
|
||||
match rng.gen_bool(0.05) {
|
||||
true => "woof",
|
||||
if rng.gen_bool(0.05) {
|
||||
"woof"
|
||||
// Will never return None. The source is statically defined.
|
||||
// We know it will always have items in it.
|
||||
false => meows
|
||||
} else {
|
||||
meows
|
||||
.choose(&mut rng)
|
||||
.ok_or("`meows` array is empty")
|
||||
.inspect_err(|e| {
|
||||
@ -108,7 +109,7 @@ pub async fn eightball(ctx: Context<'_>) -> Result<(), Error> {
|
||||
.choose(&mut rng)
|
||||
.ok_or("Response array is empty".to_string())
|
||||
.inspect_err(|e| {
|
||||
error!("Executing command `eightball` failed: {}", e)
|
||||
error!("Executing command `eightball` failed: {}", e);
|
||||
})?
|
||||
};
|
||||
ctx.say(format!("Magic 8-ball says: '{}'", *response))
|
||||
@ -151,7 +152,7 @@ pub async fn deer(ctx: Context<'_>) -> Result<(), Error> {
|
||||
.choose(&mut rng)
|
||||
.ok_or("Unable to get any hot posts")
|
||||
.inspect_err(|e| {
|
||||
error!("Executing command `deer` failed: {}", e)
|
||||
error!("Executing command `deer` failed: {}", e);
|
||||
})?
|
||||
};
|
||||
ctx.say(format!("https://vxreddit.com{}", &chosen_post.data.permalink))
|
||||
|
@ -13,10 +13,9 @@ const INVITE_LINK: &str = "https://discord.com/oauth2/authorize?client_id=103070
|
||||
pub async fn invite(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.defer_ephemeral().await?;
|
||||
ctx.say(format!(
|
||||
"To add me to your server, click [this link]({}), or open it in the \
|
||||
"To add me to your server, click [this link]({INVITE_LINK}), or open it in the \
|
||||
browser and enable all the requested permissions. Then select your \
|
||||
server to add it.",
|
||||
INVITE_LINK
|
||||
))
|
||||
.await?;
|
||||
info!("Executed command `invite` successfully");
|
||||
@ -69,14 +68,11 @@ pub async fn add_channel(
|
||||
match config.channels.iter().find(|item| **item == channel_id) {
|
||||
None => {
|
||||
config.channels.push(channel_id);
|
||||
ctx.say(format!(
|
||||
"Successfully added <#{}> to the channel registry.",
|
||||
channel_id
|
||||
))
|
||||
ctx.say(format!("Successfully added <#{channel_id}> to the channel registry."))
|
||||
.await?;
|
||||
}
|
||||
Some(_) => {
|
||||
ctx.say(format!("Channel <#{}> is already in registry.", channel_id))
|
||||
ctx.say(format!("Channel <#{channel_id}> is already in registry."))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -96,18 +92,12 @@ pub async fn remove_channel(
|
||||
let channel_id = { u64::from(channel.id()) };
|
||||
match config.channels.iter().position(|item| *item == channel_id) {
|
||||
None => {
|
||||
ctx.say(format!(
|
||||
"Channel <#{}> was not in the channel registry.",
|
||||
channel_id
|
||||
))
|
||||
ctx.say(format!("Channel <#{channel_id}> was not in the channel registry."))
|
||||
.await?;
|
||||
}
|
||||
Some(found) => {
|
||||
config.channels.remove(found);
|
||||
ctx.say(format!(
|
||||
"Successfully removed <#{}> from the channel registry.",
|
||||
channel_id
|
||||
))
|
||||
ctx.say(format!("Successfully removed <#{channel_id}> from the channel registry."))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -155,12 +145,7 @@ pub async fn dice(
|
||||
}
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
format!(
|
||||
"Rolled a random number from 1 to {}, got: {}",
|
||||
sides, answer
|
||||
)
|
||||
}
|
||||
_ => format!("Rolled a random number from 1 to {sides}, got: {answer}")
|
||||
};
|
||||
ctx.say(response).await?;
|
||||
info!("Executed command `dice` successfully");
|
||||
|
12
src/main.rs
12
src/main.rs
@ -17,9 +17,9 @@ extern crate pretty_env_logger;
|
||||
extern crate log;
|
||||
|
||||
// For managing config storage
|
||||
use serde::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
mod settings;
|
||||
use crate::settings::*;
|
||||
use crate::settings::Manager;
|
||||
|
||||
// Bot commands
|
||||
mod command;
|
||||
@ -34,7 +34,7 @@ use crate::command::{
|
||||
|
||||
// Data passed to every command (shared state)
|
||||
struct Data {
|
||||
config_manager: Arc<Mutex<SettingsManager<Settings>>>,
|
||||
config_manager: Arc<Mutex<Manager<Settings>>>,
|
||||
}
|
||||
|
||||
// Errors returnable by a command
|
||||
@ -87,9 +87,9 @@ async fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
||||
// Configure persistent options
|
||||
let config_manager: Arc<Mutex<SettingsManager<Settings>>> = Arc::new(Mutex::new(
|
||||
SettingsManager::load(SETTINGS_PATH)
|
||||
.unwrap_or(SettingsManager::manage(SETTINGS_PATH, Settings::default())),
|
||||
let config_manager: Arc<Mutex<Manager<Settings>>> = Arc::new(Mutex::new(
|
||||
Manager::load(SETTINGS_PATH)
|
||||
.unwrap_or(Manager::manage(SETTINGS_PATH, Settings::default())),
|
||||
));
|
||||
config_manager.lock().await.store();
|
||||
|
||||
|
@ -5,12 +5,12 @@ use serde::de::Deserialize;
|
||||
use serde::ser::Serialize;
|
||||
|
||||
/// A utility structure to manage a settings structure.
|
||||
pub struct SettingsManager<T: Default + Serialize + for<'a> Deserialize<'a>> {
|
||||
pub struct Manager<T: Default + Serialize + for<'a> Deserialize<'a>> {
|
||||
internal: T,
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> SettingsManager<T> {
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> Manager<T> {
|
||||
/// Instantiate new self if the path contains a valid serialization of
|
||||
/// the settings structure.
|
||||
pub fn load(path: &str) -> Option<Self> {
|
||||
@ -52,7 +52,7 @@ impl<T: Default + Serialize + for<'a> Deserialize<'a>> SettingsManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> Deref for SettingsManager<T> {
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> Deref for Manager<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -60,7 +60,7 @@ impl<T: Default + Serialize + for<'a> Deserialize<'a>> Deref for SettingsManager
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> DerefMut for SettingsManager<T> {
|
||||
impl<T: Default + Serialize + for<'a> Deserialize<'a>> DerefMut for Manager<T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.internal
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user