public async Task PurgeAllCaches(CommandContext ctx, [FromServices] ISteamWebApiHelper steamWebApiHelper) { foreach (KeyValuePair <string, SteamItemCache> kvp in steamWebApiHelper.Caches) { kvp.Value.Clear(); } await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.BotCoreModule.DiscordClient, ":white_check_mark:")); }
public async Task PurgeCache(CommandContext ctx, string cacheName, [FromServices] ISteamWebApiHelper steamWebApiHelper) { if (!steamWebApiHelper.Caches.ContainsKey(cacheName)) { await ctx.Message.Channel.SendMessageAsync("Unknown Steam cache, valid Steam caches:" + $"{Environment.NewLine}{string.Join(Environment.NewLine, steamWebApiHelper.Caches.Keys)}"); return; } steamWebApiHelper.Caches[cacheName].Clear(); await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.BotCoreModule.DiscordClient, ":white_check_mark:")); }
public SteamHelperModule(ILoggerFactory loggerFactory, IBotCoreModule botCoreModule, ISteamWebApiHelper steamWebApiHelper) { _logger = loggerFactory.CreateLogger <SteamHelperModule>(); _botCoreModule = botCoreModule; _botCoreModule.CommandHandler.RegisterCommands <SteamCommands>(); _botCoreModule.DiscordClient.MessageCreated += (client, e) => { Task.Run(async() => { await OnMessageCreated(client, e); }); return(Task.CompletedTask); }; _steamWebApiHelper = steamWebApiHelper; }
public async Task CacheStats(CommandContext ctx, [FromServices] ISteamWebApiHelper steamWebApiHelper) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder() .WithTitle($"{nameof(SteamHelperModule)} Cache Stats"); if (!ctx.IsDMs) { builder.WithCustomFooterWithColour(ctx); } foreach (KeyValuePair <string, SteamItemCache> kvp in steamWebApiHelper.Caches) { builder.AddField(kvp.Key, $"{kvp.Value.CacheItemCount} items"); } await ctx.Channel.SendMessageAsync(embed : builder.Build()); if (!ctx.IsDMs) { await ctx.Message.DeleteAsync(); } }