Skip to content

Commit

Permalink
Improve help command
Browse files Browse the repository at this point in the history
  • Loading branch information
KubaZ2 committed Aug 22, 2024
1 parent 962c62e commit 5809e22
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
30 changes: 27 additions & 3 deletions Bot/Sharp/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class Options
[Required]
public required BackendOptions Backend { get; set; }

[Required]
public required InformationOptions Information { get; set; }

public FormattingOptions Formatting { get; set; } = new();
}

Expand All @@ -31,13 +34,13 @@ public class EmojiOptions
public required string Help { get; set; }

[Required]
public required string Command { get; set; }
public required string Link { get; set; }

[Required]
public required string Support { get; set; }
public required string Command { get; set; }

[Required]
public required string Example { get; set; }
public required string Support { get; set; }
}

public class DiagnosticEmojiOptions
Expand Down Expand Up @@ -70,6 +73,27 @@ public class BackendRateLimitOptions
public int DurationSeconds { get; set; } = 30;
}

public class InformationOptions
{
[Required]
public required string Description { get; set; }

[Required]
public required string InvitationLink { get; set; }

[Required]
public required string GitHubRepository { get; set; }

[Required]
public required string SupportDiscord { get; set; }

[Required]
public required string TermsOfService { get; set; }

[Required]
public required string PrivacyPolicy { get; set; }
}

public class FormattingOptions
{
public string Indentation { get; set; } = " ";
Expand Down
62 changes: 33 additions & 29 deletions Bot/Sharp/Responding/ResponseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public class ResponseProvider(IOptions<Options> options, IOptions<CommandService

var optionsValue = options.Value;
var emojis = optionsValue.Emojis;
var information = optionsValue.Information;

var defaultArchitectureFormatted = nameFormatter.Format(optionsValue.Backend.DefaultArchitecture);

Expand All @@ -179,41 +180,44 @@ public class ResponseProvider(IOptions<Options> options, IOptions<CommandService
message.AddEmbeds(new EmbedProperties().WithDescription(
$"""
# {emojis.Help} Help
{information.Description}
## {emojis.Link} Links
- [Invitation Link]({information.InvitationLink})
- [GitHub Repository]({information.GitHubRepository})
- [Support Discord]({information.SupportDiscord})
- [Terms of Service]({information.TermsOfService})
- [Privacy Policy]({information.PrivacyPolicy})
## {emojis.Command} Commands
- `{prefix}run <architecture?> <code>` - runs the provided code, uses {defaultArchitectureFormatted} architecture by default
- `{prefix}<language> <code>` - decompiles the provided code to the specified language
- `{prefix}<architecture> <code>` - shows the architecture-specific JIT disassembly of the provided code
- `{prefix}run <architecture?> <code>` — Runs the provided code, using {defaultArchitectureFormatted} architecture by default.
- **Example**:
{prefix}run
\```c#
Console.Write("Hello, World!");
\```
- **Output**:
```
Hello, World!
```
- `{prefix}<language> <code>` — Decompiles the provided code to the specified language.
- **Example**:
{prefix}c#
\```f#
printf "Hello, World!"
\```
- `{prefix}<architecture> <code>` — Shows the architecture-specific JIT disassembly of the provided code.
- **Example**:
{prefix}{defaultArchitectureFormatted.ToLowerInvariant()}
\```c#
Console.Write("Hello, World!");
\```
The code can be provided as is, as a code block or as an attachment.
## {emojis.Support} Support
### Compilation
{string.Join('\n', compilerProvider.SupportedLanguages.Select(l => $"- {nameFormatter.Format(l)}"))}
{string.Join('\n', compilerProvider.SupportedLanguages.Select(l => $"- **{nameFormatter.Format(l)}**"))}
### Decompilation
{string.Join('\n', decompilerProvider.SupportedLanguages.Where(l => l <= Language.IL).Select(l => $"- {nameFormatter.Format(l)}"))}
{string.Join('\n', decompilerProvider.SupportedLanguages.Where(l => l <= Language.IL).Select(l => $"- **{nameFormatter.Format(l)}**"))}
### Architectures
{string.Join('\n', architectures.Select(a => $"- {nameFormatter.Format((BackendArchitecture)a)}"))}
## {emojis.Example} Examples
### Running C# code:
{prefix}run
\```c#
Console.Write("Hello, World!");
\```
### Decompiling F# code to C#:
{prefix}c#
\```f#
printf "Hello, World!"
\```
### Decompiling C# code to IL:
{prefix}il
\```c#
Console.Write("Hello, World!");
\```
### Showing JIT disassembly of C# code for {defaultArchitectureFormatted}:
{prefix}{defaultArchitectureFormatted.ToLowerInvariant()}
\```c#
Console.Write("Hello, World!");
\```
{string.Join('\n', architectures.Select(a => $"- **{nameFormatter.Format((BackendArchitecture)a)}**"))}
""")
.WithColor(new(optionsValue.PrimaryColor))
.WithTimestamp(Snowflake.CreatedAt(operationId)));
Expand Down
11 changes: 10 additions & 1 deletion Bot/Sharp/appsettings.example.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"Discord": {
"Token": "token",
"Token": "",
"Prefix": "#"
},
"Options": {
"Emojis": {
"Success": "<a:success:1266150828927090860>",
"Error": "<a:error:1266150840138203249>",
"Help": "💡",
"Link": "🔗",
"Command": "<:command:1275425478399889469>",
"Support": "🛎️",
"Example": "📘",
Expand All @@ -27,6 +28,14 @@
"Limit": 5,
"DurationSeconds": 20
}
},
"Information": {
"Description": "**Sharp** is a powerful Discord bot designed to assist .NET developers by running code snippets, decompiling code to various languages, and providing JIT disassembly for specified architectures.",
"InvitationLink": "https://discord.com/oauth2/authorize?client_id=803324257194082314&permissions=274877908992&scope=bot",
"GitHubRepository": "https://github.com/KubaZ2/Sharp",
"SupportDiscord": "https://discord.gg/meaSHTGyUH",
"TermsOfService": "https://github.com/KubaZ2/Sharp/blob/main/TOS.md",
"PrivacyPolicy": "https://github.com/KubaZ2/Sharp/blob/main/PRIVACY.md"
}
}
}

0 comments on commit 5809e22

Please sign in to comment.