Files
LaDOSE/LaDOSE.Src/LaDOSE.DiscordBot/Program.cs

148 lines
4.7 KiB
C#
Raw Normal View History

2018-10-03 21:48:18 +02:00
using System;
using System.Collections.Generic;
using System.IO;
2018-10-04 00:29:25 +02:00
using System.Threading;
2018-10-03 21:48:18 +02:00
using System.Threading.Tasks;
using DSharpPlus;
2018-10-03 23:32:44 +02:00
using DSharpPlus.Interactivity;
2018-10-04 00:29:25 +02:00
using DSharpPlus.CommandsNext;
using DSharpPlus.EventArgs;
2022-09-14 23:29:22 +02:00
using DSharpPlus.Interactivity.Extensions;
//using DSharpPlus.SlashCommands;
//using DSharpPlus.SlashCommands.Attributes;
2018-10-04 00:29:25 +02:00
using LaDOSE.DiscordBot.Command;
2018-10-04 01:32:33 +02:00
using LaDOSE.DiscordBot.Service;
2018-10-03 21:48:18 +02:00
using Microsoft.Extensions.Configuration;
2022-09-14 23:29:22 +02:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2018-10-03 21:48:18 +02:00
namespace LaDOSE.DiscordBot
{
class Program
{
static DiscordClient discord;
2022-09-14 23:29:22 +02:00
//static InteractivityModule Interactivity { get; set; }
2018-10-03 21:48:18 +02:00
static void Main(string[] args)
{
MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
}
2022-09-14 23:29:22 +02:00
2018-10-03 21:48:18 +02:00
static async Task MainAsync(string[] args)
{
Console.WriteLine(Directory.GetCurrentDirectory());
2018-10-03 21:48:18 +02:00
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("settings.json", optional: true, reloadOnChange: true).Build();
var discordToken = builder["Discord:Token"].ToString();
2018-10-04 01:32:33 +02:00
var challongeToken = builder["Challonge:Token"].ToString();
var restUrl = builder["REST:Url"].ToString();
var restUser = builder["REST:User"].ToString();
var restPassword = builder["REST:Password"].ToString();
2018-10-03 21:48:18 +02:00
2022-09-14 23:29:22 +02:00
var service = new ServiceCollection()
.AddSingleton(typeof(WebService), new WebService(new Uri(restUrl), restUser, restPassword))
.BuildServiceProvider();
2018-10-03 21:48:18 +02:00
2022-09-14 23:29:22 +02:00
Console.WriteLine($"LaDOSE.Net Discord Bot");
2018-10-04 00:29:25 +02:00
2022-09-14 23:29:22 +02:00
2018-10-03 21:48:18 +02:00
discord = new DiscordClient(new DiscordConfiguration
{
Token = discordToken,
2022-09-14 23:29:22 +02:00
TokenType = TokenType.Bot,
//AutoReconnect = true,
//MinimumLogLevel = LogLevel.Debug,
//MessageCacheSize = 0,
2018-10-03 21:48:18 +02:00
});
discord.UseInteractivity(new InteractivityConfiguration
{
2022-09-14 23:29:22 +02:00
// default pagination behaviour to just ignore the reactions
2022-09-14 23:29:22 +02:00
//PaginationBehaviour = TimeoutBehaviour.Ignore,
// default pagination timeout to 5 minutes
2022-09-14 23:29:22 +02:00
//PaginationTimeout = TimeSpan.FromMinutes(5),
// default timeout for other actions to 2 minutes
Timeout = TimeSpan.FromMinutes(2)
});
2018-10-04 00:29:25 +02:00
2022-09-14 23:29:22 +02:00
var cts = new CancellationTokenSource();
2018-10-04 00:29:25 +02:00
var _cnext = discord.UseCommandsNext(new CommandsNextConfiguration()
{
2022-09-14 23:29:22 +02:00
//CaseSensitive = false,
//EnableDefaultHelp = true,
//EnableDms = false,
//EnableMentionPrefix = true,
StringPrefixes = new List<string>() { "/", "!" },
//IgnoreExtraArguments = true,
Services = service
2018-10-04 00:29:25 +02:00
});
2022-09-14 23:29:22 +02:00
//var slashCommands = discord.UseSlashCommands(new SlashCommandsConfiguration() {Services = service});
//slashCommands.RegisterCommands<SlashCommand>(guildId:null);
//_cnext.RegisterCommands<Result>();
2022-07-30 18:22:49 +02:00
_cnext.RegisterCommands<Public>();
2022-09-14 23:29:22 +02:00
//_cnext.RegisterCommands<Shutdown>();
2022-07-30 18:22:49 +02:00
//_cnext.RegisterCommands<Todo>();
2021-11-28 02:09:04 +01:00
_cnext.RegisterCommands<Hokuto>();
2022-07-30 18:22:49 +02:00
_cnext.RegisterCommands<BotEvent>();
2018-10-04 00:29:25 +02:00
2022-09-14 23:29:22 +02:00
foreach (var registeredCommandsKey in discord.GetCommandsNext().RegisteredCommands.Keys)
{
Console.WriteLine(registeredCommandsKey);
}
2018-10-04 00:29:25 +02:00
2018-10-03 21:48:18 +02:00
2022-09-14 23:29:22 +02:00
discord.Ready += (sender, eventArgs) =>
2018-10-03 23:32:44 +02:00
{
2022-09-14 23:29:22 +02:00
Console.WriteLine($"Bot READY.");
return Task.CompletedTask;
};
discord.GuildAvailable += (sender, eventArgs) =>
{
Console.WriteLine($"Joined Guild " + eventArgs.Guild.Name);
return Task.CompletedTask;
2018-10-03 23:32:44 +02:00
};
2022-07-30 22:24:59 +02:00
2018-10-03 21:48:18 +02:00
await discord.ConnectAsync();
2022-09-14 23:29:22 +02:00
2022-07-30 22:24:59 +02:00
2022-09-14 23:29:22 +02:00
await Task.Delay(Timeout.Infinite);
//while (!cts.IsCancellationRequested)
//{
// await Task.Delay(200);
// //if(discord.GetConnectionsAsync().Result.Count)
//}
2018-10-04 00:29:25 +02:00
2018-10-03 21:48:18 +02:00
}
2022-09-14 23:29:22 +02:00
2018-10-03 21:48:18 +02:00
}
2022-09-14 23:29:22 +02:00
//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");
// }
//}
2018-10-04 00:29:25 +02:00
}