Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit 0e5e0bf

Browse files
committed
Docker
1 parent 9bf043f commit 0e5e0bf

File tree

10 files changed

+149
-12
lines changed

10 files changed

+149
-12
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.github
2+
.vscode
3+
.gitignore
4+
.editorconfig
5+
bin
6+
obj

.github/workflows/docker_image.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish Docker image
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
push_to_registry:
8+
name: Publish Docker image
9+
runs-on: self-hosted
10+
steps:
11+
- name: Check out the repo
12+
uses: actions/checkout@v2
13+
14+
- name: Get Previous tag
15+
id: previoustag
16+
uses: WyriHaximus/github-action-get-previous-tag@master
17+
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v1
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
24+
- name: Login to DockerHub
25+
uses: docker/login-action@v1
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.repository_owner }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Build and Push
32+
uses: docker/build-push-action@v2
33+
with:
34+
context: .
35+
file: ./Dockerfile
36+
push: true
37+
tags: |
38+
ghcr.io/dsharpplus/dsharpplusdocs:latest
39+
ghcr.io/dsharpplus/dsharpplusdocs:${{ steps.previoustag.outputs.tag }}

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
"program": "${workspaceFolder}/bin/Debug/net6.0/DSharpPlusDocs.dll",
13+
"args": [],
14+
"cwd": "${workspaceFolder}",
15+
"console": "internalConsole",
16+
"stopAtEntry": false
17+
},
18+
{
19+
"name": ".NET Core Attach",
20+
"type": "coreclr",
21+
"request": "attach"
22+
}
23+
]
24+
}

.vscode/tasks.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/DSharpPlusDocs.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/DSharpPlusDocs.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/DSharpPlusDocs.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
2+
WORKDIR /src
3+
4+
COPY ./ /src
5+
RUN dotnet restore -r linux-musl-x64 && dotnet publish -c Release -r linux-musl-x64 --no-restore --self-contained -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:DebugType=embedded
6+
7+
FROM alpine:latest
8+
WORKDIR /src
9+
10+
COPY --from=build /src/bin/Release/net6.0/linux-musl-x64/publish /src
11+
COPY ./res /src/res
12+
RUN apk upgrade --update-cache --available && apk add openssl libstdc++ icu-libs && rm -rf /var/cache/apk/*
13+
14+
ENTRYPOINT /src/DSharpPlusDocs

Modules/Commands.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
using Microsoft.CodeAnalysis.Scripting;
4242
using Microsoft.Extensions.DependencyInjection;
4343

44+
#pragma warning disable CA1822 // Mark members as static
45+
4446
namespace DSharpPlusDocs.Modules
4547
{
4648
public class GeneralCommands : BaseCommandModule
4749
{
4850
[Command("clean")]
4951
[Description("Delete all the messages from this bot within the last X messages")]
50-
public static async Task CleanAsync(CommandContext ctx, int messages = 30)
52+
public async Task CleanAsync(CommandContext ctx, int messages = 30)
5153
{
5254
if (messages > 50)
5355
{
@@ -68,16 +70,16 @@ public static async Task CleanAsync(CommandContext ctx, int messages = 30)
6870

6971
[Command("docs")]
7072
[Description("Show the docs url")]
71-
public static async Task DocsAsync(CommandContext ctx) => await ctx.RespondAsync($"Docs: {QueryHandler.DocsBaseUrl}");
73+
public async Task DocsAsync(CommandContext ctx) => await ctx.RespondAsync($"Docs: {QueryHandler.DocsBaseUrl}");
7274

7375
[Command("invite")]
7476
[Description("Show the invite url")]
75-
public static async Task InviteAsync(CommandContext ctx) => await ctx.RespondAsync("Invite: https://discordapp.com/oauth2/authorize?client_id=341606460720939008&scope=bot");
77+
public async Task InviteAsync(CommandContext ctx) => await ctx.RespondAsync("Invite: https://discordapp.com/oauth2/authorize?client_id=341606460720939008&scope=bot");
7678

7779
[Command("guides")]
7880
[Aliases("guide")]
7981
[Description("Show the url of a guide")]
80-
public static async Task GuidesAsync(CommandContext ctx, [RemainingText] string guide = null)
82+
public async Task GuidesAsync(CommandContext ctx, [RemainingText] string guide = null)
8183
{
8284
try
8385
{
@@ -202,7 +204,7 @@ public static async Task GuidesAsync(CommandContext ctx, [RemainingText] string
202204

203205
[Command("info")]
204206
[Description("Show some information about the application")]
205-
public static async Task InfoAsync(CommandContext ctx)
207+
public async Task InfoAsync(CommandContext ctx)
206208
{
207209
_ = ctx.Client.CurrentApplication;
208210
MainHandler mainHandler = ctx.Services.GetService<MainHandler>();
@@ -244,7 +246,7 @@ public static async Task InfoAsync(CommandContext ctx)
244246

245247
[Command("eval")] //TODO: Safe eval ? 👀
246248
[RequireOwner]
247-
public static async Task EvalAsync(CommandContext ctx, [RemainingText] string code)
249+
public async Task EvalAsync(CommandContext ctx, [RemainingText] string code)
248250
{
249251
/*using (Context.Channel.EnterTypingState())
250252
{*/
@@ -278,7 +280,7 @@ public static async Task EvalAsync(CommandContext ctx, [RemainingText] string co
278280

279281
[Command("setdocsurl")]
280282
[RequireOwner]
281-
public static async Task SetDocsUrlAsync(CommandContext ctx, [RemainingText] string url)
283+
public async Task SetDocsUrlAsync(CommandContext ctx, [RemainingText] string url)
282284
{
283285
if (!url.EndsWith("/"))
284286
{

Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ namespace DSharpPlusDocs
2525
{
2626
public class Program
2727
{
28-
public static void Main()
29-
{
30-
new DSharpPlusDocs().RunAsync().GetAwaiter().GetResult();
31-
}
28+
public static void Main() => new DSharpPlusDocs().RunAsync().GetAwaiter().GetResult();
3229
}
3330
}

Query/Extensions/BaseDisplay.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ private static string GetDocsUrlPath(object o)
130130

131131
public static bool IsInherited(object o) => o is PropertyInfoWrapper property
132132
? $"{property.Parent.TypeInfo.Namespace}.{property.Parent.TypeInfo.Name}" != $"{property.Property.DeclaringType.Namespace}.{property.Property.DeclaringType.Name}"
133-
: o is MethodInfoWrapper method && $"{method.Parent.TypeInfo.Namespace}.{method.Parent.TypeInfo.Name}" != $"{method.Method.DeclaringType.Namespace}.{method.Method.DeclaringType.Name}";
133+
: o is MethodInfoWrapper method
134+
&& $"{method.Parent.TypeInfo.Namespace}.{method.Parent.TypeInfo.Name}" != $"{method.Method.DeclaringType.Namespace}.{method.Method.DeclaringType.Name}";
134135

135136
private static List<string> GetPaths(IEnumerable<object> list) => list.Select(x => GetPath(x)).ToList();
136137

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# DSharpPlus Documentation Bot
2+
Don't host this until the rewrite. PR's to make the code more optimized are welcome.
3+
4+
# Getting Started
5+
Set the `DISCORD_TOKEN` environment variable to your bot's token, then `dotnet run`. Alternatively you can use Docker.

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.9"
2+
3+
services:
4+
tomoe:
5+
build: .
6+
environment:
7+
- "DISCORD_TOKEN": ""
8+
restart: unless-stopped

0 commit comments

Comments
 (0)