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
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `.rero` now optionally takes a message id to which to attach the reaction roles
|
||||||
|
|
||||||
## [3.0.1] - 10.09.2021
|
## [3.0.1] - 10.09.2021
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@@ -328,6 +328,15 @@ namespace NadekoBot.Services.Database
|
|||||||
.HasDefaultValue(100);
|
.HasDefaultValue(100);
|
||||||
|
|
||||||
#endregion
|
#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
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "5.0.7");
|
.HasAnnotation("ProductVersion", "5.0.8");
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.ClubApplicants", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.ClubApplicants", b =>
|
||||||
{
|
{
|
||||||
@@ -2307,7 +2307,8 @@ namespace NadekoBot.Migrations
|
|||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.ReactionRoleMessage", null)
|
b.HasOne("NadekoBot.Services.Database.Models.ReactionRoleMessage", null)
|
||||||
.WithMany("ReactionRoles")
|
.WithMany("ReactionRoles")
|
||||||
.HasForeignKey("ReactionRoleMessageId");
|
.HasForeignKey("ReactionRoleMessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.ReactionRoleMessage", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.ReactionRoleMessage", b =>
|
||||||
|
@@ -27,13 +27,13 @@ namespace NadekoBot.Modules.Administration
|
|||||||
_services = services;
|
_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 target = messageId is ulong msgId
|
||||||
var prev = (IUserMessage)msgs.FirstOrDefault(x => x is IUserMessage && x.Id != ctx.Message.Id);
|
? await ctx.Channel.GetMessageAsync(msgId).ConfigureAwait(false)
|
||||||
|
: (await ctx.Channel.GetMessagesAsync(2).FlattenAsync().ConfigureAwait(false))
|
||||||
if (prev is null)
|
.Skip(1)
|
||||||
return;
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (input.Length % 2 != 0)
|
if (input.Length % 2 != 0)
|
||||||
return;
|
return;
|
||||||
@@ -69,7 +69,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await prev.AddReactionAsync(x.emote, new RequestOptions()
|
await target.AddReactionAsync(x.emote, new RequestOptions()
|
||||||
{
|
{
|
||||||
RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit
|
RetryMode = RetryMode.Retry502 | RetryMode.RetryRatelimit
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -86,8 +86,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
if (_service.Add(ctx.Guild.Id, new ReactionRoleMessage()
|
if (_service.Add(ctx.Guild.Id, new ReactionRoleMessage()
|
||||||
{
|
{
|
||||||
Exclusive = exclusive,
|
Exclusive = exclusive,
|
||||||
MessageId = prev.Id,
|
MessageId = target.Id,
|
||||||
ChannelId = prev.Channel.Id,
|
ChannelId = target.Channel.Id,
|
||||||
ReactionRoles = all.Select(x =>
|
ReactionRoles = all.Select(x =>
|
||||||
{
|
{
|
||||||
return new ReactionRole()
|
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]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[NoPublicBot]
|
[NoPublicBot]
|
||||||
@@ -113,7 +131,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
[BotPerm(GuildPerm.ManageRoles)]
|
[BotPerm(GuildPerm.ManageRoles)]
|
||||||
[Priority(0)]
|
[Priority(0)]
|
||||||
public Task ReactionRoles(params string[] input) =>
|
public Task ReactionRoles(params string[] input) =>
|
||||||
InternalReactionRoles(false, input);
|
InternalReactionRoles(false, null, input);
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
@@ -122,7 +140,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
[BotPerm(GuildPerm.ManageRoles)]
|
[BotPerm(GuildPerm.ManageRoles)]
|
||||||
[Priority(1)]
|
[Priority(1)]
|
||||||
public Task ReactionRoles(Exclude _, params string[] input) =>
|
public Task ReactionRoles(Exclude _, params string[] input) =>
|
||||||
InternalReactionRoles(true, input);
|
InternalReactionRoles(true, null, input);
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
|
@@ -8,6 +8,8 @@ using NadekoBot.Extensions;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using NadekoBot.Db;
|
using NadekoBot.Db;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@@ -155,19 +157,23 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
|
|
||||||
public bool Add(ulong id, ReactionRoleMessage rrm)
|
public bool Add(ulong id, ReactionRoleMessage rrm)
|
||||||
{
|
{
|
||||||
using (var uow = _db.GetDbContext())
|
using var uow = _db.GetDbContext();
|
||||||
{
|
var table = uow.GetTable<ReactionRoleMessage>();
|
||||||
|
table.Delete(x => x.MessageId == rrm.MessageId);
|
||||||
|
|
||||||
var gc = uow.GuildConfigsForId(id, set => set
|
var gc = uow.GuildConfigsForId(id, set => set
|
||||||
.Include(x => x.ReactionRoleMessages)
|
.Include(x => x.ReactionRoleMessages)
|
||||||
.ThenInclude(x => x.ReactionRoles));
|
.ThenInclude(x => x.ReactionRoles));
|
||||||
|
|
||||||
if (gc.ReactionRoleMessages.Count >= 10)
|
if (gc.ReactionRoleMessages.Count >= 10)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
gc.ReactionRoleMessages.Add(rrm);
|
gc.ReactionRoleMessages.Add(rrm);
|
||||||
|
uow.SaveChanges();
|
||||||
|
|
||||||
_models.AddOrUpdate(id,
|
_models.AddOrUpdate(id,
|
||||||
gc.ReactionRoleMessages,
|
gc.ReactionRoleMessages,
|
||||||
delegate { return gc.ReactionRoleMessages; });
|
delegate { return gc.ReactionRoleMessages; });
|
||||||
uow.SaveChanges();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -362,6 +362,14 @@ namespace NadekoBot.Modules.Help
|
|||||||
if (!(serviceUrl is null || accessKey is null || secretAcccessKey is null))
|
if (!(serviceUrl is null || accessKey is null || secretAcccessKey is null))
|
||||||
{
|
{
|
||||||
var config = new AmazonS3Config {ServiceURL = serviceUrl};
|
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))
|
using (var client = new AmazonS3Client(accessKey, secretAcccessKey, config))
|
||||||
{
|
{
|
||||||
await client.PutObjectAsync(new PutObjectRequest()
|
await client.PutObjectAsync(new PutObjectRequest()
|
||||||
@@ -375,10 +383,9 @@ namespace NadekoBot.Modules.Help
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const string cmdVersionsFilePath = "../../cmd-versions.json";
|
using var ms = new MemoryStream();
|
||||||
var versionListString = File.Exists(cmdVersionsFilePath)
|
await oldVersionObject.ResponseStream.CopyToAsync(ms);
|
||||||
? await File.ReadAllTextAsync(cmdVersionsFilePath)
|
var versionListString = Encoding.UTF8.GetString(ms.ToArray());
|
||||||
: "[]";
|
|
||||||
|
|
||||||
var versionList = System.Text.Json.JsonSerializer.Deserialize<List<string>>(versionListString);
|
var versionList = System.Text.Json.JsonSerializer.Deserialize<List<string>>(versionListString);
|
||||||
if (!versionList.Contains(StatsService.BotVersion))
|
if (!versionList.Contains(StatsService.BotVersion))
|
||||||
@@ -391,7 +398,6 @@ namespace NadekoBot.Modules.Help
|
|||||||
{
|
{
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
});
|
});
|
||||||
await File.WriteAllTextAsync(cmdVersionsFilePath, versionListString);
|
|
||||||
|
|
||||||
// upload the updated version list
|
// upload the updated version list
|
||||||
using var client = new AmazonS3Client(accessKey, secretAcccessKey, config);
|
using var client = new AmazonS3Client(accessKey, secretAcccessKey, config);
|
||||||
|
@@ -10,7 +10,6 @@ using Serilog;
|
|||||||
|
|
||||||
namespace NadekoBot.Services
|
namespace NadekoBot.Services
|
||||||
{
|
{
|
||||||
// todo check why is memory usage so unstable
|
|
||||||
public sealed class BotCredsProvider
|
public sealed class BotCredsProvider
|
||||||
{
|
{
|
||||||
private readonly int? _totalShards;
|
private readonly int? _totalShards;
|
||||||
|
@@ -2008,10 +2008,12 @@ rollduel:
|
|||||||
- "50 @Someone"
|
- "50 @Someone"
|
||||||
- "@Challenger"
|
- "@Challenger"
|
||||||
reactionroles:
|
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:
|
args:
|
||||||
- "Gamer :SomeServerEmoji: Streamer :Other: Watcher :Other2:"
|
- "Gamer :SomeServerEmoji: Streamer :Other: Watcher :Other2:"
|
||||||
- "excl Horde :Horde: Alliance :Alliance:"
|
- "excl Horde :Horde: Alliance :Alliance:"
|
||||||
|
- "886382471732662332 excl Horde :Horde: Alliance :Alliance:"
|
||||||
|
- "886382471732662332 Gamer :SomeServerEmoji: Streamer :Other: Watcher :Other2:"
|
||||||
reactionroleslist:
|
reactionroleslist:
|
||||||
desc: "Lists all ReactionRole messages on this channel and their indexes."
|
desc: "Lists all ReactionRole messages on this channel and their indexes."
|
||||||
args:
|
args:
|
||||||
|
Reference in New Issue
Block a user