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

80 lines
3.0 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;
2025-03-07 14:55:00 +01:00
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Commands.Processors.TextCommands;
using DSharpPlus.Commands.Processors.TextCommands.Parsing;
using DSharpPlus.Entities;
2018-10-03 23:32:44 +02:00
using DSharpPlus.Interactivity;
2018-10-04 00:29:25 +02:00
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
{
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();
2022-09-14 23:29:22 +02:00
2025-03-07 14:55:00 +01:00
Console.WriteLine($"LaDOSE.Net Discord Bot");
2018-10-04 00:29:25 +02:00
2025-03-07 14:55:00 +01:00
DiscordClientBuilder builder2 = DiscordClientBuilder.CreateDefault(discordToken, TextCommandProcessor.RequiredIntents | SlashCommandProcessor.RequiredIntents);
2022-09-14 23:29:22 +02:00
var cts = new CancellationTokenSource();
2018-10-04 00:29:25 +02:00
2025-03-07 14:55:00 +01:00
// Setup the commands extension
builder2.UseCommands((IServiceProvider serviceProvider, CommandsExtension extension) =>
2018-10-04 00:29:25 +02:00
{
2025-03-07 14:55:00 +01:00
extension.AddCommands([typeof(Hokuto), typeof(Public)]);
TextCommandProcessor textCommandProcessor = new();
extension.AddProcessor(textCommandProcessor);
}, new CommandsConfiguration()
2022-09-14 23:29:22 +02:00
{
2025-03-07 14:55:00 +01:00
// The default value is true, however it's shown here for clarity
RegisterDefaultCommandProcessors = true,
UseDefaultCommandErrorHandler = false
// DebugGuildId = Environment.GetEnvironmentVariable("DEBUG_GUILD_ID") ?? 0,
});
2022-09-14 23:29:22 +02:00
2025-03-07 14:55:00 +01:00
DiscordClient client = builder2.Build();
2022-07-30 22:24:59 +02:00
2025-03-07 14:55:00 +01:00
// We can specify a status for our bot. Let's set it to "playing" and set the activity to "with fire".
DiscordActivity status = new("Street Fighter", DiscordActivityType.Playing);
await client.ConnectAsync(status,DiscordUserStatus.Online);
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);
2018-10-03 21:48:18 +02:00
}
}
2018-10-04 00:29:25 +02:00
}