Example #1
0
        private async Task RunCopebot()
        {
            string json;

            using (var stream = File.OpenRead(Path.Combine(Environment.CurrentDirectory, "config.json")))
                using (var reader = new StreamReader(stream, new UTF8Encoding(false)))
                    json = await reader.ReadToEndAsync();

            var configJson = JsonConvert.DeserializeObject <ConfigJson>(json);

            var config = new DiscordConfiguration
            {
                Token     = configJson.MainToken,
                TokenType = TokenType.Bot,

                AutoReconnect         = true,
                LogLevel              = LogLevel.Info,
                UseInternalLogHandler = true
            };

            var eventHandlers = new EventHandlers(configJson.TypingChannelId);

            Client = new DiscordClient(config);

            Client.MessageCreated     += eventHandlers.Bot_MessageCreated;
            Client.ChannelPinsUpdated += eventHandlers.Bot_PinsUpdated;
            Client.TypingStarted      += eventHandlers.Bot_TypingStarted;



            var interactivityConfig = new InteractivityConfiguration {
                Timeout = TimeSpan.FromMinutes(1.0)
            };

            Client.UseInteractivity(interactivityConfig);

            var prefixes = new List <string> {
                configJson.CommandPrefix
            };
            var minecraftServerHelper = new MinecraftServerHelper(HttpClient, configJson.ImgbbApiKey);
            var services = new ServiceCollection()
                           .AddSingleton(minecraftServerHelper)
                           .BuildServiceProvider();

            var commandsConfig = new CommandsNextConfiguration {
                StringPrefixes      = prefixes,
                Services            = services,
                EnableMentionPrefix = true,
                EnableDms           = true
            };

            Commands = Client.UseCommandsNext(commandsConfig);

            Commands.RegisterCommands <UngroupedBotCommands>();
            Commands.RegisterCommands <BotUserCommands>();

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
Example #2
0
        public IActionResult TestServer([FromBody] Server server)
        {
            var result = new MinecraftServerHelper().PingServer(server.Host, server.Port);

            return(new JsonResult(new
            {
                IsSuccess = result != null,
                StatusResponse = result
            }));
        }
Example #3
0
 public UngroupedBotCommands(MinecraftServerHelper minecraftServerHelper)
 {
     MinecraftServerHelper = minecraftServerHelper;
 }