Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CB.Accessors/Contracts/IClipEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface IClipEmbedAccessor
{
Task<ClipEmbedDto> GetByIdAsync(string guildId);

Task<ClipEmbedDto> UpdateAsync(ClipEmbedDto entity);
}
2 changes: 1 addition & 1 deletion src/CB.Accessors/Contracts/ICreatorChannelAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CB.Data.Entities;
using CB.Shared.Dtos;
using CB.Shared.Enums;

// ReSharper disable UnusedMember.Global

namespace CB.Accessors.Contracts;
Expand Down
10 changes: 10 additions & 0 deletions src/CB.Accessors/Contracts/ILiveEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface ILiveEmbedAccessor
{
Task<LiveEmbedDto> GetByIdAsync(string guildId);

Task<LiveEmbedDto> UpdateAsync(LiveEmbedDto entity);
}
10 changes: 10 additions & 0 deletions src/CB.Accessors/Contracts/IVodEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CB.Shared.Dtos;

namespace CB.Accessors.Contracts;

public interface IVodEmbedAccessor
{
Task<VodEmbedDto> GetByIdAsync(string guildId);

Task<VodEmbedDto> UpdateAsync(VodEmbedDto entity);
}
65 changes: 65 additions & 0 deletions src/CB.Accessors/Implementations/ClipEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using AutoMapper;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Shared.Dtos;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class ClipEmbedAccessor(CbContext context,
IMapper mapper)
: IClipEmbedAccessor
{
public async Task<ClipEmbedDto> GetByIdAsync(string guildId)
{
var entity = await context
.ClipEmbeds
.FirstOrDefaultAsync(x => x.GuildId == guildId);

if (entity == null)
{
entity = new()
{
GuildId = guildId,
Header = "New Clip @ %CHANNEL%",
Description = "%DESCRIPTION%",
Footer = "Powered by 100% Couch • Created by %CHANNEL%",
WatchButton = "Watch this Clip!",
MoreButton = "And More!",
};

await context
.ClipEmbeds
.AddAsync(entity);
await context
.SaveChangesAsync();
}

return mapper.Map<ClipEmbedDto>(entity);
}

public async Task<ClipEmbedDto> UpdateAsync(ClipEmbedDto entity)
{
var embed = await context
.ClipEmbeds
.FirstOrDefaultAsync(x => x.GuildId == entity.GuildId)
.ConfigureAwait(false);

if (embed == null)
{
return null;
}

embed.Description = entity.Description;
embed.Footer = entity.Description;
embed.Header = entity.Description;
embed.MoreButton = entity.Description;
embed.WatchButton = entity.WatchButton;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<ClipEmbedDto>(embed);
}
}
73 changes: 73 additions & 0 deletions src/CB.Accessors/Implementations/LiveEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using AutoMapper;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Shared.Dtos;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class LiveEmbedAccessor(CbContext context,
IMapper mapper)
: ILiveEmbedAccessor
{
public async Task<LiveEmbedDto> GetByIdAsync(string guildId)
{
var entity = await context
.LiveEmbeds
.FirstOrDefaultAsync(x => x.GuildId == guildId);

if (entity == null)
{
entity = new()
{
GuildId = guildId,
Header = "%CHANNEL% is now streaming!",
DescriptionLabel = "Stream Description",
Description = "%CHANNEL% is currently playing %GAME%",
LastStreamed = "Last Streamed",
AverageStream = "Average Stream",
StreamDescription = "%DESCRIPTION%",
FooterStopped = "Powered by 100% Couch • Stopped streaming",
FooterStart = "Powered by 100% Couch • Started streaming",
ChannelButton = "Creator Channel",
};

await context
.LiveEmbeds
.AddAsync(entity);
await context
.SaveChangesAsync();
}

return mapper.Map<LiveEmbedDto>(entity);
}

public async Task<LiveEmbedDto> UpdateAsync(LiveEmbedDto entity)
{
var embed = await context
.LiveEmbeds
.FirstOrDefaultAsync(x => x.GuildId == entity.GuildId)
.ConfigureAwait(false);

if (embed == null)
{
return null;
}

embed.AverageStream = entity.AverageStream;
embed.ChannelButton = entity.ChannelButton;
embed.Description = entity.Description;
embed.DescriptionLabel = entity.DescriptionLabel;
embed.FooterStart = entity.FooterStart;
embed.FooterStopped = entity.FooterStopped;
embed.Header = entity.Header;
embed.LastStreamed = entity.LastStreamed;
embed.StreamDescription = entity.StreamDescription;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<LiveEmbedDto>(embed);
}
}
65 changes: 65 additions & 0 deletions src/CB.Accessors/Implementations/VodEmbedAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using AutoMapper;
using CB.Accessors.Contracts;
using CB.Data;
using CB.Shared.Dtos;
using Microsoft.EntityFrameworkCore;

