Exemple #1
0
        public CommandHandler(DiscordSocketClient client, CommandService commands, ConfigurationFile config, DatabaseManager database, BotRuntimeInformation runtimeInformation)
        {
            this.commands           = commands;
            this.database           = database;
            this.client             = client;
            this.config             = config;
            this.runtimeInformation = runtimeInformation;

            services = new ServiceCollection()
                       .AddSingleton(config)
                       .AddSingleton(client)
                       .AddSingleton(runtimeInformation)
                       .AddSingleton(database)
                       .AddSingleton <InteractiveService>()
                       .BuildServiceProvider();
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            var client             = new DiscordSocketClient();
            var config             = ConfigurationManager.Read();
            var database           = new DatabaseManager();
            var runtimeInformation = new BotRuntimeInformation(DateTime.UtcNow, new TimerService(client));

            client.Log += Client_Log;
            var commandHandler = new CommandHandler(client, new CommandService(), config, database, runtimeInformation);
            await commandHandler.InstallCommandsAsync();

            await client.LoginAsync(TokenType.Bot, config.Token);

            await client.StartAsync();

            await runtimeInformation.Timers.RestoreTimers();

            while (true)
            {
                var response = Console.ReadLine();
                switch (response)
                {
                case "quit":
                    database.Database.Dispose();
                    await runtimeInformation.Timers.SaveTimers();

                    LoggingService.LogToTerminal(LogSeverity.Info, $"{config.Name} is shutting down.");
                    return;

                case "setbotadmin":
                    while (true)
                    {
                        Console.WriteLine("Type the user ID of the user you want to set as admin.");
                        if (ulong.TryParse(Console.ReadLine(), out var result))
                        {
                            var user = database.GetUser(result);
                            user.BotPermissions = BotPermissionLevel.BotAdministrator;

                            database.WriteUser(user);
                            Console.WriteLine("Permissions set!");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("idoit");
                        }
                    }
                    break;

                case "setbotowner":
                    while (true)
                    {
                        Console.WriteLine("Type the user ID of the user you want to set as owner.");
                        if (ulong.TryParse(Console.ReadLine(), out var result))
                        {
                            var user = database.GetUser(result);
                            user.BotPermissions = BotPermissionLevel.Owner;

                            database.WriteUser(user);
                            Console.WriteLine("Permissions set!");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("idoit");
                        }
                    }
                    break;

                case "stats":
                    Console.WriteLine($"Commands handled: {runtimeInformation.CommandsHandled}, Uptime - {DateTime.UtcNow - runtimeInformation.StartupTime}");
                    break;

                default:
                    Console.WriteLine("That's not a valid command. Valid commands are quit, setbotadmin, setbotowner, stats.");
                    break;
                }
            }
        }