mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- NadekoBot class renamed to Bot
- Implemented grpc based coordinator. Supports restarting, killing single or all shards, as well as getting current shard statuses. (Adaptation of the one used by the public bot) - Coord is setup via coord.yml file - Methods from SelfService which deal with shard/bot restart etc have been moved to ICoordinator (with GrpcRemoteCoordinator being the default implementation atm) - Vastly simplified NadekoBot/Program.cs
This commit is contained in:
@@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DbService _db;
|
||||
private readonly LogCommandService _logService;
|
||||
|
||||
public AdministrationService(NadekoBot bot, CommandHandler cmdHandler, DbService db,
|
||||
public AdministrationService(Bot bot, CommandHandler cmdHandler, DbService db,
|
||||
LogCommandService logService)
|
||||
{
|
||||
_db = db;
|
||||
|
@@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
SingleWriter = false,
|
||||
});
|
||||
|
||||
public AutoAssignRoleService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
public AutoAssignRoleService(DiscordSocketClient client, Bot bot, DbService db)
|
||||
{
|
||||
_client = client;
|
||||
_db = db;
|
||||
|
@@ -17,7 +17,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DbService _db;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public GameVoiceChannelService(DiscordSocketClient client, DbService db, NadekoBot bot)
|
||||
public GameVoiceChannelService(DiscordSocketClient client, DbService db, Bot bot)
|
||||
{
|
||||
_db = db;
|
||||
_client = client;
|
||||
|
@@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly ConcurrentDictionary<ulong, TimeZoneInfo> _timezones;
|
||||
private readonly DbService _db;
|
||||
|
||||
public GuildTimezoneService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
public GuildTimezoneService(DiscordSocketClient client, Bot bot, DbService db)
|
||||
{
|
||||
_timezones = bot.AllGuildConfigs
|
||||
.Select(GetTimzezoneTuple)
|
||||
|
@@ -20,14 +20,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly Replacer _rep;
|
||||
private readonly DbService _db;
|
||||
private readonly NadekoBot _bot;
|
||||
private readonly Bot _bot;
|
||||
|
||||
private class TimerState
|
||||
{
|
||||
public int Index { get; set; }
|
||||
}
|
||||
|
||||
public PlayingRotateService(DiscordSocketClient client, DbService db, NadekoBot bot,
|
||||
public PlayingRotateService(DiscordSocketClient client, DbService db, Bot bot,
|
||||
BotConfigService bss, IEnumerable<IPlaceholderProvider> phProviders)
|
||||
{
|
||||
_db = db;
|
||||
|
@@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
public ProtectionService(DiscordSocketClient client, NadekoBot bot,
|
||||
public ProtectionService(DiscordSocketClient client, Bot bot,
|
||||
MuteService mute, DbService db, UserPunishService punishService)
|
||||
{
|
||||
_client = client;
|
||||
|
@@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly ConcurrentDictionary<ulong, IndexedCollection<ReactionRoleMessage>> _models;
|
||||
|
||||
public RoleCommandsService(DiscordSocketClient client, DbService db,
|
||||
NadekoBot bot)
|
||||
Bot bot)
|
||||
{
|
||||
_db = db;
|
||||
_client = client;
|
||||
|
@@ -9,14 +9,13 @@ using NadekoBot.Core.Services;
|
||||
using StackExchange.Redis;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Newtonsoft.Json;
|
||||
using NadekoBot.Common.ShardCom;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using System.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using NadekoBot.Services;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services
|
||||
@@ -41,10 +40,11 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly IImageCache _imgs;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly BotConfigService _bss;
|
||||
private readonly ICoordinator _coord;
|
||||
|
||||
public SelfService(DiscordSocketClient client, CommandHandler cmdHandler, DbService db,
|
||||
IBotStrings strings, IBotCredentials creds, IDataCache cache, IHttpClientFactory factory,
|
||||
BotConfigService bss)
|
||||
BotConfigService bss, ICoordinator coord)
|
||||
{
|
||||
_redis = cache.Redis;
|
||||
_cmdHandler = cmdHandler;
|
||||
@@ -56,6 +56,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_imgs = cache.LocalImages;
|
||||
_httpFactory = factory;
|
||||
_bss = bss;
|
||||
_coord = coord;
|
||||
|
||||
var sub = _redis.GetSubscriber();
|
||||
if (_client.ShardId == 0)
|
||||
@@ -281,18 +282,6 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestartBot()
|
||||
{
|
||||
var cmd = _creds.RestartCommand;
|
||||
if (string.IsNullOrWhiteSpace(cmd?.Cmd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Restart();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveStartupCommand(int index, out AutoCommand cmd)
|
||||
{
|
||||
using (var uow = _db.GetDbContext())
|
||||
@@ -385,32 +374,6 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
sub.Publish(_creds.RedisKey() + "_reload_images", "");
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
var sub = _cache.Redis.GetSubscriber();
|
||||
sub.Publish(_creds.RedisKey() + "_die", "", CommandFlags.FireAndForget);
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
Process.Start(_creds.RestartCommand.Cmd, _creds.RestartCommand.Args);
|
||||
var sub = _cache.Redis.GetSubscriber();
|
||||
sub.Publish(_creds.RedisKey() + "_die", "", CommandFlags.FireAndForget);
|
||||
}
|
||||
|
||||
public bool RestartShard(int shardId)
|
||||
{
|
||||
if (shardId < 0 || shardId >= _creds.TotalShards)
|
||||
return false;
|
||||
|
||||
var pub = _cache.Redis.GetSubscriber();
|
||||
pub.Publish(_creds.RedisKey() + "_shardcoord_stop",
|
||||
JsonConvert.SerializeObject(shardId),
|
||||
CommandFlags.FireAndForget);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ForwardMessages()
|
||||
{
|
||||
var isForwarding = false;
|
||||
@@ -425,12 +388,5 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_bss.ModifyConfig(config => { isToAll = config.ForwardToAllOwners = !config.ForwardToAllOwners; });
|
||||
return isToAll;
|
||||
}
|
||||
|
||||
public IEnumerable<ShardComMessage> GetAllShardStatuses()
|
||||
{
|
||||
var db = _cache.Redis.GetDatabase();
|
||||
return db.ListRange(_creds.RedisKey() + "_shardstats")
|
||||
.Select(x => JsonConvert.DeserializeObject<ShardComMessage>(x));
|
||||
}
|
||||
}
|
||||
}
|
@@ -456,7 +456,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
template = JsonConvert.SerializeObject(new
|
||||
{
|
||||
color = NadekoBot.ErrorColor.RawValue,
|
||||
color = Bot.ErrorColor.RawValue,
|
||||
description = defaultMessage
|
||||
});
|
||||
|
||||
@@ -477,7 +477,7 @@ WHERE GuildId={guildId}
|
||||
{
|
||||
template = JsonConvert.SerializeObject(new
|
||||
{
|
||||
color = NadekoBot.ErrorColor.RawValue,
|
||||
color = Bot.ErrorColor.RawValue,
|
||||
description = replacer.Replace(template)
|
||||
});
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>> VcRoles { get; }
|
||||
public ConcurrentDictionary<ulong, ConcurrentQueue<(bool, IGuildUser, IRole)>> ToAssign { get; }
|
||||
|
||||
public VcRoleService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
public VcRoleService(DiscordSocketClient client, Bot bot, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_client = client;
|
||||
|
Reference in New Issue
Block a user