Beispiel #1
0
 public System(CommandService commandService, ListService systemService, CooldownService cooldownService, LeaderboardService lbService)
 {
     _commandService  = commandService;
     _systemService   = systemService;
     _cooldownService = cooldownService;
     _lbService       = lbService;
 }
Beispiel #2
0
 public Items(UserRepository userRepo, InteractiveService interactiveService, GameService gameService, CooldownService cooldownService)
 {
     _userRepo           = userRepo;
     _interactiveService = interactiveService;
     _gameService        = gameService;
     _cooldownService    = cooldownService;
 }
Beispiel #3
0
 public Gangs(GangRepository gangRepo, UserRepository userRepo, InteractiveService interactiveService, CooldownService CooldownService)
 {
     _gangRepo           = gangRepo;
     _userRepo           = userRepo;
     _interactiveService = interactiveService;
     _cooldownService    = CooldownService;
 }
Beispiel #4
0
 public General(UserRepository userRepo, GuildRepository guildRepo, GangRepository gangRepo, RankHandler rankHandler, GameService gameService, CooldownService cooldownService)
 {
     _userRepo        = userRepo;
     _guildRepo       = guildRepo;
     _gangRepo        = gangRepo;
     _RankHandler     = rankHandler;
     _gameService     = gameService;
     _cooldownService = cooldownService;
 }
Beispiel #5
0
 public Crime(UserRepository userRepo, GangRepository gangRepo, ModerationService moderationService, GameService gameService, InteractiveService interactiveService, CooldownService CooldownService)
 {
     _userRepo           = userRepo;
     _gangRepo           = gangRepo;
     _moderationService  = moderationService;
     _gameService        = gameService;
     _interactiveService = interactiveService;
     _cooldownService    = CooldownService;
 }
Beispiel #6
0
        public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo cmdInfo, IServiceProvider services)
        {
            CooldownService cooldownService = services.GetService <CooldownService>();

            if (cooldownService.IsCooldownExpired(context.Guild.Id, cmdInfo))
            {
                //cooldownService.SetCooldown(context.Guild.Id, cmdInfo, Seconds);
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }
            else
            {
                return(Task.FromResult(PreconditionResult.FromError($"The command `{cmdInfo.Name}` cannot be used for another {Math.Max(cooldownService.GetRemainingTime(context.Guild.Id, cmdInfo), 1)} seconds!")));
            }
        }
Beispiel #7
0
 public EventHookerService(DiscordSocketClient client, CommandService command, LoggerService logger,
                           GuildUserAccountService guildUser, GlobalUserAccountService user, CreateLanguageFilesService language,
                           GuildAccountService guildAccount, CooldownService cooldown, BotConfig config)
 {
     _client       = client;
     _commands     = command;
     _logger       = logger;
     _guildUser    = guildUser;
     _user         = user;
     _language     = language;
     _guildAccount = guildAccount;
     _cooldown     = cooldown;
     _config       = config;
 }
        public GuildAccountService(CreateGuildAccountFilesService guildFiles, CooldownService cooldown,
                                   InvokeService invoke)
        {
            if (!File.Exists(filePath))
            {
                CreateFile();
            }
            string json = File.ReadAllText(filePath);

            guildIDs = JsonConvert.DeserializeObject <List <ulong> >(json);

            _guildFiles = guildFiles;
            _cooldown   = cooldown;
            _invoke     = invoke;
        }
Beispiel #9
0
        public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider serviceProvider)
        {
            return(Task.Run(async() =>
            {
                _serviceProvider = serviceProvider;
                _cooldownService = _serviceProvider.GetService <CooldownService>();

                if (_cooldownService.TryGet(x => x.UserId == context.User.Id && x.GuildId == context.Guild.Id && x.CommandId == command.Name, out _cooldown))
                {
                    await context.Channel.SendErrorAsync($"Hours: {_cooldown.Hours}\nMinutes: {_cooldown.Minutes}\nSeconds: {_cooldown.Seconds}", $"{command.Name.UpperFirstChar()} cooldown for {context.User}");
                    return PreconditionResult.FromError(string.Empty);
                }

                return PreconditionResult.FromSuccess();
            }));
        }
        // DiscordSocketClient, CommandService, IConfigurationRoot, and IServiceProvider are injected automatically from the IServiceProvider
        public CommandHandler(
            DiscordShardedClient discord,
            CommandService commands,
            IConfigurationRoot config,
            IServiceProvider provider,
            CooldownService cooldownService)
        {
            _cooldown = cooldownService;
            _discord  = discord;
            _commands = commands;
            _config   = config;
            _provider = provider;

            _discord.MessageReceived += OnMessageReceivedAsync;
            _discord.MessageUpdated  += OnMessageUpdated;
        }
        public void DotaAssistansTest()
        {
            #region Arrange
            var dbContextMock = new DbContextMock <FakeContext>();

            var mockSet = dbContextMock.CreateDbSetMock(x => x.Cooldowns, GetTestCooldowns());

            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;
            var mock = new Mock <FakeContext>();
            mock.Setup(c => c.Cooldowns).Returns(mockSet.Object);

            var services = new ServiceCollection()
                           .AddScoped <IEFContext>(provider => mock.Object)
                           .AddSingleton <ILogger, LoggerEmptyService>()
                           .BuildServiceProvider();

            SaveChangesInFakeContext(mock, token, SaveFakeDbSets, mockSet);

            var cooldownService = new CooldownService(services);
            #endregion

            #region Act
            bool firstCheck = cooldownService.Check("test");
            cooldownService.Set("test");
            bool secondCheck = cooldownService.Check("test");
            Thread.Sleep(5000);
            bool thirdCheck = cooldownService.Check("test");
            #endregion

            #region Assert
            Assert.True(firstCheck);
            Assert.False(secondCheck);
            Assert.True(firstCheck);
            #endregion

            SetTestOutput("Cooldown Service test passed");
        }
 public CreateGuildAccountFilesService(GuildFilesGenerationService guildFilesGeneration, CooldownService cooldown)
 {
     _guildFilesGeneration = guildFilesGeneration;
     _cooldown             = cooldown;
 }
Beispiel #13
0
 public static async Task UpdateCooldown(this ISocketMessageChannel channel, string tag)
 => await CooldownService.UpdateCooldown("discord", Convert.ToInt64(channel.Id), tag, true);
Beispiel #14
0
 public static async Task <bool> CheckCooldown(this ISocketMessageChannel channel, string tag, int seconds)
 => await CooldownService.CheckCooldown("discord", Convert.ToInt64(channel.Id), tag, seconds, true);
Beispiel #15
0
 public static async Task UpdateCooldown(this SocketUser user, string tag)
 => await CooldownService.UpdateCooldown("discord", Convert.ToInt64(user.Id), tag, false);
Beispiel #16
0
 public static async Task <bool> CheckCooldown(this SocketUser user, string tag, int seconds)
 => await CooldownService.CheckCooldown("discord", Convert.ToInt64(user.Id), tag, seconds, false);