Compare commits
10 Commits
76a3351090
...
61285d6bc4
Author | SHA1 | Date | |
---|---|---|---|
61285d6bc4 | |||
3d1a863ab5 | |||
9e4a37baab | |||
f921d7b123 | |||
b86adff83d | |||
fc04e5f2b5 | |||
489a39c06a | |||
fab68a5d39 | |||
e00f3a865e | |||
2ac29d526c |
@ -154,14 +154,14 @@ let getRafflesWithPurchases storeId =
|
|||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [ "sid" , Sql.string storeId ]
|
|> Sql.parameters [ "sid" , Sql.string storeId ]
|
||||||
|> Sql.query """
|
|> Sql.query """
|
||||||
WITH raffles AS
|
WITH raffles AS
|
||||||
(SELECT store_id,stock,available,limit_stock,i.id AS raffle_id,name,description,icon_url,image_url,category,require_role,require_invites,sale_end,rank,
|
(SELECT store_id,stock,available,limit_stock,i.id AS raffle_id,name,description,icon_url,image_url,category,require_role,require_invites,sale_end,rank,
|
||||||
buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume,attack_power,defense_power,class_name,max_stack,mods
|
buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume,attack_power,defense_power,class_name,max_stack,mods
|
||||||
FROM store_item
|
FROM store_item
|
||||||
JOIN item i on store_item.item_id = i.id
|
JOIN item i on store_item.item_id = i.id
|
||||||
WHERE store_id = @sid AND store_item.unlisted = false)
|
WHERE store_id = @sid AND store_item.unlisted = false)
|
||||||
SELECT * FROM raffles
|
SELECT * FROM raffles
|
||||||
FULL JOIN (SELECT item_id, count(*) AS total FROM inventory_item
|
FULL JOIN (SELECT item_id, count(*) AS total FROM inventory_item
|
||||||
WHERE item_id = ANY (SELECT raffle_id FROM raffles)
|
WHERE item_id = ANY (SELECT raffle_id FROM raffles)
|
||||||
GROUP BY item_id) total_raffles ON total_raffles.item_id = raffle_id;
|
GROUP BY item_id) total_raffles ON total_raffles.item_id = raffle_id;
|
||||||
"""
|
"""
|
||||||
|
@ -76,7 +76,7 @@ let strengthBonus attacker defender =
|
|||||||
|> (*) 0.01
|
|> (*) 0.01
|
||||||
|> (*) 200.0 // Bonus
|
|> (*) 200.0 // Bonus
|
||||||
|> int
|
|> int
|
||||||
|
|
||||||
let runHackerBattle defender (hack : HackItem) =
|
let runHackerBattle defender (hack : HackItem) =
|
||||||
defender
|
defender
|
||||||
|> Player.removeExpiredActions
|
|> Player.removeExpiredActions
|
||||||
@ -108,7 +108,7 @@ let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerDa
|
|||||||
DbService.addPlayerEvent defender.DiscordId (event true) ]
|
DbService.addPlayerEvent defender.DiscordId (event true) ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
|
|
||||||
let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack : HackItem) =
|
let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack : HackItem) =
|
||||||
async {
|
async {
|
||||||
let prizeAmount , bonus =
|
let prizeAmount , bonus =
|
||||||
@ -120,9 +120,9 @@ let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack
|
|||||||
if hack.Power < int attacker.Bank
|
if hack.Power < int attacker.Bank
|
||||||
then gbt hack.Power , 0<GBT>
|
then gbt hack.Power , 0<GBT>
|
||||||
else attacker.Bank , 0<GBT>
|
else attacker.Bank , 0<GBT>
|
||||||
|
|
||||||
do! updateCombatants successfulHack attacker defender hack prizeAmount
|
do! updateCombatants successfulHack attacker defender hack prizeAmount
|
||||||
|
|
||||||
let! defenderMember = ctx.GetGuild().GetMemberAsync(defender.DiscordId) |> Async.AwaitTask
|
let! defenderMember = ctx.GetGuild().GetMemberAsync(defender.DiscordId) |> Async.AwaitTask
|
||||||
let embed = Embeds.responseSuccessfulHack2 successfulHack attacker defender (ctx.GetDiscordMember()) defenderMember prizeAmount bonus hack
|
let embed = Embeds.responseSuccessfulHack2 successfulHack attacker defender (ctx.GetDiscordMember()) defenderMember prizeAmount bonus hack
|
||||||
do! ctx.GetChannel().SendMessageAsync(embed)
|
do! ctx.GetChannel().SendMessageAsync(embed)
|
||||||
@ -368,7 +368,7 @@ type HackerGame() =
|
|||||||
[<SlashCommand("scan", "Find 5 targets connected to the network we can try to hack")>]
|
[<SlashCommand("scan", "Find 5 targets connected to the network we can try to hack")>]
|
||||||
member this.ScanCommand (ctx : InteractionContext) =
|
member this.ScanCommand (ctx : InteractionContext) =
|
||||||
enforceChannels (DiscordInteractionContext ctx) scan scan
|
enforceChannels (DiscordInteractionContext ctx) scan scan
|
||||||
|
|
||||||
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
|
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
|
||||||
member this.TestAutoComplete (ctx : InteractionContext) =
|
member this.TestAutoComplete (ctx : InteractionContext) =
|
||||||
async {
|
async {
|
||||||
@ -377,4 +377,4 @@ type HackerGame() =
|
|||||||
do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
} |> Async.StartAsTask
|
} |> Async.StartAsTask
|
||||||
:> Task
|
:> Task
|
||||||
|
@ -12,16 +12,18 @@ open Giraffe
|
|||||||
open dotenv.net
|
open dotenv.net
|
||||||
open Npgsql.FSharp
|
open Npgsql.FSharp
|
||||||
|
|
||||||
let prodEnv = DotEnv.Read(DotEnvOptions(envFilePaths = [ "../.prod.env"], overwriteExistingVars = false))
|
DotEnv.Load(DotEnvOptions(envFilePaths = [ "../.prod.env" ], overwriteExistingVars = false))
|
||||||
|
|
||||||
let ( _ , connStr ) = prodEnv.TryGetValue("DATABASE_URL")
|
let connStr = Environment.GetEnvironmentVariable("DATABASE_URL")
|
||||||
let ( _ , apiKey ) = prodEnv.TryGetValue("API_KEY")
|
.Replace("postgresql://", "postgres://")
|
||||||
|
.Replace("?sslmode=require", "")
|
||||||
|
let apiKey = Environment.GetEnvironmentVariable("API_KEY")
|
||||||
|
|
||||||
let validateApiKey (ctx : HttpContext) =
|
let validateApiKey (ctx : HttpContext) =
|
||||||
match ctx.TryGetRequestHeader "X-API-Key" with
|
match ctx.TryGetRequestHeader "X-API-Key" with
|
||||||
| Some key -> apiKey.Equals key
|
| Some key -> apiKey.Equals key
|
||||||
| None -> false
|
| None -> false
|
||||||
|
|
||||||
let accessDenied = setStatusCode 401 >=> text "Access Denied"
|
let accessDenied = setStatusCode 401 >=> text "Access Denied"
|
||||||
let requiresApiKey = authorizeRequest validateApiKey accessDenied
|
let requiresApiKey = authorizeRequest validateApiKey accessDenied
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ let getCurrentBalance (discordId : string) =
|
|||||||
| a::_ -> return Ok a
|
| a::_ -> return Ok a
|
||||||
}
|
}
|
||||||
|
|
||||||
let get (discordId : string) : HttpHandler =
|
let get (discordId : string) : HttpHandler =
|
||||||
fun (next : HttpFunc) (ctx : HttpContext) ->
|
fun (next : HttpFunc) (ctx : HttpContext) ->
|
||||||
task {
|
task {
|
||||||
try
|
try
|
||||||
@ -48,8 +50,8 @@ let get (discordId : string) : HttpHandler =
|
|||||||
with ex ->
|
with ex ->
|
||||||
return! ServerErrors.internalError (json {| Error = ex.Message |}) next ctx
|
return! ServerErrors.internalError (json {| Error = ex.Message |}) next ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
let modify sign (discordId : string) : HttpHandler =
|
let modify sign (discordId : string) : HttpHandler =
|
||||||
fun (next : HttpFunc) (ctx : HttpContext) ->
|
fun (next : HttpFunc) (ctx : HttpContext) ->
|
||||||
task {
|
task {
|
||||||
let! body = ctx.BindJsonAsync<{|Amount:int|}>()
|
let! body = ctx.BindJsonAsync<{|Amount:int|}>()
|
||||||
@ -70,7 +72,7 @@ let modify sign (discordId : string) : HttpHandler =
|
|||||||
with ex -> return! RequestErrors.notFound (json {| Error = ex.Message |}) next ctx
|
with ex -> return! RequestErrors.notFound (json {| Error = ex.Message |}) next ctx
|
||||||
| Error e -> return! RequestErrors.notFound (json {| Error = e |}) next ctx
|
| Error e -> return! RequestErrors.notFound (json {| Error = e |}) next ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
let webApp =
|
let webApp =
|
||||||
choose [
|
choose [
|
||||||
GET >=> requiresApiKey >=> routef "/user/%s/balance" get
|
GET >=> requiresApiKey >=> routef "/user/%s/balance" get
|
||||||
@ -105,8 +107,7 @@ let main args =
|
|||||||
fun webHostBuilder ->
|
fun webHostBuilder ->
|
||||||
webHostBuilder
|
webHostBuilder
|
||||||
.ConfigureKestrel(fun opt ->
|
.ConfigureKestrel(fun opt ->
|
||||||
opt.AddServerHeader <- false
|
opt.AddServerHeader <- false)
|
||||||
opt.ListenLocalhost(3333, (fun o -> o.UseHttps() |> ignore)))
|
|
||||||
.Configure(Action<IApplicationBuilder> configureApp)
|
.Configure(Action<IApplicationBuilder> configureApp)
|
||||||
.ConfigureServices(configureServices)
|
.ConfigureServices(configureServices)
|
||||||
.ConfigureLogging(configureLogging)
|
.ConfigureLogging(configureLogging)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<system.webServer>
|
<system.webServer>
|
||||||
<handlers>
|
<handlers>
|
||||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||||
</handlers>
|
</handlers>
|
||||||
<aspNetCore processPath="dotnet" arguments="CurrencyAPI.dll" stdoutLogEnabled="false" stdoutLogFile="logs/stdout" />
|
<aspNetCore processPath="dotnet" arguments="CurrencyAPI.dll" stdoutLogEnabled="false" stdoutLogFile="logs/stdout" />
|
||||||
</system.webServer>
|
</system.webServer>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
10
Dockerfile
10
Dockerfile
@ -10,14 +10,16 @@ RUN dotnet tool restore
|
|||||||
|
|
||||||
RUN dotnet restore "CurrencyAPI/CurrencyAPI.fsproj"
|
RUN dotnet restore "CurrencyAPI/CurrencyAPI.fsproj"
|
||||||
|
|
||||||
WORKDIR "/src/Bot"
|
WORKDIR "/src/CurrencyAPI/"
|
||||||
|
|
||||||
RUN dotnet build "CurrencyAPI.fsproj" -c Release -o /app/build
|
RUN dotnet build "CurrencyAPI.fsproj" -c Release -o /app/build
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
RUN dotnet publish "CurrencyAPI.fsproj" -c Release -o /app/publish
|
RUN dotnet publish "CurrencyAPI.fsproj" -c Release -o /app/publish --no-restore
|
||||||
|
|
||||||
FROM base AS final
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
ENTRYPOINT "./CurrencyAPI.App"
|
EXPOSE 80
|
||||||
|
EXPOSE 443
|
||||||
|
ENTRYPOINT [ "dotnet", "./CurrencyAPI.App.dll" ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user