Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.

Commit d6df4e8

Browse files
committed
2024 for real this time
1 parent e8a964f commit d6df4e8

File tree

19 files changed

+225
-82
lines changed

19 files changed

+225
-82
lines changed

db/migrations/20200830172615_initial.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ WITH stackcoin_reserve_system_user AS (
101101
)
102102
INSERT INTO "internal_user" SELECT id, username AS identifier FROM stackcoin_reserve_system_user;
103103

104+
SELECT setval('"user_id_seq"', (SELECT MAX(id) FROM "user"));
105+
104106
COMMIT;
105107

106108
-- +micrate Down

docker-compose.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
stackcoin:
53
build: ./.
@@ -8,31 +6,24 @@ services:
86
- ./.env
97
ports:
108
- 127.0.0.1:3000:3000
11-
networks:
12-
- backend
139

14-
postgres:
15-
image: postgres:12
10+
db:
11+
image: postgres:17
1612
env_file:
1713
- ./.env
1814
ports:
1915
- 127.0.0.1:5432:5432
20-
networks:
21-
- backend
2216
volumes:
2317
- db:/var/lib/postgresql/data
2418

2519
hasura:
26-
image: hasura/graphql-engine:v2.0.3
20+
image: hasura/graphql-engine:v2
2721
env_file:
2822
- ./.env
2923
ports:
3024
- 127.0.0.1:8080:8080
3125
depends_on:
32-
- postgres
26+
- db
3327

3428
volumes:
3529
db:
36-
37-
networks:
38-
backend:

shard.lock

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,73 @@ version: 2.0
22
shards:
33
backtracer:
44
git: https://github.com/sija/backtracer.cr.git
5-
version: 1.2.1
5+
version: 1.2.2
66

77
db:
88
git: https://github.com/crystal-lang/crystal-db.git
9-
version: 0.10.1
9+
version: 0.11.0
1010

1111
discordcr:
12-
git: https://github.com/shardlab/discordcr.git
13-
version: 0.4.1
12+
git: https://github.com/soya-daizu/discordcr.git
13+
version: 0.4.0+git.commit.a409ca150bc9a8fcd42297520a59ddd67ffaebce
1414

1515
dotenv:
1616
git: https://github.com/gdotdesign/cr-dotenv.git
1717
version: 1.0.0
1818

1919
exception_page:
2020
git: https://github.com/crystal-loot/exception_page.git
21-
version: 0.2.0
21+
version: 0.5.0
22+
23+
graphql:
24+
git: https://github.com/graphql-crystal/graphql.git
25+
version: 0.4.0
2226

2327
humanize_time:
2428
git: https://github.com/mamantoha/humanize_time.git
25-
version: 0.10.1
29+
version: 0.12.2
2630

2731
i18n:
2832
git: https://github.com/crystal-i18n/i18n.git
29-
version: 0.2.0
33+
version: 0.2.1
34+
35+
jbuilder:
36+
git: https://github.com/shootingfly/jbuilder.git
37+
version: 1.0.0
3038

3139
kemal:
3240
git: https://github.com/kemalcr/kemal.git
33-
version: 1.0.0+git.commit.218be2422172d330feb62c6a8abc7df5402fdb84
41+
version: 1.6.0+git.commit.749c537e853af6f032b01cf2b91ae2e740340d62
3442

35-
kilt:
36-
git: https://github.com/jeromegn/kilt.git
37-
version: 0.6.1
43+
logger:
44+
git: https://github.com/crystal-lang/logger.cr.git
45+
version: 0.1.0
3846

3947
micrate:
4048
git: https://github.com/amberframework/micrate.git
41-
version: 0.11.0
49+
version: 0.15.1
4250

4351
mysql:
4452
git: https://github.com/crystal-lang/crystal-mysql.git
45-
version: 0.13.0
53+
version: 0.14.0
4654

4755
pg:
4856
git: https://github.com/will/crystal-pg.git
49-
version: 0.23.2
57+
version: 0.26.0
5058

