Пример #1
0
        private async Task InitializeBot()
        {
            instance = this;

            Log.InitializeLogging(clientInformation);

            Log.Message(VersionText);

            Client = new DiscordShardedClient(new DiscordSocketConfig()
            {
                TotalShards       = clientInformation.ShardCount,
                LogLevel          = LogSeverity.Info,
                HandlerTimeout    = 10000,
                ConnectionTimeout = 300000,
            });

            LoadEvents();

            EventSystem.RegisterBot(this);

            Events.RegisterPrefixInstance(">").RegisterAsDefault();

            // fallback prefix
            Events.RegisterPrefixInstance("miki.", false);
            // debug prefix
            Events.RegisterPrefixInstance("fmiki.", false, true);

            Addons = new AddonManager();
            await Addons.Load(this);

            if (clientInformation.EventLoaderMethod != null)
            {
                await clientInformation.EventLoaderMethod(this);
            }

            //MessageReceived += async (m) => Log.Message("message received");

            foreach (DiscordSocketClient c in Client.Shards)
            {
                c.Ready += async() =>
                {
                    Log.Message($"shard {c.ShardId} ready!");
                    await c.SetGameAsync($"{c.ShardId}/{GetTotalShards()} | >help");
                };

                c.Connected += async() =>
                {
                    Log.Message($"{c.ShardId}| Connected!");
                    await Task.Delay(0);
                };

                c.Disconnected += async(e) =>
                {
                    Log.ErrorAt(c.ShardId + "| Disconnected", e.Message);
                    await Task.Delay(0);
                };
            }

            Client.Log += Client_Log;
        }
Пример #2
0
        private async Task InitializeBot()
        {
            instance = this;

            Log.InitializeLogging(clientInformation);

            Log.Message(VersionText);

            Client = new DiscordShardedClient(new DiscordSocketConfig()
            {
                TotalShards = clientInformation.ShardCount,
                LogLevel    = LogSeverity.Debug,
            });

            Events = new EventSystem(x =>
            {
                x.Name           = clientInformation.Name;
                x.Identifier     = clientInformation.Prefix;
                x.SqlInformation = clientInformation.sqlInformation;
            });

            Sql = new Sql(clientInformation.sqlInformation, clientInformation.Prefix);

            Addons = new AddonManager();
            await Addons.Load(this);

            if (clientInformation.EventLoaderMethod != null)
            {
                await clientInformation.EventLoaderMethod(this);
            }

            Application.ThreadException +=
                new ThreadExceptionEventHandler(Application_ThreadException);

            Client.MessageReceived += async(a) =>
            {
                Task.Run(() => Client_MessageReceived(a));
            };
            Client.JoinedGuild += Client_JoinedGuild;
            Client.LeftGuild   += Client_LeftGuild;
//            Client.UserUpdated += async (u1, u2) => { Log.Done($"UPDATED {u1.Username}"); };

            foreach (DiscordSocketClient c in Client.Shards)
            {
                c.Ready += async() =>
                {
                    Log.Message($"shard {c.ShardId} connected!");
                    await c.SetGameAsync($"{c.ShardId}/{GetTotalShards()} | >help");
                };
            }

            //           Client.Log += Client_Log;
        }