Skip to content
This repository was archived by the owner on Jun 8, 2022. 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
4 changes: 3 additions & 1 deletion LukeDictionary.Bot/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
README.md
appsecrets.Example.json
dockerscript.sh
7 changes: 5 additions & 2 deletions LukeDictionary.Bot/Commands/LukeWordCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using DevSubmarine.LukeDictionary.Discord;
using DevSubmarine.LukeDictionary.PasteMyst;
using DevSubmarine.LukeDictionary.Words;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
Expand All @@ -25,16 +26,18 @@ public class LukeWordCommands
private readonly ILukeWordsStore _store;
private readonly ILogger _log;
private readonly IOptionsMonitor<DevSubmarineOptions> _devsubOptions;
private readonly IOptionsMonitor<LukeWordsOptions> _wordsOptions;
private readonly IPasteMystClient _pasteMyst;
private readonly Regex _inputValidationRegex;

public LukeWordCommands(DiscordClient client, ILukeWordsStore store, ILogger<LukeWordCommands> log,
IOptionsMonitor<DevSubmarineOptions> devsubOptions, IPasteMystClient pasteMyst)
IOptionsMonitor<DevSubmarineOptions> devsubOptions, IOptionsMonitor<LukeWordsOptions> wordsOptions, IPasteMystClient pasteMyst)
{
this._client = client;
this._store = store;
this._log = log;
this._devsubOptions = devsubOptions;
this._wordsOptions = wordsOptions;
this._pasteMyst = pasteMyst;
this._inputValidationRegex = new Regex(@"^[A-Za-z0-9]{1,25}$",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled,
Expand Down Expand Up @@ -107,7 +110,7 @@ public async Task<string> GetWordsListAsync(CancellationToken cancellationToken
{
new Pasty(contentPlain, $"{title} (Plain Text)", PastyLanguages.PlainText),
new Pasty(contentJson, $"{title} (JSON)", PastyLanguages.JSON)
});
}, this._wordsOptions.CurrentValue.ListExpiration);
paste = await this._pasteMyst.CreatePasteAsync(paste, cancellationToken).ConfigureAwait(false);
return $"https://paste.myst.rs/{paste.ID}";
}
Expand Down
3 changes: 2 additions & 1 deletion LukeDictionary.Bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM mcr.microsoft.com/dotnet/runtime:5.0 AS base
FROM mcr.microsoft.com/dotnet/runtime:5.0
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "LukeDictionary.Bot.dll"]
16 changes: 14 additions & 2 deletions LukeDictionary.Bot/LukeDictionary.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>DevSubmarine,TehGM</Authors>
<Company>DevSubmarine</Company>
<Product>LukeDictionary Discord Bot</Product>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/DevSubmarine/LukeDictionary</PackageProjectUrl>
<RepositoryUrl>https://github.com/DevSubmarine/LukeDictionary</RepositoryUrl>
Expand All @@ -21,11 +21,17 @@
</PropertyGroup>

<ItemGroup>
<None Remove=".dockerignore" />
<None Remove="appsettings.Development.json" />
<None Remove="Dockerfile" />
<None Remove="dockerscript.sh" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.Development.json">
<Content Include=".dockerignore" Condition="Exists('.dockerignore')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.Development.json" Condition="Exists('appsettings.Development.json')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
Expand All @@ -34,6 +40,12 @@
<Content Include="appsecrets.json" Condition="Exists('appsecrets.json')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Dockerfile" Condition="Exists('Dockerfile')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="dockerscript.sh" Condition="Exists('dockerscript.sh')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions LukeDictionary.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using DevSubmarine.LukeDictionary.Database;
using DevSubmarine.LukeDictionary.Discord;
using DevSubmarine.LukeDictionary.PasteMyst;
using DevSubmarine.LukeDictionary.Words;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -44,6 +45,7 @@ static Task Main(string[] args)
services.Configure<MongoOptions>(context.Configuration.GetSection("Database"));
services.Configure<DevSubmarineOptions>(context.Configuration);
services.Configure<PasteMystOptions>(context.Configuration.GetSection("PasteMyst"));
services.Configure<LukeWordsOptions>(context.Configuration.GetSection("Words"));

// add services
services.AddDiscord();
Expand Down
10 changes: 10 additions & 0 deletions LukeDictionary.Bot/Words/LukeWordsOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using DevSubmarine.LukeDictionary.PasteMyst;

namespace DevSubmarine.LukeDictionary.Words
{
public class LukeWordsOptions
{
/// <summary>How long the words list paste will be alive.</summary>
public PasteExpiration ListExpiration { get; set; } = PasteExpiration.OneMonth;
}
}
3 changes: 3 additions & 0 deletions LukeDictionary.Bot/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"GuildID": 757959067812495480,

"Words": {
"ListExpiration": "OneWeek"
},
"Logging": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
Expand Down
3 changes: 3 additions & 0 deletions LukeDictionary.Bot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"Words": {
"ListExpiration": "OneMonth"
},
"Logging": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
Expand Down
21 changes: 21 additions & 0 deletions LukeDictionary.Bot/dockerscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
IMAGE="devsub/lukedictionary:latest"
CONTAINER="LukeDictionary"
ENVIRONMENT="Production"

echo "Building Docker Image"
docker build -t $IMAGE .

echo "Stopping old Docker Containers (error might pop, ignore it)"
docker stop $CONTAINER || true && docker rm $CONTAINER || true

echo "Starting new Docker Container"
docker run -d --restart=always \
--name=$CONTAINER \
-e ASPNETCORE_ENVIRONMENT=$ENVIRONMENT \
-e DOTNET_ENVIRONMENT=$ENVIRONMENT \
-v "/var/log/LukeDictionary/$ENVIRONMENT":"/logs" \
$IMAGE

echo "Pruning old Docker Images"
docker image prune -f -a
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Run on host:
3. Move published files to host machine.
4. Run `dotnet LukeDictionary.Bot.dll`, create a systemd service, or build and run Docker image using [Dockerfile](LukeDictionary.Bot/Dockerfile).

There also is a [dockerscript.sh](LukeDictionary.Bot/dockerscript.sh) script to simplify running docker image with auto-restart. Of course it requires Docker installed on the host.

> Note: Do ***NOT*** push this docker image to remote repo (like dockerhub) if you created `appsecrets.json` file. Just don't, unless you want yor secrets compromised.

## License
Expand Down