5159
radix:
5260
git: https://github.com/luislavena/radix.git
5361
version: 0.4.1
5462

63+
runcobo:
64+
git: https://github.com/runcobo/runcobo.git
65+
version: 2.0.0
66+
5567
sqlite3:
5668
git: https://github.com/crystal-lang/crystal-sqlite3.git
57-
version: 0.18.0
69+
version: 0.19.0
70+
71+
water:
72+
git: https://github.com/shootingfly/water.git
73+
version: 1.0.0
5874

shard.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ dependencies:
1515
pg:
1616
github: will/crystal-pg
1717

18+
logger:
19+
github: crystal-lang/logger.cr
20+
1821
micrate:
1922
github: amberframework/micrate
2023

2124
discordcr:
22-
github: shardlab/discordcr
25+
github: soya-daizu/discordcr
2326

2427
dotenv:
2528
github: gdotdesign/cr-dotenv
@@ -31,13 +34,11 @@ dependencies:
3134
github: kemalcr/kemal
3235
branch: master
3336

34-
#runcobo:
35-
# github: runcobo/runcobo
36-
3737
sqlite3:
3838
github: crystal-lang/crystal-sqlite3
3939

40-
#graphql:
41-
# github: graphql-crystal/graphql
40+
runcobo:
41+
github: runcobo/runcobo
4242

43-
crystal: 1.0.0
43+
graphql:
44+
github: graphql-crystal/graphql

spec/stubs.cr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ record MessageAuthor, id : Discord::Snowflake, username : String, avatar_url : S
55
end
66
end
77

8-
record MessageStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor do
8+
record MessageStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, message_reference : Discord::MessageReference? do
99
def self.new(channel_id, guild_id, content, author)
1010
channel_id = Discord::Snowflake.new(channel_id.to_u64)
1111
guild_id = Discord::Snowflake.new(guild_id.to_u64)
12-
new(channel_id, guild_id, content, author)
12+
new(channel_id, guild_id, content, author, nil)
1313
end
1414
end
1515

16-
record MessageWithEmbedStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, embed : Discord::Embed do
16+
record MessageWithEmbedStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, embed : Discord::Embed, message_reference : Discord::MessageReference? do
1717
def self.new(channel_id, guild_id, content, author, embed)
1818
channel_id = Discord::Snowflake.new(channel_id.to_u64)
1919
guild_id = Discord::Snowflake.new(guild_id.to_u64)
20-
new(channel_id, guild_id, content, author, embed)
20+
new(channel_id, guild_id, content, author, embed, nil)
2121
end
2222
end
2323

@@ -33,12 +33,12 @@ class MockClient
3333

3434
# TODO class_property current_guild = CSBOIS_GUILD_SNOWFLAKE
3535

36-
def create_message(channel_id : Discord::Snowflake, content : String)
37-
# TODO MessageStub.new(channel_id, @@current_guild, content)
36+
def create_message(channel_id : Discord::Snowflake, content : String, message_reference : Discord::MessageReference? = nil)
37+
# TODO MessageStub.new(channel_id, @@current_guild, content, message_reference)
3838
end
3939

40-
def create_message(channel_id : Discord::Snowflake, content : String, embed : Discord::Embed)
41-
# TODO MessageWithEmbedStub.new(channel_id, @@current_guild, content, embed)
40+
def create_message(channel_id : Discord::Snowflake, content : String, embed : Discord::Embed, message_reference : Discord::MessageReference? = nil)
41+
# TODO MessageWithEmbedStub.new(channel_id, @@current_guild, content, embed, message_reference)
4242
end
4343

4444
def create_dm(user_id : Discord::Snowflake)

src/cli.cr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ parser = OptionParser.parse do |parser|
3838
exit
3939
end
4040

41-
# TODO bringb back api
42-
# parser.on("-s", "--schema", "Print the schema of the internal GraphQL Api") do
43-
# puts StackCoin::Api::Internal::Gql.schema.document.to_s
44-
# exit
45-
# end
41+
parser.on("-s", "--schema", "Print the schema of the internal GraphQL Api") do
42+
puts StackCoin::Api::Internal::Gql.schema.document.to_s
43+
exit
44+
end
4645

