Merge branch 'wip' into 1.9
This commit is contained in:
commit
dad87457bf
@ -18,10 +18,15 @@ namespace NadekoBot.Modules.Administration
|
||||
public class UserPunishCommands : NadekoSubmodule<UserPunishService>
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
public UserPunishCommands(DbService db, MuteService muteService)
|
||||
public UserPunishCommands(DbService db, MuteService muteService,
|
||||
CurrencyService cs, IBotConfigProvider bc)
|
||||
{
|
||||
_db = db;
|
||||
_cs = cs;
|
||||
_bc = bc;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -397,6 +402,92 @@ namespace NadekoBot.Modules.Administration
|
||||
.AddField(efb => efb.WithName("ID").WithValue(user.Id.ToString()).WithIsInline(true)))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireUserPermission(GuildPermission.BanMembers)]
|
||||
[RequireBotPermission(GuildPermission.BanMembers)]
|
||||
[OwnerOnly]
|
||||
public async Task MassKill([Remainder] string people)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(people))
|
||||
return;
|
||||
|
||||
var gusers = ((SocketGuild)Context.Guild).Users;
|
||||
//get user objects and reasons
|
||||
var bans = people.Split("\n")
|
||||
.Select(x =>
|
||||
{
|
||||
var split = x.Trim().Split(" ");
|
||||
|
||||
var reason = string.Join(" ", split.Skip(1));
|
||||
|
||||
if (ulong.TryParse(split[0], out var id))
|
||||
return (Original: split[0], Id: id, Reason: reason);
|
||||
|
||||
return (Original: split[0],
|
||||
Id: gusers
|
||||
.FirstOrDefault(u => u.ToString().ToLowerInvariant() == x)
|
||||
?.Id,
|
||||
Reason: reason);
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
//if user is null, means that person couldn't be found
|
||||
var missing = bans
|
||||
.Where(x => !x.Id.HasValue)
|
||||
.ToArray();
|
||||
|
||||
//get only data for found users
|
||||
var found = bans
|
||||
.Where(x => x.Id.HasValue)
|
||||
.Select(x => x.Id.Value)
|
||||
.ToArray();
|
||||
|
||||
var missStr = string.Join("\n", missing);
|
||||
if (string.IsNullOrWhiteSpace(missStr))
|
||||
missStr = "-";
|
||||
|
||||
//send a message but don't wait for it
|
||||
var banningMessageTask = Context.Channel.EmbedAsync(new EmbedBuilder()
|
||||
.WithDescription(GetText("mass_kill_in_progress", bans.Length))
|
||||
.AddField(GetText("invalid", missing.Length), missStr)
|
||||
.WithOkColor());
|
||||
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.Blacklist));
|
||||
//blacklist the users
|
||||
bc.Blacklist.AddRange(found.Select(x =>
|
||||
new BlacklistItem
|
||||
{
|
||||
ItemId = x,
|
||||
Type = BlacklistType.User,
|
||||
}));
|
||||
//clear their currencies
|
||||
uow.Currency.RemoveFromMany(found.Select(x => (long)x).ToList());
|
||||
uow.Complete();
|
||||
}
|
||||
|
||||
_bc.Reload();
|
||||
|
||||
//do the banning
|
||||
await Task.WhenAll(bans
|
||||
.Where(x => x.Id.HasValue)
|
||||
.Select(x => Context.Guild.AddBanAsync(x.Id.Value, 7, x.Reason, new RequestOptions() {
|
||||
RetryMode = RetryMode.AlwaysRetry,
|
||||
})))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
//wait for the message and edit it
|
||||
var banningMessage = await banningMessageTask.ConfigureAwait(false);
|
||||
|
||||
await banningMessage.ModifyAsync(x => x.Embed = new EmbedBuilder()
|
||||
.WithDescription(GetText("mass_kill_completed", bans.Length))
|
||||
.AddField(GetText("invalid", missing.Length), missStr)
|
||||
.WithOkColor()
|
||||
.Build()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,22 @@ namespace NadekoBot.Modules.Gambling
|
||||
await Context.Channel.SendConfirmAsync("🎟 "+ GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RaffleAny([Remainder] IRole role = null)
|
||||
{
|
||||
role = role ?? Context.Guild.EveryoneRole;
|
||||
|
||||
var members = (await role.GetMembersAsync());
|
||||
var membersArray = members as IUser[] ?? members.ToArray();
|
||||
if (membersArray.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
|
||||
await Context.Channel.SendConfirmAsync("🎟 " + GetText("raffled_user"), $"**{usr.Username}#{usr.Discriminator}**", footer: $"ID: {usr.Id}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[Priority(1)]
|
||||
public async Task Cash([Remainder] IUser user = null)
|
||||
|
@ -53,10 +53,28 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
private readonly ConcurrentDictionary<ulong, HashSet<string>> _blacklistedTags = new ConcurrentDictionary<ulong, HashSet<string>>();
|
||||
private readonly Timer _t;
|
||||
|
||||
private readonly SemaphoreSlim _cryptoLock = new SemaphoreSlim(1, 1);
|
||||
public async Task<CryptoData[]> CryptoData()
|
||||
{
|
||||
var data = await _cache.Redis.GetDatabase()
|
||||
.StringGetAsync("crypto_data").ConfigureAwait(false);
|
||||
string data;
|
||||
var r = _cache.Redis.GetDatabase();
|
||||
await _cryptoLock.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
data = await r.StringGetAsync("crypto_data").ConfigureAwait(false);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
data = await Http.GetStringAsync("https://api.coinmarketcap.com/v1/ticker/")
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await r.StringSetAsync("crypto_data", data, TimeSpan.FromHours(6)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_cryptoLock.Release();
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<CryptoData[]>(data);
|
||||
}
|
||||
@ -121,14 +139,7 @@ namespace NadekoBot.Modules.Searches.Services
|
||||
var r = _cache.Redis.GetDatabase();
|
||||
try
|
||||
{
|
||||
var data = (string)(await r.StringGetAsync("crypto_data").ConfigureAwait(false));
|
||||
if (data == null)
|
||||
{
|
||||
data = await Http.GetStringAsync("https://api.coinmarketcap.com/v1/ticker/")
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await r.StringSetAsync("crypto_data", data, TimeSpan.FromHours(6)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -9,5 +9,6 @@ namespace NadekoBot.Core.Services.Database.Repositories
|
||||
long GetUserCurrency(ulong userId);
|
||||
bool TryUpdateState(ulong userId, long change);
|
||||
IEnumerable<Currency> GetTopRichest(int count, int skip);
|
||||
void RemoveFromMany(List<long> ids);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
public long GetUserCurrency(ulong userId) =>
|
||||
GetOrCreate(userId).Amount;
|
||||
|
||||
public void RemoveFromMany(List<long> ids)
|
||||
{
|
||||
_set.RemoveRange(_set.Where(x => ids.Contains((long)x.UserId)));
|
||||
}
|
||||
|
||||
public bool TryUpdateState(ulong userId, long change)
|
||||
{
|
||||
var cur = GetOrCreate(userId);
|
||||
|
@ -6,11 +6,14 @@ namespace NadekoBot.Core.Services.Impl
|
||||
public class BotConfigProvider : IBotConfigProvider
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly IDataCache _cache;
|
||||
|
||||
public BotConfig BotConfig { get; private set; }
|
||||
|
||||
public BotConfigProvider(DbService db, BotConfig bc)
|
||||
public BotConfigProvider(DbService db, BotConfig bc, IDataCache cache)
|
||||
{
|
||||
_db = db;
|
||||
_cache = cache;
|
||||
BotConfig = bc;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ namespace NadekoBot
|
||||
{
|
||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
|
||||
IBotConfigProvider botConfigProvider = new BotConfigProvider(_db, _botConfig);
|
||||
IBotConfigProvider botConfigProvider = new BotConfigProvider(_db, _botConfig, Cache);
|
||||
|
||||
//initialize Services
|
||||
Services = new NServiceProvider()
|
||||
|
@ -919,5 +919,8 @@
|
||||
"searches_crypto_not_found": "Cryptocurrency with that name was not found.",
|
||||
"searches_did_you_mean": "Did you mean {0}?",
|
||||
"administration_self_assign_level_req": "Self assignable role {0} now requires at least server level {1}.",
|
||||
"administration_self_assign_not_level": "That self-assignable role requires at least server level {0}."
|
||||
"administration_self_assign_not_level": "That self-assignable role requires at least server level {0}.",
|
||||
"administration_invalid": "Invalid / Can't be found ({0})",
|
||||
"administration_mass_kill_in_progress": "Mass Banning and Blacklisting of {0} users is in progress...",
|
||||
"administration_mass_kill_completed": "Mass Banning and Blacklisting of {0} users is complete."
|
||||
}
|
@ -940,12 +940,20 @@
|
||||
},
|
||||
"raffle": {
|
||||
"Cmd": "raffle",
|
||||
"Desc": "Prints a name and ID of a random user from the online list from the (optional) role.",
|
||||
"Desc": "Prints a name and ID of a random online user from the server, or from the online user in the specified role.",
|
||||
"Usage": [
|
||||
"{0}raffle",
|
||||
"{0}raffle RoleName"
|
||||
]
|
||||
},
|
||||
"raffleany": {
|
||||
"Cmd": "raffleany",
|
||||
"Desc": "Prints a name and ID of a random user from the server, or from the specified role.",
|
||||
"Usage": [
|
||||
"{0}raffleany",
|
||||
"{0}raffleany RoleName"
|
||||
]
|
||||
},
|
||||
"give": {
|
||||
"Cmd": "give",
|
||||
"Desc": "Give someone a certain amount of currency.",
|
||||
@ -3105,5 +3113,12 @@
|
||||
"usage": [
|
||||
"{0}rlr 5 SomeRole"
|
||||
]
|
||||
},
|
||||
"masskill": {
|
||||
"cmd": "masskill",
|
||||
"desc": "Specify a new-line separated list of `userid reason`. You can use Username#discrim instead of UserId. Specified users will be banned from the current server, blacklisted from the bot, and have all of their flowers taken away.",
|
||||
"usage": [
|
||||
"{0}masskill BadPerson#1234 Toxic person"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user