namespace CB.Accessors.Implementations;

public class VodEmbedAccessor(CbContext context,
IMapper mapper)
: IVodEmbedAccessor
{
public async Task<VodEmbedDto> GetByIdAsync(string guildId)
{
var entity = await context
.VodEmbeds
.FirstOrDefaultAsync(x => x.GuildId == guildId);

if (entity == null)
{
entity = new()
{
GuildId = guildId,
Header = "%CHANNEL% has published a new video!",
Description = "%DESCRIPTION%",
DescriptionLabel = "Video Description",
Footer = "Powered by 100% Couch",
ChannelButton = "Creator Channel!",
};

await context
.VodEmbeds
.AddAsync(entity);
await context
.SaveChangesAsync();
}

return mapper.Map<VodEmbedDto>(entity);
}

public async Task<VodEmbedDto> UpdateAsync(VodEmbedDto entity)
{
var embed = await context
.VodEmbeds
.FirstOrDefaultAsync(x => x.GuildId == entity.GuildId)
.ConfigureAwait(false);

if (embed == null)
{
return null;
}

embed.Header = entity.Header;
embed.ChannelButton = entity.ChannelButton;
embed.Description = entity.Description;
embed.DescriptionLabel = entity.DescriptionLabel;
embed.Footer = entity.Footer;

await context
.SaveChangesAsync()
.ConfigureAwait(false);

return mapper.Map<VodEmbedDto>(embed);
}
}
4 changes: 0 additions & 4 deletions src/CB.Bot/CB.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,4 @@
<ProjectReference Include="..\CB.Data\CB.Data.csproj" />
<ProjectReference Include="..\CB.Engines\CB.Engines.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Commands\Application\" />
</ItemGroup>
</Project>
93 changes: 93 additions & 0 deletions src/CB.Bot/Commands/Application/CustomizationCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using CB.Accessors.Contracts;
using Discord;
using Discord.Interactions;

namespace CB.Bot.Commands.Application;

public enum CustomizeType
{
Clips,
Vod,
Live1,
Live2,
}

