Discord.Net.BotMvc 1.0.1

dotnet add package Discord.Net.BotMvc --version 1.0.1                
NuGet\Install-Package Discord.Net.BotMvc -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Discord.Net.BotMvc" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Net.BotMvc --version 1.0.1                
#r "nuget: Discord.Net.BotMvc, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Discord.Net.BotMvc as a Cake Addin
#addin nuget:?package=Discord.Net.BotMvc&version=1.0.1

// Install Discord.Net.BotMvc as a Cake Tool
#tool nuget:?package=Discord.Net.BotMvc&version=1.0.1                

Introduction

This library realise a MVC pattern for Discord.Net library.

Discord.Net Modules (ModuleBase) is a Controller equivalent.

There is also an available DI in all added services.

Configuring

You can configure the bot the way you do it in an ASP project.

class MyBot : BotBase
{
    private IConfiguration _config;

    public MyBot(IConfiguration config)
        : base(config["token"], config["prefix"])
    {
        _config = config;
    }
    
    // Lets configure the bot
    protected override Configure(IBotBuilder botBuilder)
    {
        // Subscribe to some events
        botBuilder.Client.OnMessageRecieved += ConsoleLog;
        
        // Or add your own extensions-methods like `.Use*()` in ASP
        botBuilder.UsePosts(config => config.AllowCreting = true);
    }
    
    protected override ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton(_config);
        
        services.AddPosts();
        
        services.AddDbContext<SomeDbContext>();
    }
    
    // Simple logging
    private Task ConsoleLog(LogMessage arg)
    {
        Console.WriteLine(arg);
        return Task.CompletedTask;
    }
}

Views

StringMessageResult

Be sure to return the type RuntimeResult, not StringMessageResult, ErrorResult, or your YourOwnResult : RuntimeResult. Discord.Net allowed to do it only this way. (I hope it will be fixed in future releases of Discord.Net)

[Command("ping")]
public async Task<RuntimeResult> PingAsync()
{
    return new StringMessageResult("Pong!");
}

Prints Pong! message to the channel where this command was called.

EmbedMessageResult & ErrorResult

[Command("help")]
public async Task<RuntimeResult> HelpAsync(string input)
{
    var result = _commandService.Search(input);
    if (!result.IsSuccess)
        // Here
        return new ErrorResult(result.Reason);
    
    var command = result.Commands.First();
    
    var eb = new EmbedBuilder()
        .WithTitle(command.Aliases.First())
        .AddField(command.Remarks, command.Summary);
    
    // And here
    return new EmbedMessageResult(eb.Build());
}

Prints coincident embed.

Misc

There are also some stuff, such as

EmoteButton

that allow you to call some a method when a user emote the message.

You need to use the IEmoteFactory to create new EmoteButton using the method IEmoteButton Create(IEmote emote, ulong messageId, ButtonTrigger trigger); , where ButtonTrigger is delegate Task ButtonTrigger(IUser user)

For example:

class SomeService
{
    public static readonly IEmote PlusEmote = new Emoji("\u2795");

    public SomeService(IEmoteFactory emoteFactory)
    {
        emoteFactory.Craete(PlusEmote, Messages.AddNewPostMessageId, OnButtonTriggered);
    }
    
    private async Task OnButtonTriggered(IUser user)
    {
        // do something
    }
}

Many more usefulness will be added.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 659 8/26/2019
1.0.0 556 8/17/2019