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;
|
|
|
|
|
2023-09-30 16:58:32 +03:00
|
|
|
namespace 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-08-05 21:02:40 +03:00
|
|
|
{
|
2023-10-02 17:41:43 +03:00
|
|
|
("Yoko & the Gold Bazookas", "Rockagilly Blues", new TimeSpan(0, 3, 37)),
|
|
|
|
("Splatoon 3", "Seep and Destroy", new TimeSpan(0, 2, 42)),
|
|
|
|
("Deep Cut", "Big Betrayal", new TimeSpan(0, 1, 42)),
|
|
|
|
("Squid Sisters", "Tomorrow's Nostalgia Today", new TimeSpan(0, 2, 8)),
|
|
|
|
("Deep Cut", "Anarchy Rainbow", new TimeSpan(0, 1, 51)),
|
|
|
|
("Squid Sisters feat. Ian BGM", "Liquid Sunshine", new TimeSpan(0, 1, 32)),
|
|
|
|
("Damp Socks feat. Off the Hook", "Candy-Coated Rocks", new TimeSpan(0, 1, 11)),
|
|
|
|
("H2Whoa", "Aquasonic", new TimeSpan(0, 1, 1)),
|
|
|
|
("Yoko & the Gold Bazookas", "Ska-BLAM", new TimeSpan(0, 4, 4)),
|
|
|
|
("Off the Hook", "Muck Warfare", new TimeSpan(0, 3, 39)),
|
|
|
|
("Off the Hook", "Acid Hues", new TimeSpan(0, 3, 39)),
|
|
|
|
("Off the Hook", "Shark Bytes", new TimeSpan(0, 3, 48)),
|
|
|
|
("DJ Octavio feat. Squid Sisters & Deep Cut", "Calamari Inkantation 3MIX", new TimeSpan(0, 7, 9)),
|
|
|
|
("Squid Sisters", "Ink Me Up", new TimeSpan(0, 2, 13))
|
2023-08-05 21:02:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private readonly List<Activity> _activityList = new(1)
|
|
|
|
{
|
|
|
|
new Activity("with Remora.Discord", ActivityType.Game)
|
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
var nextSong = SongList[_nextSongIndex];
|
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));
|
|
|
|
_nextSongIndex++;
|
|
|
|
if (_nextSongIndex >= SongList.Length)
|
|
|
|
{
|
|
|
|
_nextSongIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Task.Delay(nextSong.Duration, ct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|