// TODO this is WIP
public class CustomizationCommands(IGuildAccessor guildAccessor,
IClipEmbedAccessor clipEmbedAccessor,
ILiveEmbedAccessor liveEmbedAccessor,
IVodEmbedAccessor vodEmbedAccessor) : BaseSlashCommands
{
//private readonly IGuildAccessor _guildAccessor;
//private readonly IClipEmbedAccessor _clipEmbedAccessor;
//private readonly ILiveEmbedAccessor _liveEmbedAccessor;
//private readonly IVodEmbedAccessor _vodEmbedAccessor;

//public CustomizationCommands(IGuildAccessor guildAccessor,
// IServiceScopeFactory serviceScopeFactory)
//{
// _guildAccessor = guildAccessor;

// var scope = serviceScopeFactory.CreateScope();
// _clipEmbedAccessor = scope.ServiceProvider.GetRequiredService<IClipEmbedAccessor>();
// _liveEmbedAccessor = scope.ServiceProvider.GetRequiredService<ILiveEmbedAccessor>();
// _vodEmbedAccessor = scope.ServiceProvider.GetRequiredService<IVodEmbedAccessor>();
//}

[SlashCommand("customize", "Announcement customization")]
public async Task CustomizeAsync(CustomizeType type)
{
await DeferAsync(true);
if (Context.User.Id != 93015586698727424)
{
return;
}

switch (type)
{
case CustomizeType.Clips:
var clipEmbed = await clipEmbedAccessor.GetByIdAsync(SocketInteraction.GuildId.ToString());
await Context.Interaction.RespondWithModalAsync(new ModalBuilder()
.WithTitle("Customize Your Clips Embed!")
.WithCustomId($"clips_{Context.Guild.Id}_{Guid.NewGuid().ToString().Replace("-", "")}")
.AddTextInput("Header", "Header", placeholder: "New Clip @ %CHANNEL%", required: false, value: clipEmbed.Header)
.AddTextInput("Description", "Description", placeholder: "%DESCRIPTION%", required: false, value: clipEmbed.Description)
.AddTextInput("Footer", "Footer", placeholder: "Powered by 100% Couch • Created by %CHANNEL%", required: false, value: clipEmbed.Footer)
.AddTextInput("Watch Button", "WatchButton", placeholder: "Watch this Clip!", required: false, value: clipEmbed.WatchButton)
.AddTextInput("More Button", "MoreButton", placeholder: "And More!", required: false, value: clipEmbed.MoreButton).Build());
break;
case CustomizeType.Vod:
var vodEmbed = await vodEmbedAccessor.GetByIdAsync(SocketInteraction.GuildId.ToString());
await Context.Interaction.RespondWithModalAsync(new ModalBuilder()
.WithTitle("Customize Your VOD Embed!")
.WithCustomId($"vod_{Context.Guild.Id}_{Guid.NewGuid().ToString().Replace("-", "")}")
.AddTextInput("Header", "Header", placeholder: "%CHANNEL% has published a new video!", required: false, value: vodEmbed.Header)
.AddTextInput("Description Label", "DescriptionLabel", placeholder: "Video Description", required: false, value: vodEmbed.DescriptionLabel)
.AddTextInput("Description", "Description", placeholder: "%DESCRIPTION%", required: false, value: vodEmbed.Description)
.AddTextInput("Footer", "Footer", placeholder: "Powered by 100% Couch", required: false, value: vodEmbed.Footer)
.AddTextInput("Channel Button", "ChannelButton", placeholder: "Creator Channel!", required: false, value: vodEmbed.ChannelButton).Build());
break;
case CustomizeType.Live1:
var liveEmbed1 = await liveEmbedAccessor.GetByIdAsync(SocketInteraction.GuildId.ToString());
await Context.Interaction.RespondWithModalAsync(new ModalBuilder()
.WithTitle("Customize Your Live Embed (1/2)!")
.WithCustomId($"live_{Context.Guild.Id}_{Guid.NewGuid().ToString().Replace("-", "")}")
.AddTextInput("Header", "Header", placeholder: "%CHANNEL% is now streaming!", required: false, value: liveEmbed1.Header)
.AddTextInput("Description", "Description", placeholder: "%CHANNEL% is currently playing %GAME%", required: false, value: liveEmbed1.Description)
.AddTextInput("Last Streamed Label", "LastStreamed", placeholder: "Last Streamed", required: false, value: liveEmbed1.LastStreamed)
.AddTextInput("Average Stream Label", "AverageStream", placeholder: "Average Stream", required: false, value: liveEmbed1.AverageStream).Build());
break;
case CustomizeType.Live2:
var liveEmbed2 = await liveEmbedAccessor.GetByIdAsync(SocketInteraction.GuildId.ToString());
await Context.Interaction.RespondWithModalAsync(new ModalBuilder()
.WithTitle("Customize Your Live Embed (2/2)!")
.WithCustomId($"live_{Context.Guild.Id}_{Guid.NewGuid().ToString().Replace("-", "")}")
.AddTextInput("Description Label", "DescriptionLabel", placeholder: "Stream Description", required: false, value: liveEmbed2.DescriptionLabel)
.AddTextInput("Stream Description", "StreamDescription", placeholder: "%DESCRIPTION%", required: false, value: liveEmbed2.StreamDescription)
.AddTextInput("Footer Start", "FooterStart", placeholder: "Powered by 100% Couch • Started streaming", required: false, value: liveEmbed2.FooterStart)
.AddTextInput("Footer Stopped", "FooterStopped", placeholder: "Powered by 100% Couch • Stopped streaming", required: false, value: liveEmbed2.FooterStopped)
.AddTextInput("Channel Button", "ChannelButton", placeholder: "Creator Channel", required: false, value: liveEmbed2.ChannelButton).Build());
break;
}
}
}
6 changes: 5 additions & 1 deletion src/CB.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CB.Accessors.Implementations;
using CB.Bot.Services;
using CB.Data;
using CB.Engines.Contracts;
using CB.Engines.Implementations;
using CB.Shared.Dtos;
using Discord;
using Discord.Commands;
Expand Down Expand Up @@ -42,12 +44,14 @@
builder.Services.AddScoped<IGuildAccessor, GuildAccessor>();
builder.Services.AddScoped<IGuildConfigurationAccessor, GuildConfigurationAccessor>();
builder.Services.AddScoped<IUserAccessor, UserAccessor>();
builder.Services.AddScoped<IYouTubeAccessor, YouTubeAccessor>();
builder.Services.AddScoped<ICreatorEngine, CreatorEngine>();

builder.Services.AddDbContext<CbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddAutoMapper(cfg => { }, typeof(CbProfile));

builder.Services.AddHostedService<DiscordBotService>();

builder.Services.AddHttpClient();
var host = builder.Build();
host.Run();
Loading
Loading