Clean up code
Clean up warnings on newer Rust versions. Drop some no-longer used tables and columns
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
SET foreign_key_checks = 0;
|
||||
|
||||
-- Drop all old tables
|
||||
DROP TABLE IF EXISTS users_old;
|
||||
DROP TABLE IF EXISTS messages;
|
||||
DROP TABLE IF EXISTS embeds;
|
||||
DROP TABLE IF EXISTS embed_fields;
|
||||
DROP TABLE IF EXISTS command_aliases;
|
||||
DROP TABLE IF EXISTS macro;
|
||||
DROP TABLE IF EXISTS roles;
|
||||
DROP TABLE IF EXISTS command_restrictions;
|
||||
|
||||
-- Drop columns from channels that are no longer used
|
||||
ALTER TABLE channels DROP COLUMN `name`;
|
||||
ALTER TABLE channels DROP COLUMN `blacklisted`;
|
||||
|
||||
SET foreign_key_checks = 1;
|
||||
@@ -56,7 +56,7 @@ impl Recordable for Options {
|
||||
}),
|
||||
};
|
||||
|
||||
let channel_id = if let Some(channel) = ctx.channel_id().to_channel_cached(&ctx.cache()) {
|
||||
let channel_id = if let Some(channel) = ctx.cache().guild_channel(ctx.channel_id()) {
|
||||
if Some(channel.guild_id) == ctx.guild_id() {
|
||||
flags.channel_id.unwrap_or_else(|| ctx.channel_id())
|
||||
} else {
|
||||
@@ -67,7 +67,7 @@ impl Recordable for Options {
|
||||
};
|
||||
|
||||
let channel_name =
|
||||
channel_id.to_channel_cached(&ctx.cache()).map(|channel| channel.name.clone());
|
||||
ctx.cache().guild_channel(channel_id).map(|channel| channel.name.clone());
|
||||
|
||||
let reminders = Reminder::from_channel(&ctx.data().database, channel_id, &flags).await;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ impl ComponentDataModel {
|
||||
let flags = pager.flags;
|
||||
|
||||
let channel_id = {
|
||||
let channel_opt = component.channel_id.to_channel_cached(&ctx.cache);
|
||||
let channel_opt = ctx.cache.guild_channel(component.channel_id);
|
||||
|
||||
if let Some(channel) = channel_opt {
|
||||
if Some(channel.guild_id) == component.guild_id {
|
||||
@@ -85,7 +85,7 @@ impl ComponentDataModel {
|
||||
.div_ceil(EMBED_DESCRIPTION_MAX_LENGTH);
|
||||
|
||||
let channel_name =
|
||||
channel_id.to_channel_cached(&ctx.cache).map(|channel| channel.name.clone());
|
||||
ctx.cache.guild_channel(channel_id).map(|channel| channel.name.clone());
|
||||
|
||||
let next_page = pager.next_page(pages);
|
||||
|
||||
|
||||
+2
-3
@@ -99,9 +99,8 @@ async fn check_self_permissions(ctx: Context<'_>) -> bool {
|
||||
match ctx.guild().map(|g| g.to_owned()) {
|
||||
Some(guild) => {
|
||||
let manage_webhooks = guild
|
||||
.member(&ctx, user_id)
|
||||
.await
|
||||
.map_or(false, |m| m.permissions(&ctx).map_or(false, |p| p.manage_webhooks()));
|
||||
.member_permissions_in(&ctx, ctx.channel_id(), user_id)
|
||||
.map_or(false, |p| p.manage_webhooks());
|
||||
|
||||
if let Some(permissions) = app_permissions {
|
||||
return if permissions.send_messages()
|
||||
|
||||
@@ -8,9 +8,7 @@ use crate::{consts::DEFAULT_AVATAR, Error};
|
||||
pub struct ChannelData {
|
||||
pub id: u32,
|
||||
pub channel: u64,
|
||||
pub name: Option<String>,
|
||||
pub nudge: i16,
|
||||
pub blacklisted: bool,
|
||||
pub webhook_id: Option<u64>,
|
||||
pub webhook_token: Option<String>,
|
||||
pub paused: bool,
|
||||
@@ -27,7 +25,7 @@ impl ChannelData {
|
||||
if let Ok(c) = sqlx::query_as_unchecked!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused,
|
||||
SELECT id, channel, nudge, webhook_id, webhook_token, paused,
|
||||
paused_until
|
||||
FROM channels
|
||||
WHERE channel = ?
|
||||
@@ -56,7 +54,7 @@ impl ChannelData {
|
||||
Ok(sqlx::query_as_unchecked!(
|
||||
Self,
|
||||
"
|
||||
SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until
|
||||
SELECT id, channel, nudge, webhook_id, webhook_token, paused, paused_until
|
||||
FROM channels
|
||||
WHERE channel = ?
|
||||
",
|
||||
@@ -72,18 +70,14 @@ impl ChannelData {
|
||||
"
|
||||
UPDATE channels
|
||||
SET
|
||||
name = ?,
|
||||
nudge = ?,
|
||||
blacklisted = ?,
|
||||
webhook_id = ?,
|
||||
webhook_token = ?,
|
||||
paused = ?,
|
||||
paused_until = ?
|
||||
WHERE id = ?
|
||||
",
|
||||
self.name,
|
||||
self.nudge,
|
||||
self.blacklisted,
|
||||
self.webhook_id,
|
||||
self.webhook_token,
|
||||
self.paused,
|
||||
|
||||
@@ -42,7 +42,7 @@ impl IpBlocking {
|
||||
fn contains<I: Into<u32>>(&self, ip: I) -> bool {
|
||||
let ip: u32 = ip.into();
|
||||
|
||||
let mut prev_index = self.upper_ips.len() - 1;
|
||||
let _prev_index = self.upper_ips.len() - 1;
|
||||
let mut index = self.upper_ips.len() / 2;
|
||||
loop {
|
||||
if self.upper_ips[index] <= ip && self.lower_ips[index] >= ip {
|
||||
|
||||
+6
-7
@@ -63,7 +63,6 @@ use log::{error, info, warn};
|
||||
use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl};
|
||||
use poise::serenity_prelude::{
|
||||
client::Context,
|
||||
http::CacheHttp,
|
||||
model::id::{GuildId, UserId},
|
||||
};
|
||||
use rocket::{
|
||||
@@ -76,13 +75,9 @@ use rocket::{
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
use sqlx::{MySql, Pool};
|
||||
use std::net::Ipv4Addr;
|
||||
use std::{env, path::Path};
|
||||
|
||||
use crate::web::{
|
||||
consts::{CNC_GUILD, DISCORD_OAUTH_AUTHORIZE, DISCORD_OAUTH_TOKEN, SUBSCRIPTION_ROLES},
|
||||
fairings::metrics::MetricProducer,
|
||||
};
|
||||
use crate::web::fairings::metrics::MetricProducer;
|
||||
|
||||
type Database = MySql;
|
||||
|
||||
@@ -255,7 +250,11 @@ pub async fn check_authorization(
|
||||
|
||||
match guild_id.member(ctx, UserId::new(user_id)).await {
|
||||
Ok(member) => {
|
||||
let permissions_res = member.permissions(ctx);
|
||||
let permissions_res = ctx
|
||||
.cache
|
||||
.guild(guild_id)
|
||||
.map(|g| g.member_permissions_in(ctx, UserId::new(user_id)))
|
||||
.unwrap_or(Err(serenity::all::Error::Other("Guild not in cache")));
|
||||
|
||||
match permissions_res {
|
||||
Err(_) => {
|
||||
|
||||
@@ -5,8 +5,6 @@ mod roles;
|
||||
mod templates;
|
||||
pub mod todos;
|
||||
|
||||
use std::env;
|
||||
|
||||
use crate::utils::check_subscription;
|
||||
use crate::web::guards::transaction::Transaction;
|
||||
use crate::web::{check_authorization, routes::JsonResult};
|
||||
@@ -16,10 +14,7 @@ pub use reminders::*;
|
||||
use rocket::{get, http::CookieJar, serde::json::json, State};
|
||||
pub use roles::get_guild_roles;
|
||||
use serenity::all::UserId;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::id::{GuildId, RoleId},
|
||||
};
|
||||
use serenity::{client::Context, model::id::GuildId};
|
||||
pub use templates::*;
|
||||
|
||||
#[get("/api/guild/<id>")]
|
||||
|
||||
@@ -267,8 +267,9 @@ pub async fn edit_reminder(
|
||||
}
|
||||
|
||||
if reminder.channel > 0 {
|
||||
let channel_guild = ChannelId::new(reminder.channel)
|
||||
.to_channel_cached(&ctx.cache)
|
||||
let channel_guild = ctx
|
||||
.cache
|
||||
.guild_channel(ChannelId::new(reminder.channel))
|
||||
.map(|channel| channel.guild_id);
|
||||
match channel_guild {
|
||||
Some(channel_guild) => {
|
||||
|
||||
@@ -3,13 +3,10 @@ use crate::web::{
|
||||
check_authorization,
|
||||
guards::transaction::Transaction,
|
||||
routes::{
|
||||
dashboard::{
|
||||
create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv,
|
||||
},
|
||||
dashboard::{ImportBody, ReminderTemplateCsv},
|
||||
JsonResult,
|
||||
},
|
||||
};
|
||||
use crate::Database;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
use csv::{QuoteStyle, WriterBuilder};
|
||||
use log::warn;
|
||||
@@ -20,10 +17,7 @@ use rocket::{
|
||||
serde::json::{json, Json},
|
||||
State,
|
||||
};
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
};
|
||||
use serenity::{client::Context, model::id::GuildId};
|
||||
use sqlx::{MySql, Pool};
|
||||
|
||||
#[get("/api/guild/<id>/export/reminder_templates")]
|
||||
|
||||
@@ -2,9 +2,7 @@ use crate::web::{
|
||||
check_authorization,
|
||||
guards::transaction::Transaction,
|
||||
routes::{
|
||||
dashboard::{
|
||||
create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv,
|
||||
},
|
||||
dashboard::{create_reminder, CreateReminder, ImportBody, ReminderCsv},
|
||||
JsonResult,
|
||||
},
|
||||
};
|
||||
@@ -21,7 +19,7 @@ use rocket::{
|
||||
};
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
model::id::{GuildId, UserId},
|
||||
};
|
||||
use sqlx::{MySql, Pool};
|
||||
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::web::{
|
||||
check_authorization,
|
||||
guards::transaction::Transaction,
|
||||
routes::{
|
||||
dashboard::{
|
||||
create_reminder, CreateReminder, ImportBody, ReminderCsv, ReminderTemplateCsv, TodoCsv,
|
||||
},
|
||||
dashboard::{ImportBody, TodoCsv},
|
||||
JsonResult,
|
||||
},
|
||||
};
|
||||
use crate::Database;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
use csv::{QuoteStyle, WriterBuilder};
|
||||
use log::warn;
|
||||
@@ -21,7 +17,7 @@ use rocket::{
|
||||
};
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
model::id::{ChannelId, GuildId},
|
||||
};
|
||||
use sqlx::{MySql, Pool};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ use rocket::{
|
||||
fs::NamedFile, get, http::CookieJar, response::Redirect, serde::json::json, Responder,
|
||||
};
|
||||
use rocket_dyn_templates::Template;
|
||||
use secrecy::ExposeSecret;
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serenity::http::HttpError;
|
||||
use serenity::{
|
||||
|
||||
Reference in New Issue
Block a user