示例#1
0
        public async Task LoadDiscord()
        {
            bot = new Bot(Global.Config.AmountShards, new DiscordSocketConfig()
            {
                ShardId           = Global.Config.ShardId,
                TotalShards       = Global.Config.ShardCount,
                ConnectionTimeout = 100000,
                LargeThreshold    = 250,
            }, new ClientInformation()
            {
                Name       = "Miki",
                Version    = "0.6.2",
                ShardCount = Global.Config.ShardCount,
                DatabaseConnectionString = Global.Config.ConnString,
            });

            EventSystem eventSystem = new EventSystem(new EventSystemConfig()
            {
                Developers        = Global.Config.DeveloperIds,
                ErrorEmbedBuilder = new EmbedBuilder().WithTitle($"🚫 Something went wrong!").WithColor(new Color(1.0f, 0.0f, 0.0f))
            });

            bot.Attach(eventSystem);
            ConfigurationManager mg = new ConfigurationManager();

            var commandMap = new CommandMap();

            commandMap.OnModuleLoaded += (module) =>
            {
                mg.RegisterType(module.GetReflectedInstance());
            };
            commandMap.RegisterAttributeCommands();
            commandMap.Install(eventSystem, bot);

            var handler = new SimpleCommandHandler(commandMap);

            handler.AddPrefix(">", true);
            handler.AddPrefix("miki.");

            var sessionHandler = new SessionBasedCommandHandler();
            var messageHandler = new MessageListener();

            eventSystem.AddCommandHandler(sessionHandler);
            eventSystem.AddCommandHandler(messageHandler);
            eventSystem.AddCommandHandler(handler);

            foreach (var x in mg.Containers)
            {
                Console.WriteLine(x.Type.Name);
                foreach (var y in x.ConfigurableItems)
                {
                    Console.WriteLine($"=> {y.Type.Name} : {y.Type.PropertyType} = {y.GetValue<object>().ToString()}");
                }
            }

            Console.WriteLine("---- loading config.json ----\nVALUES CHANGED TO:");

            await mg.ImportAsync(new JsonSerializationProvider(), "./testexport.json");

            foreach (var x in mg.Containers)
            {
                Console.WriteLine(x.Type.Name);
                foreach (var y in x.ConfigurableItems)
                {
                    Console.WriteLine($"=> {y.Type.Name} : {y.Type.PropertyType} = {y.GetValue<object>().ToString()}");
                }
            }

            if (!string.IsNullOrWhiteSpace(Global.Config.SharpRavenKey))
            {
                Global.ravenClient = new SharpRaven.RavenClient(Global.Config.SharpRavenKey);
            }

            bot.Client.MessageReceived += Bot_MessageReceived;

            bot.Client.JoinedGuild += Client_JoinedGuild;
            bot.Client.LeftGuild   += Client_LeftGuild;
            bot.Client.UserUpdated += Client_UserUpdated;

            bot.Client.ShardConnected    += Bot_OnShardConnect;
            bot.Client.ShardDisconnected += Bot_OnShardDisconnect;
        }