mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
.rero now optionally takes a message id to which to attach the reaction roles
This commit is contained in:
@@ -4,6 +4,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- `.rero` now optionally takes a message id to which to attach the reaction roles
|
||||
|
||||
## [3.0.1] - 10.09.2021
|
||||
|
||||
### Fixed
|
||||
|
@@ -328,6 +328,15 @@ namespace NadekoBot.Services.Database
|
||||
.HasDefaultValue(100);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reaction roles
|
||||
|
||||
modelBuilder.Entity<ReactionRoleMessage>(rrm => rrm
|
||||
.HasMany(x => x.ReactionRoles)
|
||||
.WithOne()
|
||||
.OnDelete(DeleteBehavior.Cascade));
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2626
src/NadekoBot/Migrations/20210911225622_rero-cascade.Designer.cs
generated
Normal file
2626
src/NadekoBot/Migrations/20210911225622_rero-cascade.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
src/NadekoBot/Migrations/20210911225622_rero-cascade.cs
Normal file
37
src/NadekoBot/Migrations/20210911225622_rero-cascade.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
public partial class rerocascade : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ReactionRole_ReactionRoleMessage_ReactionRoleMessageId",
|
||||
table: "ReactionRole");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ReactionRole_ReactionRoleMessage_ReactionRoleMessageId",
|
||||
table: "ReactionRole",
|
||||
column: "ReactionRoleMessageId",
|
||||
principalTable: "ReactionRoleMessage",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_ReactionRole_ReactionRoleMessage_ReactionRoleMessageId",
|
||||
table: "ReactionRole");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_ReactionRole_ReactionRoleMessage_ReactionRoleMessageId",
|
||||
table: "ReactionRole",
|
||||
column: "ReactionRoleMessageId",
|
||||
principalTable: "ReactionRoleMessage",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ namespace NadekoBot.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "5.0.7");
|
||||
.HasAnnotation("ProductVersion", "5.0.8");
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Db.Models.ClubApplicants", b =>
|
||||
{
|
||||
@@ -2307,7 +2307,8 @@ namespace NadekoBot.Migrations
|
||||
{
|
||||
b.HasOne("NadekoBot.Services.Database.Models.ReactionRoleMessage", null)
|
||||
.WithMany("ReactionRoles")
|
||||
.HasForeignKey("ReactionRoleMessageId");
|
||||
.HasForeignKey("ReactionRoleMessageId")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ReactionRoleMessage", b =>
|
||||
|
@@ -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)]
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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,10 +383,9 @@ 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);
|
||||
|
@@ -10,7 +10,6 @@ using Serilog;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
// todo check why is memory usage so unstable
|
||||
public sealed class BotCredsProvider
|
||||
{
|
||||
private readonly int? _totalShards;
|
||||
|
@@ -2008,10 +2008,12 @@ rollduel:
|
||||
- "50 @Someone"
|
||||
- "@Challenger"
|
||||
reactionroles:
|
||||
desc: "Specify role names and server emojis with which they're represented, the bot will then add those emojis to the previous message in the channel, and users will be able to get the roles by clicking on the emoji. You can set 'excl' as the first parameter to make them exclusive. You can have up to 5 of these enabled on one server at a time."
|
||||
desc: "Specify role names and server emojis with which they're represented, the bot will then add those emojis to the previous message in the channel, and users will be able to get the roles by clicking on the emoji. You can set 'excl' as the parameter before the reactions and roles to make them exclusive. You can have up to 5 of these enabled on one server at a time. Optionally you can specify target message if you don't want it to be the previous one."
|
||||
args:
|
||||
- "Gamer :SomeServerEmoji: Streamer :Other: Watcher :Other2:"
|
||||
- "excl Horde :Horde: Alliance :Alliance:"
|
||||
- "886382471732662332 excl Horde :Horde: Alliance :Alliance:"
|
||||
- "886382471732662332 Gamer :SomeServerEmoji: Streamer :Other: Watcher :Other2:"
|
||||
reactionroleslist:
|
||||
desc: "Lists all ReactionRole messages on this channel and their indexes."
|
||||
args:
|
||||
|
Reference in New Issue
Block a user