Add prefix customization command
This commit is contained in:
@@ -253,6 +253,36 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_or_create_by_id(
|
||||
id: u64,
|
||||
session: &Session,
|
||||
http: &Client,
|
||||
) -> Result<Self, DatabaseOrDiscordError> {
|
||||
let server = Server::get_by_id(id, session)
|
||||
.await
|
||||
.map_err(DatabaseOrDiscordError::Database)?;
|
||||
|
||||
if let Some(server) = server {
|
||||
Ok(server)
|
||||
} else {
|
||||
let server: Server = http
|
||||
.guild(Id::new(id))
|
||||
.await
|
||||
.map_err(DatabaseOrDiscordError::Discord)?
|
||||
.model()
|
||||
.await
|
||||
.map_err(|_| DatabaseOrDiscordError::DiscordDeserializationFailed)?
|
||||
.into();
|
||||
|
||||
server
|
||||
.insert(session)
|
||||
.await
|
||||
.map_err(DatabaseOrDiscordError::Database)?;
|
||||
|
||||
Ok(server)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn insert(&self, session: &Session) -> Result<(), DatabaseError> {
|
||||
session
|
||||
.query_unpaged(
|
||||
|
||||
Reference in New Issue
Block a user