mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- Owner only attributes will now use fresh creds every time (no need for restart for owner only commands to start working once creds are changed)
- setgame/setstream use the new pubsub (also setstream will actually apply to all shards now) - setgame/setstream moved to SelfService - small cleanup
This commit is contained in:
@@ -432,7 +432,7 @@ namespace NadekoBot.Modules.Administration
|
||||
.WithDefault(Context)
|
||||
.Build();
|
||||
|
||||
await _bot.SetGameAsync(game is null ? game : rep.Replace(game), type).ConfigureAwait(false);
|
||||
await _service.SetGameAsync(game is null ? game : rep.Replace(game), type).ConfigureAwait(false);
|
||||
|
||||
await ReplyConfirmLocalizedAsync("set_game").ConfigureAwait(false);
|
||||
}
|
||||
@@ -443,7 +443,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
name = name ?? "";
|
||||
|
||||
await _client.SetGameAsync(name, url, ActivityType.Streaming).ConfigureAwait(false);
|
||||
await _service.SetStreamAsync(name, url).ConfigureAwait(false);
|
||||
|
||||
await ReplyConfirmLocalizedAsync("set_stream").ConfigureAwait(false);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
private readonly Timer _t;
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly SelfService _selfService;
|
||||
private readonly Replacer _rep;
|
||||
private readonly DbService _db;
|
||||
private readonly Bot _bot;
|
||||
@@ -28,11 +29,12 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
}
|
||||
|
||||
public PlayingRotateService(DiscordSocketClient client, DbService db, Bot bot,
|
||||
BotConfigService bss, IEnumerable<IPlaceholderProvider> phProviders)
|
||||
BotConfigService bss, IEnumerable<IPlaceholderProvider> phProviders, SelfService selfService)
|
||||
{
|
||||
_db = db;
|
||||
_bot = bot;
|
||||
_bss = bss;
|
||||
_selfService = selfService;
|
||||
|
||||
if (client.ShardId == 0)
|
||||
{
|
||||
@@ -70,7 +72,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
: rotatingStatuses[state.Index++];
|
||||
|
||||
var statusText = _rep.Replace(playingStatus.Status);
|
||||
await _bot.SetGameAsync(statusText, playingStatus.Type);
|
||||
await _selfService.SetGameAsync(statusText, playingStatus.Type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -14,6 +14,7 @@ using System.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using NadekoBot.Common;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services
|
||||
@@ -38,10 +39,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly IImageCache _imgs;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly IPubSub _pubSub;
|
||||
|
||||
//keys
|
||||
private readonly TypedKey<ActivityPubData> _activitySetKey;
|
||||
|
||||
public SelfService(DiscordSocketClient client, CommandHandler cmdHandler, DbService db,
|
||||
IBotStrings strings, IBotCredentials creds, IDataCache cache, IHttpClientFactory factory,
|
||||
BotConfigService bss)
|
||||
BotConfigService bss, IPubSub pubSub)
|
||||
{
|
||||
_redis = cache.Redis;
|
||||
_cmdHandler = cmdHandler;
|
||||
@@ -53,7 +58,11 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_imgs = cache.LocalImages;
|
||||
_httpFactory = factory;
|
||||
_bss = bss;
|
||||
|
||||
_pubSub = pubSub;
|
||||
_activitySetKey = new("activity.set");
|
||||
|
||||
HandleStatusChanges();
|
||||
|
||||
var sub = _redis.GetSubscriber();
|
||||
if (_client.ShardId == 0)
|
||||
{
|
||||
@@ -384,5 +393,34 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_bss.ModifyConfig(config => { isToAll = config.ForwardToAllOwners = !config.ForwardToAllOwners; });
|
||||
return isToAll;
|
||||
}
|
||||
|
||||
// todo pubsub via IPubSub
|
||||
private void HandleStatusChanges()
|
||||
{
|
||||
_pubSub.Sub(_activitySetKey, async data =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await _client.SetGameAsync(data.Name, data.Link, type: data.Type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error setting activity");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Task SetGameAsync(string game, ActivityType type)
|
||||
=> _pubSub.Pub(_activitySetKey, new() {Name = game, Link = null, Type = type});
|
||||
|
||||
public Task SetStreamAsync(string name, string link)
|
||||
=> _pubSub.Pub(_activitySetKey, new() { Name = name, Link = link, Type = ActivityType.Streaming });
|
||||
|
||||
private class ActivityPubData
|
||||
{
|
||||
public string Name { get; init; }
|
||||
public string Link { get; init; }
|
||||
public ActivityType Type { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user