public async Task RemoveFromBlacklist(String name) { if (String.IsNullOrWhiteSpace(name)) { Log("You need to specify a name.", (int)LogType.Text); return; } var account = CloudStorageAccount.Parse(connectionString); var client = account.CreateCloudTableClient(); var table = client.GetTableReference("blacklist"); TableOperation retrieve = TableOperation.Retrieve <BlacklistItem>("sweaty", name); TableResult result = await table.ExecuteAsync(retrieve); if (result.Result != null) { BlacklistItem item = (BlacklistItem)result.Result; TableOperation delete = TableOperation.Delete(item); await table.ExecuteAsync(delete); Log($"Blacklist item {name} deleted.", (int)LogType.Text); } else { Log($"Blacklist item {name} not found.", (int)LogType.Text); } }
public BlacklistVerificationEnum ValidateBlacklistItem(BlacklistItem item) { if (string.IsNullOrEmpty(item.Type) && string.IsNullOrEmpty(item.Member)) { return(BlacklistVerificationEnum.Empty); } if (string.IsNullOrEmpty(item.Type) && !string.IsNullOrEmpty(item.Member)) { return(BlacklistVerificationEnum.NoType); } var targetType = FindTypeInAllAssemblies(item.Type); if (targetType != null && string.IsNullOrEmpty(item.Member)) { return(BlacklistVerificationEnum.Ok); } if (targetType == null) { return(BlacklistVerificationEnum.InvalidType); } if (targetType.GetMember(item.Member).Length > 0) { return(BlacklistVerificationEnum.Ok); } else { return(BlacklistVerificationEnum.InvalidMember); } }
public async Task AddToBlacklist(String name, String rid, String reason) { if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(rid)) { Log("You need to specify a name and rid | !blacklistadd name rid [reason]", (int)LogType.Text); return; } var account = CloudStorageAccount.Parse(connectionString); var client = account.CreateCloudTableClient(); var table = client.GetTableReference("blacklist"); TableOperation retrieve = TableOperation.Retrieve <BlacklistItem>("sweaty", name); TableResult result = await table.ExecuteAsync(retrieve); if (result.Result != null) { Log($"Blacklist item {name} already exists.", (int)LogType.Text); } else { BlacklistItem item = new BlacklistItem(name) { rid = rid, reason = reason }; TableOperation insertOperation = TableOperation.Insert(item); await table.ExecuteAsync(insertOperation); Log($"Blacklist item {name} added.", (int)LogType.Text); } }
public async Task UpdateBlacklist(String name, String rid, String reason) { if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(rid)) { Log("You need to specify a name and rid", (int)LogType.Text); return; } var account = CloudStorageAccount.Parse(connectionString); var client = account.CreateCloudTableClient(); var table = client.GetTableReference("blacklist"); TableOperation retrieve = TableOperation.Retrieve <BlacklistItem>("sweaty", name); TableResult result = await table.ExecuteAsync(retrieve); if (result != null) { BlacklistItem item = (BlacklistItem)result.Result; item.rid = rid; item.reason = reason; TableOperation update = TableOperation.Replace(item); await table.ExecuteAsync(update); Log($"Blacklist item {name} updated.", (int)LogType.Text); } else { Log($"Blacklist item {name} not found.", (int)LogType.Text); } }
private async Task Blacklist(AddRemove action, ulong id, BlacklistType type) { using (var uow = DbHandler.UnitOfWork()) { if (action == AddRemove.Add) { var item = new BlacklistItem { ItemId = id, Type = type }; uow.BotConfig.GetOrCreate().Blacklist.Add(item); BlacklistedItems.Add(item); } else { uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type); BlacklistedItems.RemoveWhere(bi => bi.ItemId == id && bi.Type == type); } await uow.CompleteAsync().ConfigureAwait(false); } if (action == AddRemove.Add) { TriviaGame tg; switch (type) { case BlacklistType.Server: Games.Games.TriviaCommands.RunningTrivias.TryRemove(id, out tg); if (tg != null) { await tg.StopGame().ConfigureAwait(false); } break; case BlacklistType.Channel: var item = Games.Games.TriviaCommands.RunningTrivias.FirstOrDefault(kvp => kvp.Value.channel.Id == id); Games.Games.TriviaCommands.RunningTrivias.TryRemove(item.Key, out tg); if (tg != null) { await tg.StopGame().ConfigureAwait(false); } break; case BlacklistType.User: break; default: break; } } if (action == AddRemove.Add) { await Context.Channel.SendConfirmAsync($"Blacklisted a `{type}` with id `{id}`").ConfigureAwait(false); } else { await Context.Channel.SendConfirmAsync($"Unblacklisted a `{type}` with id `{id}`").ConfigureAwait(false); } }
private async Task Blacklist(AddRemove action, ulong id, BlacklistType type) { if (action == AddRemove.Add && _creds.OwnerIds.Contains(id)) { return; } using (var uow = _db.UnitOfWork) { if (action == AddRemove.Add) { var item = new BlacklistItem { ItemId = id, Type = type }; uow.BotConfig.GetOrCreate().Blacklist.Add(item); if (type == BlacklistType.Server) { BlacklistedGuilds.Add(id); } else if (type == BlacklistType.Channel) { BlacklistedChannels.Add(id); } else if (type == BlacklistType.User) { BlacklistedUsers.Add(id); } } else { uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type); if (type == BlacklistType.Server) { BlacklistedGuilds.TryRemove(id); } else if (type == BlacklistType.Channel) { BlacklistedChannels.TryRemove(id); } else if (type == BlacklistType.User) { BlacklistedUsers.TryRemove(id); } } await uow.CompleteAsync().ConfigureAwait(false); } if (action == AddRemove.Add) { await ReplyConfirmLocalized("blacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalized("unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } }
public void Remove(BlacklistItem item) { if (Items.Remove(item)) { _saveBusy.DoDelay(() => { try { _watcherBusy.Delay(500); File.WriteAllText(_filename, Items.Select(x => x.Guid).JoinToString("\n")); } catch (Exception e) { NonfatalError.NotifyBackground("Failed to save blacklist", e); } }, 500); } }
private async Task Blacklist(AddRemove action, ulong id, BlacklistType type) { if (action == AddRemove.Add && _creds.OwnerIds.Contains(id)) { return; } using (var uow = _db.UnitOfWork) { if (action == AddRemove.Add) { var item = new BlacklistItem { ItemId = id, Type = type }; uow.BotConfig.GetOrCreate().Blacklist.Add(item); } else { var objs = uow.BotConfig .GetOrCreate(set => set.Include(x => x.Blacklist)) .Blacklist .Where(bi => bi.ItemId == id && bi.Type == type); if (objs.Any()) { uow._context.Set <BlacklistItem>().RemoveRange(objs); } } await uow.CompleteAsync().ConfigureAwait(false); } if (action == AddRemove.Add) { await ReplyConfirmLocalizedAsync("blacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalizedAsync("unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } }
private async Task Blacklist(AddRemove action, ulong id, BlacklistType type) { if (action == AddRemove.Add && _creds.OwnerIds.Contains(id)) { return; } using (var uow = _db.UnitOfWork) { if (action == AddRemove.Add) { var item = new BlacklistItem { ItemId = id, Type = type }; uow.BotConfig.GetOrCreate().Blacklist.Add(item); if (type == BlacklistType.Server) { BlacklistedGuilds.Add(id); } else if (type == BlacklistType.Channel) { BlacklistedChannels.Add(id); } else if (type == BlacklistType.User) { BlacklistedUsers.Add(id); } } else { uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type); if (type == BlacklistType.Server) { BlacklistedGuilds.TryRemove(id); } else if (type == BlacklistType.Channel) { BlacklistedChannels.TryRemove(id); } else if (type == BlacklistType.User) { BlacklistedUsers.TryRemove(id); } } await uow.CompleteAsync().ConfigureAwait(false); } if (action == AddRemove.Add) { TriviaGame tg; switch (type) { case BlacklistType.Server: Games.Games.TriviaCommands.RunningTrivias.TryRemove(id, out tg); if (tg != null) { await tg.StopGame().ConfigureAwait(false); } break; case BlacklistType.Channel: var item = Games.Games.TriviaCommands.RunningTrivias.FirstOrDefault(kvp => kvp.Value.Channel.Id == id); Games.Games.TriviaCommands.RunningTrivias.TryRemove(item.Key, out tg); if (tg != null) { await tg.StopGame().ConfigureAwait(false); } break; case BlacklistType.User: break; } } if (action == AddRemove.Add) { await ReplyConfirmLocalized("blacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } else { await ReplyConfirmLocalized("unblacklisted", Format.Code(type.ToString()), Format.Code(id.ToString())).ConfigureAwait(false); } }