Merge remote-tracking branch 'Kwoth/1.9' into 1.9

This commit is contained in:
Shikhir Arora
2017-11-13 17:23:29 -05:00
16 changed files with 205 additions and 47 deletions

View File

@ -261,7 +261,7 @@ namespace NadekoBot.Modules.Administration
public async Task CreatVoiChanl([Remainder] string channelName)
{
var ch = await Context.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false);
await ReplyConfirmLocalized("createvoich",Format.Bold(ch.Name)).ConfigureAwait(false);
await ReplyConfirmLocalized("createvoich", Format.Bold(ch.Name)).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -312,7 +312,7 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.MentionEveryone)]
public async Task MentionRole(params IRole[] roles)
{
string send = "❕" +GetText("menrole",Context.User.Mention);
string send = "❕" + GetText("menrole", Context.User.Mention);
foreach (var role in roles)
{
send += $"\n**{role.Name}**\n";

View File

@ -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]
@ -101,7 +106,7 @@ namespace NadekoBot.Modules.Administration
var embed = new EmbedBuilder().WithOkColor()
.WithTitle(GetText("warnlog_for", (Context.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString()))
.WithFooter(efb => efb.WithText(GetText("page", page + 1)));
.WithFooter(efb => efb.WithText(GetText("page", page + 1)));
if (!warnings.Any())
{
@ -202,8 +207,8 @@ namespace NadekoBot.Modules.Administration
uow.Complete();
}
await ReplyConfirmLocalized("warn_punish_set",
Format.Bold(punish.ToString()),
await ReplyConfirmLocalized("warn_punish_set",
Format.Bold(punish.ToString()),
Format.Bold(number.ToString())).ConfigureAwait(false);
}
@ -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);
}
}
}
}

View File

@ -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)

View File

@ -26,7 +26,7 @@ namespace NadekoBot.Modules.Searches
if (novelData == null)
{
await ReplyErrorLocalized("failed_finding_novel").ConfigureAwait(false);
await ReplyErrorLocalized("error_finding_novel").ConfigureAwait(false);
return;
}

View File

@ -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(1)).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)
{