Skip to content

Commit

Permalink
Add list of suspicious joins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammon Smith committed Jun 22, 2019
1 parent 56a0d1a commit d3c86d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion id_to_snowflake.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- datetime.utcfromtimestamp(((id >> 22) + DISCORD_EPOCH) / 1000)
-- where DISCORD_EPOCH is 1420070400000

CREATE FUNCTION snowflake_time(id bigint)
CREATE FUNCTION snowflake_time(id BIGINT)
RETURNS TIMESTAMP WITH TIME ZONE
LANGUAGE SQL
AS 'SELECT to_timestamp(((id >> 22) + 1420070400000) / 1000) AS timestamp'
Expand Down
26 changes: 26 additions & 0 deletions suspicious_joined_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Looks for suspicious new joins.
-- Specifically looks at people who made their account soon before joining,
-- and do not have the 'Member' role.

-- Uses snowflake_time from id_to_snowflake.sql

SELECT
users.name || '#' || users.discriminator AS username,
joined_at - snowflake_time(users.real_user_id) AS time_before_join,
snowflake_time(users.real_user_id) AS created_at,
guild_membership.joined_at,
users.real_user_id,
users.int_user_id
FROM guild_membership
JOIN users
ON guild_membership.int_user_id = users.int_user_id
LEFT JOIN (
SELECT *
FROM role_membership
WHERE role_membership.role_id = 205477488707502081 -- Member role
) AS members
ON guild_membership.int_user_id = members.int_user_id
AND guild_membership.guild_id = members.guild_id
WHERE joined_at - snowflake_time(users.real_user_id) < '30 days'::interval
AND guild_membership.joined_at > '2019-06-22 07:22:29'::timestamp -- CHANGE ME
ORDER BY joined_at, created_at;

0 comments on commit d3c86d8

Please sign in to comment.