Fixed an issue where using .prune wouldn't work if there was a message older than 2 weeks in the last 100 messages. Also some string fixes

This commit is contained in:
Master Kwoth 2017-05-16 23:57:25 +02:00
parent 1cd7852674
commit 631e17a569
3 changed files with 15 additions and 7 deletions

View File

@ -381,12 +381,14 @@ namespace NadekoBot.Modules.Administration
{ {
var user = await Context.Guild.GetCurrentUserAsync().ConfigureAwait(false); var user = await Context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
var enumerable = (await Context.Channel.GetMessagesAsync().Flatten()).AsEnumerable(); var enumerable = (await Context.Channel.GetMessagesAsync().Flatten())
enumerable = enumerable.Where(x => x.Author.Id == user.Id); .Where(x => x.Author.Id == user.Id && DateTime.Now - x.CreatedAt < twoWeeks);
await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false); await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false);
Context.Message.DeleteAfter(3); Context.Message.DeleteAfter(3);
} }
private TimeSpan twoWeeks => TimeSpan.FromDays(14);
// prune x // prune x
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
@ -399,7 +401,8 @@ namespace NadekoBot.Modules.Administration
return; return;
await Context.Message.DeleteAsync().ConfigureAwait(false); await Context.Message.DeleteAsync().ConfigureAwait(false);
int limit = (count < 100) ? count + 1 : 100; int limit = (count < 100) ? count + 1 : 100;
var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten().ConfigureAwait(false)); var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten().ConfigureAwait(false))
.Where(x => DateTime.Now - x.CreatedAt < twoWeeks);
if (enumerable.FirstOrDefault()?.Id == Context.Message.Id) if (enumerable.FirstOrDefault()?.Id == Context.Message.Id)
enumerable = enumerable.Skip(1).ToArray(); enumerable = enumerable.Skip(1).ToArray();
else else
@ -422,7 +425,8 @@ namespace NadekoBot.Modules.Administration
count += 1; count += 1;
int limit = (count < 100) ? count : 100; int limit = (count < 100) ? count : 100;
var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten()).Where(m => m.Author == user); var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten())
.Where(m => m.Author == user && DateTime.Now - m.CreatedAt < twoWeeks);
await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false); await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false);
Context.Message.DeleteAfter(3); Context.Message.DeleteAfter(3);
@ -437,7 +441,9 @@ namespace NadekoBot.Modules.Administration
foreach (var role in roles) foreach (var role in roles)
{ {
send += $"\n**{role.Name}**\n"; send += $"\n**{role.Name}**\n";
send += string.Join(", ", (await Context.Guild.GetUsersAsync()).Where(u => u.GetRoles().Contains(role)).Take(50).Select(u => u.Mention)); send += string.Join(", ", (await Context.Guild.GetUsersAsync())
.Where(u => u.GetRoles().Contains(role))
.Take(50).Select(u => u.Mention));
} }
while (send.Length > 2000) while (send.Length > 2000)

View File

@ -173,6 +173,8 @@ namespace NadekoBot.Modules.Gambling
amount + CurrencySign); amount + CurrencySign);
if (w.Affinity?.UserId == Context.User.Id) if (w.Affinity?.UserId == Context.User.Id)
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign); msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign);
else
msg = " " + msg;
await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false); await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
} }

View File

@ -2038,7 +2038,7 @@
<value>chucknorris cn</value> <value>chucknorris cn</value>
</data> </data>
<data name="chucknorris_desc" xml:space="preserve"> <data name="chucknorris_desc" xml:space="preserve">
<value>Shows a random Chuck Norris joke from &lt;http://tambal.azurewebsites.net/joke/random&gt;</value> <value>Shows a random Chuck Norris joke from &lt;http://api.icndb.com/jokes/random/&gt;</value>
</data> </data>
<data name="chucknorris_usage" xml:space="preserve"> <data name="chucknorris_usage" xml:space="preserve">
<value>`{0}cn`</value> <value>`{0}cn`</value>
@ -3406,7 +3406,7 @@
<value>Toggles if this role is displayed in the sidebar or not</value> <value>Toggles if this role is displayed in the sidebar or not</value>
</data> </data>
<data name="rolehoist_usage" xml:space="preserve"> <data name="rolehoist_usage" xml:space="preserve">
<value>`{0}rh Guests true` or `{0}rh "Space Wizards" true</value> <value>`{0}rh Guests true` or `{0}rh "Space Wizards" true`</value>
</data> </data>
<data name="buy_cmd" xml:space="preserve"> <data name="buy_cmd" xml:space="preserve">
<value>buy</value> <value>buy</value>