.rlr - Set a level requirement on a self-assignable role
This commit is contained in:
parent
7f5961e905
commit
f7ef8eae12
1994
NadekoBot.Core/Migrations/20171107131810_sar-level-req.Designer.cs
generated
Normal file
1994
NadekoBot.Core/Migrations/20171107131810_sar-level-req.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
NadekoBot.Core/Migrations/20171107131810_sar-level-req.cs
Normal file
26
NadekoBot.Core/Migrations/20171107131810_sar-level-req.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
public partial class sarlevelreq : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "LevelRequirement",
|
||||
table: "SelfAssignableRoles",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LevelRequirement",
|
||||
table: "SelfAssignableRoles");
|
||||
}
|
||||
}
|
||||
}
|
@ -1149,6 +1149,8 @@ namespace NadekoBot.Migrations
|
||||
|
||||
b.Property<ulong>("GuildId");
|
||||
|
||||
b.Property<int>("LevelRequirement");
|
||||
|
||||
b.Property<ulong>("RoleId");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
@ -10,6 +10,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Common.Collections;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Modules.Xp.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
@ -147,7 +149,10 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
else
|
||||
{
|
||||
rolesStr.AppendLine(Format.Bold(role.Name));
|
||||
if (roleModel.LevelRequirement == 0)
|
||||
rolesStr.AppendLine(Format.Bold(role.Name));
|
||||
else
|
||||
rolesStr.AppendLine(Format.Bold(role.Name) + $" (lvl {roleModel.LevelRequirement}+)");
|
||||
roleCnt++;
|
||||
}
|
||||
}
|
||||
@ -188,6 +193,42 @@ namespace NadekoBot.Modules.Administration
|
||||
await ReplyConfirmLocalized("self_assign_no_excl").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
public async Task RoleLevelReq(int level, [Remainder] IRole role)
|
||||
{
|
||||
if (level < 0)
|
||||
return;
|
||||
|
||||
bool notExists = false;
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
//todo add firacode font to visual studio
|
||||
var roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
|
||||
var sar = roles.SelectMany(x => x).FirstOrDefault(x => x.RoleId == role.Id);
|
||||
if (sar != null)
|
||||
{
|
||||
sar.LevelRequirement = level;
|
||||
uow.Complete();
|
||||
}
|
||||
else
|
||||
{
|
||||
notExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (notExists)
|
||||
{
|
||||
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalized("self_assign_level_req",
|
||||
Format.Bold(role.Name),
|
||||
Format.Bold(level.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Iam([Remainder] IRole role)
|
||||
@ -196,12 +237,16 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
GuildConfig conf;
|
||||
SelfAssignedRole[] roles;
|
||||
LevelStats userLevelData;
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
|
||||
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id)
|
||||
.SelectMany(x => x)
|
||||
.ToArray();
|
||||
|
||||
var stats = uow.Xp.GetOrCreateUser(Context.Guild.Id, Context.User.Id);
|
||||
userLevelData = new LevelStats(stats.Xp + stats.AwardedXp);
|
||||
}
|
||||
var theRoleYouWant = roles.FirstOrDefault(r => r.RoleId == role.Id);
|
||||
if (theRoleYouWant == null)
|
||||
@ -209,6 +254,11 @@ namespace NadekoBot.Modules.Administration
|
||||
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
if (theRoleYouWant.LevelRequirement > userLevelData.Level)
|
||||
{
|
||||
await ReplyErrorLocalized("self_assign_not_level", Format.Bold(theRoleYouWant.LevelRequirement.ToString())).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
if (guildUser.RoleIds.Contains(role.Id))
|
||||
{
|
||||
await ReplyErrorLocalized("self_assign_already", Format.Bold(role.Name)).ConfigureAwait(false);
|
||||
|
@ -6,5 +6,6 @@
|
||||
public ulong RoleId { get; set; }
|
||||
|
||||
public int Group { get; set; }
|
||||
public int LevelRequirement { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user