aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-02-14 12:13:46 -0500
committerCara Salter <cara@devcara.com>2022-02-14 12:13:46 -0500
commit830682ca08060df66c688478a013e43499c24fff (patch)
tree2f59526d0ced29f6de5f991d356375e7f2d4f71f
parente9543136f018d52b3dc4abb93412d07bfc4dc8c7 (diff)
downloadglitch-ng-830682ca08060df66c688478a013e43499c24fff.tar.gz
glitch-ng-830682ca08060df66c688478a013e43499c24fff.zip
Fix CI
-rw-r--r--.drone.yml8
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--build.rs5
-rw-r--r--sqlx-data.json132
-rw-r--r--src/handler.rs73
-rw-r--r--src/main.rs3
7 files changed, 221 insertions, 8 deletions
diff --git a/.drone.yml b/.drone.yml
index ea000ae..9de6cf3 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -6,12 +6,4 @@ steps:
- name: build
image: rust:latest
commands:
- - apt update
- - apt install postgresql -y
- - pg_ctlcluster 13 main start
- - cargo install sqlx-cli
- - cargo sqlx migrate run
- cargo check
- - cargo fmt -- --check
- environment:
- DATABASE_URL: postgres://postgres@localhost/campmaster
diff --git a/Cargo.lock b/Cargo.lock
index bb60e12..0bccd81 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -310,6 +310,9 @@ name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
+dependencies = [
+ "serde",
+]
[[package]]
name = "encoding_rs"
@@ -1301,6 +1304,7 @@ version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
+ "indexmap",
"itoa",
"ryu",
"serde",
@@ -1501,9 +1505,12 @@ dependencies = [
"dotenv",
"either",
"heck",
+ "hex",
"once_cell",
"proc-macro2",
"quote",
+ "serde",
+ "serde_json",
"sha2",
"sqlx-core",
"sqlx-rt",
diff --git a/Cargo.toml b/Cargo.toml
index 6f6534d..80c5bd6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,4 +65,5 @@ features = [
"chrono",
"migrate",
"macros",
+ "offline",
]
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..7609593
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,5 @@
+// generated by `sqlx migrate build-script`
+fn main() {
+ // trigger recompilation when a new migration is added
+ println!("cargo:rerun-if-changed=migrations");
+} \ No newline at end of file
diff --git a/sqlx-data.json b/sqlx-data.json
new file mode 100644
index 0000000..b6bb605
--- /dev/null
+++ b/sqlx-data.json
@@ -0,0 +1,132 @@
+{
+ "db": "PostgreSQL",
+ "04383f28e708546beb642eb13c81048dc166b3a7994c110922abbced8470a93c": {
+ "query": "DELETE FROM reaction_roles WHERE id=$1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Int4"
+ ]
+ },
+ "nullable": []
+ }
+ },
+ "277984fe7b7a2aa1c3b02913db57caae607875e2389c9191d22a6efc46aa7e4a": {
+ "query": "SELECT * FROM reaction_roles WHERE message_id=$1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "guild_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "reaction",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "role_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ }
+ },
+ "2900553c18f0b74b218a9ecf289cc4d74ceda4ebe1e5494f0b28a8160f5c651a": {
+ "query": "SELECT * FROM reaction_roles WHERE message_id=$1 AND reaction=$2",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "message_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "guild_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "reaction",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "role_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false
+ ]
+ }
+ },
+ "f8d670f7e142e9658916ed389e2def233430420c4121aa473c0277c61c5cfcee": {
+ "query": "INSERT INTO reaction_roles (channel_id, message_id, guild_id, reaction, role_id) VALUES ($1, $2, $3, $4, $5)",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ }
+ }
+} \ No newline at end of file
diff --git a/src/handler.rs b/src/handler.rs
new file mode 100644
index 0000000..ef8fc00
--- /dev/null
+++ b/src/handler.rs
@@ -0,0 +1,73 @@
+use poise::serenity_prelude as serenity;
+
+use crate::models::ReactionRole;
+use crate::{Data, Error};
+
+pub async fn event_handler(
+ ctx: &serenity::Context,
+ event: &poise::Event<'_>,
+ data: &Data,
+) -> Result<(), Error> {
+ {
+ let pool = data.pg.lock().unwrap().clone();
+ match event {
+ poise::Event::ReactionAdd { add_reaction } => {
+ let current_user = ctx.http.get_current_user().await?;
+ if add_reaction.user_id.unwrap() == current_user.id {
+ return Ok(());
+ }
+ let rrole = sqlx::query_as!(
+ ReactionRole,
+ "SELECT * FROM reaction_roles WHERE message_id=$1 AND reaction=$2",
+ add_reaction.message_id.0.to_string(),
+ add_reaction.emoji.to_string()
+ )
+ .fetch_one(&pool)
+ .await?;
+ let member = ctx
+ .http
+ .get_member(
+ rrole.guild_id.parse::<u64>()?,
+ add_reaction.user_id.unwrap().0,
+ )
+ .await?;
+ let member_roles = member.roles;
+ let role_id = serenity::RoleId(rrole.role_id.parse::<u64>()?);
+ if member_roles.contains(&role_id) {
+ ctx.http
+ .remove_member_role(
+ member.guild_id.0,
+ member.user.id.0,
+ role_id.0,
+ Some("Reaction Role Menu"),
+ )
+ .await?;
+ } else {
+ ctx.http
+ .add_member_role(
+ rrole.guild_id.parse::<u64>()?,
+ add_reaction.user_id.unwrap().0,
+ rrole.role_id.parse::<u64>()?,
+ Some("Reaction Role"),
+ )
+ .await?;
+ }
+
+ if let Ok(dm_chan) = add_reaction
+ .user_id
+ .unwrap()
+ .create_dm_channel(&ctx.http)
+ .await {
+ dm_chan.say(ctx, format!("Toggled the role!")).await?;
+ } else {
+ println!("Could not DM user, but we did the role anyways");
+ }
+
+ add_reaction.delete(&ctx.http).await?;
+ }
+ _ => (),
+ }
+ }
+
+ Ok(())
+}
diff --git a/src/main.rs b/src/main.rs
index 2968f20..8693381 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -123,6 +123,9 @@ async fn main() {
)
.await
.expect("Couldn't connect to postgresql");
+ sqlx::migrate!("./migrations")
+ .run(&pool)
+ .await.unwrap();
Ok(Data {
pg: Mutex::new(pool),
})