Skip to content
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*.userosscache
*.sln.docstates

**\.idea

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# DisCatSharp.ProjectTemplates

These project templates serve as a starting point for creating your Discord bot(s) in C#!
These project templates serve as a starting point for creating your Discord bot(s) in C#!

## Web Host Bot (Class Library)
Allows you, the developer, to pick and choose which modules you'd like to include from [DisCatSharp](https://github.com/Aiko-IT-Systems/DisCatSharp) then sets up
the project for you.

This is a class library, meant to be added as a project reference for web-app projects. Add your Bot's namespace in the web host project, this will
This is a class library, meant to be added as a project reference for hosted projects. Add your Bot's namespace in the web host project, this will
allow you to use the extension methods provided in `ServiceCollectionExtensions` to add both the configuration file and bot.

## WIP: Web Host
Contains the skeleton of your typical web project. Adding support for MVC / API is in progress.
## Web Host
Contains the skeleton of your typical web project.

Converting Microsoft's Web Project template to have DCS as well is a low-priority WIP. For those waiting for this, or need it, please open an issue for it. If enough community interest is there we can allocate more resources towards getting it completed.

# **Important**
Rider currently **DOES NOT** support parameters in custom projects. So unfortunately, anyone who wants to use these templates with Rider
Expand All @@ -20,4 +20,4 @@ will need to utilize the command line...
To view the available parameters for the Bot Template, please use this command
```
dotnet new DCSWebHostBot --help
```
```
12 changes: 8 additions & 4 deletions build-nuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ $versioned = (Join-Path -path $srcDir "DisCatSharpTemplates-versioned.nuspec")
git fetch -t

$tag=(git describe --abbrev=0)

Write-Host "Using Git Tag: $tag ..."

# nuget.exe needs to be on the path or aliased
Expand Down Expand Up @@ -39,6 +38,8 @@ function Clean(){
}

function SetupNuspec(){
Write-Host "Version in Nuspec: $tag"

if (Test-Path -LiteralPath $versioned)
{
Write-Host "Removing Old $versioned..."
Expand Down Expand Up @@ -82,10 +83,13 @@ else{
}

# If the user wants to install the templates they must pass in a true value
if($installTemplates){
$pathtonupkg = join-path $scriptDir "nupkg/DisCatSharp.ProjectTemplates.$tag.nupkg"
if($installTemplates){
$item = Get-ChildItem -Path "$scriptDir/nupkg" -File -Filter *.nupkg

# install nuget package using dotnet new --install
if(test-path $pathtonupkg){
if($item){
$name = $item.Name
$pathtonupkg = join-path $scriptDir "nupkg/$name"
Reset-Templates
'installing template with command "dotnet new --install {0}"' -f $pathtonupkg | write-host
&dotnet new --install $pathtonupkg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
"UseVoiceNatives": {
"longName": "use-voice-natives",
"shortName": "uvn"

},

"AddTranslations": {
"longName": "add-translations",
"shortName": "add-trans"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"longName": "use-voice-natives",
"shortName": "uvn"

},
"AddTranslations": {
"longName": "add-translations",
"shortName": "add-trans"
}
}
}
12 changes: 11 additions & 1 deletion src/Content/DisCatSharpProjectBot/.template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
"isVisible": "true",
"defaultValue": "true"
},

{
"id": "AddTranslations",
"name": {
"text": "Add Translations"
},
"description": {
"text": "Requires UseApplicationCommands as well. This adds localization to your project"
},
"isVisible": "true",
"defaultValue": "true"
},
{
"id": "UseCommon",
"name": {
Expand Down
30 changes: 28 additions & 2 deletions src/Content/DisCatSharpProjectBot/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

"sourceName": "DisCatSharpProject",
"defaultName": "DisCatSharpProject",

"symbols": {
"DiscordToken": {
"type": "parameter",
Expand All @@ -31,6 +31,13 @@
"description": "Does your bot use the DisCatSharp.ApplicationCommands module?"
},

"AddTranslations": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Requires ApplicationCommands. Adds Localization to your project"
},

"UseCommon": {
"type": "parameter",
"datatype": "bool",
Expand Down Expand Up @@ -64,6 +71,25 @@
"datatype": "bool",
"defaultValue": "false",
"description": "Does your bot use the DisCatSharp.VoiceNext.Natives module?"
}
},

"UseTranslations": {
"type": "computed",
"value": "(UseApplicationCommands && AddTranslations)"
},

"sources": [
{
"modifiers": [
{
"condition": "(!UseTranslations)",
"exclude": [
"**/translations/*.json",
"**/Commands/MyCommand.cs"
]
}
]
}
]
}
}
25 changes: 25 additions & 0 deletions src/Content/DisCatSharpProjectBot/Commands/MyCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace DisCatSharpProject.Bot.Commands;
public class MyCommand : ApplicationCommandsModule
{
[SlashCommandGroup("my_command", "This is description of the command group")]
public class MyCommandGroup : ApplicationCommandsModule
{
[SlashCommand("first", "This is description of the command")]
public async Task MySlashCommand(InteractionContext context)
{
await context.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
{
Content = "This is first subcommand."
});
}

[SlashCommand("second", "This is description of the command")]
public async Task MySecondCommand(InteractionContext context, [Option("value", "Some string value.")] string value)
{
await context.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder()
{
Content = "This is second subcommand. The value was " + value
});
}
}
}
25 changes: 15 additions & 10 deletions src/Content/DisCatSharpProjectBot/DisCatSharpProject.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,51 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DisCatSharp" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Configuration" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Hosting" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Hosting.DependencyInjection" Version="9.8.4" />
<PackageReference Include="DisCatSharp" Version="9.8.5-nightly-00237" />
<PackageReference Include="DisCatSharp.Configuration" Version="9.8.5-nightly-00237" />
<PackageReference Include="DisCatSharp.Hosting" Version="9.8.5-nightly-00237" />
<PackageReference Include="DisCatSharp.Hosting.DependencyInjection" Version="9.8.5-nightly-00237" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
</ItemGroup>

<!--#if (UseApplicationCommands) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="9.8.4" />
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="9.8.5-nightly-00237" />
</ItemGroup>

<!--#endif -->
<!--#if (UseCommon) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.Common" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Common" Version="9.8.5-nightly-00237" />
</ItemGroup>

<!--#endif -->
<!--#if (UseInteractivity) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.Interactivity" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Interactivity" Version="9.8.5-nightly-00237" />
</ItemGroup>

<!--#endif -->
<!--#if (UseLavalink) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.Lavalink" Version="9.8.4" />
<PackageReference Include="DisCatSharp.Lavalink" Version="9.8.5-nightly-00237" />
</ItemGroup>

<!--#endif -->
<!--#if (UseVoice) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.VoiceNext" Version="9.8.4" />
<PackageReference Include="DisCatSharp.VoiceNext" Version="9.8.5-nightly-00237" />
</ItemGroup>

<!--#endif -->
<!--#if (UseVoiceNatives) -->
<ItemGroup>
<PackageReference Include="DisCatSharp.VoiceNext.Natives" Version="9.8.4" />
<PackageReference Include="DisCatSharp.VoiceNext.Natives" Version="9.8.5-nightly-00237" />
</ItemGroup>
<ItemGroup>
<None Update="translations\my_simple_command.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<!--#endif -->
Expand Down
11 changes: 10 additions & 1 deletion src/Content/DisCatSharpProjectBot/DisCatSharpProjectBot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DisCatSharpProject.Bot;
using DisCatSharpProject.Bot.Commands;

namespace DisCatSharpProject.Bot;
internal class DisCatSharpProjectBot : DiscordHostedService, IDisCatSharpProjectBot
{
public DisCatSharpProjectBot(IConfiguration config,
Expand Down Expand Up @@ -42,6 +44,13 @@ multiple json files
RegisterCommands(commandsExtension);
#endif

#if (UseTranslations)
/*this.Client.GetApplicationCommands().RegisterCommands<MyCommand>(translationSetup: translations =>
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "translations/my_simple_command.json");
translations.AddTranslation(path);
});*/
#endif
return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"name": "my_command",
"name_translations": {
"en-US": "my_command",
"de": "mein_befehl"
},
"description_translations": {
"en-US": "This is decription of the command group.",
"de": "Das ist die Beschreibung der Befehl Gruppe."
},
"commands": [
{
"name": "first",
"type": 1,
"name_translations": {
"en-US": "first",
"de": "erste"
},
"description_translations": {
"en-US": "This is decription of the command.",
"de": "Das ist die Beschreibung des Befehls."
}
},
{
"name": "second",
"type": 1,
"name_translations": {
"en-US": "second",
"de": "zweite"
},
"description_translations": {
"en-US": "This is decription of the command.",
"de": "Das ist die Beschreibung des Befehls."
},
"options": [
{
"name": "value",
"name_translations": {
"en-US": "value",
"de": "wert"
},
"description_translations": {
"en-US": "Some string value.",
"de": "Ein string Wert."
}
}
]
}
]
}
]
14 changes: 13 additions & 1 deletion src/Content/DisCatSharpProjectWeb/DisCatSharpProject.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@
<Copy
SourceFiles="@(MySourceFiles)"
DestinationFolder="$(OutDir)"/>
</Target>
</Target>
<!--END CONFIGURATION COPY SECTION-->

<!--#if (UseTranslations) -->
<ItemGroup>
<TranslationFiles Include="$(SolutionDir)*\translations\*.json"/>
</ItemGroup>

<Target Name="CopyTranslationFiles" AfterTargets="Build">
<Copy
SourceFiles="@(TranslationFiles)"
DestinationFolder="$(OutDir)\translations"/>
</Target>
<!--#endif-->

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"longName": "use-voice-natives",
"shortName": "uvn"

},
"AddTranslations": {
"longName": "add-translations",
"shortName": "add-trans"
}
}
}
Loading