Skip to content

Commit

Permalink
Add first queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammon Smith committed Nov 27, 2017
1 parent c091fb1 commit 968903e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# statbot-queries
A list of queries useful for a Statbot dataset
A list of queries useful for a [Statbot](https://github.com/strinking/statbot) dataset.

Available under the terms of the [MIT License](LICENSE).
12 changes: 12 additions & 0 deletions channel_messages.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Lists all channels by number of messages.

SELECT channels.name, t.*
FROM (
SELECT channel_id, count(*)
FROM messages
WHERE guild_id = 181866934353133570 -- Programming
GROUP BY channel_id
) AS t
JOIN channels
ON channels.channel_id = t.channel_id
ORDER BY channels.name;
34 changes: 34 additions & 0 deletions channel_percentage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- This query measures the "meme" ratio of our guild.
-- Really this is just what percentage of a person's
-- posts are in #general vs. the rest of the guild.
-- Since percentages for people with low post counts
-- can be skewed, this query will ignore those with
-- fewer than 400 messages total.

SELECT
users.name,
totals.user_id,
100.0 * general.count / totals.count as percentage,
totals.count as total_messages
FROM (
SELECT
user_id,
COUNT(user_id)
FROM messages
WHERE guild_id = 181866934353133570 -- Programming
GROUP BY user_id
) as totals
JOIN (
SELECT
user_id,
COUNT(user_id)
FROM messages
WHERE channel_id = 181866934353133570 -- #general
GROUP BY user_id
) as general
ON totals.user_id = general.user_id
JOIN users
ON totals.user_id = users.user_id
WHERE totals.count > 400 -- Limit to people 400 posts or more
GROUP BY totals.user_id, general.count, totals.count, users.name
ORDER BY percentage DESC;
13 changes: 13 additions & 0 deletions music_links.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- This query extracts YouTube URLs from #music.
-- It works on messages with multiple links, and
-- doesn't need any regex or parsing since it
-- just queries the list of embeds.

SELECT DISTINCT json_array_elements(embeds::json)->>'url' AS url
FROM messages
WHERE channel_id = 280778849615216640 -- #music
AND (
content LIKE '%youtube.com/watch%'
OR content LIKE '%youtube.com/playlist%'
OR content LIKE '%youtu.be/%'
);
11 changes: 11 additions & 0 deletions selfbot_embeds.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- This query counts how many messages have embeds,
-- but were not made by bot accounts.
-- This means that they are running selfbots.

SELECT count(*)
FROM messages
JOIN users
ON messages.user_id = users.user_id
WHERE messages.guild_id = 181866934353133570 -- Programming
AND messages.embeds != '[]'
AND NOT users.is_bot;

0 comments on commit 968903e

Please sign in to comment.