Skip to content

Commit

Permalink
Somehow forgot this.
Browse files Browse the repository at this point in the history
  • Loading branch information
sylveonnotdeko committed Apr 11, 2024
1 parent 05efdd7 commit 9632afa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Mewdeko/Modules/Music/CustomPlayer/MewdekoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,31 @@ private async Task<IMessageChannel> GetMusicChannel(ulong guildId)
return channelId.HasValue ? client.GetGuild(base.GuildId)?.GetTextChannel(channelId.Value) : this.channel;

Check warning on line 129 in src/Mewdeko/Modules/Music/CustomPlayer/MewdekoPlayer.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity
}

/// <summary>
/// Sets the music channel for the player.
/// </summary>
/// <param name="channelId">The channel id to set.</param>
/// <param name="guildId">The guild id to set the channel for.</param>
public async Task SetMusicChannelAsync(ulong channelId, ulong guildId)
{
await using var uow = dbService.GetDbContext();
var settings = await uow.MusicPlayerSettings.FirstOrDefaultAsync(x => x.GuildId == base.GuildId);

Check failure on line 140 in src/Mewdeko/Modules/Music/CustomPlayer/MewdekoPlayer.cs

View workflow job for this annotation

GitHub Actions / build

An expression tree may not contain a base access
if (settings is null)
{
settings = new MusicPlayerSettings
{
GuildId = base.GuildId, MusicChannelId = channelId
};
await uow.MusicPlayerSettings.AddAsync(settings);
}
else
{
settings.MusicChannelId = channelId;
}

await uow.SaveChangesAsync();
}

/// <summary>
/// Gets the repeat type for the player.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/Mewdeko/Modules/Music/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,24 @@ async Task<PageBuilder> PageFactory(int index)
}
}

/// <summary>
/// Sets the channel where music events will be sent.
/// </summary>
/// <param name="channel">The channel where music events will be sent.</param>
[Cmd, Aliases, RequireContext(ContextType.Guild)]
public async Task SetMusicChannel(IMessageChannel channel)
{
var (player, reason) = await GetPlayerAsync(false);
if (reason is not null)
{
await ReplyErrorLocalizedAsync("music_join_fail").ConfigureAwait(false);
return;
}

await player.SetMusicChannelAsync(channel.Id, ctx.Guild.Id).ConfigureAwait(false);
await ReplyConfirmLocalizedAsync("music_channel_set", channel.Id).ConfigureAwait(false);
}

/// <summary>
/// Sets if the bot should loop and how.
/// </summary>
Expand All @@ -417,6 +435,7 @@ public async Task Loop(PlayerRepeatType repeatType)
await ReplyConfirmLocalizedAsync("music_repeat_type", repeatType).ConfigureAwait(false);
}


private async ValueTask<(MewdekoPlayer, string?)> GetPlayerAsync(bool connectToVoiceChannel = true)
{
var channelBehavior = connectToVoiceChannel
Expand Down
1 change: 1 addition & 0 deletions src/Mewdeko/data/strings/responses/responses.en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@
"music_song_removed_stop": "Song removed from the queue and the player has been stopped.",
"music_no_current_track": "No song is currently playing.",
"music_repeat_type": "Repeat type set to {0}",
"music_channel_set": "Music channel set to <#{0}>",
"music_song_moved": "{0} has been moved to queue position {1}",
"music_volume_set": "Volume set to {0}%",
"music_volume_invalid": "Invalid volume specified. Please specify a number between 1 and 100",
Expand Down

0 comments on commit 9632afa

Please sign in to comment.