Exemplo n.º 1
0
 public async Task <bool> SetPrefix(ulong id, string prefix)
 {
     // Let's set it in the DB. And if it succeeds we'll also add it to our cache
     if (!await _guildRepo.SetGuildPrefix(CacheId.PrefixCacheId(id), prefix).ConfigureAwait(false))
     {
         return(false);
     }
     // Update the Cache
     _cacheService.Set(id, prefix);
     return(true);
 }
Exemplo n.º 2
0
        private async Task OnLeftGuild(SocketGuild guild)
        {
            var sw = new Stopwatch();

            sw.Start();
            using var scope = _scopeFactory.CreateScope();
            // Alright so we just remove everything that has to do with the guild.
            // For this we don't rly need a separate thread i believe so we're gonna do it on the GW thread.
            var guildRepo = scope.ServiceProvider.GetRequiredService <IGuildRepository>();
            await guildRepo.RemoveGuild(guild.Id).ConfigureAwait(false);

            sw.Stop();
            _log.LogInformation($"Removing Guild from DB in {sw.ElapsedMilliseconds.ToString()} ms.");
            // Clear the cache for prefix etc
            _cacheService.TryRemove(CacheId.PrefixCacheId(guild.Id));
        }
Exemplo n.º 3
0
 public async Task <string> GetPrefix(ulong id)
 {
     return((await _cacheService.GetOrSetAndGetAsync(CacheId.PrefixCacheId(id),
                                                     async() => await _guildRepo.GetGuildPrefix(id).ConfigureAwait(false) ?? "$"
                                                     ).ConfigureAwait(false)).Some());
 }