cleared up more clippy issues
This commit is contained in:
parent
e515589879
commit
f13853d445
@ -121,7 +121,7 @@ async fn clock(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
|
@ -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 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_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();
|
||||
|
||||
if args.len() == 0 {
|
||||
if args.is_empty() {
|
||||
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "offset/help").await).await;
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
else {
|
||||
@ -248,7 +248,7 @@ impl LookFlags {
|
||||
fn from_string(args: &str) -> Self {
|
||||
let mut new_flags: Self = Default::default();
|
||||
|
||||
for arg in args.split(" ") {
|
||||
for arg in args.split(' ') {
|
||||
match arg {
|
||||
"enabled" => {
|
||||
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 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,
|
||||
"
|
||||
@ -340,7 +340,7 @@ LIMIT
|
||||
.await
|
||||
}.unwrap();
|
||||
|
||||
if reminders.len() == 0 {
|
||||
if reminders.is_empty() {
|
||||
let _ = msg.channel_id.say(&ctx, user_data.response(&pool, "look/no_reminders").await).await;
|
||||
}
|
||||
else {
|
||||
@ -419,7 +419,7 @@ WHERE
|
||||
.channel_id(msg.channel_id).await;
|
||||
|
||||
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
|
||||
.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 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() {
|
||||
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 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 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(time_crop)
|
||||
.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()
|
||||
.await;
|
||||
|
||||
|
@ -294,10 +294,8 @@ impl Framework for RegexFramework {
|
||||
// gate to prevent analysing messages unnecessarily
|
||||
if (msg.author.bot && self.ignore_bots) ||
|
||||
msg.tts ||
|
||||
msg.content.len() == 0 ||
|
||||
msg.attachments.len() > 0 {
|
||||
return
|
||||
}
|
||||
msg.content.is_empty() ||
|
||||
!msg.attachments.is_empty() {}
|
||||
|
||||
// Guild Command
|
||||
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
|
||||
else {
|
||||
if let Some(full_match) = self.dm_regex_matcher.captures(&msg.content[..]) {
|
||||
else 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 args = full_match.name("args")
|
||||
.map(|m| m.as_str())
|
||||
@ -361,4 +358,3 @@ impl Framework for RegexFramework {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
.map(
|
||||
|var| var
|
||||
.split(",")
|
||||
.split(',')
|
||||
.filter_map(|item| {
|
||||
item.parse::<u64>().ok()
|
||||
})
|
||||
|
@ -21,7 +21,7 @@ pub struct GuildData {
|
||||
|
||||
impl GuildData {
|
||||
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,
|
||||
"
|
||||
@ -85,7 +85,7 @@ SELECT * FROM channels WHERE channel = ?
|
||||
pub async fn from_channel(channel: Channel, pool: &MySqlPool)
|
||||
-> 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,
|
||||
"
|
||||
@ -97,7 +97,7 @@ SELECT * FROM channels WHERE channel = ?
|
||||
Ok(c)
|
||||
}
|
||||
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 {
|
||||
(Some(a), Some(b))
|
||||
@ -142,7 +142,7 @@ pub struct UserData {
|
||||
|
||||
impl UserData {
|
||||
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,
|
||||
"
|
||||
@ -198,9 +198,9 @@ SELECT value FROM strings WHERE (language = ? OR language = 'EN') AND name = ? O
|
||||
", self.language, name)
|
||||
.fetch_one(pool)
|
||||
.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user