This commit is contained in:
@@ -1,58 +1,55 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
using LaDOSE.DiscordBot.Service;
|
using LaDOSE.DiscordBot.Service;
|
||||||
using LaDOSE.DTO;
|
using LaDOSE.DTO;
|
||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
public class BotEvent : BaseCommandModule
|
// public class BotEvent : BaseCommandModule
|
||||||
{
|
// {
|
||||||
private WebService dep;
|
// private WebService dep;
|
||||||
public BotEvent(WebService d)
|
// public BotEvent(WebService d)
|
||||||
{
|
// {
|
||||||
dep = d;
|
// dep = d;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
[RequireRolesAttribute(RoleCheckMode.Any, "Staff")]
|
// [Command("newevent")]
|
||||||
[Command("newevent")]
|
// public async Task NewEventAsync(CommandContext ctx, string command)
|
||||||
public async Task NewEventAsync(CommandContext ctx, string command)
|
// {
|
||||||
{
|
//
|
||||||
|
// await ctx.RespondAsync(dep.RestService.CreateBotEvent(command).ToString());
|
||||||
await ctx.RespondAsync(dep.RestService.CreateBotEvent(command).ToString());
|
// }
|
||||||
}
|
// [RequireRolesAttribute(RoleCheckMode.Any,"Staff")]
|
||||||
[RequireRolesAttribute(RoleCheckMode.Any,"Staff")]
|
// [Command("staffs")]
|
||||||
[Command("staffs")]
|
// public async Task StaffAsync(CommandContext ctx)
|
||||||
public async Task StaffAsync(CommandContext ctx)
|
// {
|
||||||
{
|
// BotEventDTO currentEvent = dep.RestService.GetLastBotEvent();
|
||||||
BotEventDTO currentEvent = dep.RestService.GetLastBotEvent();
|
// StringBuilder stringBuilder = new StringBuilder();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
//
|
||||||
|
// var present = currentEvent.Results.Where(x => x.Result).ToList();
|
||||||
var present = currentEvent.Results.Where(x => x.Result).ToList();
|
// var absent = currentEvent.Results.Where(x => !x.Result).ToList();
|
||||||
var absent = currentEvent.Results.Where(x => !x.Result).ToList();
|
//
|
||||||
|
// stringBuilder.AppendLine($"Pour {currentEvent.Name} : ");
|
||||||
stringBuilder.AppendLine($"Pour {currentEvent.Name} : ");
|
// present.ForEach(x => stringBuilder.AppendLine($":white_check_mark: {x.Name}"));
|
||||||
present.ForEach(x => stringBuilder.AppendLine($":white_check_mark: {x.Name}"));
|
// absent.ForEach(x => stringBuilder.AppendLine($":x: {x.Name}"));
|
||||||
absent.ForEach(x => stringBuilder.AppendLine($":x: {x.Name}"));
|
//
|
||||||
|
// await ctx.RespondAsync(stringBuilder.ToString());
|
||||||
await ctx.RespondAsync(stringBuilder.ToString());
|
//
|
||||||
|
// }
|
||||||
}
|
// [RequireRolesAttribute(RoleCheckMode.Any, "Staff")]
|
||||||
[RequireRolesAttribute(RoleCheckMode.Any, "Staff")]
|
// [Command("present")]
|
||||||
[Command("present")]
|
// public async Task PresentAsync(CommandContext ctx)
|
||||||
public async Task PresentAsync(CommandContext ctx)
|
// {
|
||||||
{
|
// await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = true }).ToString());
|
||||||
await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = true }).ToString());
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
}
|
// [RequireRolesAttribute(RoleCheckMode.Any, "Staff")]
|
||||||
[RequireRolesAttribute(RoleCheckMode.Any, "Staff")]
|
// [Command("absent")]
|
||||||
[Command("absent")]
|
// public async Task AbsentAsync(CommandContext ctx)
|
||||||
public async Task AbsentAsync(CommandContext ctx)
|
// {
|
||||||
{
|
// await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = false }).ToString());
|
||||||
await ctx.RespondAsync(dep.RestService.ResultBotEvent(new DTO.BotEventSendDTO() { DiscordId = ctx.Member.Id.ToString(), DiscordName = ctx.Member.DisplayName, Present = false }).ToString());
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,15 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.Commands;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
using DSharpPlus.Commands.ArgumentModifiers;
|
||||||
|
using DSharpPlus.Commands.Processors.TextCommands;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
|
|
||||||
public class Hokuto : BaseCommandModule
|
public class Hokuto
|
||||||
{
|
{
|
||||||
|
|
||||||
private static List<string> Games = new List<string> { "2X", "3.3", "Karnov" };
|
private static List<string> Games = new List<string> { "2X", "3.3", "Karnov" };
|
||||||
@@ -21,14 +22,21 @@ namespace LaDOSE.DiscordBot.Command
|
|||||||
|
|
||||||
|
|
||||||
[Command("hokuto")]
|
[Command("hokuto")]
|
||||||
public async Task HokutoUserAsync(CommandContext ctx, params DiscordMember[] user)
|
public async ValueTask HokutoUserAsync(TextCommandContext ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var i = r.Next(0, 3);
|
var i = r.Next(0, 3);
|
||||||
if (user!=null && user.Length>0)
|
if (ctx.Message.MentionedUsers is { Count: 1 } )
|
||||||
{
|
{
|
||||||
await ctx.RespondAsync(ctx.User?.Mention + " vs " + user[0].Mention + " : " + Games[i].ToString());
|
foreach (var arg in ctx.Message.MentionedUsers)
|
||||||
|
{
|
||||||
|
if (arg is DiscordUser member)
|
||||||
|
{
|
||||||
|
await ctx.RespondAsync(ctx.User?.Mention + " vs " + member.Mention + " : " + Games[i].ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,12 +4,11 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus.CommandsNext;
|
using DSharpPlus.Commands;
|
||||||
using DSharpPlus.CommandsNext.Attributes;
|
|
||||||
|
|
||||||
namespace LaDOSE.DiscordBot.Command
|
namespace LaDOSE.DiscordBot.Command
|
||||||
{
|
{
|
||||||
public class Public : BaseCommandModule
|
public class Public
|
||||||
{
|
{
|
||||||
|
|
||||||
private static List<string> Quotes { get; set; }
|
private static List<string> Quotes { get; set; }
|
||||||
|
|||||||
@@ -7,11 +7,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DSharpPlus" Version="4.5.0" />
|
<PackageReference Include="DSharpPlus" Version="5.0.0-alpha.5" />
|
||||||
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.5.0" />
|
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-alpha.5" />
|
||||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.5.0" />
|
<PackageReference Include="DSharpPlus.Interactivity" Version="5.0.0-alpha.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ using System.IO;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
|
using DSharpPlus.Commands;
|
||||||
|
using DSharpPlus.Commands.Processors.SlashCommands;
|
||||||
|
using DSharpPlus.Commands.Processors.TextCommands;
|
||||||
|
using DSharpPlus.Commands.Processors.TextCommands.Parsing;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
using DSharpPlus.Interactivity;
|
using DSharpPlus.Interactivity;
|
||||||
using DSharpPlus.CommandsNext;
|
|
||||||
using DSharpPlus.EventArgs;
|
using DSharpPlus.EventArgs;
|
||||||
using DSharpPlus.Interactivity.Extensions;
|
using DSharpPlus.Interactivity.Extensions;
|
||||||
//using DSharpPlus.SlashCommands;
|
//using DSharpPlus.SlashCommands;
|
||||||
@@ -20,7 +24,6 @@ namespace LaDOSE.DiscordBot
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static DiscordClient discord;
|
|
||||||
|
|
||||||
//static InteractivityModule Interactivity { get; set; }
|
//static InteractivityModule Interactivity { get; set; }
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -42,107 +45,36 @@ namespace LaDOSE.DiscordBot
|
|||||||
var restUrl = builder["REST:Url"].ToString();
|
var restUrl = builder["REST:Url"].ToString();
|
||||||
var restUser = builder["REST:User"].ToString();
|
var restUser = builder["REST:User"].ToString();
|
||||||
var restPassword = builder["REST:Password"].ToString();
|
var restPassword = builder["REST:Password"].ToString();
|
||||||
|
|
||||||
var service = new ServiceCollection()
|
|
||||||
.AddSingleton(typeof(WebService), new WebService(new Uri(restUrl), restUser, restPassword))
|
|
||||||
.BuildServiceProvider();
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine($"LaDOSE.Net Discord Bot");
|
Console.WriteLine($"LaDOSE.Net Discord Bot");
|
||||||
|
|
||||||
|
DiscordClientBuilder builder2 = DiscordClientBuilder.CreateDefault(discordToken, TextCommandProcessor.RequiredIntents | SlashCommandProcessor.RequiredIntents);
|
||||||
discord = new DiscordClient(new DiscordConfiguration
|
|
||||||
{
|
|
||||||
Token = discordToken,
|
|
||||||
TokenType = TokenType.Bot,
|
|
||||||
//AutoReconnect = true,
|
|
||||||
//MinimumLogLevel = LogLevel.Debug,
|
|
||||||
//MessageCacheSize = 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
discord.UseInteractivity(new InteractivityConfiguration
|
|
||||||
{
|
|
||||||
|
|
||||||
// default pagination behaviour to just ignore the reactions
|
|
||||||
//PaginationBehaviour = TimeoutBehaviour.Ignore,
|
|
||||||
|
|
||||||
// default pagination timeout to 5 minutes
|
|
||||||
//PaginationTimeout = TimeSpan.FromMinutes(5),
|
|
||||||
|
|
||||||
// default timeout for other actions to 2 minutes
|
|
||||||
Timeout = TimeSpan.FromMinutes(2)
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration()
|
// Setup the commands extension
|
||||||
|
builder2.UseCommands((IServiceProvider serviceProvider, CommandsExtension extension) =>
|
||||||
{
|
{
|
||||||
//CaseSensitive = false,
|
extension.AddCommands([typeof(Hokuto), typeof(Public)]);
|
||||||
//EnableDefaultHelp = true,
|
TextCommandProcessor textCommandProcessor = new();
|
||||||
//EnableDms = false,
|
extension.AddProcessor(textCommandProcessor);
|
||||||
//EnableMentionPrefix = true,
|
}, new CommandsConfiguration()
|
||||||
StringPrefixes = new List<string>() { "/", "!" },
|
{
|
||||||
//IgnoreExtraArguments = true,
|
// The default value is true, however it's shown here for clarity
|
||||||
Services = service
|
RegisterDefaultCommandProcessors = true,
|
||||||
|
UseDefaultCommandErrorHandler = false
|
||||||
|
// DebugGuildId = Environment.GetEnvironmentVariable("DEBUG_GUILD_ID") ?? 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DiscordClient client = builder2.Build();
|
||||||
|
|
||||||
//var slashCommands = discord.UseSlashCommands(new SlashCommandsConfiguration() {Services = service});
|
// We can specify a status for our bot. Let's set it to "playing" and set the activity to "with fire".
|
||||||
//slashCommands.RegisterCommands<SlashCommand>(guildId:null);
|
DiscordActivity status = new("Street Fighter", DiscordActivityType.Playing);
|
||||||
|
await client.ConnectAsync(status,DiscordUserStatus.Online);
|
||||||
|
|
||||||
//_cnext.RegisterCommands<Result>();
|
|
||||||
_cnext.RegisterCommands<Public>();
|
|
||||||
//_cnext.RegisterCommands<Shutdown>();
|
|
||||||
//_cnext.RegisterCommands<Todo>();
|
|
||||||
_cnext.RegisterCommands<Hokuto>();
|
|
||||||
_cnext.RegisterCommands<BotEvent>();
|
|
||||||
|
|
||||||
foreach (var registeredCommandsKey in discord.GetCommandsNext().RegisteredCommands.Keys)
|
|
||||||
{
|
|
||||||
Console.WriteLine(registeredCommandsKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
discord.Ready += (sender, eventArgs) =>
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Bot READY.");
|
|
||||||
return Task.CompletedTask;
|
|
||||||
};
|
|
||||||
discord.GuildAvailable += (sender, eventArgs) =>
|
|
||||||
{
|
|
||||||
|
|
||||||
Console.WriteLine($"Joined Guild " + eventArgs.Guild.Name);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
await discord.ConnectAsync();
|
|
||||||
|
|
||||||
|
|
||||||
await Task.Delay(Timeout.Infinite);
|
await Task.Delay(Timeout.Infinite);
|
||||||
|
|
||||||
//while (!cts.IsCancellationRequested)
|
|
||||||
//{
|
|
||||||
// await Task.Delay(200);
|
|
||||||
// //if(discord.GetConnectionsAsync().Result.Count)
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//internal class SlashCommand : ApplicationCommandModule
|
|
||||||
//{
|
|
||||||
// [SlashCommand("test", "A slash command made to test the DSharpPlusSlashCommands library!")]
|
|
||||||
|
|
||||||
// public async Task TestCommand(InteractionContext ctx)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// await ctx.CreateResponseAsync("Lol");
|
|
||||||
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user