Final migration updates
This commit is contained in:
+130
-29
@@ -13,9 +13,7 @@ use thiserror::Error;
|
||||
use time::{Duration, OffsetDateTime, UtcDateTime, UtcOffset};
|
||||
use twilight_http::Client;
|
||||
use twilight_model::{
|
||||
channel::Message as TwilightMessage,
|
||||
guild::{Guild as TwilightGuild, GuildInfo as TwilightGuildInfo},
|
||||
id::Id,
|
||||
channel::Message as TwilightMessage, guild::Guild as TwilightGuild, id::Id,
|
||||
user::User as TwilightUser,
|
||||
};
|
||||
|
||||
@@ -205,7 +203,7 @@ impl User {
|
||||
pub async fn incident(
|
||||
&self,
|
||||
reason: String,
|
||||
message: MessageData,
|
||||
message: Option<MessageData>,
|
||||
created_by_id: Option<u64>,
|
||||
session: &Session,
|
||||
) -> Result<NewUserIncident, DatabaseError> {
|
||||
@@ -270,21 +268,28 @@ pub struct Server {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub prefix: String,
|
||||
pub language: String,
|
||||
}
|
||||
|
||||
impl<'a> Object<'a> for Server {
|
||||
type Row = (i64, String, String);
|
||||
type Row = (i64, String, String, String);
|
||||
|
||||
fn from_row(row: Self::Row) -> Self {
|
||||
Self {
|
||||
id: i64_to_u64(row.0),
|
||||
name: row.1,
|
||||
prefix: row.2,
|
||||
language: row.3,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_row(value: Self) -> Self::Row {
|
||||
(u64_to_i64(value.id), value.name, value.prefix)
|
||||
(
|
||||
u64_to_i64(value.id),
|
||||
value.name,
|
||||
value.prefix,
|
||||
value.language,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +303,8 @@ impl Server {
|
||||
SELECT
|
||||
server_id,
|
||||
name,
|
||||
prefix
|
||||
prefix,
|
||||
language
|
||||
FROM
|
||||
payphone.servers
|
||||
WHERE
|
||||
@@ -360,8 +366,9 @@ impl Server {
|
||||
INSERT INTO payphone.servers (
|
||||
server_id,
|
||||
name,
|
||||
prefix
|
||||
) VALUES (?, ?, ?) IF NOT EXISTS;
|
||||
prefix,
|
||||
language
|
||||
) VALUES (?, ?, ?, ?) IF NOT EXISTS;
|
||||
"#,
|
||||
Self::to_row(self.clone()),
|
||||
)
|
||||
@@ -379,11 +386,13 @@ impl Server {
|
||||
INSERT INTO payphone.servers (
|
||||
server_id,
|
||||
name,
|
||||
prefix
|
||||
prefix,
|
||||
language
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?
|
||||
?,
|
||||
?
|
||||
);
|
||||
"#,
|
||||
Self::to_row(self.clone()),
|
||||
@@ -413,16 +422,7 @@ impl From<TwilightGuild> for Server {
|
||||
id: value.id.get(),
|
||||
name: value.name,
|
||||
prefix: DEFAULT_PREFIX.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TwilightGuildInfo> for Server {
|
||||
fn from(value: TwilightGuildInfo) -> Self {
|
||||
Self {
|
||||
id: value.id.get(),
|
||||
name: value.name,
|
||||
prefix: DEFAULT_PREFIX.into(),
|
||||
language: value.preferred_locale,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -933,7 +933,7 @@ pub struct MessageData {
|
||||
pub propagation_message_id: Option<i64>,
|
||||
pub propagation_channel_id: Option<i64>,
|
||||
|
||||
pub replying_to_id: Option<i64>,
|
||||
pub replying_to_message_id: Option<i64>,
|
||||
|
||||
pub is_deleted: bool,
|
||||
pub is_edited: bool,
|
||||
@@ -952,7 +952,7 @@ pub struct MessageBuilder {
|
||||
is_censored: bool,
|
||||
propagation_message_id: Option<u64>,
|
||||
propagation_channel_id: Option<u64>,
|
||||
replying_to_id: Option<u64>,
|
||||
replying_to_message_id: Option<u64>,
|
||||
}
|
||||
|
||||
impl MessageBuilder {
|
||||
@@ -964,7 +964,7 @@ impl MessageBuilder {
|
||||
is_censored: false,
|
||||
propagation_message_id: None,
|
||||
propagation_channel_id: None,
|
||||
replying_to_id: None,
|
||||
replying_to_message_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1001,8 +1001,8 @@ impl MessageBuilder {
|
||||
|
||||
// Argument is made optional here because it happens to be more convenient for where this is
|
||||
// used.
|
||||
pub fn replying_to_id(mut self, replying_to_id: Option<u64>) -> Self {
|
||||
self.replying_to_id = replying_to_id;
|
||||
pub fn replying_to_message_id(mut self, replying_to_id: Option<u64>) -> Self {
|
||||
self.replying_to_message_id = replying_to_id;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1026,7 +1026,7 @@ impl MessageBuilder {
|
||||
.map(|s| u64_to_i64(s.id.get())),
|
||||
propagation_message_id: self.propagation_message_id.map(u64_to_i64),
|
||||
propagation_channel_id: self.propagation_channel_id.map(u64_to_i64),
|
||||
replying_to_id: self.replying_to_id.map(u64_to_i64),
|
||||
replying_to_message_id: self.replying_to_message_id.map(u64_to_i64),
|
||||
|
||||
// You can't create a deleted message, this is always going to be false when
|
||||
// initializing
|
||||
@@ -1225,6 +1225,107 @@ impl MessageByPropagationId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ReportResolution {
|
||||
Ban,
|
||||
Warn,
|
||||
Skip,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Report {
|
||||
pub id: u64,
|
||||
pub user_id: u64,
|
||||
|
||||
pub message: MessageData,
|
||||
pub replying_to: Option<MessageData>,
|
||||
|
||||
pub created_at: UtcDateTime,
|
||||
pub reviewed_at: Option<UtcDateTime>,
|
||||
|
||||
pub created_by_ids: Vec<u64>,
|
||||
|
||||
pub reviewed_by_id: Option<u64>,
|
||||
pub resolution: Option<ReportResolution>,
|
||||
}
|
||||
|
||||
impl<'a> Object<'a> for Report {
|
||||
type Row = (
|
||||
i64,
|
||||
i64,
|
||||
MessageData,
|
||||
Option<MessageData>,
|
||||
OffsetDateTime,
|
||||
Option<OffsetDateTime>,
|
||||
Vec<i64>,
|
||||
Option<i64>,
|
||||
Option<String>,
|
||||
);
|
||||
|
||||
fn from_row(row: Self::Row) -> Self {
|
||||
Self {
|
||||
id: i64_to_u64(row.0),
|
||||
user_id: i64_to_u64(row.1),
|
||||
message: row.2,
|
||||
replying_to: row.3,
|
||||
created_at: row.4.to_utc(),
|
||||
reviewed_at: row.5.map(|i| i.to_utc()),
|
||||
created_by_ids: row.6.into_iter().map(i64_to_u64).collect(),
|
||||
reviewed_by_id: row.7.map(i64_to_u64),
|
||||
resolution: row.8.map(|r| match r.as_str() {
|
||||
"ban" => ReportResolution::Ban,
|
||||
"warn" => ReportResolution::Warn,
|
||||
"skip" => ReportResolution::Skip,
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_row(value: Self) -> Self::Row {
|
||||
(
|
||||
u64_to_i64(value.id),
|
||||
u64_to_i64(value.user_id),
|
||||
value.message,
|
||||
value.replying_to,
|
||||
value.created_at.to_offset(UtcOffset::UTC),
|
||||
value.reviewed_at.map(|i| i.to_offset(UtcOffset::UTC)),
|
||||
value.created_by_ids.into_iter().map(u64_to_i64).collect(),
|
||||
value.reviewed_by_id.map(u64_to_i64),
|
||||
value.resolution.map(|r| match r {
|
||||
ReportResolution::Ban => "ban".into(),
|
||||
ReportResolution::Warn => "warn".into(),
|
||||
ReportResolution::Skip => "skip".into(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Report {
|
||||
pub async fn insert(&self, session: &Session) -> Result<(), DatabaseError> {
|
||||
session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
INSERT INTO payphone.reports (
|
||||
report_id,
|
||||
user_id,
|
||||
message,
|
||||
replying_to,
|
||||
created_at,
|
||||
reviewed_at,
|
||||
created_by_ids,
|
||||
reviewed_by_id,
|
||||
resolution
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
"#,
|
||||
Self::to_row(self.clone()),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum UserIncidentType {
|
||||
Warning,
|
||||
@@ -1239,7 +1340,7 @@ pub struct UserIncident {
|
||||
|
||||
pub r#type: UserIncidentType,
|
||||
|
||||
pub message: MessageData,
|
||||
pub message: Option<MessageData>,
|
||||
|
||||
pub reason: String,
|
||||
|
||||
@@ -1256,7 +1357,7 @@ impl<'a> Object<'a> for UserIncident {
|
||||
i64,
|
||||
Option<i64>,
|
||||
String,
|
||||
MessageData,
|
||||
Option<MessageData>,
|
||||
String,
|
||||
Option<i64>,
|
||||
OffsetDateTime,
|
||||
|
||||
Reference in New Issue
Block a user