.rero now optionally takes a message id to which to attach the reaction roles

This commit is contained in:
Kwoth
2021-09-12 01:07:19 +02:00
parent 596a5c05e0
commit 1df947d54b
10 changed files with 2742 additions and 34 deletions

View File

@@ -27,13 +27,13 @@ namespace NadekoBot.Modules.Administration
_services = services;
}
public async Task InternalReactionRoles(bool exclusive, params string[] input)
public async Task InternalReactionRoles(bool exclusive, ulong? messageId, params string[] input)
{
var msgs = await ((SocketTextChannel)ctx.Channel).GetMessagesAsync().FlattenAsync().ConfigureAwait(false);
var prev = (IUserMessage)msgs.FirstOrDefault(x => x is IUserMessage && x.Id != ctx.Message.Id);
if (prev is null)
return;
var target = messageId is ulong msgId
? await ctx.Channel.GetMessageAsync(msgId).ConfigureAwait(false)
: (await ctx.Channel.GetMessagesAsync(2).FlattenAsync().ConfigureAwait(false))
.Skip(1)
.FirstOrDefault();
if (input.Length % 2 != 0)
return;
@@ -69,7 +69,7 @@ namespace NadekoBot.Modules.Administration
{
try
{
await prev.AddReactionAsync(x.emote, new RequestOptions()
await target.AddReactionAsync(x.emote, new RequestOptions()
{
RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit
}).ConfigureAwait(false);
@@ -86,8 +86,8 @@ namespace NadekoBot.Modules.Administration
if (_service.Add(ctx.Guild.Id, new ReactionRoleMessage()
{
Exclusive = exclusive,
MessageId = prev.Id,
ChannelId = prev.Channel.Id,
MessageId = target.Id,
ChannelId = target.Channel.Id,
ReactionRoles = all.Select(x =>
{
return new ReactionRole()
@@ -106,6 +106,24 @@ namespace NadekoBot.Modules.Administration
}
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[NoPublicBot]
[UserPerm(GuildPerm.ManageRoles)]
[BotPerm(GuildPerm.ManageRoles)]
[Priority(0)]
public Task ReactionRoles(ulong messageId, params string[] input) =>
InternalReactionRoles(false, messageId, input);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[NoPublicBot]
[UserPerm(GuildPerm.ManageRoles)]
[BotPerm(GuildPerm.ManageRoles)]
[Priority(1)]
public Task ReactionRoles(ulong messageId, Exclude _, params string[] input) =>
InternalReactionRoles(true, messageId, input);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[NoPublicBot]
@@ -113,7 +131,7 @@ namespace NadekoBot.Modules.Administration
[BotPerm(GuildPerm.ManageRoles)]
[Priority(0)]
public Task ReactionRoles(params string[] input) =>
InternalReactionRoles(false, input);
InternalReactionRoles(false, null, input);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -122,7 +140,7 @@ namespace NadekoBot.Modules.Administration
[BotPerm(GuildPerm.ManageRoles)]
[Priority(1)]
public Task ReactionRoles(Exclude _, params string[] input) =>
InternalReactionRoles(true, input);
InternalReactionRoles(true, null, input);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]

View File

@@ -8,6 +8,8 @@ using NadekoBot.Extensions;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using NadekoBot.Db;
using Serilog;
@@ -155,19 +157,23 @@ namespace NadekoBot.Modules.Administration.Services
public bool Add(ulong id, ReactionRoleMessage rrm)
{
using (var uow = _db.GetDbContext())
{
var gc = uow.GuildConfigsForId(id, set => set
.Include(x => x.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles));
if (gc.ReactionRoleMessages.Count >= 10)
return false;
gc.ReactionRoleMessages.Add(rrm);
_models.AddOrUpdate(id,
gc.ReactionRoleMessages,
delegate { return gc.ReactionRoleMessages; });
uow.SaveChanges();
}
using var uow = _db.GetDbContext();
var table = uow.GetTable<ReactionRoleMessage>();
table.Delete(x => x.MessageId == rrm.MessageId);
var gc = uow.GuildConfigsForId(id, set => set
.Include(x => x.ReactionRoleMessages)
.ThenInclude(x => x.ReactionRoles));
if (gc.ReactionRoleMessages.Count >= 10)
return false;
gc.ReactionRoleMessages.Add(rrm);
uow.SaveChanges();
_models.AddOrUpdate(id,
gc.ReactionRoleMessages,
delegate { return gc.ReactionRoleMessages; });
return true;
}

View File

@@ -362,6 +362,14 @@ namespace NadekoBot.Modules.Help
if (!(serviceUrl is null || accessKey is null || secretAcccessKey is null))
{
var config = new AmazonS3Config {ServiceURL = serviceUrl};
using var dlClient = new AmazonS3Client(accessKey, secretAcccessKey, config);
var oldVersionObject = await dlClient.GetObjectAsync(new GetObjectRequest()
{
BucketName = "nadeko-pictures",
Key = "cmds/versions.json",
});
using (var client = new AmazonS3Client(accessKey, secretAcccessKey, config))
{
await client.PutObjectAsync(new PutObjectRequest()
@@ -375,11 +383,10 @@ namespace NadekoBot.Modules.Help
});
}
const string cmdVersionsFilePath = "../../cmd-versions.json";
var versionListString = File.Exists(cmdVersionsFilePath)
? await File.ReadAllTextAsync(cmdVersionsFilePath)
: "[]";
using var ms = new MemoryStream();
await oldVersionObject.ResponseStream.CopyToAsync(ms);
var versionListString = Encoding.UTF8.GetString(ms.ToArray());
var versionList = System.Text.Json.JsonSerializer.Deserialize<List<string>>(versionListString);
if (!versionList.Contains(StatsService.BotVersion))
{
@@ -391,7 +398,6 @@ namespace NadekoBot.Modules.Help
{
WriteIndented = true
});
await File.WriteAllTextAsync(cmdVersionsFilePath, versionListString);
// upload the updated version list
using var client = new AmazonS3Client(accessKey, secretAcccessKey, config);