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