-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,556 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Publish Docker image | ||
on: | ||
push: | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Publish Docker image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and Push ModularAssistentForDiscordServer | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
file: ./ModularAssistentForDiscordServer/Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/plerx2493/mads:latest | ||
ghcr.io/plerx2493/mads:${{ github.sha }} | ||
build-args: | | ||
"BUILD_VER=${{ github.sha }}" | ||
- name: Build and Push QuartzDB | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
file: ./QuartzNetDocker/Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/plerx2493/quartz-db-mysql:latest | ||
ghcr.io/plerx2493/quartz-db-mysql:${{ github.sha }} | ||
build-args: | | ||
"BUILD_VER=${{ github.sha }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2023 Plerx2493 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using DeepL; | ||
using DSharpPlus; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.SlashCommands; | ||
using MADS.CustomComponents; | ||
using MADS.Extensions; | ||
using MADS.Services; | ||
using Quartz.Util; | ||
|
||
namespace MADS.Commands.ContextMenu; | ||
|
||
public class TranslateMessage : MadsBaseApplicationCommand | ||
{ | ||
private readonly TranslateInformationService _translateInformationService; | ||
private readonly Translator _translator; | ||
|
||
public TranslateMessage(TranslateInformationService translateInformationService, Translator translator) | ||
{ | ||
_translateInformationService = translateInformationService; | ||
_translator = translator; | ||
} | ||
|
||
[ContextMenu(ApplicationCommandType.MessageContextMenu, "Translate message")] | ||
public async Task TranslateAsync(ContextMenuContext ctx) | ||
{ | ||
await ctx.DeferAsync(true); | ||
|
||
var preferredLanguage = await _translateInformationService.GetPreferredLanguage(ctx.User.Id); | ||
bool isPreferredLanguageSet = !preferredLanguage.IsNullOrWhiteSpace(); | ||
|
||
if(!isPreferredLanguageSet) preferredLanguage = "en-US"; | ||
|
||
var messageId = ctx.TargetMessage.Id; | ||
var message = await ctx.Channel.GetMessageAsync(messageId); | ||
var messageContent = message.Content; | ||
|
||
if (messageContent.IsNullOrWhiteSpace() || messageContent is null) | ||
{ | ||
await ctx.CreateResponseAsync("⚠️ Message is empty!"); | ||
return; | ||
} | ||
|
||
if (preferredLanguage is null) | ||
{ | ||
await ctx.CreateResponseAsync("⚠️ No language set!"); | ||
return; | ||
} | ||
|
||
var transaltedMessage = | ||
await _translator.TranslateTextAsync(messageContent, null, preferredLanguage); | ||
|
||
var embed = new DiscordEmbedBuilder() | ||
.WithAuthor(message.Author?.Username, | ||
message.Author?.AvatarUrl) | ||
.WithDescription(transaltedMessage.Text) | ||
.WithColor(new DiscordColor(0, 255, 194)) | ||
.WithFooter($"Translated from {transaltedMessage.DetectedSourceLanguageCode} to {preferredLanguage}") | ||
.WithTimestamp(DateTime.Now); | ||
|
||
await ctx.CreateResponseAsync(embed); | ||
|
||
if (isPreferredLanguageSet) return; | ||
|
||
var followUpMessage = new DiscordFollowupMessageBuilder() | ||
.WithContent("⚠️ You haven't set a preferred language yet. Default is english.") | ||
.AddComponents(new DiscordButtonComponent(ButtonStyle.Primary, "setLanguage", "Set language").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage)) | ||
.AddComponents(new DiscordButtonComponent(ButtonStyle.Primary, "setLanguage", "Set your language to en-US").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage, "en-US")) | ||
.AsEphemeral(); | ||
|
||
|
||
await ctx.FollowUpAsync(followUpMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.