4746
parser.on("-h", "--help", "Show this help") do
4847
puts parser

src/stackcoin.cr

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ require "./stackcoin/config"
22
require "./stackcoin/db"
33
require "./stackcoin/core"
44
require "./stackcoin/bot"
5-
6-
# TODO bring back api
7-
# require "./stackcoin/api"
5+
require "./stackcoin/api"
86

97
module StackCoin
8+
TMP_DIR = "/tmp/stackcoin/"
9+
1010
def self.run!
11-
Dir.mkdir_p("/tmp/stackcoin/")
11+
Dir.mkdir_p(TMP_DIR)
1212

1313
run_migrations
1414

15-
# TODO bring back api
16-
# spawn(Api::External.run!)
17-
# spawn(Api::Internal.run!)
15+
spawn(Api::External.run!)
16+
spawn(Api::Internal.run!)
1817

1918
spawn(Bot.run!)
2019

src/stackcoin/api/external.cr

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ class StackCoin::Api::External::Default < BaseAction
3333
get "/*"
3434

3535
call do |context|
36-
render_plain("...")
36+
context = render_plain(<<-HTML
37+
<html>
38+
<head>
39+
<style>
40+
body {
41+
margin: 2rem;
42+
font-family: sans-serif;
43+
}
44+
.bal {
45+
margin: 1rem 0;
46+
padding: 1rem;
47+
border-radius: 4px;
48+
border: 1px solid rgba(0,0,0,0.25);
49+
}
50+
.bal p {
51+
margin: 0;
52+
}
53+
</style>
54+
</head>
55+
<body>
56+
<a href="/">
57+
<p align="center">
58+
<img width="512" height="512" src="https://i.imgur.com/ou12BG6.png">
59+
</p>
60+
</a>
61+
</body>
62+
</html>
63+
HTML
64+
)
65+
66+
context.response.content_type = "text/html"
67+
context
3768
end
3869
end

src/stackcoin/api/internal.cr

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
require "http/server"
2+
require "log"
23

34
class StackCoin::Api::Internal
45
end
56

67
require "./internal/*"
78

89
class StackCoin::Api::Internal
9-
def self.not_found(r)
10-
r.status_code = 404
10+
Log = ::Log.for("stackcoin.api.internal")
11+
12+
def self.basic_message(r, message)
13+
r.status_code = 200
1114
r.content_type = "text/plain"
12-
r.print("Not found")
15+
r.print(message)
16+
end
17+
18+
def self.not_found(r)
19+
basic_message(r, "Not found")
20+
end
21+
22+
def self.invalid_method(r)
23+
basic_message(r, "Invalid method")
1324
end
1425

1526
class SchemaExecuteInput
@@ -32,7 +43,7 @@ class StackCoin::Api::Internal
3243
case resource
3344
when "/auth"
3445
unless method == "GET"
35-
next not_found(r)
46+
next invalid_method(r)
3647
end
3748

3849
if token = context.request.headers["Authorization"]?
@@ -59,7 +70,7 @@ class StackCoin::Api::Internal
5970
next
6071
when "/graphql"
6172
unless method == "POST"
62-
next not_found(r)
73+
next invalid_method(r)
6374
end
6475

6576
headers = context.request.headers
@@ -92,6 +103,7 @@ class StackCoin::Api::Internal
92103
end
93104

94105
address = server.bind_tcp(4000)
106+
Log.info { "Listening on #{address}" }
95107
server.listen
96108
end
97109
end

src/stackcoin/api/internal/graphql.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class StackCoin::Api::Internal::Gql
6161
include GraphQL::QueryType
6262

6363
@[GraphQL::Field]
64-
def pid : Int64
65-
Process.pid
64+
def pid : String
65+
Process.pid.to_s
6666
end
6767
end
6868

0 commit comments

Comments
 (0)