2023-08-05 21:02:40 +03:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Remora.Discord.API.Abstractions.Objects;
|
|
|
|
using Remora.Discord.API.Gateway.Commands;
|
|
|
|
using Remora.Discord.API.Objects;
|
|
|
|
using Remora.Discord.Gateway;
|
|
|
|
|
2024-05-16 18:34:26 +03:00
|
|
|
namespace TeamOctolings.Octobot.Services.Update;
|
2023-08-05 21:02:40 +03:00
|
|
|
|
|
|
|
public sealed class SongUpdateService : BackgroundService
|
|
|
|
{
|
2023-10-02 17:41:43 +03:00
|
|
|
private static readonly (string Author, string Name, TimeSpan Duration)[] SongList =
|
2023-12-20 19:23:37 +03:00
|
|
|
[
|
2023-12-08 14:15:44 +03:00
|
|
|
("Yoko & the Gold Bazookas", "Rockagilly Blues", new TimeSpan(0, 2, 52)),
|
|
|
|
("Deep Cut", "Big Betrayal", new TimeSpan(0, 5, 55)),
|
|
|
|
("Squid Sisters", "Tomorrow's Nostalgia Today", new TimeSpan(0, 3, 7)),
|
|
|
|
("Deep Cut", "Anarchy Rainbow", new TimeSpan(0, 3, 20)),
|
|
|
|
("Squid Sisters feat. Ian BGM", "Liquid Sunshine", new TimeSpan(0, 2, 37)),
|
|
|
|
("Damp Socks feat. Off the Hook", "Candy-Coated Rocks", new TimeSpan(0, 2, 58)),
|
|
|
|
("H2Whoa", "Aquasonic", new TimeSpan(0, 2, 51)),
|
|
|
|
("Yoko & the Gold Bazookas", "Ska-BLAM", new TimeSpan(0, 2, 57)),
|
|
|
|
("Off the Hook", "Muck Warfare", new TimeSpan(0, 3, 20)),
|
|
|
|
("Off the Hook", "Acid Hues", new TimeSpan(0, 3, 15)),
|
|
|
|
("Off the Hook", "Shark Bytes", new TimeSpan(0, 3, 34)),
|
|
|
|
("Squid Sisters", "Calamari Inkantation", new TimeSpan(0, 2, 14)),
|
|
|
|
("Squid Sisters", "Ink Me Up", new TimeSpan(0, 2, 13)),
|
|
|
|
("Chirpy Chips", "No Quarters", new TimeSpan(0, 2, 36)),
|
|
|
|
("Chirpy Chips", "Shellfie", new TimeSpan(0, 2, 1)),
|
|
|
|
("Dedf1sh", "#11 above", new TimeSpan(0, 2, 10)),
|
|
|
|
("Callie", "Bomb Rush Blush", new TimeSpan(0, 2, 18)),
|
|
|
|
("Turquoise October", "Octoling Rendezvous", new TimeSpan(0, 1, 57)),
|
|
|
|
("Damp Socks feat. Off the Hook", "Tentacle to the Metal", new TimeSpan(0, 2, 51)),
|
2024-08-25 10:11:54 +03:00
|
|
|
("Off the Hook feat. Dedf1sh", "Spectrum Obligato ~ Ebb & Flow (Out of Order)", new TimeSpan(0, 4, 30)),
|
|
|
|
("Dedf1sh feat. Off the Hook", "#47 onward", new TimeSpan(0, 4, 40)),
|
|
|
|
("Free Association", "EchΘ Θnslaught", new TimeSpan(0, 2, 52)),
|
|
|
|
("Off the Hook", "Short Order", new TimeSpan(0, 3, 36)),
|
|
|
|
("Deep Cut", "Fins in the Air", new TimeSpan(0, 3, 1))
|
2023-12-20 19:23:37 +03:00
|
|
|
];
|
2023-08-05 21:02:40 +03:00
|
|
|
|
2024-04-07 13:51:28 +03:00
|
|
|
private static readonly (string Author, string Name, TimeSpan Duration)[] SpecialSongList =
|
|
|
|
[
|
|
|
|
("Squid Sisters", "Maritime Memory", new TimeSpan(0, 2, 47))
|
|
|
|
];
|
|
|
|
|
2024-09-23 21:55:58 +03:00
|
|
|
private readonly List<Activity> _activityList = [new("with Remora.Discord", ActivityType.Game)];
|
2023-08-05 21:02:40 +03:00
|
|
|
|
|
|
|
private readonly DiscordGatewayClient _client;
|
|
|
|
private readonly GuildDataService _guildData;
|
|
|
|
|
|
|
|
private uint _nextSongIndex;
|
|
|
|
|
|
|
|
public SongUpdateService(DiscordGatewayClient client, GuildDataService guildData)
|
|
|
|
{
|
|
|
|
_client = client;
|
|
|
|
_guildData = guildData;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken ct)
|
|
|
|
{
|
|
|
|
while (_guildData.GetGuildIds().Count is 0)
|
|
|
|
{
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(5), ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!ct.IsCancellationRequested)
|
|
|
|
{
|
2024-04-07 13:51:28 +03:00
|
|
|
var nextSong = NextSong();
|
2023-10-02 17:41:43 +03:00
|
|
|
_activityList[0] = new Activity($"{nextSong.Name} / {nextSong.Author}",
|
|
|
|
ActivityType.Listening);
|
2023-08-05 21:02:40 +03:00
|
|
|
_client.SubmitCommand(
|
|
|
|
new UpdatePresence(
|
|
|
|
UserStatus.Online, false, DateTimeOffset.UtcNow, _activityList));
|
|
|
|
|
|
|
|
await Task.Delay(nextSong.Duration, ct);
|
|
|
|
}
|
|
|
|
}
|
2024-04-07 13:51:28 +03:00
|
|
|
|
|
|
|
private (string Author, string Name, TimeSpan Duration) NextSong()
|
|
|
|
{
|
|
|
|
var today = DateTime.Today;
|
|
|
|
// Discontinuation of Online Services for Nintendo Wii U
|
|
|
|
if (today.Day is 8 or 9 && today.Month is 4)
|
|
|
|
{
|
|
|
|
return SpecialSongList[0]; // Maritime Memory / Squid Sisters
|
|
|
|
}
|
|
|
|
|
|
|
|
var nextSong = SongList[_nextSongIndex];
|
|
|
|
_nextSongIndex++;
|
|
|
|
if (_nextSongIndex >= SongList.Length)
|
|
|
|
{
|
|
|
|
_nextSongIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextSong;
|
|
|
|
}
|
2023-08-05 21:02:40 +03:00
|
|
|
}
|