Skip to content

Commit 968903e

Browse files
author
Ammon Smith
committed
Add first queries.
1 parent c091fb1 commit 968903e

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# statbot-queries
2-
A list of queries useful for a Statbot dataset
2+
A list of queries useful for a [Statbot](https://github.com/strinking/statbot) dataset.
3+
4+
Available under the terms of the [MIT License](LICENSE).

channel_messages.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Lists all channels by number of messages.
2+
3+
SELECT channels.name, t.*
4+
FROM (
5+
SELECT channel_id, count(*)
6+
FROM messages
7+
WHERE guild_id = 181866934353133570 -- Programming
8+
GROUP BY channel_id
9+
) AS t
10+
JOIN channels
11+
ON channels.channel_id = t.channel_id
12+
ORDER BY channels.name;

channel_percentage.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- This query measures the "meme" ratio of our guild.
2+
-- Really this is just what percentage of a person's
3+
-- posts are in #general vs. the rest of the guild.
4+
-- Since percentages for people with low post counts
5+
-- can be skewed, this query will ignore those with
6+
-- fewer than 400 messages total.
7+
8+
SELECT
9+
users.name,
10+
totals.user_id,
11+
100.0 * general.count / totals.count as percentage,
12+
totals.count as total_messages
13+
FROM (
14+
SELECT
15+
user_id,
16+
COUNT(user_id)
17+
FROM messages
18+
WHERE guild_id = 181866934353133570 -- Programming
19+
GROUP BY user_id
20+
) as totals
21+
JOIN (
22+
SELECT
23+
user_id,
24+
COUNT(user_id)
25+
FROM messages
26+
WHERE channel_id = 181866934353133570 -- #general
27+
GROUP BY user_id
28+
) as general
29+
ON totals.user_id = general.user_id
30+
JOIN users
31+
ON totals.user_id = users.user_id
32+
WHERE totals.count > 400 -- Limit to people 400 posts or more
33+
GROUP BY totals.user_id, general.count, totals.count, users.name
34+
ORDER BY percentage DESC;

music_links.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- This query extracts YouTube URLs from #music.
2+
-- It works on messages with multiple links, and
3+
-- doesn't need any regex or parsing since it
4+
-- just queries the list of embeds.
5+
6+
SELECT DISTINCT json_array_elements(embeds::json)->>'url' AS url
7+
FROM messages
8+
WHERE channel_id = 280778849615216640 -- #music
9+
AND (
10+
content LIKE '%youtube.com/watch%'
11+
OR content LIKE '%youtube.com/playlist%'
12+
OR content LIKE '%youtu.be/%'
13+
);

selfbot_embeds.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- This query counts how many messages have embeds,
2+
-- but were not made by bot accounts.
3+
-- This means that they are running selfbots.
4+
5+
SELECT count(*)
6+
FROM messages
7+
JOIN users
8+
ON messages.user_id = users.user_id
9+
WHERE messages.guild_id = 181866934353133570 -- Programming
10+
AND messages.embeds != '[]'
11+
AND NOT users.is_bot;

0 commit comments

Comments
 (0)