public async Task <SlashCommandResponse> Handle(SlashCommandContext context) { var leagueId = int.Parse(context.CommandInput.Value); var league = await _leagueClient.GetClassicLeague(leagueId, tolerate404 : true); if (league == null) { return(Respond($"Could not find a classic league of id '{leagueId}'", success: false)); } var existingSub = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); if (existingSub == null) { await _repo.InsertGuildSubscription(new GuildFplSubscription(context.GuildId, context.ChannelId, leagueId, new [] { EventSubscription.All })); return(Respond($"Now following the '{$"{league.Properties.Name}"}' FPL league. (Auto-subbed to all events) ")); } await _repo.UpdateGuildSubscription(existingSub with { LeagueId = leagueId }); return(Respond($"Now following the '{$"{league.Properties.Name}"}' FPL league. ")); }
public async Task <SlashCommandResponse> Handle(SlashCommandContext context) { var existingSub = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); if (existingSub == null || !existingSub.Subscriptions.Any()) { return(Respond($"🤷♀️O RLY?", $"Did not find any subscription(s) in this channel to remove!")); } EventSubscription eventSub = Enum.Parse <EventSubscription>(context.CommandInput.Value); bool isLastSub = existingSub.Subscriptions.Count() == 1 && existingSub.Subscriptions.First() == eventSub; if (existingSub.LeagueId == null && (isLastSub || eventSub == EventSubscription.All)) { await _repo.DeleteGuildSubscription(context.GuildId, context.ChannelId); return(Respond($"✅ Success!", $"Removed subscription to this channel.")); } bool existingIsAll = existingSub.Subscriptions.Count() == 1 && existingSub.Subscriptions.First() == EventSubscription.All; if (existingIsAll && eventSub != EventSubscription.All) { var allTypes = EventSubscriptionHelper.GetAllSubscriptionTypes().ToList(); allTypes.Remove(EventSubscription.All); await _repo.UpdateGuildSubscription(existingSub with { Subscriptions = allTypes }); var updatedFromAll = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); return(Respond($"✅ Success!", $"No longer subscribing to all events. Updated list:\n{Formatter.BulletPoints(updatedFromAll.Subscriptions)}")); } var updated = new List <EventSubscription>(existingSub.Subscriptions); if (eventSub == EventSubscription.All) { updated = new List <EventSubscription>(); } else { updated.Remove(eventSub); } await _repo.UpdateGuildSubscription(existingSub with { Subscriptions = updated }); var regularUpdate = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); if (regularUpdate.Subscriptions.Any()) { return(Respond($"✅ Success!", $"Unsubscribed from {eventSub}. Updated list:\n{Formatter.BulletPoints(regularUpdate.Subscriptions)}")); } return(Respond($"✅ Success!", $"No longer subscribing to any events.")); }
public async Task <SlashCommandResponse> Handle(SlashCommandContext context) { var existingSub = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); EventSubscription newEventSub = Enum.Parse <EventSubscription>(context.CommandInput.Value); if (existingSub == null) { await _repo.InsertGuildSubscription(new GuildFplSubscription(context.GuildId, context.ChannelId, null, new[] { newEventSub })); var newSub = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); return(Respond("✅ Success!", $"Added new subscription! Subscriptions:\n{Formatter.BulletPoints(newSub.Subscriptions)}")); } if (existingSub.Subscriptions.Contains(newEventSub)) { return(Respond("⚠️", $"Already subscribing to {context.CommandInput.Value}")); } var updatedList = new List <EventSubscription>(existingSub.Subscriptions) { newEventSub }; if (newEventSub == EventSubscription.All) { updatedList = new List <EventSubscription> { EventSubscription.All }; } else if (existingSub.Subscriptions.Count() == 1 && existingSub.Subscriptions.First() == EventSubscription.All) // from "all" to "1 specific" => 1 specifc { updatedList = new List <EventSubscription> { newEventSub }; } await _repo.UpdateGuildSubscription(existingSub with { Subscriptions = updatedList }); var all = await _repo.GetGuildSubscription(context.GuildId, context.ChannelId); return(Respond("✅ Success!", $"Updated subscriptions:\n{Formatter.BulletPoints(all.Subscriptions)}")); }
public async Task <SlashCommandResponse> Handle(SlashCommandContext context) { var content = ""; var sub = await _store.GetGuildSubscription(context.GuildId, context.ChannelId); if (sub != null) { if (sub.LeagueId.HasValue) { var league = await _client.GetClassicLeague(sub.LeagueId.Value, tolerate404 : true); if (league != null) { content += $"\n**League:**\nCurrently following the '{league.Properties.Name}' league"; } } else { content += $"\n ⚠️ Not following any FPL leagues"; } var allTypes = EventSubscriptionHelper.GetAllSubscriptionTypes(); if (sub.Subscriptions.Any()) { content += $"\n\n**Subscriptions:**\n{string.Join("\n", sub.Subscriptions.Select(s => $" ✅ {s}"))}"; if (!sub.Subscriptions.Contains(EventSubscription.All)) { var allTypesExceptSubs = allTypes.Except(sub.Subscriptions).Except(new [] { EventSubscription.All }); content += $"\n\n**Not subscribing:**\n{string.Join("\n", allTypesExceptSubs.Select(s => $" ❌ {s}"))}"; } } else { content += "\n\n**Subscriptions:**\n ⚠️ No subscriptions"; content += $"\n\n**Events you may subscribe to:**\n{string.Join("\n", allTypes.Select(s => $" ▪️ {s}"))}"; } } else { content = "⚠️ Not subscribing to any events. Add one to get notifications!"; } return(Respond(content)); }
private async Task SlashCommandExecuted(SocketSlashCommand arg) { var ctx = new SlashCommandContext(arg); await _commandManager.InvokeCommandAsync(arg.CommandName, ctx); }