Merge remote-tracking branch 'refs/remotes/Kwoth/1.4' into 1.4

This commit is contained in:
samvaio 2017-06-17 00:00:08 +05:30
commit e17163170d
21 changed files with 1668 additions and 43 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class maxdropamount : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "CurrencyDropAmountMax",
table: "BotConfig",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CurrencyDropAmountMax",
table: "BotConfig");
}
}
}

View File

@ -137,6 +137,8 @@ namespace NadekoBot.Migrations
b.Property<int>("CurrencyDropAmount");
b.Property<int?>("CurrencyDropAmountMax");
b.Property<float>("CurrencyGenerationChance");
b.Property<int>("CurrencyGenerationCooldown");

View File

@ -359,12 +359,14 @@ namespace NadekoBot.Modules.Administration
if (count < 1)
return;
if (count > 100)
count = 100;
if (user.Id == Context.User.Id)
count += 1;
int limit = (count < 100) ? count : 100;
var enumerable = (await Context.Channel.GetMessagesAsync(limit: limit).Flatten())
.Where(m => m.Author == user && DateTime.UtcNow - m.CreatedAt < twoWeeks);
var enumerable = (await Context.Channel.GetMessagesAsync().Flatten())
.Where(m => m.Author.Id == user.Id && DateTime.UtcNow - m.CreatedAt < twoWeeks)
.Take(count);
await Context.Channel.DeleteMessagesAsync(enumerable).ConfigureAwait(false);
Context.Message.DeleteAfter(3);

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
@ -105,8 +106,11 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Lsar()
public async Task Lsar(int page = 1)
{
if (--page < 0)
return;
var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
var removeMsg = new StringBuilder();
var roles = new List<string>();
@ -131,11 +135,18 @@ namespace NadekoBot.Modules.Administration
}
foreach (var role in toRemove)
{
removeMsg.AppendLine(GetText("role_clean", role.RoleId));
roles.Add(GetText("role_clean", role.RoleId));
}
await uow.CompleteAsync();
}
await Context.Channel.SendConfirmAsync(GetText("self_assign_list", roleCnt), "\n" + string.Join(", ", roles) + "\n\n" + removeMsg).ConfigureAwait(false);
await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page, (curPage) =>
{
return new EmbedBuilder()
.WithTitle(GetText("self_assign_list", roleCnt))
.WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10)))
.WithOkColor();
}, roles.Count / 10);
}
[NadekoCommand, Usage, Description, Aliases]

View File

