public async Task <IActionResult> Upsert(AddChannelViewModel model) { if (!ModelState.IsValid) { var user = await TryGetUser(User); model.Owners.AddRange(await GetLegitUsers(user)); return(View("Add", model)); } if (string.IsNullOrEmpty(model.Channel.Name)) { ModelState.AddModelError("Name", "Channel must have a name"); var user = await TryGetUser(User); model.Owners.AddRange(await GetLegitUsers(user)); return(View("Add", model)); } if (string.IsNullOrEmpty(model.Channel.WebHookAddress)) { ModelState.AddModelError("Name", "Channel must have an endpoint or an address."); var user = await TryGetUser(User); model.Owners.AddRange(await GetLegitUsers(user)); return(View("Add", model)); } var existingChannel = _channelManager.GetChannelByName(model.OwnerUserId, model.Channel.Name); if (existingChannel != null) { ModelState.AddModelError("Name", "This user already owns a channel with the same name."); var user = await TryGetUser(User); model.Owners.AddRange(await GetLegitUsers(user)); return(View("Add", model)); } model.Channel.OwnerUserId = model.OwnerUserId; if (model.Channel.Id == 0) { await _channelManager.AddChannel(model.Channel); } else { await _channelManager.UpdateChannel(model.Channel); } return(RedirectToAction("Index")); }
public async Task Add(string channelId, string groupName) { var translation = await GetTranslation(); if (!IsOwner) { return; } var youTubeChannel = await _youTubeManager.GetYouTubeChannelByChannelId(channelId); if (youTubeChannel == null && youTubeChannel.Items.Count == 0) { await Context.Channel.SendMessageAsync("Sorry, a YouTube Channel with that ID does not exist."); return; } var group = await _groupManager.GetGuildGroupByGuildIdAndName(Context.Guild.Id, groupName); if (group == null) { await Context.Channel.SendMessageAsync($"{translation.GroupCommands.InvalidGroupName} '{Prefix} group list'"); return; } var groupChannel = await _channelManager.GetChannelByGuildGroupIdAndChannelId(group.Id, channelId); if (groupChannel != null) { await Context.Channel.SendMessageAsync("Sorry, a this Youtube channel has already been added to this group."); return; } await _channelManager.AddChannel(new GuildGroupChannel { ChannelId = channelId, GuildGroupId = group.Id, Platform = Platform.YouTube }); await Context.Channel.SendMessageAsync("This new YouTube channel has been added."); }
public async Task Add(string channelName, string groupName) { var translation = await GetTranslation(); if (!IsOwner) { return; } var mixerChannel = await _mixerManager.GetMixerChannelByChannelName(channelName); if (mixerChannel == null) { await Context.Channel.SendMessageAsync("Sorry, a Mixer channel with that name does not exist."); return; } var group = await _groupManager.GetGuildGroupByGuildIdAndName(Context.Guild.Id, groupName); if (group == null) { await Context.Channel.SendMessageAsync($"{translation.GroupCommands.InvalidGroupName} '{Prefix} group list'"); return; } var groupChannel = await _channelManager.GetChannelByGuildGroupIdAndChannelId(group.Id, mixerChannel.Id.ToString()); if (groupChannel != null) { await Context.Channel.SendMessageAsync("Sorry, a this Mixer channel has already been added to this group."); return; } await _channelManager.AddChannel(new GuildGroupChannel { ChannelId = mixerChannel.Id.ToString(), GuildGroupId = group.Id, Platform = Platform.Mixer }); await Context.Channel.SendMessageAsync("This new Mixer channel has been added."); }
public async Task Add(string loginName, string groupName) { var translation = await GetTranslation(); if (!IsOwner) { return; } var twitchChannel = await _twitchManager.GetTwitchUserByLoginName(loginName); if (twitchChannel == null || twitchChannel.Users.Count < 1) { await Context.Channel.SendMessageAsync("Sorry, a Twitch channel with that name does not exist."); return; } var group = await _groupManager.GetGuildGroupByGuildIdAndName(Context.Guild.Id, groupName); if (group == null) { await Context.Channel.SendMessageAsync($"{translation.GroupCommands.InvalidGroupName} '{Prefix} group list'"); return; } var groupChannel = await _channelManager.GetChannelByGuildGroupIdAndChannelId(group.Id, twitchChannel.Users[0].Id); if (groupChannel != null) { await Context.Channel.SendMessageAsync("Sorry, a this Twitch channel has already been added to this group."); return; } await _channelManager.AddChannel(new GuildGroupChannel { ChannelId = twitchChannel.Users[0].Id, GuildGroupId = group.Id, Platform = Platform.Twitch }); await Context.Channel.SendMessageAsync("This new Twitch channel has been added."); }