currency levelup rewards wip
This commit is contained in:
parent
aca03cdc01
commit
461dfd553f
@ -241,6 +241,50 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
}, token);
|
||||
}
|
||||
|
||||
public void SetCurrencyReward(ulong guildId, int level, int amount)
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var settings = uow.GuildConfigs.XpSettingsFor(guildId);
|
||||
|
||||
if (amount <= 0)
|
||||
{
|
||||
var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||
if (toRemove != null)
|
||||
{
|
||||
uow._context.Remove(toRemove);
|
||||
settings.CurrencyRewards.Remove(toRemove);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var rew = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||
|
||||
if (rew != null)
|
||||
rew.Amount = amount;
|
||||
else
|
||||
settings.CurrencyRewards.Add(new XpCurrencyReward()
|
||||
{
|
||||
Level = level,
|
||||
Amount = amount,
|
||||
});
|
||||
}
|
||||
|
||||
uow.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<XpCurrencyReward> GetCurrencyRewards(ulong id)
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
return uow.GuildConfigs.XpSettingsFor(id)
|
||||
.CurrencyRewards
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<XpRoleReward> GetRoleRewards(ulong id)
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
|
@ -23,34 +23,10 @@ namespace NadekoBot.Modules.Xp
|
||||
_client = client;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
//[NadekoCommand, Usage, Description, Aliases]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//[OwnerOnly]
|
||||
//public async Task Populate()
|
||||
//{
|
||||
// var rng = new NadekoRandom();
|
||||
// using (var uow = _db.UnitOfWork)
|
||||
// {
|
||||
// for (var i = 0ul; i < 1000000; i++)
|
||||
// {
|
||||
// uow.DiscordUsers.Add(new DiscordUser()
|
||||
// {
|
||||
// AvatarId = i.ToString(),
|
||||
// Discriminator = "1234",
|
||||
// UserId = i,
|
||||
// Username = i.ToString(),
|
||||
// Club = null,
|
||||
// });
|
||||
// var xp = uow.Xp.GetOrCreateUser(Context.Guild.Id, i);
|
||||
// xp.Xp = rng.Next(100, 100000);
|
||||
// }
|
||||
// uow.Complete();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
//todo add ratelimit attribute
|
||||
//[Ratelimit(30)]
|
||||
public async Task Experience([Remainder]IUser user = null)
|
||||
{
|
||||
@ -82,7 +58,7 @@ namespace NadekoBot.Modules.Xp
|
||||
.Take(9);
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle(GetText("role_rewards"))
|
||||
.WithTitle(GetText("level_up_rewards"))
|
||||
.WithOkColor();
|
||||
|
||||
if (!roles.Any())
|
||||
@ -116,6 +92,21 @@ namespace NadekoBot.Modules.Xp
|
||||
await ReplyConfirmLocalized("role_reward_added", level, Format.Bold(role.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpCurrencyReward(int level, int amount=0)
|
||||
{
|
||||
if (level < 1 || amount < 0)
|
||||
return;
|
||||
|
||||
_service.SetCurrencyReward(Context.Guild.Id, level, amount);
|
||||
|
||||
if (amount == 0)
|
||||
await ReplyConfirmLocalized("cur_reward_cleared", level).ConfigureAwait(false);
|
||||
else
|
||||
await ReplyConfirmLocalized("cur_reward_added", level, Format.Bold(amount.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public enum NotifyPlace
|
||||
{
|
||||
Server = 0,
|
||||
|
@ -8,6 +8,7 @@ namespace NadekoBot.Core.Services.Database.Models
|
||||
public GuildConfig GuildConfig { get; set; }
|
||||
|
||||
public HashSet<XpRoleReward> RoleRewards { get; set; } = new HashSet<XpRoleReward>();
|
||||
public HashSet<XpCurrencyReward> CurrencyRewards { get; set; } = new HashSet<XpCurrencyReward>();
|
||||
public bool XpRoleRewardExclusive { get; set; }
|
||||
public string NotifyMessage { get; set; } = "Congratulations {0}! You have reached level {1}!";
|
||||
public HashSet<ExcludedItem> ExclusionList { get; set; } = new HashSet<ExcludedItem>();
|
||||
@ -35,6 +36,25 @@ namespace NadekoBot.Core.Services.Database.Models
|
||||
}
|
||||
}
|
||||
|
||||
public class XpCurrencyReward : DbEntity
|
||||
{
|
||||
public int XpSettingsId { get; set; }
|
||||
public XpSettings XpSettings { get; set; }
|
||||
|
||||
public int Level { get; set; }
|
||||
public int Amount { get; set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is XpCurrencyReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
|
||||
}
|
||||
}
|
||||
|
||||
public class ExcludedItem : DbEntity
|
||||
{
|
||||
public ulong ItemId { get; set; }
|
||||
|
@ -200,6 +200,8 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
set => set.Include(x => x.XpSettings)
|
||||
.ThenInclude(x => x.RoleRewards)
|
||||
.Include(x => x.XpSettings)
|
||||
.ThenInclude(x => x.CurrencyRewards)
|
||||
.Include(x => x.XpSettings)
|
||||
.ThenInclude(x => x.ExclusionList));
|
||||
|
||||
if (gc.XpSettings == null)
|
||||
|
@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly DateTime _started;
|
||||
|
||||
public const string BotVersion = "2.4.4";
|
||||
public const string BotVersion = "2.5.0";
|
||||
|
||||
public string Author => "Kwoth#2560";
|
||||
public string Library => "Discord.Net";
|
||||
|
Loading…
Reference in New Issue
Block a user