@ -26,7 +26,7 @@ namespace NadekoBot.Modules.Administration
[RequireContext(ContextType.Guild)]
public async Task Timezones(int page = 1)
{
page -= 1;
page--;
if (page < 0 || page > 20)
return;
@ -36,11 +36,11 @@ namespace NadekoBot.Modules.Administration
.ToArray();
var timezonesPerPage = 20;
await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page + 1,
await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page,
(curPage) => new EmbedBuilder()
.WithOkColor()
.WithTitle(GetText("timezones_available"))
.WithDescription(string.Join("\n", timezones.Skip((curPage - 1) * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
.WithDescription(string.Join("\n", timezones.Skip(curPage * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
timezones.Length / timezonesPerPage);
}

View File

@ -87,7 +87,7 @@ namespace NadekoBot.Modules.CustomReactions
[Priority(0)]
public async Task ListCustReact(int page = 1)
{
if (page < 1 || page > 1000)
if (--page < 0 || page > 999)
return;
CustomReaction[] customReactions;
if (Context.Guild == null)
@ -106,7 +106,7 @@ namespace NadekoBot.Modules.CustomReactions
new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name"))
.WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger)
.Skip((curPage - 1) * 20)
.Skip(curPage * 20)
.Take(20)
.Select(cr =>
{
@ -161,7 +161,7 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases]
public async Task ListCustReactG(int page = 1)
{
if (page < 1 || page > 10000)
if (--page < 0 || page > 9999)
return;
CustomReaction[] customReactions;
if (Context.Guild == null)
@ -185,7 +185,7 @@ namespace NadekoBot.Modules.CustomReactions
new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name"))
.WithDescription(string.Join("\r\n", ordered
.Skip((curPage - 1) * 20)
.Skip(curPage * 20)
.Take(20)
.Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage)
.ConfigureAwait(false);
@ -399,14 +399,14 @@ namespace NadekoBot.Modules.CustomReactions
[NadekoCommand, Usage, Description, Aliases]
public async Task CrStats(int page = 1)
{
if (page < 1)
if (--page < 0)
return;
var ordered = _crs.ReactionStats.OrderByDescending(x => x.Value).ToArray();
if (!ordered.Any())
return;
var lastPage = ordered.Length / 9;
await Context.Channel.SendPaginatedConfirmAsync(_client, page,
(curPage) => ordered.Skip((curPage - 1) * 9)
(curPage) => ordered.Skip(curPage * 9)
.Take(9)
.Aggregate(new EmbedBuilder().WithOkColor().WithTitle(GetText("stats")),
(agg, cur) => agg.AddField(efb => efb.WithName(cur.Key).WithValue(cur.Value.ToString()).WithIsInline(true))), lastPage)

View File

@ -46,9 +46,8 @@ namespace NadekoBot.Modules.Gambling
[RequireContext(ContextType.Guild)]
public async Task Shop(int page = 1)
{
if (page <= 0)
if (--page < 0)
return;
page -= 1;
List<ShopEntry> entries;
using (var uow = _db.UnitOfWork)
{
@ -57,9 +56,9 @@ namespace NadekoBot.Modules.Gambling
.ThenInclude(x => x.Items)).ShopEntries);
}
await Context.Channel.SendPaginatedConfirmAsync(_client, page + 1, (curPage) =>
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
{
var theseEntries = entries.Skip((curPage - 1) * 9).Take(9);
var theseEntries = entries.Skip(curPage * 9).Take(9);
if (!theseEntries.Any())
return new EmbedBuilder().WithErrorColor()

View File

@ -377,12 +377,17 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task WaifuLeaderboard()
public async Task WaifuLeaderboard(int page = 1)
{
page--;
if (page < 0)
return;
IList<WaifuInfo> waifus;
using (var uow = _db.UnitOfWork)
{
waifus = uow.Waifus.GetTop(9);
waifus = uow.Waifus.GetTop(9, page * 9);
}
if (waifus.Count == 0)
@ -400,7 +405,7 @@ namespace NadekoBot.Modules.Gambling
var w = waifus[i];
var j = i;
embed.AddField(efb => efb.WithName("#" + (j + 1) + " - " + w.Price + _bc.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
}
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);

View File

@ -244,7 +244,8 @@ namespace NadekoBot.Modules.Music
await ReplyErrorLocalized("no_player").ConfigureAwait(false);
return;
}
if (page <= 0)
if (--page < 0)
return;
try { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { }
@ -260,7 +261,7 @@ namespace NadekoBot.Modules.Music
var lastPage = musicPlayer.Playlist.Count / itemsPerPage;
Func<int, EmbedBuilder> printAction = curPage =>
{
var startAt = itemsPerPage * (curPage - 1);
var startAt = itemsPerPage * curPage;
var number = 0 + startAt;
var desc = string.Join("\n", musicPlayer.Playlist
.Skip(startAt)
@ -277,7 +278,7 @@ namespace NadekoBot.Modules.Music
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName(GetText("player_queue", curPage, lastPage + 1))
.WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, lastPage + 1))
.WithMusicIcon())
.WithDescription(desc)
.WithFooter(ef => ef.WithText($"{musicPlayer.PrettyVolume} | {musicPlayer.Playlist.Count} " +

View File

@ -1,4 +1,5 @@
using Discord.Commands;
using AngleSharp;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
@ -37,8 +38,17 @@ namespace NadekoBot.Modules.Searches
{
using (var http = new HttpClient())
{
var response = await http.GetStringAsync("http://tambal.azurewebsites.net/joke/random").ConfigureAwait(false);
await Context.Channel.SendConfirmAsync(JObject.Parse(response)["joke"].ToString() + " 😆").ConfigureAwait(false);
http.AddFakeHeaders();
var config = Configuration.Default.WithDefaultLoader();
var document = await BrowsingContext.New(config).OpenAsync("http://www.goodbadjokes.com/random");
var html = document.QuerySelector(".post > .joke-content");
var part1 = html.QuerySelector("dt").TextContent;
var part2 = html.QuerySelector("dd").TextContent;
await Context.Channel.SendConfirmAsync("", part1 + "\n\n" + part2, footer: document.BaseUri).ConfigureAwait(false);
}
}

View File

@ -124,12 +124,12 @@ namespace NadekoBot.Modules.Utility
var arr = maps.ToArray();
await Context.Channel.SendPaginatedConfirmAsync(_client, page + 1, (curPage) =>
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
{
return new EmbedBuilder().WithOkColor()
.WithTitle(GetText("alias_list"))
.WithDescription(string.Join("\n",
arr.Skip((curPage - 1) * 10).Take(10).Select(x => $"`{x.Key}` => `{x.Value}`")));
arr.Skip(curPage * 10).Take(10).Select(x => $"`{x.Key}` => `{x.Value}`")));
}, arr.Length / 10).ConfigureAwait(false);
}

View File

@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases]
public async Task ShardStats(int page = 1)
{
if (page < 1)
if (--page < 0)
return;
var status = string.Join(", ", _client.Shards.GroupBy(x => x.ConnectionState)
@ -374,7 +374,7 @@ namespace NadekoBot.Modules.Utility
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
{
var str = string.Join("\n", allShardStrings.Skip(25 * (curPage - 1)).Take(25));
var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25));
if (string.IsNullOrWhiteSpace(str))
str = GetText("no_shards_on_page");

View File

@ -3037,10 +3037,10 @@
<value>waifus waifulb</value>
</data>
<data name="waifuleaderboard_desc" xml:space="preserve">
<value>Shows top 9 waifus.</value>
<value>Shows top 9 waifus. You can specify another page to show other waifus.</value>
</data>
<data name="waifuleaderboard_usage" xml:space="preserve">
<value>`{0}waifus`</value>
<value>`{0}waifus` or `{0}waifulb 3`</value>
</data>
<data name="divorce_cmd" xml:space="preserve">
<value>divorce</value>

View File

@ -28,6 +28,7 @@ namespace NadekoBot.Services.Database.Models
public int MinimumBetAmount { get; set; } = 2;
public float BetflipMultiplier { get; set; } = 1.95f;
public int CurrencyDropAmount { get; set; } = 1;
public int? CurrencyDropAmountMax { get; set; } = null;
public float Betroll67Multiplier { get; set; } = 2;
public float Betroll91Multiplier { get; set; } = 4;
public float Betroll100Multiplier { get; set; } = 10;

View File

@ -5,7 +5,7 @@ namespace NadekoBot.Services.Database.Repositories
{
public interface IWaifuRepository : IRepository<WaifuInfo>
{
IList<WaifuInfo> GetTop(int count);
IList<WaifuInfo> GetTop(int count, int skip = 0);
WaifuInfo ByWaifuUserId(ulong userId);
IList<WaifuInfo> ByClaimerUserId(ulong userId);
}

View File

@ -29,7 +29,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl
.ToList();
}
public IList<WaifuInfo> GetTop(int count)
public IList<WaifuInfo> GetTop(int count, int skip = 0)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
@ -40,6 +40,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl
.Include(wi => wi.Affinity)
.Include(wi => wi.Claimer)
.OrderByDescending(wi => wi.Price)
.Skip(skip)
.Take(count)
.ToList();
}

View File

@ -125,6 +125,10 @@ namespace NadekoBot.Services.Games
if (num > 100 && LastGenerations.TryUpdate(channel.Id, DateTime.UtcNow, lastGeneration))
{
var dropAmount = _bc.CurrencyDropAmount;
var dropAmountMax = _bc.CurrencyDropAmountMax;
if (dropAmountMax != null && dropAmountMax > dropAmount)
dropAmount = new NadekoRandom().Next(dropAmount, dropAmountMax.Value + 1);
if (dropAmount > 0)
{

View File

@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl
private readonly IBotCredentials _creds;
private readonly DateTime _started;
public const string BotVersion = "1.42";
public const string BotVersion = "1.43";
public string Author => "Kwoth#2560";
public string Library => "Discord.Net";

View File

@ -54,7 +54,6 @@ namespace NadekoBot.Extensions
/// </summary>
public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordShardedClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true)
{
lastPage += 1;
var embed = pageFunc(currentPage);
if(addPaginatedFooter)
@ -62,7 +61,7 @@ namespace NadekoBot.Extensions
var msg = await channel.EmbedAsync(embed) as IUserMessage;
if (currentPage >= lastPage && lastPage == 1)
if (lastPage == 0)
return;
@ -77,7 +76,7 @@ namespace NadekoBot.Extensions
{
if (r.Emote.Name == arrow_left.Name)
{
if (currentPage == 1)
if (currentPage == 0)
return;
var toSend = pageFunc(--currentPage);
if (addPaginatedFooter)
@ -109,7 +108,7 @@ namespace NadekoBot.Extensions
private static EmbedBuilder AddPaginatedFooter(this EmbedBuilder embed, int curPage, int? lastPage)
{
if (lastPage != null)
return embed.WithFooter(efb => efb.WithText($"{curPage} / {lastPage}"));
return embed.WithFooter(efb => efb.WithText($"{curPage + 1} / {lastPage + 1}"));
else
return embed.WithFooter(efb => efb.WithText(curPage.ToString()));
}

View File

@ -290,7 +290,7 @@
"help_cmdlist_donate": "You can support the project on patreon: <{0}> or paypal: <{1}>",
"help_cmd_and_alias": "Commands and aliases",
"help_commandlist_regen": "Commandlist regenerated.",
"help_commands_instr": "Type `{0}h CommandName` to see the help for that specified command. e.g. `{0}h >8ball`",
"help_commands_instr": "Type `{0}h CommandName` to see the help for that specified command. e.g. `{0}h {0}8ball`",
"help_command_not_found": "I can't find that command. Please verify that the command exists before trying again.",
"help_desc": "Description",
"help_donate": "You can support the NadekoBot project on \nPatreon <{0}> or\nPaypal <{1}>\nDon't forget to leave your discord name or id in the message.\n\n**Thank you** ♥️",