This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change status if not main * Moved postgre functions
- Loading branch information
Showing
6 changed files
with
104 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
use std::process::Command; | ||
|
||
fn main() { | ||
let output = Command::new("git") | ||
let commit = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let git_hash = String::from_utf8(output.stdout).unwrap(); | ||
let branch = Command::new("git") | ||
.args(&["rev-parse", "--abbrev-ref", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
|
||
let git_hash = String::from_utf8(commit.stdout).unwrap(); | ||
let git_branch = String::from_utf8(branch.stdout).unwrap(); | ||
|
||
println!("cargo:rustc-env=GIT_HASH={}", git_hash); | ||
println!("cargo:rustc-env=GIT_BRANCH={}", git_branch); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::PostgresPool; | ||
use serenity::{ | ||
client::Context, | ||
model::id::{GuildId, RoleId, UserId}, | ||
}; | ||
use std::convert::TryFrom; | ||
|
||
pub async fn role(ctx: Context, guild_id: GuildId, role_id: RoleId) { | ||
let data = ctx.data.read().await; | ||
let pool = match data.get::<PostgresPool>() { | ||
Some(v) => v.get().await.unwrap(), | ||
None => { | ||
log::error!("Error getting the postgres pool."); | ||
return; | ||
} | ||
}; | ||
|
||
match pool | ||
.query( | ||
"DELETE FROM roles WHERE id = $1 AND guild_id = $2", | ||
&[ | ||
&i64::try_from(*role_id.as_u64()).unwrap(), | ||
&i64::try_from(*guild_id.as_u64()).unwrap(), | ||
], | ||
) | ||
.await | ||
{ | ||
Ok(_) => log::debug!("Deleted role {} in {}", role_id, guild_id), | ||
Err(e) => log::error!("{:#?}", e), | ||
}; | ||
} | ||
|
||
pub async fn member(ctx: Context, guild_id: GuildId, user_id: UserId) { | ||
let data = ctx.data.read().await; | ||
let pool = match data.get::<PostgresPool>() { | ||
Some(v) => v.get().await.unwrap(), | ||
None => { | ||
log::error!("Error getting the postgres pool."); | ||
return; | ||
} | ||
}; | ||
|
||
match pool | ||
.query( | ||
"DELETE FROM members WHERE id = $1 AND guild_id = $2", | ||
&[ | ||
&i64::try_from(*user_id.as_u64()).unwrap(), | ||
&i64::try_from(*guild_id.as_u64()).unwrap(), | ||
], | ||
) | ||
.await | ||
{ | ||
Ok(_) => log::debug!("Deleted member {} in {}", user_id, guild_id), | ||
Err(e) => log::error!("{:#?}", e), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::PostgresPool; | ||
use serenity::{client::Context, model::id::GuildId}; | ||
use std::convert::TryFrom; | ||
|
||
pub async fn is_new_guild(ctx: Context, guild_id: GuildId) -> bool { | ||
let data = ctx.data.read().await; | ||
let pool = match data.get::<PostgresPool>() { | ||
Some(v) => v.get().await.unwrap(), | ||
None => { | ||
log::error!("Error getting the postgres pool."); | ||
return false; | ||
} | ||
}; | ||
|
||
let has_guild = pool | ||
.query( | ||
"SELECT 1 FROM guilds WHERE id = $1", | ||
&[&i64::try_from(*guild_id.as_u64()).unwrap()], | ||
) | ||
.await | ||
.ok(); | ||
|
||
has_guild.unwrap().get(0).is_none() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod connection; | ||
pub mod delete; | ||
pub mod get; | ||
pub mod store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters