Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions db/migrations/20200830172615_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ WITH stackcoin_reserve_system_user AS (
)
INSERT INTO "internal_user" SELECT id, username AS identifier FROM stackcoin_reserve_system_user;

SELECT setval('"user_id_seq"', (SELECT MAX(id) FROM "user"));

COMMIT;

-- +micrate Down
Expand Down
17 changes: 4 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
stackcoin:
build: ./.
Expand All @@ -8,31 +6,24 @@ services:
- ./.env
ports:
- 127.0.0.1:3000:3000
networks:
- backend

postgres:
image: postgres:12
db:
image: postgres:17
env_file:
- ./.env
ports:
- 127.0.0.1:5432:5432
networks:
- backend
volumes:
- db:/var/lib/postgresql/data

hasura:
image: hasura/graphql-engine:v2.0.3
image: hasura/graphql-engine:v2
env_file:
- ./.env
ports:
- 127.0.0.1:8080:8080
depends_on:
- postgres
- db

volumes:
db:

networks:
backend:
46 changes: 31 additions & 15 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,73 @@ version: 2.0
shards:
backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.1
version: 1.2.2

db:
git: https://github.com/crystal-lang/crystal-db.git
version: 0.10.1
version: 0.11.0

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

dotenv:
git: https://github.com/gdotdesign/cr-dotenv.git
version: 1.0.0

exception_page:
git: https://github.com/crystal-loot/exception_page.git
version: 0.2.0
version: 0.5.0

graphql:
git: https://github.com/graphql-crystal/graphql.git
version: 0.4.0

humanize_time:
git: https://github.com/mamantoha/humanize_time.git
version: 0.10.1
version: 0.12.2

i18n:
git: https://github.com/crystal-i18n/i18n.git
version: 0.2.0
version: 0.2.1

jbuilder:
git: https://github.com/shootingfly/jbuilder.git
version: 1.0.0

kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.0.0+git.commit.218be2422172d330feb62c6a8abc7df5402fdb84
version: 1.6.0+git.commit.749c537e853af6f032b01cf2b91ae2e740340d62

kilt:
git: https://github.com/jeromegn/kilt.git
version: 0.6.1
logger:
git: https://github.com/crystal-lang/logger.cr.git
version: 0.1.0

micrate:
git: https://github.com/amberframework/micrate.git
version: 0.11.0
version: 0.15.1

mysql:
git: https://github.com/crystal-lang/crystal-mysql.git
version: 0.13.0
version: 0.14.0

pg:
git: https://github.com/will/crystal-pg.git
version: 0.23.2
version: 0.26.0

radix:
git: https://github.com/luislavena/radix.git
version: 0.4.1

runcobo:
git: https://github.com/runcobo/runcobo.git
version: 2.0.0

sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
version: 0.18.0
version: 0.19.0

water:
git: https://github.com/shootingfly/water.git
version: 1.0.0

15 changes: 8 additions & 7 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ dependencies:
pg:
github: will/crystal-pg

logger:
github: crystal-lang/logger.cr

micrate:
github: amberframework/micrate

discordcr:
github: shardlab/discordcr
github: soya-daizu/discordcr

dotenv:
github: gdotdesign/cr-dotenv
Expand All @@ -31,13 +34,11 @@ dependencies:
github: kemalcr/kemal
branch: master

#runcobo:
# github: runcobo/runcobo

sqlite3:
github: crystal-lang/crystal-sqlite3

#graphql:
# github: graphql-crystal/graphql
runcobo:
github: runcobo/runcobo

crystal: 1.0.0
graphql:
github: graphql-crystal/graphql
16 changes: 8 additions & 8 deletions spec/stubs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ record MessageAuthor, id : Discord::Snowflake, username : String, avatar_url : S
end
end

record MessageStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor do
record MessageStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, message_reference : Discord::MessageReference? do
def self.new(channel_id, guild_id, content, author)
channel_id = Discord::Snowflake.new(channel_id.to_u64)
guild_id = Discord::Snowflake.new(guild_id.to_u64)
new(channel_id, guild_id, content, author)
new(channel_id, guild_id, content, author, nil)
end
end

record MessageWithEmbedStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, embed : Discord::Embed do
record MessageWithEmbedStub, channel_id : Discord::Snowflake, guild_id : Discord::Snowflake, content : String, author : MessageAuthor, embed : Discord::Embed, message_reference : Discord::MessageReference? do
def self.new(channel_id, guild_id, content, author, embed)
channel_id = Discord::Snowflake.new(channel_id.to_u64)
guild_id = Discord::Snowflake.new(guild_id.to_u64)
new(channel_id, guild_id, content, author, embed)
new(channel_id, guild_id, content, author, embed, nil)
end
end

Expand All @@ -33,12 +33,12 @@ class MockClient

# TODO class_property current_guild = CSBOIS_GUILD_SNOWFLAKE

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

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

def create_dm(user_id : Discord::Snowflake)
Expand Down
9 changes: 4 additions & 5 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ parser = OptionParser.parse do |parser|
exit
end

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

parser.on("-h", "--help", "Show this help") do
puts parser
Expand Down
13 changes: 6 additions & 7 deletions src/stackcoin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ require "./stackcoin/config"
require "./stackcoin/db"
require "./stackcoin/core"
require "./stackcoin/bot"

# TODO bring back api
# require "./stackcoin/api"
require "./stackcoin/api"

module StackCoin
TMP_DIR = "/tmp/stackcoin/"

def self.run!
Dir.mkdir_p("/tmp/stackcoin/")
Dir.mkdir_p(TMP_DIR)

run_migrations

# TODO bring back api
# spawn(Api::External.run!)
# spawn(Api::Internal.run!)
spawn(Api::External.run!)
spawn(Api::Internal.run!)

spawn(Bot.run!)

Expand Down
57 changes: 55 additions & 2 deletions src/stackcoin/api/external.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class StackCoin::Api::External::Auth < BaseAction
cookie = Core::SessionStore::Session.to_cookie(result.new_session_id)
context.response.cookies << cookie

render_plain("TODO redirect") # TODO redirect
context = render_plain("redirecting")

context.response.status_code = 303
context.response.headers["Location"] = "/"
context
else
render_plain(result.message)
end
Expand All @@ -33,6 +37,55 @@ class StackCoin::Api::External::Default < BaseAction
get "/*"

call do |context|
render_plain("...")
context = render_plain(<<-HTML
<html>
<head>
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<style>
:root {
font-family: Inter, sans-serif;
font-feature-settings: 'liga' 1, 'calt' 1;
}
@supports (font-variation-settings: normal) {
:root { font-family: InterVariable, sans-serif; }
}
body {
margin: 2rem;
font-size: 1.4rem;
}
.no-func {
color: gray;
font-style: italic;
}

img {
width: 30rem;
max-width: 100%;
}

main {
max-width: 40rem;
margin: 0 auto;
}
</style>
</head>
<body>
<a href="/">
<p align="center">
<img src="https://i.imgur.com/ou12BG6.png">
</p>
</a>
<main>
<p>stackcoin</p>
<p class="no-func">this website has no functionality, at the moment</p>
</main>
</body>
</html>
HTML
)

context.response.content_type = "text/html"
context
end
end
22 changes: 17 additions & 5 deletions src/stackcoin/api/internal.cr
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
require "http/server"
require "log"

class StackCoin::Api::Internal
end

require "./internal/*"

class StackCoin::Api::Internal
def self.not_found(r)
r.status_code = 404
Log = ::Log.for("stackcoin.api.internal")

def self.basic_message(r, message)
r.status_code = 200
r.content_type = "text/plain"
r.print("Not found")
r.print(message)
end

def self.not_found(r)
basic_message(r, "Not found")
end

def self.invalid_method(r)
basic_message(r, "Invalid method")
end

class SchemaExecuteInput
Expand All @@ -32,7 +43,7 @@ class StackCoin::Api::Internal
case resource
when "/auth"
unless method == "GET"
next not_found(r)
next invalid_method(r)
end

if token = context.request.headers["Authorization"]?
Expand All @@ -59,7 +70,7 @@ class StackCoin::Api::Internal
next
when "/graphql"
unless method == "POST"
next not_found(r)
next invalid_method(r)
end

headers = context.request.headers
Expand Down Expand Up @@ -92,6 +103,7 @@ class StackCoin::Api::Internal
end

address = server.bind_tcp(4000)
Log.info { "Listening on #{address}" }
server.listen
end
end
4 changes: 2 additions & 2 deletions src/stackcoin/api/internal/graphql.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class StackCoin::Api::Internal::Gql
include GraphQL::QueryType

@[GraphQL::Field]
def pid : Int64
Process.pid
def pid : String
Process.pid.to_s
end
end

Expand Down
Loading