mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Bring back listening statuses
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
b46c366e5e
commit
b1855c5257
3 changed files with 40 additions and 15 deletions
10
Boyfriend.cs
10
Boyfriend.cs
|
@ -8,7 +8,6 @@ using Microsoft.Extensions.Logging;
|
|||
using Remora.Commands.Extensions;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Commands;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Gateway.Commands;
|
||||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Caching.Extensions;
|
||||
using Remora.Discord.Caching.Services;
|
||||
|
@ -54,14 +53,9 @@ public class Boyfriend {
|
|||
).ConfigureServices(
|
||||
(_, services) => {
|
||||
services.Configure<DiscordGatewayClientOptions>(
|
||||
options => {
|
||||
options.Intents |= GatewayIntents.MessageContents
|
||||
options => options.Intents |= GatewayIntents.MessageContents
|
||||
| GatewayIntents.GuildMembers
|
||||
| GatewayIntents.GuildScheduledEvents;
|
||||
options.Presence = new UpdatePresence(
|
||||
UserStatus.Online, false, DateTimeOffset.UtcNow,
|
||||
new[] { new Activity("with Remora.Discord", ActivityType.Game) });
|
||||
});
|
||||
| GatewayIntents.GuildScheduledEvents);
|
||||
services.Configure<CacheSettings>(
|
||||
settings => {
|
||||
settings.SetDefaultAbsoluteExpiration(TimeSpan.FromHours(1));
|
||||
|
|
|
@ -103,7 +103,7 @@ public class GuildDataService : IHostedService {
|
|||
return (await GetData(guildId, ct)).GetMemberData(userId);
|
||||
}
|
||||
|
||||
public IEnumerable<Snowflake> GetGuildIds() {
|
||||
public ICollection<Snowflake> GetGuildIds() {
|
||||
return _datas.Keys;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
using Boyfriend.Data;
|
||||
using Boyfriend.Services.Data;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Discord.API.Gateway.Commands;
|
||||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Discord.Gateway;
|
||||
using Remora.Discord.Gateway.Responders;
|
||||
using Remora.Discord.Interactivity;
|
||||
using Remora.Rest.Core;
|
||||
|
@ -18,23 +21,38 @@ namespace Boyfriend.Services;
|
|||
/// Handles executing guild updates (also called "ticks") once per second.
|
||||
/// </summary>
|
||||
public class GuildUpdateService : BackgroundService {
|
||||
private static readonly (string Name, TimeSpan Duration)[] SongList = {
|
||||
("UNDEAD CORPORATION - The Empress", new TimeSpan(0, 4, 34)),
|
||||
("UNDEAD CORPORATION - Everything will freeze", new TimeSpan(0, 3, 17)),
|
||||
("Splatoon 3 - Rockagilly Blues (Yoko & the Gold Bazookas)", new TimeSpan(0, 3, 37)),
|
||||
("Splatoon 3 - Seep and Destroy", new TimeSpan(0, 2, 42)),
|
||||
("IA - A Tale of Six Trillion Years and a Night", new TimeSpan(0, 3, 40)),
|
||||
("Manuel - Gas Gas Gas", new TimeSpan(0, 3, 17))
|
||||
};
|
||||
|
||||
private readonly List<Activity> _activityList = new(1) { new Activity("with Remora.Discord", ActivityType.Game) };
|
||||
|
||||
private readonly IDiscordRestChannelAPI _channelApi;
|
||||
private readonly GuildDataService _dataService;
|
||||
private readonly IDiscordRestGuildScheduledEventAPI _eventApi;
|
||||
private readonly IDiscordRestGuildAPI _guildApi;
|
||||
private readonly ILogger<GuildUpdateService> _logger;
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly IDiscordRestUserAPI _userApi;
|
||||
private readonly UtilityService _utility;
|
||||
private DateTimeOffset _nextSongAt = DateTimeOffset.MinValue;
|
||||
private uint _nextSongIndex;
|
||||
|
||||
public GuildUpdateService(
|
||||
IDiscordRestChannelAPI channelApi, GuildDataService dataService, IDiscordRestGuildAPI guildApi,
|
||||
IDiscordRestGuildScheduledEventAPI eventApi, ILogger<GuildUpdateService> logger, IDiscordRestUserAPI userApi,
|
||||
UtilityService utility) {
|
||||
IDiscordRestChannelAPI channelApi, GuildDataService dataService, IDiscordRestGuildScheduledEventAPI eventApi,
|
||||
IDiscordRestGuildAPI guildApi, ILogger<GuildUpdateService> logger, IServiceProvider provider,
|
||||
IDiscordRestUserAPI userApi, UtilityService utility) {
|
||||
_channelApi = channelApi;
|
||||
_dataService = dataService;
|
||||
_guildApi = guildApi;
|
||||
_eventApi = eventApi;
|
||||
_guildApi = guildApi;
|
||||
_logger = logger;
|
||||
_provider = provider;
|
||||
_userApi = userApi;
|
||||
_utility = utility;
|
||||
}
|
||||
|
@ -49,7 +67,20 @@ public class GuildUpdateService : BackgroundService {
|
|||
var tasks = new List<Task>();
|
||||
|
||||
while (await timer.WaitForNextTickAsync(ct)) {
|
||||
tasks.AddRange(_dataService.GetGuildIds().Select(id => TickGuildAsync(id, ct)));
|
||||
var guildIds = _dataService.GetGuildIds();
|
||||
if (guildIds.Count > 0 && DateTimeOffset.UtcNow >= _nextSongAt) {
|
||||
var nextSong = SongList[_nextSongIndex];
|
||||
_activityList[0] = new Activity(nextSong.Name, ActivityType.Listening);
|
||||
var client = _provider.GetRequiredService<DiscordGatewayClient>();
|
||||
client.SubmitCommand(
|
||||
new UpdatePresence(
|
||||
UserStatus.Online, false, DateTimeOffset.UtcNow, _activityList));
|
||||
_nextSongAt = DateTimeOffset.UtcNow.Add(nextSong.Duration);
|
||||
_nextSongIndex++;
|
||||
if (_nextSongIndex >= SongList.Length) _nextSongIndex = 0;
|
||||
}
|
||||
|
||||
tasks.AddRange(guildIds.Select(id => TickGuildAsync(id, ct)));
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
tasks.Clear();
|
||||
|
|
Loading…
Add table
Reference in a new issue