Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaderboard & Stats #132

Merged
merged 5 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ reqwest = "0.11.12"
thiserror = "1.0.37"
sentry = "0.29.0"
floodgate = "0.5.0"
thousands = "0.2.0"
205 changes: 205 additions & 0 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,27 @@
},
"query": "UPDATE messages SET frozen=$1 WHERE message_id=$2 RETURNING *"
},
"2ad322ad75dd8bc977edfbfe65ed5ef7a4d0b561ebd2a885e2036ee91dbc442c": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1 AND user_id=$2\n AND is_downvote=true"
},
"2ba33811711a776b21ed9f1aab88903c81d572838f9ec3c133112ed009efb20e": {
"describe": {
"columns": [
Expand Down Expand Up @@ -1376,6 +1397,45 @@
},
"query": "DELETE FROM starboards WHERE name=$1 AND guild_id=$2\n RETURNING *"
},
"4799c2a2b60b149a964d4e435f3991a8b12a9ecdd8f5d413fbbe01649b185470": {
"describe": {
"columns": [
{
"name": "user_id",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "guild_id",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "xp",
"ordinal": 2,
"type_info": "Float4"
},
{
"name": "autoredeem_enabled",
"ordinal": 3,
"type_info": "Bool"
}
],
"nullable": [
false,
false,
false,
false
],
"parameters": {
"Left": [
"Int8",
"Int8"
]
}
},
"query": "SELECT * FROM members WHERE guild_id=$1 AND xp > 0 ORDER BY xp DESC LIMIT $2"
},
"49d63a74ba11ef0279ae492c469cd578a6c97e81fe63715ef999e39f74a433d5": {
"describe": {
"columns": [
Expand Down Expand Up @@ -1572,6 +1632,46 @@
},
"query": "UPDATE autostar_channels SET name=$1 WHERE name=$2 AND guild_id=$3\n RETURNING *"
},
"5f937665dfcfdc26d1e6986203a9b81d64b38407fc6ad871640efcb092079a45": {
"describe": {
"columns": [
{
"name": "user_id",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "guild_id",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "xp",
"ordinal": 2,
"type_info": "Float4"
},
{
"name": "autoredeem_enabled",
"ordinal": 3,
"type_info": "Bool"
}
],
"nullable": [
false,
false,
false,
false
],
"parameters": {
"Left": [
"Float4",
"Int8",
"Int8"
]
}
},
"query": "UPDATE members SET xp=$1 WHERE user_id=$2 AND guild_id=$3 RETURNING *"
},
"62dfbdacb72b9b8d9dba195684068e31c3daddf4e9682041c8a87697c9bebd7d": {
"describe": {
"columns": [
Expand Down Expand Up @@ -2105,6 +2205,27 @@
},
"query": "INSERT INTO posroles\n (role_id, guild_id)\n VALUES ($1, $2)\n RETURNING *"
},
"7b137ea29ecca19db96e259ed6b24d8a0f3fa5a3cb493c6e6be0b2bf54979e90": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=true"
},
"7e14b14e400319e69ca7b7a581257ee46e1b60ee05872f90474bc3c107a47e08": {
"describe": {
"columns": [
Expand Down Expand Up @@ -2444,6 +2565,27 @@
},
"query": "INSERT INTO VOTES\n (message_id, starboard_id, user_id,\n target_author_id, is_downvote)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING *"
},
"88357902cae7c5ecc5625d473a99b55a5acd4323de003c6fa89afd9543c7fe25": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1 AND user_id=$2\n AND is_downvote=false"
},
"888f1c27ec8291239d8041c2a148a9f9d72f872bfa520c43e0a5c6ad65636218": {
"describe": {
"columns": [
Expand Down Expand Up @@ -2790,6 +2932,27 @@
},
"query": "DELETE FROM permrole_starboards WHERE permrole_id=$1 AND starboard_id=$2 RETURNING *"
},
"b40efe37213d4d3b754f0e3f2c6889c2a866059568d8ffba713b7d5939626e35": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=true"
},
"b41aaaf9153c7dd373e0f1825ecc78d16c78f4d084e8618f68c6695ce4aad635": {
"describe": {
"columns": [
Expand Down Expand Up @@ -3435,6 +3598,27 @@
},
"query": "SELECT COUNT(*) as count FROM permroles WHERE guild_id=$1"
},
"d9d12cee8a2062669bf160b9f2a1cb20ee03e5bf5c59436a1a21d6bd2e767c06": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=false"
},
"db47dd094d91342ad83996e3ebe7cacc85c7f77f1e7ecd0c9d8ba6914fb9ec8a": {
"describe": {
"columns": [
Expand Down Expand Up @@ -3614,6 +3798,27 @@
},
"query": "SELECT * FROM permrole_starboards WHERE permrole_id=$1"
},
"e5f7837179d4f5a285bda9334b7509fee5226207eac9905e62adc7280c5db05f": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "SELECT count(*) FROM votes WHERE starboard_id=$1\n AND target_author_id=$2 AND is_downvote=false"
},
"e605d15eeb3e0939bc83e98b98b9ac9814bf2f0983ebdc30c235d8b530bf0ada": {
"describe": {
"columns": [
Expand Down
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod emoji;
pub mod has_image;
pub mod permroles;
pub mod starboard;
pub mod stats;
25 changes: 15 additions & 10 deletions src/core/starboard/reaction_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use twilight_model::gateway::payload::incoming::{ReactionAdd, ReactionRemove};

use crate::{
client::bot::StarboardBot,
core::emoji::SimpleEmoji,
core::{emoji::SimpleEmoji, stats::refresh_xp},
database::{Member, Message, User, Vote},
errors::StarboardResult,
map_dup_none,
Expand Down Expand Up @@ -107,8 +107,11 @@ pub async fn handle_reaction_add(
};
let status = VoteStatus::get_vote_status(bot, vote, configs).await?;

// for future user, since orig_msg is moved
let author_id = orig_msg.author_id;

match status {
VoteStatus::Ignore => Ok(()),
VoteStatus::Ignore => (),
VoteStatus::Remove => {
let _ = bot
.http
Expand All @@ -118,9 +121,7 @@ pub async fn handle_reaction_add(
&emoji.reactable(),
event.user_id,
)
.await;

Ok(())
.await?;
}
VoteStatus::Valid((upvote, downvote)) => {
// create reactor data
Expand Down Expand Up @@ -165,10 +166,12 @@ pub async fn handle_reaction_add(
refresh.set_configs(all_configs);
refresh.set_sql_message(orig_msg);
refresh.refresh(false).await?;

Ok(())
}
}

refresh_xp(bot, guild_id.get_i64(), author_id).await?;

Ok(())
}

pub async fn handle_reaction_remove(
Expand Down Expand Up @@ -212,9 +215,11 @@ pub async fn handle_reaction_remove(
refresh.set_sql_message(orig);
refresh.set_configs(all_configs);
refresh.refresh(false).await?;

Ok(())
}
VoteStatus::Ignore | VoteStatus::Remove => Ok(()),
VoteStatus::Ignore | VoteStatus::Remove => (),
}

refresh_xp(bot, guild_id.get_i64(), author.user_id).await?;

Ok(())
}
Loading