Slowmode whitelists done, need testing
This commit is contained in:
parent
3a5aed213b
commit
2b65518649
1435
src/NadekoBot/Migrations/20170401161600_slowmode-whitelist.Designer.cs
generated
Normal file
1435
src/NadekoBot/Migrations/20170401161600_slowmode-whitelist.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class slowmodewhitelist : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SlowmodeIgnoredRole",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
DateAdded = table.Column<DateTime>(nullable: true),
|
||||||
|
GuildConfigId = table.Column<int>(nullable: true),
|
||||||
|
RoleId = table.Column<ulong>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SlowmodeIgnoredRole", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SlowmodeIgnoredRole_GuildConfigs_GuildConfigId",
|
||||||
|
column: x => x.GuildConfigId,
|
||||||
|
principalTable: "GuildConfigs",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SlowmodeIgnoredUser",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
DateAdded = table.Column<DateTime>(nullable: true),
|
||||||
|
GuildConfigId = table.Column<int>(nullable: true),
|
||||||
|
UserId = table.Column<ulong>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SlowmodeIgnoredUser", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_SlowmodeIgnoredUser_GuildConfigs_GuildConfigId",
|
||||||
|
column: x => x.GuildConfigId,
|
||||||
|
principalTable: "GuildConfigs",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_SlowmodeIgnoredRole_GuildConfigId",
|
||||||
|
table: "SlowmodeIgnoredRole",
|
||||||
|
column: "GuildConfigId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_SlowmodeIgnoredUser_GuildConfigId",
|
||||||
|
table: "SlowmodeIgnoredUser",
|
||||||
|
column: "GuildConfigId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SlowmodeIgnoredRole");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SlowmodeIgnoredUser");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -950,6 +950,42 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("SelfAssignableRoles");
|
b.ToTable("SelfAssignableRoles");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateAdded");
|
||||||
|
|
||||||
|
b.Property<int?>("GuildConfigId");
|
||||||
|
|
||||||
|
b.Property<ulong>("RoleId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildConfigId");
|
||||||
|
|
||||||
|
b.ToTable("SlowmodeIgnoredRole");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateAdded");
|
||||||
|
|
||||||
|
b.Property<int?>("GuildConfigId");
|
||||||
|
|
||||||
|
b.Property<ulong>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildConfigId");
|
||||||
|
|
||||||
|
b.ToTable("SlowmodeIgnoredUser");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -1320,6 +1356,20 @@ namespace NadekoBot.Migrations
|
|||||||
.HasForeignKey("BotConfigId");
|
.HasForeignKey("BotConfigId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredRole", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")
|
||||||
|
.WithMany("SlowmodeIgnoredRoles")
|
||||||
|
.HasForeignKey("GuildConfigId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.SlowmodeIgnoredUser", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("NadekoBot.Services.Database.Models.GuildConfig")
|
||||||
|
.WithMany("SlowmodeIgnoredUsers")
|
||||||
|
.HasForeignKey("GuildConfigId");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.StartupCommand", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
using NLog;
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -23,6 +27,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
public class Ratelimiter
|
public class Ratelimiter
|
||||||
{
|
{
|
||||||
|
public HashSet<ulong> IgnoreUsers { get; set; } = new HashSet<ulong>();
|
||||||
|
public HashSet<ulong> IgnoreRoles { get; set; } = new HashSet<ulong>();
|
||||||
|
|
||||||
public class RatelimitedUser
|
public class RatelimitedUser
|
||||||
{
|
{
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
@ -38,10 +45,14 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
public ConcurrentDictionary<ulong, RatelimitedUser> Users { get; set; } = new ConcurrentDictionary<ulong, RatelimitedUser>();
|
public ConcurrentDictionary<ulong, RatelimitedUser> Users { get; set; } = new ConcurrentDictionary<ulong, RatelimitedUser>();
|
||||||
|
|
||||||
public bool CheckUserRatelimit(ulong id)
|
public bool CheckUserRatelimit(ulong id, SocketGuildUser optUser)
|
||||||
{
|
{
|
||||||
|
if (IgnoreUsers.Contains(id) ||
|
||||||
|
(optUser != null && optUser.RoleIds.Any(x => IgnoreRoles.Contains(x))))
|
||||||
|
return false;
|
||||||
|
|
||||||
var usr = Users.GetOrAdd(id, (key) => new RatelimitedUser() { UserId = id });
|
var usr = Users.GetOrAdd(id, (key) => new RatelimitedUser() { UserId = id });
|
||||||
if (usr.MessageCount == MaxMessages)
|
if (usr.MessageCount >= MaxMessages)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -67,8 +78,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var usrMsg = umsg as IUserMessage;
|
var usrMsg = umsg as SocketUserMessage;
|
||||||
var channel = usrMsg?.Channel as ITextChannel;
|
var channel = usrMsg?.Channel as SocketTextChannel;
|
||||||
|
|
||||||
if (channel == null || usrMsg.IsAuthor())
|
if (channel == null || usrMsg.IsAuthor())
|
||||||
return;
|
return;
|
||||||
@ -76,7 +87,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
|
if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
|
if (limiter.CheckUserRatelimit(usrMsg.Author.Id, usrMsg.Author as SocketGuildUser))
|
||||||
await usrMsg.DeleteAsync();
|
await usrMsg.DeleteAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex) { _log.Warn(ex); }
|
catch (Exception ex) { _log.Warn(ex); }
|
||||||
@ -122,29 +133,76 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//[RequireUserPermission(GuildPermission.ManageMessages)]
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||||
//public async Task SlowmodeWhitelist(IUser user)
|
[Priority(1)]
|
||||||
//{
|
public async Task SlowmodeWhitelist(IUser user)
|
||||||
// Ratelimiter throwaway;
|
{
|
||||||
// if (RatelimitingChannels.TryRemove(Context.Channel.Id, out throwaway))
|
var siu = new SlowmodeIgnoredUser
|
||||||
// {
|
{
|
||||||
// throwaway.cancelSource.Cancel();
|
UserId = user.Id
|
||||||
// await ReplyConfirmLocalized("slowmode_disabled").ConfigureAwait(false);
|
};
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//[NadekoCommand, Usage, Description, Aliases]
|
HashSet<SlowmodeIgnoredUser> usrs;
|
||||||
//[RequireContext(ContextType.Guild)]
|
bool removed;
|
||||||
//[RequireUserPermission(GuildPermission.ManageMessages)]
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
//public async Task SlowmodeWhitelist(IRole role)
|
{
|
||||||
//{
|
usrs = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.SlowmodeIgnoredUsers))
|
||||||
// using (var uow = DbHandler.UnitOfWork())
|
.SlowmodeIgnoredUsers;
|
||||||
// {
|
|
||||||
// uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.SlowmodeWhitelists)).
|
if (!(removed = usrs.Remove(siu)))
|
||||||
// }
|
usrs.Add(siu);
|
||||||
//}
|
|
||||||
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ratelimiter rl;
|
||||||
|
if (RatelimitingChannels.TryGetValue(Context.Guild.Id, out rl))
|
||||||
|
{
|
||||||
|
rl.IgnoreUsers = new HashSet<ulong>(usrs.Select(x => x.UserId));
|
||||||
|
}
|
||||||
|
if(removed)
|
||||||
|
await ReplyConfirmLocalized("slowmodewl_user_stop", Format.Bold(user.ToString())).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await ReplyConfirmLocalized("slowmodewl_user_start", Format.Bold(user.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||||
|
[Priority(0)]
|
||||||
|
public async Task SlowmodeWhitelist(IRole role)
|
||||||
|
{
|
||||||
|
var sir = new SlowmodeIgnoredRole
|
||||||
|
{
|
||||||
|
RoleId = role.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
HashSet<SlowmodeIgnoredRole> roles;
|
||||||
|
bool removed;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
roles = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.SlowmodeIgnoredRoles))
|
||||||
|
.SlowmodeIgnoredRoles;
|
||||||
|
|
||||||
|
if (!(removed = roles.Remove(sir)))
|
||||||
|
roles.Add(sir);
|
||||||
|
|
||||||
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ratelimiter rl;
|
||||||
|
if (RatelimitingChannels.TryGetValue(Context.Guild.Id, out rl))
|
||||||
|
{
|
||||||
|
rl.IgnoreRoles = new HashSet<ulong>(roles.Select(x => x.RoleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removed)
|
||||||
|
await ReplyConfirmLocalized("slowmodewl_role_stop", Format.Bold(role.ToString())).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await ReplyConfirmLocalized("slowmodewl_role_start", Format.Bold(role.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,6 +9,9 @@
|
|||||||
//using System.Threading;
|
//using System.Threading;
|
||||||
//using System;
|
//using System;
|
||||||
//using System.Collections.Immutable;
|
//using System.Collections.Immutable;
|
||||||
|
//using NadekoBot.Services;
|
||||||
|
//using NadekoBot.Services.Database.Models;
|
||||||
|
//using NadekoBot.Extensions;
|
||||||
|
|
||||||
//namespace NadekoBot.Modules.Utility
|
//namespace NadekoBot.Modules.Utility
|
||||||
//{
|
//{
|
||||||
@ -17,20 +20,45 @@
|
|||||||
// [Group]
|
// [Group]
|
||||||
// public class PatreonCommands : NadekoSubmodule
|
// public class PatreonCommands : NadekoSubmodule
|
||||||
// {
|
// {
|
||||||
|
// private static readonly PatreonThingy patreon;
|
||||||
|
|
||||||
|
// static PatreonCommands()
|
||||||
|
// {
|
||||||
|
// patreon = PatreonThingy.Instance;
|
||||||
|
// }
|
||||||
// [NadekoCommand, Usage, Description, Aliases]
|
// [NadekoCommand, Usage, Description, Aliases]
|
||||||
// public async Task ClaimPatreonRewards()
|
// public async Task ClaimPatreonRewards()
|
||||||
// {
|
// {
|
||||||
// var patreon = PatreonThingy.Instance;
|
// if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
|
||||||
|
// return;
|
||||||
// var pledges = (await patreon.GetPledges().ConfigureAwait(false))
|
// if (DateTime.UtcNow.Day < 5)
|
||||||
// .OrderByDescending(x => x.Reward.attributes.amount_cents);
|
|
||||||
|
|
||||||
// if (pledges == null)
|
|
||||||
// {
|
// {
|
||||||
// await ReplyErrorLocalized("pledges_loading").ConfigureAwait(false);
|
// await ReplyErrorLocalized("claimpatreon_too_early").ConfigureAwait(false);
|
||||||
|
// }
|
||||||
|
// int amount = 0;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// amount = await patreon.ClaimReward(Context.User.Id).ConfigureAwait(false);
|
||||||
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// _log.Warn(ex);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (amount > 0)
|
||||||
|
// {
|
||||||
|
// await ReplyConfirmLocalized("claimpatreon_success", amount).ConfigureAwait(false);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// await Context.Channel.EmbedAsync(new Discord.EmbedBuilder().WithOkColor()
|
||||||
|
// .WithDescription(GetText("claimpatreon_fail"))
|
||||||
|
// .AddField(efb => efb.WithName("").WithValue(""))
|
||||||
|
// .AddField(efb => efb.WithName("").WithValue(""))
|
||||||
|
// .AddField(efb => efb.WithName("").WithValue("")))
|
||||||
|
// .ConfigureAwait(false);
|
||||||
|
|
||||||
|
// await ReplyErrorLocalized("claimpatreon_fail").ConfigureAwait(false);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -41,21 +69,16 @@
|
|||||||
|
|
||||||
// private readonly SemaphoreSlim getPledgesLocker = new SemaphoreSlim(1, 1);
|
// private readonly SemaphoreSlim getPledgesLocker = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
// private ImmutableArray<PatreonUserAndReward> pledges;
|
// public ImmutableArray<PatreonUserAndReward> Pledges { get; private set; }
|
||||||
|
|
||||||
// static PatreonThingy() { }
|
// private readonly Timer update;
|
||||||
|
// private readonly SemaphoreSlim claimLockJustInCase = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
// public async Task<ImmutableArray<PatreonUserAndReward>> GetPledges()
|
// private PatreonThingy()
|
||||||
// {
|
// {
|
||||||
// try
|
// if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
|
||||||
// {
|
// return;
|
||||||
// await LoadPledges().ConfigureAwait(false);
|
// update = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, TimeSpan.FromHours(3));
|
||||||
// return pledges;
|
|
||||||
// }
|
|
||||||
// catch (OperationCanceledException)
|
|
||||||
// {
|
|
||||||
// return pledges;
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// public async Task LoadPledges()
|
// public async Task LoadPledges()
|
||||||
@ -89,7 +112,7 @@
|
|||||||
// .Select(x => JsonConvert.DeserializeObject<PatreonUser>(x.ToString())));
|
// .Select(x => JsonConvert.DeserializeObject<PatreonUser>(x.ToString())));
|
||||||
// } while (!string.IsNullOrWhiteSpace(data.Links.next));
|
// } while (!string.IsNullOrWhiteSpace(data.Links.next));
|
||||||
// }
|
// }
|
||||||
// pledges = rewards.Join(users, (r) => r.relationships?.patron?.data?.id, (u) => u.id, (x, y) => new PatreonUserAndReward()
|
// Pledges = rewards.Join(users, (r) => r.relationships?.patron?.data?.id, (u) => u.id, (x, y) => new PatreonUserAndReward()
|
||||||
// {
|
// {
|
||||||
// User = y,
|
// User = y,
|
||||||
// Reward = x,
|
// Reward = x,
|
||||||
@ -102,7 +125,55 @@
|
|||||||
// await Task.Delay(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
|
// await Task.Delay(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
|
||||||
// getPledgesLocker.Release();
|
// getPledgesLocker.Release();
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public async Task<int> ClaimReward(ulong userId)
|
||||||
|
// {
|
||||||
|
// await claimLockJustInCase.WaitAsync();
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// var data = Pledges.FirstOrDefault(x => x.User.id == userId.ToString());
|
||||||
|
|
||||||
|
// if (data == null)
|
||||||
|
// return 0;
|
||||||
|
|
||||||
|
// var amount = data.Reward.attributes.amount_cents;
|
||||||
|
|
||||||
|
// using (var uow = DbHandler.UnitOfWork())
|
||||||
|
// {
|
||||||
|
// var users = uow._context.Set<RewardedUser>();
|
||||||
|
// var usr = users.FirstOrDefault(x => x.UserId == userId);
|
||||||
|
|
||||||
|
// if (usr == null)
|
||||||
|
// {
|
||||||
|
// users.Add(new RewardedUser()
|
||||||
|
// {
|
||||||
|
// UserId = userId,
|
||||||
|
// LastReward = DateTime.UtcNow,
|
||||||
|
// AmountRewardedThisMonth = amount,
|
||||||
|
// });
|
||||||
|
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
|
// return amount;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (usr.AmountRewardedThisMonth < amount)
|
||||||
|
// {
|
||||||
|
// var toAward = amount - usr.AmountRewardedThisMonth;
|
||||||
|
|
||||||
|
// usr.LastReward = DateTime.UtcNow;
|
||||||
|
// usr.AmountRewardedThisMonth = amount;
|
||||||
|
|
||||||
|
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
|
// return toAward;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// finally
|
||||||
|
// {
|
||||||
|
// claimLockJustInCase.Release();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
54
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
54
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -1706,6 +1706,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to claimpatreonrewards.
|
||||||
|
/// </summary>
|
||||||
|
public static string claimpatreonrewards_cmd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("claimpatreonrewards_cmd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to If you're subscribed to bot owner's patreon you can user this command to claim your rewards - assuming bot owner did setup has their patreon key..
|
||||||
|
/// </summary>
|
||||||
|
public static string claimpatreonrewards_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("claimpatreonrewards_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `{0}claimpatreonrewards`.
|
||||||
|
/// </summary>
|
||||||
|
public static string claimpatreonrewards_usage {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("claimpatreonrewards_usage", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to cleanup.
|
/// Looks up a localized string similar to cleanup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -7673,6 +7700,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to slowmodewl.
|
||||||
|
/// </summary>
|
||||||
|
public static string slowmodewhitelist_cmd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("slowmodewhitelist_cmd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Ignores a role or a user from the slowmode feature..
|
||||||
|
/// </summary>
|
||||||
|
public static string slowmodewhitelist_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("slowmodewhitelist_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`.
|
||||||
|
/// </summary>
|
||||||
|
public static string slowmodewhitelist_usage {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("slowmodewhitelist_usage", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to softban sb.
|
/// Looks up a localized string similar to softban sb.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3321,4 +3321,22 @@
|
|||||||
<data name="warnpunish_usage" xml:space="preserve">
|
<data name="warnpunish_usage" xml:space="preserve">
|
||||||
<value>`{0}warnpunish 5 Ban` or `{0}warnpunish 3`</value>
|
<value>`{0}warnpunish 5 Ban` or `{0}warnpunish 3`</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="claimpatreonrewards_cmd" xml:space="preserve">
|
||||||
|
<value>claimpatreonrewards</value>
|
||||||
|
</data>
|
||||||
|
<data name="claimpatreonrewards_desc" xml:space="preserve">
|
||||||
|
<value>If you're subscribed to bot owner's patreon you can user this command to claim your rewards - assuming bot owner did setup has their patreon key.</value>
|
||||||
|
</data>
|
||||||
|
<data name="claimpatreonrewards_usage" xml:space="preserve">
|
||||||
|
<value>`{0}claimpatreonrewards`</value>
|
||||||
|
</data>
|
||||||
|
<data name="slowmodewhitelist_cmd" xml:space="preserve">
|
||||||
|
<value>slowmodewl</value>
|
||||||
|
</data>
|
||||||
|
<data name="slowmodewhitelist_desc" xml:space="preserve">
|
||||||
|
<value>Ignores a role or a user from the slowmode feature.</value>
|
||||||
|
</data>
|
||||||
|
<data name="slowmodewhitelist_usage" xml:space="preserve">
|
||||||
|
<value>`{0}slowmodewl SomeRole` or `{0}slowmodewl AdminDude`</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
117
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
117
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
@ -1512,6 +1512,42 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Slowmode will now ignore role {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string administration_slowmodewl_role_start {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("administration_slowmodewl_role_start", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Slowmode will no longer ignore role {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string administration_slowmodewl_role_stop {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("administration_slowmodewl_role_stop", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Slowmode will now ignore user {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string administration_slowmodewl_user_start {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("administration_slowmodewl_user_start", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Slowmode will no longer ignore user {0}.
|
||||||
|
/// </summary>
|
||||||
|
public static string administration_slowmodewl_user_stop {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("administration_slowmodewl_user_stop", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to soft-banned.
|
/// Looks up a localized string similar to soft-banned.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -5989,6 +6025,87 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Failed claiming rewards due to one of the following reasons:.
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Maybe you have already received your reward for this month. You can receive rewards only once a month unless you increase your pledge..
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_already {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_already", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Already rewarded.
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_already_title {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_already_title", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to In order to be eligible for the reward, you must support the project on patreon. Use {0} command to get the link..
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_sup {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_sup", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Not supporting.
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_sup_title {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_sup_title", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to You have to wait a few hours after making your pledge, if you didn't, waiut a bit and then try again later..
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_wait {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_wait", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Wait some time.
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_fail_wait_title {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_fail_wait_title", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to You've received {0}. Thanks for supporting the project!.
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_success {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_success", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Rewards can be claimed on or after 5th of each month..
|
||||||
|
/// </summary>
|
||||||
|
public static string utility_claimpatreon_too_early {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("utility_claimpatreon_too_early", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Commands ran.
|
/// Looks up a localized string similar to Commands ran.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2357,4 +2357,43 @@ Owner ID: {2}</value>
|
|||||||
<data name="administration_warn_punish_set" xml:space="preserve">
|
<data name="administration_warn_punish_set" xml:space="preserve">
|
||||||
<value>I will apply {0} punishment to users with {1} warnings.</value>
|
<value>I will apply {0} punishment to users with {1} warnings.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="administration_slowmodewl_role_start" xml:space="preserve">
|
||||||
|
<value>Slowmode will now ignore role {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="administration_slowmodewl_role_stop" xml:space="preserve">
|
||||||
|
<value>Slowmode will no longer ignore role {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="administration_slowmodewl_user_start" xml:space="preserve">
|
||||||
|
<value>Slowmode will now ignore user {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="administration_slowmodewl_user_stop" xml:space="preserve">
|
||||||
|
<value>Slowmode will no longer ignore user {0}</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail" xml:space="preserve">
|
||||||
|
<value>Failed claiming rewards due to one of the following reasons:</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_already" xml:space="preserve">
|
||||||
|
<value>Maybe you have already received your reward for this month. You can receive rewards only once a month unless you increase your pledge.</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_already_title" xml:space="preserve">
|
||||||
|
<value>Already rewarded</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_sup" xml:space="preserve">
|
||||||
|
<value>In order to be eligible for the reward, you must support the project on patreon. Use {0} command to get the link.</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_sup_title" xml:space="preserve">
|
||||||
|
<value>Not supporting</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_wait" xml:space="preserve">
|
||||||
|
<value>You have to wait a few hours after making your pledge, if you didn't, waiut a bit and then try again later.</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_fail_wait_title" xml:space="preserve">
|
||||||
|
<value>Wait some time</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_success" xml:space="preserve">
|
||||||
|
<value>You've received {0}. Thanks for supporting the project!</value>
|
||||||
|
</data>
|
||||||
|
<data name="utility_claimpatreon_too_early" xml:space="preserve">
|
||||||
|
<value>Rewards can be claimed on or after 5th of each month.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -73,10 +73,56 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public HashSet<CommandAlias> CommandAliases { get; set; } = new HashSet<CommandAlias>();
|
public HashSet<CommandAlias> CommandAliases { get; set; } = new HashSet<CommandAlias>();
|
||||||
public List<WarningPunishment> WarnPunishments { get; set; } = new List<WarningPunishment>();
|
public List<WarningPunishment> WarnPunishments { get; set; } = new List<WarningPunishment>();
|
||||||
public bool WarningsInitialized { get; set; }
|
public bool WarningsInitialized { get; set; }
|
||||||
|
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
|
||||||
|
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
|
||||||
|
|
||||||
//public List<ProtectionIgnoredChannel> ProtectionIgnoredChannels { get; set; } = new List<ProtectionIgnoredChannel>();
|
//public List<ProtectionIgnoredChannel> ProtectionIgnoredChannels { get; set; } = new List<ProtectionIgnoredChannel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SlowmodeIgnoredUser : DbEntity
|
||||||
|
{
|
||||||
|
public ulong UserId { get; set; }
|
||||||
|
|
||||||
|
// override object.Equals
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || GetType() != obj.GetType())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((SlowmodeIgnoredUser)obj).UserId == UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// override object.GetHashCode
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return UserId.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SlowmodeIgnoredRole : DbEntity
|
||||||
|
{
|
||||||
|
public ulong RoleId { get; set; }
|
||||||
|
|
||||||
|
// override object.Equals
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || GetType() != obj.GetType())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((SlowmodeIgnoredRole)obj).RoleId == RoleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// override object.GetHashCode
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return RoleId.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class WarningPunishment : DbEntity
|
public class WarningPunishment : DbEntity
|
||||||
{
|
{
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
11
src/NadekoBot/Services/Database/Models/RewardedUser.cs
Normal file
11
src/NadekoBot/Services/Database/Models/RewardedUser.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//using System;
|
||||||
|
|
||||||
|
//namespace NadekoBot.Services.Database.Models
|
||||||
|
//{
|
||||||
|
// public class RewardedUser
|
||||||
|
// {
|
||||||
|
// public ulong UserId { get; set; }
|
||||||
|
// public int AmountRewardedThisMonth { get; set; }
|
||||||
|
// public DateTime LastReward { get; set; }
|
||||||
|
// }
|
||||||
|
//}
|
Loading…
Reference in New Issue
Block a user