Beispiel #1
0
        public static void OnClientInit(DiscordSocketClient client)
        {
            client.MessageReceived += MessageSystem.MessageReceived;
            client.MessageUpdated  += MessageSystem.MessageUpdated;
            client.MessageDeleted  += MessageSystem.MessageDeleted;
            client.ReactionAdded   += MessageSystem.ReactionAdded;
            client.UserJoined      += async user => await BotSystem.CallForEnabledSystems(user.Guild, s => s.OnUserJoined(user));

            client.UserLeft += async user => await BotSystem.CallForEnabledSystems(user.Guild, s => s.OnUserLeft(user));

            client.GuildMemberUpdated += async(oldUser, newUser) => {
                await BotSystem.CallForEnabledSystems(newUser.Guild, s => s.OnUserUpdated(oldUser, newUser));
            };
        }
Beispiel #2
0
        /// <summary>
        /// Uruchamia licznik czasowy w którym gracz może podjać decyzję
        /// </summary>
        public void RunActionTimer()
        {
            var gameTable = Game.GameTableModel;

            Console.WriteLine("RunActionTimer()");

            //Gracz poza grą, wykonujemy domyślną akcję
            if (Game.GameTableModel.ActionPlayer.Status.HasFlag(PlayerModel.PlayerStatus.DONTPLAY))
            {
                ActionPlayerNoAction(null, null);
                return;
            }

            //Gracz w tym momencie teoretycznie musi wykonać akcję
            //Jednak inicjujemy także moduł bota gdy wymagany
            if (gameTable.ActionPlayer.User.Username.Contains("Bot"))
            {
                Task.Factory.StartNew(() =>
                {
                    var bot = new BotSystem();
                    bot.Initial(Game);
                    bot.ActionFor(gameTable.ActionTimer);
                });
            }

            ActionPlayerTimer           = new System.Timers.Timer(gameTable.ActionTimer);
            ActionPlayerTimer.Elapsed  += ActionPlayerNoAction;
            ActionPlayerTimer.AutoReset = false;
            ActionPlayerTimer.Enabled   = true;

            //Wysylamy wiadomosc do wszystkich ze gracz otrzymal taka akcje, ogranicza sie to tylko do akcji
            //BetOfferAction, reszta akcji pozostaje tylko do konkretnych graczy
            var betOfferAction = this.GetBetOfferAction();

            foreach (UserModel user in gameTable.WatchingList)
            {
                if (user.IsOnline())
                {
                    Task.Factory.StartNew(() =>
                    {
                        user.GetClient().OnGameActionOffer(gameTable, betOfferAction);
                    });
                }
            }
        }
Beispiel #3
0
        public async Task Run()
        {
            GlobalConfiguration.Initialize();

            tempFolder = Path.GetFullPath("Temp") + Path.DirectorySeparatorChar;

            Directory.CreateDirectory(tempFolder);

            optAlwaysRetry           = RequestOptions.Default;
            optAlwaysRetry.RetryMode = RetryMode.AlwaysRetry;

            #region SystemInstancing

            //regions r bad
            //TODO: Add system priorities, replace this.

            await AddSystem <DiscordConnectionSystem>();
            await AddSystem <MemorySystem>();
            await AddSystem <ChannelSystem>();
            await AddSystem <CommandSystem>();
            await AddSystem <MessageSystem>();
            await AddSystem <StatusSystem>();

            botAssembly = Assembly.GetExecutingAssembly();
            botTypes    = botAssembly.GetTypes();
            Type[] systemTypes = botTypes.Where(t => !t.IsAbstract && t.IsDerivedFrom(typeof(BotSystem))).ToArray();

            var toggles    = GlobalConfiguration.config.systemToggles;
            var newToggles = new Dictionary <string, bool>();

            for (int i = 0; i < systemTypes.Length; i++)
            {
                var thisType = systemTypes[i];

                if (!systems.Any(q => q.GetType() == thisType))
                {
                    string name   = thisType.Name;
                    var    config = BotSystem.GetConfiguration(thisType);

                    bool isEnabled;

                    if (config.AlwaysEnabled)
                    {
                        isEnabled = true;
                    }
                    else
                    {
                        if (toggles == null || !toggles.TryGetValue(name, out isEnabled))
                        {
                            isEnabled = true;
                        }

                        newToggles[name] = isEnabled;
                    }

                    if (isEnabled)
                    {
                        await AddSystem(thisType);                         //TODO: Pass config, so this method doesn't have to search for it again?
                    }
                }
            }

            if (toggles == null || newToggles.Count != toggles.Count || newToggles.Any(t => !toggles.ContainsKey(t.Key)))
            {
                GlobalConfiguration.config.systemToggles = newToggles;
                GlobalConfiguration.Save();
            }

            #endregion

            await InitializeSystems();

            //TODO: Unhardcode
            CommandSystem.StaticInit();

            serviceProvaider = new ServiceCollection()
                               .AddSingleton(client)
                               .AddSingleton(CommandSystem.commandService)
                               .BuildServiceProvider();

            await CommandSystem.commandService.AddModulesAsync(Assembly.GetEntryAssembly(), serviceProvaider);

            while (true)
            {
                try {
                    await UpdateSystems(true);

                    await Task.Delay(1000);
                }
                catch (FatalException e) {
                    await HandleException(e);

                    return;
                }
                catch (Exception e) {
                    await HandleException(e);
                }
            }
        }