Skip to content

Commit

Permalink
Merge pull request #68 from BrammyS/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
BrammyS authored Dec 23, 2022
2 parents a373981 + ae70fe8 commit b9c6b01
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
17 changes: 10 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +25,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How has this been tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
<!--- your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
36 changes: 26 additions & 10 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@

## About The Project

A simple Discord Bot Template build with the [Color-Chan.Discord library](https://github.com/Color-Chan/Color-Chan.Discord).
This template includes basic commands including a help command with multiple pages using buttons. Plus a simple [MongoDB](https://www.mongodb.com/) connection.
A simple Discord Bot Template build with
the [Color-Chan.Discord library](https://github.com/Color-Chan/Color-Chan.Discord).
This template includes basic commands including a help command with multiple pages using buttons. Plus a
simple [MongoDB](https://www.mongodb.com/) connection.

- Basic commands
- Persistent command request logging
Expand Down Expand Up @@ -94,10 +96,13 @@ To get a local copy up and running follow these simple steps.

#### Using the template

See the [Create reposotiry from a template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) guide for a more detailed explanation.
See
the [Create reposotiry from a template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
guide for a more detailed explanation.

1. Navigate to the main page of the repository.
2. Above the file list, click `Use this template`.
![Use template button](https://cdn.brammys.com/file/brammys/screenshots/2022/02/use-this-template-button.png)
![Use template button](https://cdn.brammys.com/file/brammys/screenshots/2022/02/use-this-template-button.png)
3. Enter the name for your new repository and choose a visibility option.
4. Click the `Create repositoiry from template` button.

Expand All @@ -116,22 +121,28 @@ See the [Create reposotiry from a template](https://docs.github.com/en/repositor
dotnet build
```


### Usage

#### Environment variables
To run the Bot you will need to set 2 environment variables first.
#### Secrets

To run the Bot you will need to set a couple of secrets first.
You can set these secret either as environment variables or using the [dotnet secret manager](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets#set-a-secret).

- `BOT_TOKEN` : Add your bot token as the value. The bot token van be found [here](https://discord.com/developers/applications/).
- `MONGO_CON_STRING` : Add your MongoDB connection string as the value. You can get a free MongoDB host on [MongoDB Atlas](https://www.mongodb.com/atlas/database).

#### Constants

After this you need to set the `PublicKey` and the `BotId` for your bot. These can be set in the [Constants.cs](https://github.com/BrammyS/Discord-Bot-Template/blob/dev/src/Bot.Discord/Constants.cs) class in Bot.Discord.
After this you need to set the `PublicKey` and the `BotId` for your bot. These can be set in
the [Constants.cs](https://github.com/BrammyS/Discord-Bot-Template/blob/dev/src/Bot.Discord/Constants.cs) class in
Bot.Discord.

### URL

Set the interaction end point for your bot. You will need to add this URL to you [application](https://discord.com/developers/applications/).
The interaction endpoint is located at `https://YOUR_DOMAIN.COM:5001/api/v1/discord/interaction`. Please do keep in mind that you will need to be able to access this endpoint from outside of your network.
Set the interaction end point for your bot. You will need to add this URL to
you [application](https://discord.com/developers/applications/).
The interaction endpoint is located at `https://YOUR_DOMAIN.COM:5001/api/v1/discord/interaction`. Please do keep in mind
that you will need to be able to access this endpoint from outside of your network.
[![interactionUrlSetup](https://cdn.colorchan.com/examples/interactionUrlExample.png)](https://discord.com/developers/applications/)

<!-- CONTRIBUTING -->
Expand Down Expand Up @@ -166,8 +177,13 @@ Distributed under the MIT License. See `LICENSE` for more information.
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[stars-shield]: https://img.shields.io/github/stars/BrammyS/Discord-Bot-Template?style=for-the-badge

[stars-url]: https://github.com/BrammyS/Discord-Bot-Template/stargazers

[issues-shield]: https://img.shields.io/github/issues/BrammyS/Discord-Bot-Template?style=for-the-badge

[issues-url]: https://github.com/BrammyS/Discord-Bot-Template/issues

[license-shield]: https://img.shields.io/github/license/BrammyS/Discord-Bot-Template?style=for-the-badge

[license-url]: https://github.com/BrammyS/Discord-Bot-Template/blob/main/LICENSE
4 changes: 2 additions & 2 deletions .github/workflows/dotnetBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
os: [ubuntu-latest]
os: [ ubuntu-latest ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 7.0.x

- name: Install dependencies
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion src/Bot.Discord/Bot.Discord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Color-Chan.Discord" Version="1.10.11"/>
<PackageReference Include="Color-Chan.Discord" Version="2.0.1"/>
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions src/Bot.Discord/Commands/InviteCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class InviteCommands : SlashCommandModule
public const string InviteCommandName = "invite";
public const string InviteCommandDesc = "Invite the bot somewhere else!";

public static readonly IDiscordComponent InviteMe =
new ActionRowComponentBuilder()
.WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands")
.Build();

/// <summary>
/// An invitation command where the bot will reply back with a link to be added to other servers.
/// </summary>
Expand All @@ -28,24 +33,19 @@ public class InviteCommands : SlashCommandModule
public Task<Result<IDiscordInteractionResponse>> InviteAsync()
{
var inviteMeEmbed = new DiscordEmbedBuilder()
.WithTitle("Invite me")
.WithDescription("I need more friends, add me to other Discord servers!")
.WithColor(Constants.Colors.Successful)
.WithTimeStamp()
.Build();
.WithTitle("Invite me")
.WithDescription("I need more friends, add me to other Discord servers!")
.WithColor(Constants.Colors.Successful)
.WithTimeStamp()
.Build();

// Build the embedded response.
var inviteResponse = new InteractionResponseBuilder()
.WithEmbed(inviteMeEmbed)
.WithComponent(InviteMe)
.Build();
.WithEmbed(inviteMeEmbed)
.WithComponent(InviteMe)
.Build();

// Return the response to Discord.
return Task.FromResult(FromSuccess(inviteResponse));
}

public static readonly IDiscordComponent InviteMe =
new ActionRowComponentBuilder()
.WithButton("Invite me!", DiscordButtonStyle.Link, null, $"https://discord.com/api/oauth2/authorize?client_id={Constants.BotId}&permissions=0&scope=bot%20applications.commands")
.Build();
}
13 changes: 6 additions & 7 deletions src/Bot.Discord/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
using Color_Chan.Discord.Commands.Extensions;
using Color_Chan.Discord.Configurations;
using Color_Chan.Discord.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Bot.Discord.Extensions;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddDiscord(this IServiceCollection services)
public static IServiceCollection AddDiscord(this IServiceCollection services, IConfiguration configuration)
{
var token = Environment.GetEnvironmentVariable("BOT_TOKEN");
var token = configuration["BOT_TOKEN"];
if (token is null)
{
throw new NullReferenceException("Please set the BOT_TOKEN env variable!");
throw new NullReferenceException("Please set the BOT_TOKEN configuration!");
}

// Configure Color-Chan.Discord
Expand All @@ -23,10 +24,8 @@ public static IServiceCollection AddDiscord(this IServiceCollection services)
SlashCommandConfigs = slashOptions => { slashOptions.SendDefaultErrorMessage = true; }
};

services.AddSlashCommandPipeline<GuildDbPipeline>();
services.AddSlashCommandPipeline<CommandLoggingPipeline>();
services.AddComponentInteractionPipeline<ComponentLoggingPipeline>();

services.AddInteractionPipeline<GuildDbPipeline>();
services.AddInteractionPipeline<InteractionLoggingPipeline>();

services.AddColorChanDiscord(token, Constants.PublicKey, Constants.BotId, config);
services.AddMongoDb();
Expand Down
12 changes: 12 additions & 0 deletions src/Bot.Discord/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Bot.Discord.Helpers;

public static class CommandHelper
{
public static string SanitizeCommandName(string commandName)
{
var paramIndex = commandName.IndexOf(';');
return paramIndex >= 0
? commandName.Remove(paramIndex)
: commandName;
}
}
74 changes: 0 additions & 74 deletions src/Bot.Discord/Pipelines/ComponentLoggingPipeline.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Bot.Discord/Pipelines/GuildDbPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Bot.Discord.Pipelines;

public class GuildDbPipeline : ISlashCommandPipeline
public class GuildDbPipeline : IInteractionPipeline
{
private readonly ILogger<GuildDbPipeline> _logger;
private readonly IUnitOfWork _unitOfWork;
Expand All @@ -25,7 +25,7 @@ public GuildDbPipeline(ILogger<GuildDbPipeline> logger, IUnitOfWork unitOfWork)
}

/// <inheritdoc />
public async Task<Result<IDiscordInteractionResponse>> HandleAsync(ISlashCommandContext context, SlashCommandHandlerDelegate next)
public async Task<Result<IDiscordInteractionResponse>> HandleAsync(IInteractionContext context, InteractionHandlerDelegate next)
{
// Skip commands that were used outside of a guild.
if (context.GuildId is null)
Expand Down
Loading

0 comments on commit b9c6b01

Please sign in to comment.