.tesar now has groups!
This commit is contained in:
parent
204cdbfb2b
commit
95ee386475
1911
NadekoBot.Core/Migrations/20171021092614_tesar-grouping.Designer.cs
generated
Normal file
1911
NadekoBot.Core/Migrations/20171021092614_tesar-grouping.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
NadekoBot.Core/Migrations/20171021092614_tesar-grouping.cs
Normal file
27
NadekoBot.Core/Migrations/20171021092614_tesar-grouping.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class tesargrouping : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "Group",
|
||||||
|
table: "SelfAssignableRoles",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Group",
|
||||||
|
table: "SelfAssignableRoles");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1076,6 +1076,10 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Property<DateTime?>("DateAdded");
|
b.Property<DateTime?>("DateAdded");
|
||||||
|
|
||||||
|
b.Property<int>("Group")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasDefaultValue(0);
|
||||||
|
|
||||||
b.Property<ulong>("GuildId");
|
b.Property<ulong>("GuildId");
|
||||||
|
|
||||||
b.Property<ulong>("RoleId");
|
b.Property<ulong>("RoleId");
|
||||||
|
@ -11,6 +11,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NadekoBot.Common.Attributes;
|
using NadekoBot.Common.Attributes;
|
||||||
using NadekoBot.Common.Collections;
|
using NadekoBot.Common.Collections;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
{
|
{
|
||||||
@ -46,7 +47,15 @@ namespace NadekoBot.Modules.Administration
|
|||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||||
public async Task Asar([Remainder] IRole role)
|
[Priority(1)]
|
||||||
|
public Task Asar([Remainder] IRole role) =>
|
||||||
|
Asar(0, role);
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||||
|
[Priority(0)]
|
||||||
|
public async Task Asar(int group, [Remainder] IRole role)
|
||||||
{
|
{
|
||||||
IEnumerable<SelfAssignedRole> roles;
|
IEnumerable<SelfAssignedRole> roles;
|
||||||
|
|
||||||
@ -58,7 +67,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var error = false;
|
var error = false;
|
||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
{
|
{
|
||||||
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
|
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id)
|
||||||
|
.SelectMany(x => x);
|
||||||
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
|
||||||
{
|
{
|
||||||
msg = GetText("role_in_list", Format.Bold(role.Name));
|
msg = GetText("role_in_list", Format.Bold(role.Name));
|
||||||
@ -68,11 +78,12 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
uow.SelfAssignedRoles.Add(new SelfAssignedRole
|
uow.SelfAssignedRoles.Add(new SelfAssignedRole
|
||||||
{
|
{
|
||||||
|
Group = group,
|
||||||
RoleId = role.Id,
|
RoleId = role.Id,
|
||||||
GuildId = role.Guild.Id
|
GuildId = role.Guild.Id
|
||||||
});
|
});
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
msg = GetText("role_added", Format.Bold(role.Name));
|
msg = GetText("role_added", Format.Bold(role.Name), Format.Bold(group.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error)
|
if (error)
|
||||||
@ -113,40 +124,49 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
|
var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
|
||||||
var removeMsg = new StringBuilder();
|
var removeMsg = new StringBuilder();
|
||||||
var roles = new List<string>();
|
var rolesStr = new StringBuilder();
|
||||||
var roleCnt = 0;
|
var roleCnt = 0;
|
||||||
|
var exclusive = false;
|
||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
{
|
{
|
||||||
var roleModels = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id).ToList();
|
exclusive = uow.GuildConfigs.For(Context.Guild.Id, set => set)
|
||||||
|
.ExclusiveSelfAssignedRoles;
|
||||||
foreach (var roleModel in roleModels)
|
var roleModels = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id)
|
||||||
|
.ToDictionary(x => x.Key, x => x.AsEnumerable().ToArray())
|
||||||
|
.OrderBy(x => x.Key);
|
||||||
|
foreach (var kvp in roleModels)
|
||||||
{
|
{
|
||||||
var role = Context.Guild.Roles.FirstOrDefault(r => r.Id == roleModel.RoleId);
|
rolesStr.AppendLine("\t\t\t\t『" + Format.Bold(GetText("self_assign_group", kvp.Key)) + "』");
|
||||||
if (role == null)
|
foreach (var roleModel in kvp.Value)
|
||||||
{
|
{
|
||||||
toRemove.Add(roleModel);
|
var role = Context.Guild.Roles.FirstOrDefault(r => r.Id == roleModel.RoleId);
|
||||||
uow.SelfAssignedRoles.Remove(roleModel);
|
if (role == null)
|
||||||
}
|
{
|
||||||
else
|
toRemove.Add(roleModel);
|
||||||
{
|
uow.SelfAssignedRoles.Remove(roleModel);
|
||||||
roles.Add(Format.Bold(role.Name));
|
}
|
||||||
roleCnt++;
|
else
|
||||||
|
{
|
||||||
|
rolesStr.AppendLine(Format.Bold(role.Name));
|
||||||
|
roleCnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(toRemove.Any())
|
||||||
|
rolesStr.AppendLine("\t\t\t\t『』");
|
||||||
foreach (var role in toRemove)
|
foreach (var role in toRemove)
|
||||||
{
|
{
|
||||||
roles.Add(GetText("role_clean", role.RoleId));
|
rolesStr.AppendLine(GetText("role_clean", role.RoleId));
|
||||||
}
|
}
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Context.Channel.SendPaginatedConfirmAsync((DiscordSocketClient)Context.Client, page, (curPage) =>
|
await Context.Channel.SendConfirmAsync("",
|
||||||
{
|
Format.Bold(GetText("self_assign_list", roleCnt))
|
||||||
return new EmbedBuilder()
|
+ "\n\n" + rolesStr.ToString(),
|
||||||
.WithTitle(GetText("self_assign_list", roleCnt))
|
footer: exclusive
|
||||||
.WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10)))
|
? GetText("self_assign_are_exclusive")
|
||||||
.WithOkColor();
|
: GetText("self_assign_are_not_exclusive")).ConfigureAwait(false);
|
||||||
}, roles.Count, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -162,7 +182,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
|
areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
|
||||||
await uow.CompleteAsync();
|
await uow.CompleteAsync();
|
||||||
}
|
}
|
||||||
if(areExclusive)
|
if (areExclusive)
|
||||||
await ReplyConfirmLocalized("self_assign_excl").ConfigureAwait(false);
|
await ReplyConfirmLocalized("self_assign_excl").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await ReplyConfirmLocalized("self_assign_no_excl").ConfigureAwait(false);
|
await ReplyConfirmLocalized("self_assign_no_excl").ConfigureAwait(false);
|
||||||
@ -179,9 +199,12 @@ namespace NadekoBot.Modules.Administration
|
|||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
{
|
{
|
||||||
conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
||||||
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id).ToArray();
|
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id)
|
||||||
|
.SelectMany(x => x)
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
if (roles.FirstOrDefault(r=>r.RoleId == role.Id) == null)
|
var theRoleYouWant = roles.FirstOrDefault(r => r.RoleId == role.Id);
|
||||||
|
if (theRoleYouWant == null)
|
||||||
{
|
{
|
||||||
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
|
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
@ -192,11 +215,14 @@ namespace NadekoBot.Modules.Administration
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var roleIds = roles.Select(x => x.RoleId).ToArray();
|
var roleIds = roles
|
||||||
|
.Where(x => x.Group == theRoleYouWant.Group)
|
||||||
|
.Select(x => x.RoleId).ToArray();
|
||||||
if (conf.ExclusiveSelfAssignedRoles)
|
if (conf.ExclusiveSelfAssignedRoles)
|
||||||
{
|
{
|
||||||
var sameRoles = guildUser.RoleIds.Where(r => roleIds.Contains(r));
|
var sameRoles = guildUser.RoleIds
|
||||||
|
.Where(r => roleIds.Contains(r));
|
||||||
|
|
||||||
foreach (var roleId in sameRoles)
|
foreach (var roleId in sameRoles)
|
||||||
{
|
{
|
||||||
var sameRole = Context.Guild.GetRole(roleId);
|
var sameRole = Context.Guild.GetRole(roleId);
|
||||||
@ -224,7 +250,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
_log.Info(ex);
|
_log.Info(ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var msg = await ReplyConfirmLocalized("self_assign_success",Format.Bold(role.Name)).ConfigureAwait(false);
|
var msg = await ReplyConfirmLocalized("self_assign_success", Format.Bold(role.Name)).ConfigureAwait(false);
|
||||||
|
|
||||||
if (conf.AutoDeleteSelfAssignedRoleMessages)
|
if (conf.AutoDeleteSelfAssignedRoleMessages)
|
||||||
{
|
{
|
||||||
@ -244,7 +270,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
{
|
{
|
||||||
autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(Context.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages;
|
autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(Context.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages;
|
||||||
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
|
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id)
|
||||||
|
.SelectMany(x => x);
|
||||||
}
|
}
|
||||||
if (roles.FirstOrDefault(r => r.RoleId == role.Id) == null)
|
if (roles.FirstOrDefault(r => r.RoleId == role.Id) == null)
|
||||||
{
|
{
|
||||||
@ -253,7 +280,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
if (!guildUser.RoleIds.Contains(role.Id))
|
if (!guildUser.RoleIds.Contains(role.Id))
|
||||||
{
|
{
|
||||||
await ReplyErrorLocalized("self_assign_not_have",Format.Bold(role.Name)).ConfigureAwait(false);
|
await ReplyErrorLocalized("self_assign_not_have", Format.Bold(role.Name)).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@ -275,4 +302,4 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -65,7 +65,7 @@ namespace NadekoBot.Core.Modules.Gambling.Services
|
|||||||
{
|
{
|
||||||
var _t = Task.Run(async () =>
|
var _t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(30000).ConfigureAwait(false);
|
await Task.Delay(60000).ConfigureAwait(false);
|
||||||
await _locker.WaitAsync().ConfigureAwait(false);
|
await _locker.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -4,5 +4,7 @@
|
|||||||
{
|
{
|
||||||
public ulong GuildId { get; set; }
|
public ulong GuildId { get; set; }
|
||||||
public ulong RoleId { get; set; }
|
public ulong RoleId { get; set; }
|
||||||
|
|
||||||
|
public int Group { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,10 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
.HasIndex(s => new { s.GuildId, s.RoleId })
|
.HasIndex(s => new { s.GuildId, s.RoleId })
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
|
selfassignableRolesEntity
|
||||||
|
.Property(x => x.Group)
|
||||||
|
.HasDefaultValue(0);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Currency
|
#region Currency
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
using NadekoBot.Core.Services.Database.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories
|
namespace NadekoBot.Core.Services.Database.Repositories
|
||||||
{
|
{
|
||||||
public interface ISelfAssignedRolesRepository : IRepository<SelfAssignedRole>
|
public interface ISelfAssignedRolesRepository : IRepository<SelfAssignedRole>
|
||||||
{
|
{
|
||||||
bool DeleteByGuildAndRoleId(ulong guildId, ulong roleId);
|
bool DeleteByGuildAndRoleId(ulong guildId, ulong roleId);
|
||||||
IEnumerable<SelfAssignedRole> GetFromGuild(ulong guildId);
|
IEnumerable<IGrouping<int, SelfAssignedRole>> GetFromGuild(ulong guildId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,9 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<SelfAssignedRole> GetFromGuild(ulong guildId) =>
|
public IEnumerable<IGrouping<int, SelfAssignedRole>> GetFromGuild(ulong guildId)
|
||||||
_set.Where(s => s.GuildId == guildId).ToList();
|
=> _set.Where(s => s.GuildId == guildId)
|
||||||
|
.AsEnumerable()
|
||||||
|
.GroupBy(x => x.Group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@
|
|||||||
"administration_renrole_err": "Failed to rename role. I have insufficient permissions.",
|
"administration_renrole_err": "Failed to rename role. I have insufficient permissions.",
|
||||||
"administration_renrole_perms": "You can't edit roles higher than your highest role.",
|
"administration_renrole_perms": "You can't edit roles higher than your highest role.",
|
||||||
"administration_reprm": "Removed the playing message: {0}",
|
"administration_reprm": "Removed the playing message: {0}",
|
||||||
"administration_role_added": "Role {0} has been added to the list.",
|
"administration_role_added": "Role {0} has been added to the list in group {1}.",
|
||||||
"administration_role_clean": "{0} not found.Cleaned up.",
|
"administration_role_clean": "{0} not found.Cleaned up.",
|
||||||
"administration_role_in_list": "Role {0} is already in the list.",
|
"administration_role_in_list": "Role {0} is already in the list.",
|
||||||
"administration_ropl_added": "Added.",
|
"administration_ropl_added": "Added.",
|
||||||
@ -166,6 +166,8 @@
|
|||||||
"administration_ropl_list": "Here is a list of rotating statuses:\n{0}",
|
"administration_ropl_list": "Here is a list of rotating statuses:\n{0}",
|
||||||
"administration_ropl_not_set": "No rotating playing statuses set.",
|
"administration_ropl_not_set": "No rotating playing statuses set.",
|
||||||
"administration_self_assign_already": "You already have {0} role.",
|
"administration_self_assign_already": "You already have {0} role.",
|
||||||
|
"administration_self_assign_are_exclusive": "You can only choose 1 role from each group.",
|
||||||
|
"administration_self_assign_are_not_exclusive": "You can choose any number of roles from any group.",
|
||||||
"administration_self_assign_already_excl": "You already have {0} exclusive self-assigned role.",
|
"administration_self_assign_already_excl": "You already have {0} exclusive self-assigned role.",
|
||||||
"administration_self_assign_excl": "Self assigned roles are now exclusive!",
|
"administration_self_assign_excl": "Self assigned roles are now exclusive!",
|
||||||
"administration_self_assign_list": "There are {0} self assignable roles",
|
"administration_self_assign_list": "There are {0} self assignable roles",
|
||||||
@ -176,6 +178,7 @@
|
|||||||
"administration_self_assign_rem": "{0} has been removed from the list of self-assignable roles.",
|
"administration_self_assign_rem": "{0} has been removed from the list of self-assignable roles.",
|
||||||
"administration_self_assign_remove": "You no longer have {0} role.",
|
"administration_self_assign_remove": "You no longer have {0} role.",
|
||||||
"administration_self_assign_success": "You now have {0} role.",
|
"administration_self_assign_success": "You now have {0} role.",
|
||||||
|
"administration_self_assign_group": "Group {0}",
|
||||||
"administration_setrole": "Successfully added role {0} to user {1}",
|
"administration_setrole": "Successfully added role {0} to user {1}",
|
||||||
"administration_setrole_err": "Failed to add role. I have insufficient permissions.",
|
"administration_setrole_err": "Failed to add role. I have insufficient permissions.",
|
||||||
"administration_set_avatar": "New avatar set!",
|
"administration_set_avatar": "New avatar set!",
|
||||||
|
@ -204,9 +204,11 @@
|
|||||||
},
|
},
|
||||||
"asar": {
|
"asar": {
|
||||||
"Cmd": "asar",
|
"Cmd": "asar",
|
||||||
"Desc": "Adds a role to the list of self-assignable roles.",
|
"Desc": "Adds a role to the list of self-assignable roles. You can also specify a group. If 'Exclusive self-assignable roles' feature is enabled, users will be able to pick one role per group.",
|
||||||
"Usage": [
|
"Usage": [
|
||||||
"{0}asar Gamer"
|
"{0}asar Gamer",
|
||||||
|
"{0}asar 1 Alliance",
|
||||||
|
"{0}asar 1 Horde"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"rsar": {
|
"rsar": {
|
||||||
@ -225,7 +227,7 @@
|
|||||||
},
|
},
|
||||||
"tesar": {
|
"tesar": {
|
||||||
"Cmd": "togglexclsar tesar",
|
"Cmd": "togglexclsar tesar",
|
||||||
"Desc": "Toggles whether the self-assigned roles are exclusive. (So that any person can have only one of the self assignable roles)",
|
"Desc": "Toggles whether the self-assigned roles are exclusive. While enabled, users can only have one self-assignable role per group.",
|
||||||
"Usage": [
|
"Usage": [
|
||||||
"{0}tesar"
|
"{0}tesar"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user