diff --git a/src/endpoints/levels/downloadLevel.cr b/src/endpoints/levels/downloadLevel.cr
index 322ef15..f77f2c4 100644
--- a/src/endpoints/levels/downloadLevel.cr
+++ b/src/endpoints/levels/downloadLevel.cr
@@ -160,6 +160,21 @@ CrystalGauntlet.endpoints["/downloadGJLevel22.php"] = ->(context : HTTP::Server:
if DATABASE.scalar("select count(*) from ip_actions where action = ? and value = ? and ip = ? limit 1", "download", level_id, ip).as?(Int64) == 0
DATABASE.exec("update levels set downloads = downloads + 1 where id = ?", level_id)
DATABASE.exec("insert into ip_actions (action, value, ip) values (?, ?, ?)", "download", level_id, ip)
+
+ downloads = DATABASE.scalar("select downloads from levels where id = ?", level_id).as(Int64)
+ if downloads == 300
+ # notify the creator of 300 downloads
+
+ account_id, level_name = DATABASE.query_one("select users.account_id, levels.name from levels left join users on users.id = levels.user_id where levels.id = ?", level_id, as: {Int32?, String})
+ if account_id
+ if DATABASE.scalar("select count(*) from notifications where type = \"download_milestone\" and target = ? and account_id = ?", level_id, account_id).as(Int64) == 0
+ Notifications.send_notification(account_id, "download_milestone", level_id, {
+ "level_name" => level_name,
+ "amount" => downloads
+ })
+ end
+ end
+ end
end
end
diff --git a/src/endpoints/misc/likeItem.cr b/src/endpoints/misc/likeItem.cr
index 5fc6d6e..db9fb41 100644
--- a/src/endpoints/misc/likeItem.cr
+++ b/src/endpoints/misc/likeItem.cr
@@ -38,6 +38,23 @@ CrystalGauntlet.endpoints["/likeGJItem211.php"] = ->(context : HTTP::Server::Con
if DATABASE.scalar("select count(*) from ip_actions where action = ? and value = ? and ip = ? limit 1", "like_#{type}", item_id, ip).as?(Int64) == 0
DATABASE.exec("update #{table} set likes = likes #{sign} 1 where #{column} = ?", item_id)
DATABASE.exec("insert into ip_actions (action, value, ip) values (?, ?, ?)", "like_#{type}", item_id, ip)
+
+ if type == 1 # level
+ likes = DATABASE.scalar("select likes from #{table} where #{column} = ?", item_id).as(Int64)
+ if likes == 100
+ # notify the creator of 100 likes
+
+ account_id, level_name = DATABASE.query_one("select users.account_id, #{table}.name from #{table} left join users on users.id = #{table}.user_id where #{table}.#{column} = ?", item_id, as: {Int32?, String})
+ if account_id
+ if DATABASE.scalar("select count(*) from notifications where type = \"like_milestone\" and target = ? and account_id = ?", item_id, account_id).as(Int64) == 0
+ Notifications.send_notification(account_id, "like_milestone", item_id, {
+ "level_name" => level_name,
+ "amount" => likes
+ })
+ end
+ end
+ end
+ end
end
"1"
diff --git a/src/lib/notifications.cr b/src/lib/notifications.cr
index cd7cb23..a99496a 100644
--- a/src/lib/notifications.cr
+++ b/src/lib/notifications.cr
@@ -17,12 +17,20 @@ module CrystalGauntlet::Notifications
NOTIFICATION_STRINGS = {
"authored_level_featured" => %(Your level %{level_name} has been featured!),
- "authored_level_rated" => %(Your level %{level_name} has been rated!)
+ "authored_level_rated" => %(Your level %{level_name} has been rated!),
+ "like_milestone" => %(Your level %{level_name} has reached %{amount} likes!),
+ "download_milestone" => %(Your level %{level_name} has reached %{amount} downloads!)
}
def format_notification(type : String, target : Int32?, details : NotificationDetails? = nil, html_safe : Bool = false)
details = details || {} of String => String | Int64 | Bool | Float64 | Nil
- string = NOTIFICATION_STRINGS[type]
+ string = NOTIFICATION_STRINGS[type]?
+
+ if !string
+ LOG.error { "No notification string found for #{type}" }
+ # might aswell have a fallback
+ return type
+ end
#case type
#when "authored_level_featured", "authored_level_rated"