cleared up more clippy issues

This commit is contained in:
jude 2020-09-25 23:07:22 +01:00
parent e515589879
commit f13853d445
5 changed files with 28 additions and 32 deletions

View File

@ -121,7 +121,7 @@ async fn clock(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let now = Utc::now().with_timezone(&tz); let now = Utc::now().with_timezone(&tz);
if args == "12".to_string() { if args == "12" {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "clock/time").await.replacen("{}", &now.format("%I:%M:%S %p").to_string(), 1)).await; let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "clock/time").await.replacen("{}", &now.format("%I:%M:%S %p").to_string(), 1)).await;
} }
else { else {

View File

@ -93,7 +93,7 @@ async fn pause(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool).await.unwrap(); let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool).await.unwrap();
if args.len() == 0 { if args.is_empty() {
channel.paused = !channel.paused; channel.paused = !channel.paused;
channel.paused_until = None; channel.paused_until = None;
@ -137,7 +137,7 @@ async fn offset(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
if args.len() == 0 { if args.is_empty() {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "offset/help").await).await; let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "offset/help").await).await;
} }
else { else {
@ -189,7 +189,7 @@ async fn nudge(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool).await.unwrap(); let mut channel = ChannelData::from_channel(msg.channel(&ctx).await.unwrap(), &pool).await.unwrap();
if args.len() == 0 { if args.is_empty() {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "nudge/invalid_time").await).await; let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "nudge/invalid_time").await).await;
} }
else { else {
@ -248,7 +248,7 @@ impl LookFlags {
fn from_string(args: &str) -> Self { fn from_string(args: &str) -> Self {
let mut new_flags: Self = Default::default(); let mut new_flags: Self = Default::default();
for arg in args.split(" ") { for arg in args.split(' ') {
match arg { match arg {
"enabled" => { "enabled" => {
new_flags.show_disabled = false; new_flags.show_disabled = false;
@ -301,7 +301,7 @@ async fn look(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let enabled = if flags.show_disabled { "0,1" } else { "1" }; let enabled = if flags.show_disabled { "0,1" } else { "1" };
let reminders = if let Some(guild_id) = msg.guild_id.map(|f| f.as_u64().to_owned()) { let reminders = if let Some(guild_id) = msg.guild_id.map(|f| f.as_u64().to_owned()) {
let channel_id = flags.channel_id.unwrap_or(msg.channel_id.as_u64().to_owned()); let channel_id = flags.channel_id.unwrap_or_else(|| msg.channel_id.as_u64().to_owned());
sqlx::query_as!(Reminder, sqlx::query_as!(Reminder,
" "
@ -340,7 +340,7 @@ LIMIT
.await .await
}.unwrap(); }.unwrap();
if reminders.len() == 0 { if reminders.is_empty() {
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "look/no_reminders").await).await; let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "look/no_reminders").await).await;
} }
else { else {
@ -419,7 +419,7 @@ WHERE
.channel_id(msg.channel_id).await; .channel_id(msg.channel_id).await;
if let Some(content) = reply.map(|m| m.content.replace(",", " ")) { if let Some(content) = reply.map(|m| m.content.replace(",", " ")) {
let parts = content.split(" ").filter(|i| i.len() > 0).collect::<Vec<&str>>(); let parts = content.split(' ').filter(|i| !i.is_empty()).collect::<Vec<&str>>();
let valid_parts = parts let valid_parts = parts
.iter() .iter()
@ -474,9 +474,9 @@ async fn timer(ctx: &Context, msg: &Message, args: String) -> CommandResult {
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let mut args_iter = args.splitn(2, " "); let mut args_iter = args.splitn(2, ' ');
let owner = msg.guild_id.map(|g| g.as_u64().to_owned()).unwrap_or(msg.author.id.as_u64().to_owned()); let owner = msg.guild_id.map(|g| g.as_u64().to_owned()).unwrap_or_else(|| msg.author.id.as_u64().to_owned());
match args_iter.next() { match args_iter.next() {
Some("list") => { Some("list") => {
@ -670,7 +670,7 @@ async fn remind_command(ctx: &Context, msg: &Message, args: String, command: Rem
let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap(); let user_data = UserData::from_user(&msg.author, &ctx, &pool).await.unwrap();
let mut args_iter = args.split(' ').filter(|s| s.len() > 0); let mut args_iter = args.split(' ').filter(|s| !s.is_empty());
let mut time_parser = None; let mut time_parser = None;
let mut scope_id = ReminderScope::Channel(msg.channel_id.as_u64().to_owned()); let mut scope_id = ReminderScope::Channel(msg.channel_id.as_u64().to_owned());
@ -740,7 +740,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult {
.arg("dp.py") .arg("dp.py")
.arg(time_crop) .arg(time_crop)
.arg(user_data.timezone) .arg(user_data.timezone)
.arg(&env::var("LOCAL_TIMEZONE").unwrap_or("UTC".to_string())) .arg(&env::var("LOCAL_TIMEZONE").unwrap_or_else(|_| "UTC".to_string()))
.output() .output()
.await; .await;

View File

@ -294,10 +294,8 @@ impl Framework for RegexFramework {
// gate to prevent analysing messages unnecessarily // gate to prevent analysing messages unnecessarily
if (msg.author.bot && self.ignore_bots) || if (msg.author.bot && self.ignore_bots) ||
msg.tts || msg.tts ||
msg.content.len() == 0 || msg.content.is_empty() ||
msg.attachments.len() > 0 { !msg.attachments.is_empty() {}
return
}
// Guild Command // Guild Command
else if let (Some(guild), Some(Channel::Guild(channel))) = (msg.guild(&ctx).await, msg.channel(&ctx).await) { else if let (Some(guild), Some(Channel::Guild(channel))) = (msg.guild(&ctx).await, msg.channel(&ctx).await) {
@ -349,8 +347,7 @@ impl Framework for RegexFramework {
} }
// DM Command // DM Command
else { else if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap(); let command = self.commands.get(full_match.name("cmd").unwrap().as_str()).unwrap();
let args = full_match.name("args") let args = full_match.name("args")
.map(|m| m.as_str()) .map(|m| m.as_str())
@ -361,4 +358,3 @@ impl Framework for RegexFramework {
} }
} }
} }
}

View File

@ -135,7 +135,7 @@ pub async fn check_subscription(cache_http: impl CacheHttp, user_id: impl Into<U
let role_ids = env::var("SUBSCRIPTION_ROLES") let role_ids = env::var("SUBSCRIPTION_ROLES")
.map( .map(
|var| var |var| var
.split(",") .split(',')
.filter_map(|item| { .filter_map(|item| {
item.parse::<u64>().ok() item.parse::<u64>().ok()
}) })

View File

@ -21,7 +21,7 @@ pub struct GuildData {
impl GuildData { impl GuildData {
pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> { pub async fn from_guild(guild: Guild, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
let guild_id = guild.id.as_u64().clone(); let guild_id = guild.id.as_u64().to_owned();
if let Ok(g) = sqlx::query_as!(Self, if let Ok(g) = sqlx::query_as!(Self,
" "
@ -85,7 +85,7 @@ SELECT * FROM channels WHERE channel = ?
pub async fn from_channel(channel: Channel, pool: &MySqlPool) pub async fn from_channel(channel: Channel, pool: &MySqlPool)
-> Result<Self, Box<dyn std::error::Error + Sync + Send>> -> Result<Self, Box<dyn std::error::Error + Sync + Send>>
{ {
let channel_id = channel.id().as_u64().clone(); let channel_id = channel.id().as_u64().to_owned();
if let Ok(c) = sqlx::query_as_unchecked!(Self, if let Ok(c) = sqlx::query_as_unchecked!(Self,
" "
@ -97,7 +97,7 @@ SELECT * FROM channels WHERE channel = ?
Ok(c) Ok(c)
} }
else { else {
let props = channel.guild().map(|g| (g.guild_id.as_u64().clone(), g.name)); let props = channel.guild().map(|g| (g.guild_id.as_u64().to_owned(), g.name));
let (guild_id, channel_name) = if let Some((a, b)) = props { let (guild_id, channel_name) = if let Some((a, b)) = props {
(Some(a), Some(b)) (Some(a), Some(b))
@ -142,7 +142,7 @@ pub struct UserData {
impl UserData { impl UserData {
pub async fn from_user(user: &User, ctx: impl CacheHttp, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> { pub async fn from_user(user: &User, ctx: impl CacheHttp, pool: &MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
let user_id = user.id.as_u64().clone(); let user_id = user.id.as_u64().to_owned();
if let Ok(c) = sqlx::query_as_unchecked!(Self, if let Ok(c) = sqlx::query_as_unchecked!(Self,
" "
@ -198,9 +198,9 @@ SELECT value FROM strings WHERE (language = ? OR language = 'EN') AND name = ? O
", self.language, name) ", self.language, name)
.fetch_one(pool) .fetch_one(pool)
.await .await
.expect(&format!("No string with that name: {}", name)); .unwrap_or_else(|_| panic!("No string with that name: {}", name));
row.value.expect(&format!("Null string with that name: {}", name)) row.value.unwrap_or_else(|| panic!("Null string with that name: {}", name))
} }
pub fn timezone(&self) -> Tz { pub fn timezone(&self) -> Tz {