Beispiel #1
0
        public async Task RunAsync()
        {
            R2Command.s_StartDateTime = DateTime.Now;

            RandomizeChatterThreshold();
            RandomizeRareChatterThreshold();
            RandomizeMythicChatterThreshold();

            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = await sr.ReadToEndAsync().ConfigureAwait(false);

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

            m_Prefix = configJson.Prefix;

            var config = new DiscordConfiguration
            {
                Token         = configJson.Token,
                TokenType     = TokenType.Bot,
                AutoReconnect = true,
                //LogLevel = LogLevel.Debug,
                //UseInternalLogHandler = true,
            };

            m_Client = new DiscordClient(config);
            m_Client.UseVoiceNext();

            m_Client.Ready          += OnClientReady;
            m_Client.MessageCreated += OnMessageCreated;
            m_Client.MessageCreated += CheckForPlaySyntax;
            m_Client.MessageCreated += Chatter;
            m_Client.MessageUpdated += OnMessageUpdated;
            m_Client.MessageUpdated += CheckUpdatedMessageForPlaySyntax;

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new string[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDms           = true, // maybe change this to allow commands via PM
                DmHelp = true,
                IgnoreExtraArguments = true,
            };

            m_Commands = m_Client.UseCommandsNext(commandsConfig);

            m_Commands.RegisterCommands <R2Command>();

            m_Commands.CommandExecuted += OnCommandExecuted;

            await m_Client.ConnectAsync();

            R2Command.LoadSavedData();

            await Task.Delay(-1);
        }