Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
31ce6ca
Automatically play queueing music when the play context is stopped
Desz01ate Jan 20, 2023
e53709b
Add Discord Bot integration
Desz01ate Jan 20, 2023
793fe41
Fix spotify client access token expired periodically
Desz01ate Jan 23, 2023
cbcaf5b
Add search function
Desz01ate Jan 23, 2023
612c54c
Git workflows (#1)
Desz01ate Jan 23, 2023
57008d5
Add logging (#2)
LittleBearXii Jan 23, 2023
7069912
YOLO
Desz01ate Jan 23, 2023
351a0f3
Limit queue listing to maximum 10 items
Desz01ate Jan 23, 2023
354ae4f
Substring presence to 128 characters
Desz01ate Jan 24, 2023
b31536a
Merge pull request #6 from codehardth/fix-too-long-discord-presence
totowolf2 Jan 24, 2023
a3585bb
Merge pull request #6 from codehardth/fix-too-long-discord-presence
totowolf2 Jan 24, 2023
7295db6
Add throttle to queue and skip command
Desz01ate Jan 25, 2023
64bbf2b
Remove cancellation token during bootstraping step
Desz01ate Jan 25, 2023
5c8fa84
Merge branch 'main' of https://github.com/codehardth/DJ
Desz01ate Jan 25, 2023
5b22843
Refactor GetPlayingTrackInfoAsync to be more readable
Desz01ate Jan 25, 2023
b5eca71
Merge branch 'main' of https://github.com/codehardth/DJ
Desz01ate Jan 25, 2023
eee19dd
Fix presence to update more deterministic
Desz01ate Jan 25, 2023
615d3e7
Merge branch 'main' of https://github.com/codehardth/DJ
Desz01ate Jan 25, 2023
3220ce5
Update cache policy for skip
Desz01ate Jan 29, 2023
8f73eac
Add member and played track
Desz01ate Jan 29, 2023
4a4d89c
Add artist info to search api
Desz01ate Jan 29, 2023
693df45
Remove unused project
Desz01ate Jan 29, 2023
8214363
Allow cooldown to be adjust via configuration
Desz01ate Jan 29, 2023
2b7ef17
Add stat command
Desz01ate Jan 29, 2023
8420e95
Add bullet icon
LittleBearXii Jan 30, 2023
ca58954
Merge pull request #13 from codehardth/add-comma
LittleBearXii Jan 30, 2023
54128f6
Allow reaction to queue the song instantly
Desz01ate Jan 30, 2023
00c18fb
Enhance search result cosmetic
Desz01ate Jan 31, 2023
f81891a
Add search page size
LittleBearXii Feb 5, 2023
96b88d0
Remove token in appsettings
LittleBearXii Feb 5, 2023
61dcded
Re formet appsettings
LittleBearXii Feb 5, 2023
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
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: merge to main

on:
push:
branches: [ main ]

jobs:
build_dotnet_core:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Publish ubuntu 20.04 x64
run: dotnet publish -c Release -r ubuntu.20.04-x64
- name: Publish windows 10 x64
run: dotnet publish -c Release -r win10-x64
- name: Upload ubuntu build artifact
uses: actions/upload-artifact@v2
with:
name: DJ_ubuntu_2004_x64
path: /home/runner/work/DJ/DJ/Codehard.DJ/bin/Release/net7.0/ubuntu.20.04-x64/publish/
- name: Upload windows build artifact
uses: actions/upload-artifact@v2
with:
name: DJ_win10_x64
path: /home/runner/work/DJ/DJ/Codehard.DJ/bin/Release/net7.0/win10-x64/publish/
23 changes: 23 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: dotnet core pull request continuous integration

on:
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
18 changes: 18 additions & 0 deletions Codehard.DJ.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codehard.DJ", "Codehard.DJ\Codehard.DJ.csproj", "{BF36D43A-FEC3-41A0-B6D3-4B0E7DFE2143}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure.Discord", "Infrastructure.Discord\Infrastructure.Discord.csproj", "{1EDF35FF-A84C-4C62-9365-6B6AF8BD0607}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DJ.Domain", "DJ.Domain\DJ.Domain.csproj", "{42301BDB-63DB-4F18-A542-3EDB3CDB8FCB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DJ.Infrastructure", "DJ.Infrastructure\DJ.Infrastructure.csproj", "{0A1D4F4D-DEFA-450D-8AB5-7D37C52D86A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +18,17 @@ Global
{BF36D43A-FEC3-41A0-B6D3-4B0E7DFE2143}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF36D43A-FEC3-41A0-B6D3-4B0E7DFE2143}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF36D43A-FEC3-41A0-B6D3-4B0E7DFE2143}.Release|Any CPU.Build.0 = Release|Any CPU
{1EDF35FF-A84C-4C62-9365-6B6AF8BD0607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EDF35FF-A84C-4C62-9365-6B6AF8BD0607}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EDF35FF-A84C-4C62-9365-6B6AF8BD0607}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EDF35FF-A84C-4C62-9365-6B6AF8BD0607}.Release|Any CPU.Build.0 = Release|Any CPU
{42301BDB-63DB-4F18-A542-3EDB3CDB8FCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42301BDB-63DB-4F18-A542-3EDB3CDB8FCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42301BDB-63DB-4F18-A542-3EDB3CDB8FCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42301BDB-63DB-4F18-A542-3EDB3CDB8FCB}.Release|Any CPU.Build.0 = Release|Any CPU
{0A1D4F4D-DEFA-450D-8AB5-7D37C52D86A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A1D4F4D-DEFA-450D-8AB5-7D37C52D86A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A1D4F4D-DEFA-450D-8AB5-7D37C52D86A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A1D4F4D-DEFA-450D-8AB5-7D37C52D86A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
58 changes: 49 additions & 9 deletions Codehard.DJ/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
using SpotifyAPI.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Auth;

namespace Codehard.DJ;

public static class Bootstrap
{
public static async Task<SpotifyClient> InitializeSpotifyClientAsync(string clientId, CancellationToken cancellationToken = default)
public static async Task<SpotifyClient> InitializeSpotifyClientAsync(
string clientId,
string clientSecret,
CancellationToken cancellationToken = default)
{
var server = new EmbedIOAuthServer(new Uri("http://localhost:8800/callback"), 8800);
var callbackUri = new Uri("http://localhost:8800/callback");

var server = new EmbedIOAuthServer(callbackUri, 8800);

await server.Start();

string? accessToken = default;
SpotifyClient? client = default;

server.ImplictGrantReceived += async (sender, response) =>
server.AuthorizationCodeReceived += async (sender, response) =>
{
var server = (EmbedIOAuthServer)sender;

await server.Stop();

accessToken = response.AccessToken;
var tokenResponse = await new OAuthClient()
.RequestToken(
new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, callbackUri),
cancellationToken);

var config = SpotifyClientConfig
.CreateDefault()
.WithAuthenticator(new AuthorizationCodeAuthenticator(clientId, clientSecret, tokenResponse));

client = new SpotifyClient(config);
};

server.ErrorReceived += async (sender, error, state) =>
{
Console.WriteLine($"Aborting authorization, error received: {error}");
Expand All @@ -33,7 +51,7 @@ public static async Task<SpotifyClient> InitializeSpotifyClientAsync(string clie
var request = new LoginRequest(
server.BaseUri,
clientId,
LoginRequest.ResponseType.Token)
LoginRequest.ResponseType.Code)
{
Scope = new List<string>
{
Expand All @@ -51,9 +69,9 @@ public static async Task<SpotifyClient> InitializeSpotifyClientAsync(string clie
{
try
{
if (!string.IsNullOrWhiteSpace(accessToken))
if (client != null)
{
return new SpotifyClient(accessToken);
return client;
}

await Task.Delay(300, cancellationToken).ConfigureAwait(false);
Expand All @@ -66,4 +84,26 @@ public static async Task<SpotifyClient> InitializeSpotifyClientAsync(string clie
}
}
}

public static async Task ApplyMigrationsAsync<T>(this IHost host, CancellationToken cancellationToken = default)
where T : DbContext
{
using var scope = host.Services.CreateScope();

await using var dbContext = scope.ServiceProvider.GetService<T>();

if (dbContext == null)
{
throw new InvalidOperationException($"Unable to resolve '{typeof(T)}' from host.");
}

var migrations = await dbContext.Database.GetPendingMigrationsAsync(cancellationToken);

if (migrations.Any())
{
await dbContext.Database.MigrateAsync(CancellationToken.None);
}

await dbContext.Database.EnsureCreatedAsync(cancellationToken);
}
}
7 changes: 7 additions & 0 deletions Codehard.DJ/Codehard.DJ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="SpotifyAPI.Web.Auth" Version="7.0.0" />
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,4 +21,10 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DJ.Domain\DJ.Domain.csproj" />
<ProjectReference Include="..\DJ.Infrastructure\DJ.Infrastructure.csproj" />
<ProjectReference Include="..\Infrastructure.Discord\Infrastructure.Discord.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions Codehard.DJ/DiscordBotHostingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Codehard.DJ.Providers;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Codehard.DJ;

public class DiscordBotHostingService : IHostedService
{
private readonly DjDiscordClient _discordClient;
private readonly IMusicProvider _provider;
private readonly ILogger<DiscordBotHostingService> _logger;

public DiscordBotHostingService(
DjDiscordClient discordClient,
IMusicProvider provider,
ILogger<DiscordBotHostingService> logger)
{
this._discordClient = discordClient;
this._logger = logger;
this._provider = provider;
this._provider.PlayStartEvent += (sender, args) => { this._logger.LogInformation($"{args.Music.Title} started"); };
this._provider.PlayEndEvent += (sender, args) => { this._logger.LogInformation($"{args.Music.Title} ended"); };
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await this._discordClient.ConnectAsync(cancellationToken);

await Task.Delay(-1, CancellationToken.None);
}

public async Task StopAsync(CancellationToken cancellationToken)
{
this._provider.Dispose();

await this._discordClient.DisposeAsync();
}
}
Loading