Beispiel #1
0
 public MatchmakingFilter(PlayerDBService connection, IEnumerable <IMatchmaking> matchmakings)
 {
     DBConnection        = connection;
     _matchmakerServices = new Dictionary <string, Filter> ();
     foreach (var matchmaker in matchmakings)
     {
         _matchmakerServices.Add(matchmaker.GetKey(), matchmaker.MatchmakingFilter);
     }
     _matchmakerServices.Add(Match.DefaultTopic, GeneralFilter);
 }
 public PlayerController(PlayerDBService playerDBService)
 {
     _playerDBService = playerDBService;
 }
Beispiel #3
0
        public SmashBot(IServiceProvider services)
        {
            DBService = (PlayerDBService)services.GetService(typeof(PlayerDBService));
            Lobby     = (LobbyService)services.GetService(typeof(ILobbyService));
            const string tokenKey = "smashbot_token";
            string       token    = "";

#if CONFIG_FILE
            const string path = "config.json";
            if (!File.Exists(path))
            {
                new BotConfig().Save(path);

                return;
            }
            else
            {
                token = BotConfig.FromFile(path).Token;
            }
#else
            token = Environment.GetEnvironmentVariable(tokenKey);
            if (string.IsNullOrEmpty(token))
            {
                Console.WriteLine($"El token {tokenKey} debe estar registrado en las variables de entorno! El bot no se inició");
                return;
            }
#endif

            var config = new DiscordConfiguration {
                Token         = token,
                TokenType     = TokenType.Bot,
                AutoReconnect = true
            };

            Client = new DiscordClient(config);

            Client.Ready          += OnClientReady;
            Client.GuildCreated   += OnGuildEntered;
            Client.GuildDeleted   += OnGuildLeave;
            Client.MessageCreated += Lobby.OnMessage;

            Client.UseInteractivity(new InteractivityConfiguration {
                Timeout = TimeSpan.FromSeconds(20)
            });

            var commandsConfig = new CommandsNextConfiguration {
                StringPrefixes      = new string[] { "s!", "!!" },
                EnableDms           = false,
                EnableMentionPrefix = true,
                Services            = services
            };

            var commands = Client.UseCommandsNext(commandsConfig);

            //commands.RegisterCommands<ReportCommands> ();
            //commands.RegisterCommands<InfoCommands> ();
            commands.RegisterCommands <UtilsCommands> ();
            //commands.RegisterCommands<SmashfestCommands> ();
            commands.RegisterCommands <LobbyCommands> ();
            //commands.RegisterCommands<DebugCommands> ();
            commands.RegisterCommands <TimerCommands> ();
            Client.ConnectAsync();
        }