So many fixes. Thanks a lot to @fearnlj01 for the testing

This commit is contained in:
Kwoth
2016-10-10 02:27:33 +02:00
parent 46000b3604
commit 75c4da7edd
11 changed files with 146 additions and 163 deletions

View File

@@ -86,6 +86,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.ManageMessages)]
public async Task Slowmode(IUserMessage umsg, int msg = 1, int perSec = 5)
{
var channel = (ITextChannel)umsg.Channel;

View File

@@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Help
var helpstr = new StringBuilder();
var lastModule = "";
foreach (var com in _commands.Commands)
foreach (var com in _commands.Commands.GroupBy(c=>c.Text).Select(g=>g.First()))
{
if (com.Module.Name != lastModule)
{

View File

@@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Searches
await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" });
}
[NadekoCommand, Usage, Description, Aliases]
public async Task Convert(IUserMessage msg, string origin, string target, decimal value)
public async Task Convert(IUserMessage msg, string origin, string target, double value)
{
var originUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(origin.ToLowerInvariant()));
var targetUnit = Units.Find(x => x.Triggers.Select(y => y.ToLowerInvariant()).Contains(target.ToLowerInvariant()));
@@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Searches
await msg.Reply(string.Format("Cannot convert {0} to {1}: types of unit are not equal", originUnit.Triggers.First(), targetUnit.Triggers.First()));
return;
}
decimal res;
double res;
if (originUnit.Triggers == targetUnit.Triggers) res = value;
else if (originUnit.UnitType == "temperature")
{
@@ -131,10 +131,10 @@ namespace NadekoBot.Modules.Searches
switch (originUnit.Triggers.First().ToUpperInvariant())
{
case "C":
res = value + (decimal)273.15; //celcius!
res = value + 273.15; //celcius!
break;
case "F":
res = (value + (decimal)459.67) * ((decimal)5 / 9);
res = (value + 459.67) * (5 / 9);
break;
default:
res = value;
@@ -144,10 +144,10 @@ namespace NadekoBot.Modules.Searches
switch (targetUnit.Triggers.First())
{
case "C":
res = value - (decimal)273.15; //celcius!
res = value - 273.15; //celcius!
break;
case "F":
res = res * ((decimal)9 / 5) - (decimal)458.67;
res = res * (9 / 5) - 458.67;
break;
default:
break;
@@ -157,13 +157,14 @@ namespace NadekoBot.Modules.Searches
{
if (originUnit.UnitType == "currency")
{
res = (value * targetUnit.Modifier) / originUnit.Modifier;
res = (value * (double)targetUnit.Modifier) / (double)originUnit.Modifier;
}
else
res = (value * originUnit.Modifier) / targetUnit.Modifier;
res = (value * (double)originUnit.Modifier) / (double)targetUnit.Modifier;
}
res = Math.Round(res, 2);
await msg.Reply(string.Format("{0} {1} is equal to {2} {3}", value, originUnit.Triggers.First(), res, targetUnit.Triggers.First()));
await msg.Reply(string.Format("{0} {1}s is equal to {2} {3}s", value, originUnit.Triggers.First().SnPl(value.IsInteger() ? (int)value : 2), res, targetUnit.Triggers.First().SnPl(res.IsInteger() ? (int)res : 2)));
}
}

View File

@@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Searches
country = city.Replace(" ", "");
string response;
using (var http = new HttpClient())
response = await http.GetStringAsync($"http://api.lawlypopzz.xyz/nadekobot/weather/?city={city}&country={country}").ConfigureAwait(false);
response = await http.GetStringAsync($"http://api.ninetales.us/nadekobot/weather/?city={city}&country={country}").ConfigureAwait(false);
var obj = JObject.Parse(response)["weather"];

View File

@@ -73,18 +73,22 @@ namespace NadekoBot.Modules.Utility
if (string.IsNullOrWhiteSpace(keyword))
return;
var isAdmin = ((IGuildUser)umsg.Author).GuildPermissions.Administrator;
keyword = keyword.ToUpperInvariant();
string response;
using (var uow = DbHandler.UnitOfWork())
{
var q = await uow.Quotes.GetRandomQuoteByKeywordAsync(channel.Guild.Id, keyword).ConfigureAwait(false);
var qs = uow.Quotes.GetAllQuotesByKeyword(channel.Guild.Id, keyword);
if (q == null)
if (qs==null || !qs.Any())
{
response = "`No quotes found.`";
return;
}
var q = qs.Shuffle().FirstOrDefault(elem => isAdmin || elem.AuthorId == umsg.Author.Id);
uow.Quotes.Remove(q);
await uow.CompleteAsync().ConfigureAwait(false);
response = "`Deleted a random quote`";
@@ -94,6 +98,7 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.Administrator)]
public async Task DelAllQuotes(IUserMessage umsg, [Remainder] string keyword)
{
var channel = (ITextChannel)umsg.Channel;
@@ -105,7 +110,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = DbHandler.UnitOfWork())
{
var quotes = uow.Quotes.GetAllQuotesByKeyword(keyword);
var quotes = uow.Quotes.GetAllQuotesByKeyword(channel.Guild.Id, keyword);
uow.Quotes.RemoveRange(quotes.ToArray());//wtf?!

View File

@@ -116,20 +116,30 @@ namespace NadekoBot.Modules.Utility
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Roles(IUserMessage msg, IGuildUser target = null)
public async Task Roles(IUserMessage msg, IGuildUser target, int page = 1)
{
var channel = (ITextChannel)msg.Channel;
var guild = channel.Guild;
const int RolesPerPage = 20;
if (page < 1 || page > 100)
return;
if (target != null)
{
await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)).SanitizeMentions());
await msg.Reply($"`Page #{page} of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Skip((page-1) * RolesPerPage).Take(RolesPerPage).Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)).SanitizeMentions());
}
else
{
await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r=>r.Position)).SanitizeMentions());
await msg.Reply($"`Page #{page} of all roles on this server:` \n• " + string.Join("\n• ", guild.Roles.Skip((page - 1) * RolesPerPage).Take(RolesPerPage).Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)).SanitizeMentions());
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Roles(IUserMessage msg, int page = 1) =>
Roles(msg, null, page);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ChannelTopic(IUserMessage umsg)