Ajout de CommandNext
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
public partial class Twitch
|
||||
{
|
||||
internal class Result
|
||||
{
|
||||
Dependencies dep;
|
||||
public Result(Dependencies d)
|
||||
{
|
||||
this.dep = d;
|
||||
}
|
||||
|
||||
[Command("result")]
|
||||
public async Task ResultAsync(CommandContext ctx)
|
||||
{
|
||||
await ctx.RespondAsync("Resultat");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
[RequireRolesAttribute("SuperAdmin")]
|
||||
internal class Shutdown
|
||||
{
|
||||
private readonly Dependencies dep;
|
||||
|
||||
public Shutdown(Dependencies d)
|
||||
{
|
||||
dep = d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Command("shutdown")]
|
||||
public async Task ShutDownAsync(CommandContext ctx)
|
||||
{
|
||||
await ctx.RespondAsync("Hasta la vista, baby");
|
||||
dep.Cts.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
|
||||
namespace LaDOSE.DiscordBot.Command
|
||||
{
|
||||
public partial class Result
|
||||
{
|
||||
|
||||
internal class Twitch
|
||||
{
|
||||
Dependencies dep;
|
||||
public Twitch(Dependencies d)
|
||||
{
|
||||
this.dep = d;
|
||||
}
|
||||
|
||||
[Command("twitch")]
|
||||
public async Task TwitchAsync(CommandContext ctx)
|
||||
{
|
||||
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Threading;
|
||||
using DSharpPlus.Interactivity;
|
||||
|
||||
namespace LaDOSE.DiscordBot
|
||||
{
|
||||
internal class Dependencies
|
||||
{
|
||||
internal InteractivityModule Interactivity { get; set; }
|
||||
internal CancellationTokenSource Cts { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DSharpPlus" Version="3.2.3" />
|
||||
<PackageReference Include="DSharpPlus.CommandsNext" Version="3.2.3" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="3.2.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Interactivity;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.EventArgs;
|
||||
using LaDOSE.DiscordBot.Command;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace LaDOSE.DiscordBot
|
||||
{
|
||||
class Program
|
||||
{
|
||||
|
||||
static DiscordClient discord;
|
||||
static InteractivityModule _interactivity;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
|
||||
MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
static async Task MainAsync(string[] args)
|
||||
{
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build();
|
||||
@@ -46,26 +47,53 @@ namespace LaDOSE.DiscordBot
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
});
|
||||
|
||||
discord.MessageCreated += async e =>
|
||||
var _cts = new CancellationTokenSource();
|
||||
DependencyCollection dep = null;
|
||||
|
||||
using (var d = new DependencyCollectionBuilder())
|
||||
{
|
||||
if (e.Message.Content.ToLower().Equals("!result"))
|
||||
await e.Message.RespondAsync("Les Résultats du dernier Ranking : XXXX");
|
||||
if (e.Message.Content.ToLower().Equals("!twitch"))
|
||||
await e.Message.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
||||
};
|
||||
d.AddInstance(new Dependencies()
|
||||
{
|
||||
Interactivity = _interactivity,
|
||||
Cts = _cts
|
||||
});
|
||||
dep = d.Build();
|
||||
}
|
||||
|
||||
var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration()
|
||||
{
|
||||
CaseSensitive = false,
|
||||
EnableDefaultHelp = true,
|
||||
EnableDms = false,
|
||||
EnableMentionPrefix = true,
|
||||
StringPrefix = "!",
|
||||
IgnoreExtraArguments = true,
|
||||
Dependencies = dep
|
||||
});
|
||||
|
||||
_cnext.RegisterCommands<Result>();
|
||||
_cnext.RegisterCommands<Twitch>();
|
||||
_cnext.RegisterCommands<Shutdown>();
|
||||
|
||||
|
||||
//discord.MessageCreated += async e =>
|
||||
//{
|
||||
// if (e.Message.Content.ToLower().Equals("!result"))
|
||||
// await e.Message.RespondAsync("Les Résultats du dernier Ranking : XXXX");
|
||||
// if (e.Message.Content.ToLower().Equals("!twitch"))
|
||||
// await e.Message.RespondAsync("https://www.twitch.tv/LaDOSETV");
|
||||
//};
|
||||
|
||||
discord.GuildMemberAdded += async e =>
|
||||
{
|
||||
await e.Guild.GetDefaultChannel().SendMessageAsync($"Bonjour {e.Member.Nickname}!");
|
||||
await e.Guild.GetDefaultChannel().SendMessageAsync($"Bonjour {e.Member.DisplayName}!");
|
||||
};
|
||||
await discord.ConnectAsync();
|
||||
await Task.Delay(-1);
|
||||
while (!_cts.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user