Merge remote-tracking branch 'refs/remotes/Kwoth/1.0' into unitconversion

This commit is contained in:
appelemac
2016-09-04 18:21:43 +02:00
23 changed files with 104 additions and 2986 deletions

View File

@@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Administration
NadekoBot.CommandHandler.CommandExecuted += DelMsgOnCmd_Handler;
}
private void DelMsgOnCmd_Handler(object sender, CommandExecutedEventArgs e)
private async void DelMsgOnCmd_Handler(object sender, CommandExecutedEventArgs e)
{
try
{
@@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Administration
}
if (shouldDelete)
e.Message.DeleteAsync();
await e.Message.DeleteAsync();
}
catch (Exception ex)
{

View File

@@ -19,22 +19,26 @@ namespace NadekoBot.Modules.Administration
public AutoAssignRoleCommands()
{
var _client = NadekoBot.Client;
_client.UserJoined += async (user) =>
_client.UserJoined += (user) =>
{
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
var t = Task.Run(async () =>
{
conf = uow.GuildConfigs.For(user.Guild.Id);
}
var aarType = conf.AutoAssignRoleId.GetType();
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
{
conf = uow.GuildConfigs.For(user.Guild.Id);
}
var aarType = conf.AutoAssignRoleId.GetType();
if (conf.AutoAssignRoleId == 0)
return;
if (conf.AutoAssignRoleId == 0)
return;
var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId);
var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId);
if (role != null)
await user.AddRolesAsync(role);
if (role != null)
await user.AddRolesAsync(role);
});
return Task.CompletedTask;
};
}

View File

@@ -46,7 +46,6 @@ namespace NadekoBot.Modules.Administration
}
catch { }
});
return Task.CompletedTask;
};
}

View File

@@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using System;
using System.Collections.Concurrent;
@@ -24,10 +25,23 @@ namespace NadekoBot.Modules.Administration
_client.MessageReceived += _client_MessageReceived;
}
private Task _client_MessageReceived(IMessage arg)
private Task _client_MessageReceived(IMessage imsg)
{
throw new NotImplementedException();
var msg = imsg as IUserMessage;
if (msg == null)
return Task.CompletedTask;
return Task.CompletedTask;
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task LogServer(IUserMessage msg)
{
var channel = (ITextChannel)msg.Channel;
}
}
}
}

View File

@@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration
private Task UserUpdatedEventHandler(IGuildUser before, IGuildUser after)
{
Task.Run(async () =>
var task = Task.Run(async () =>
{
var guild = before.Guild ?? after.Guild;
var botUserPerms = guild.GetCurrentUser().GuildPermissions;

View File

@@ -143,7 +143,6 @@ namespace NadekoBot.Modules.Gambling
//update the state
participants.ForEach(p =>
{
p.Total += 1 + rng.Next(0, 10);
if (p.Total > 60)
{

View File

@@ -107,26 +107,36 @@ namespace NadekoBot.Modules.Games
}
}
private async Task Vote(IMessage imsg)
private Task Vote(IMessage imsg)
{
var msg = imsg as ISystemMessage;
// has to be a user message
var msg = imsg as IUserMessage;
if (msg == null)
return;
try
return Task.CompletedTask;
// channel must be private
IPrivateChannel ch;
if ((ch = msg.Channel as IPrivateChannel) == null)
return Task.CompletedTask;
// has to be an integer
int vote;
if (!int.TryParse(msg.Content, out vote)) return Task.CompletedTask;
var t = Task.Run(async () =>
{
IPrivateChannel ch;
if ((ch = msg.Channel as IPrivateChannel) == null)
return;
int vote;
if (!int.TryParse(msg.Content, out vote)) return;
if (vote < 1 || vote > answers.Length)
return;
if (participants.TryAdd(msg.Author, vote))
try
{
await (ch as ITextChannel).SendMessageAsync($"Thanks for voting **{msg.Author.Username}**.").ConfigureAwait(false);
if (vote < 1 || vote > answers.Length)
return;
if (participants.TryAdd(msg.Author, vote))
{
await (ch as ITextChannel).SendMessageAsync($"Thanks for voting **{msg.Author.Username}**.").ConfigureAwait(false);
}
}
}
catch { }
catch { }
});
return Task.CompletedTask;
}
}
}

View File

@@ -92,30 +92,34 @@ namespace NadekoBot.Modules.Games
NadekoBot.Client.MessageReceived += AnswerReceived;
}
private async Task AnswerReceived(IMessage imsg)
private Task AnswerReceived(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null)
return;
try
return Task.CompletedTask;
var t = Task.Run(async () =>
{
if (channel== null || channel.Id != channel.Id || msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
var guess = msg.Content;
var distance = CurrentSentence.LevenshteinDistance(guess);
var decision = Judge(distance, guess.Length);
if (decision && !finishedUserIds.Contains(msg.Author.Id))
try
{
finishedUserIds.Add(msg.Author.Id);
await channel.SendMessageAsync($"{msg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
if (finishedUserIds.Count % 2 == 0)
if (channel == null || channel.Id != channel.Id || msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
var guess = msg.Content;
var distance = CurrentSentence.LevenshteinDistance(guess);
var decision = Judge(distance, guess.Length);
if (decision && !finishedUserIds.Contains(msg.Author.Id))
{
await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
finishedUserIds.Add(msg.Author.Id);
await channel.SendMessageAsync($"{msg.Author.Mention} finished in **{sw.Elapsed.Seconds}** seconds with { distance } errors, **{ CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60 }** WPM!").ConfigureAwait(false);
if (finishedUserIds.Count % 2 == 0)
{
await channel.SendMessageAsync($":exclamation: `A lot of people finished, here is the text for those still typing:`\n\n:book:**{CurrentSentence}**:book:").ConfigureAwait(false);
}
}
}
}
catch { }
catch { }
});
return Task.CompletedTask;
}
private bool Judge(int errors, int textLength) => errors <= textLength / 25;

View File

@@ -105,34 +105,36 @@ namespace NadekoBot.Modules.Games.Trivia
var umsg = imsg as IUserMessage;
if (umsg == null)
return;
try
var t = Task.Run(async () =>
{
if (!(umsg.Channel is IGuildChannel && umsg.Channel is ITextChannel)) return;
if ((umsg.Channel as ITextChannel).Guild != guild) return;
if (umsg.Author.Id == (await NadekoBot.Client.GetCurrentUserAsync()).Id) return;
var guildUser = umsg.Author as IGuildUser;
var guess = false;
await _guessLock.WaitAsync().ConfigureAwait(false);
try
{
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !triviaCancelSource.IsCancellationRequested)
if (!(umsg.Channel is IGuildChannel && umsg.Channel is ITextChannel)) return;
if ((umsg.Channel as ITextChannel).Guild != guild) return;
if (umsg.Author.Id == (await NadekoBot.Client.GetCurrentUserAsync()).Id) return;
var guildUser = umsg.Author as IGuildUser;
var guess = false;
await _guessLock.WaitAsync().ConfigureAwait(false);
try
{
Users.AddOrUpdate(guildUser, 0, (gu, old) => old++);
guess = true;
if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !triviaCancelSource.IsCancellationRequested)
{
Users.AddOrUpdate(guildUser, 0, (gu, old) => old++);
guess = true;
}
}
finally { _guessLock.Release(); }
if (!guess) return;
triviaCancelSource.Cancel();
await channel.SendMessageAsync($"☑️ {guildUser.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false);
if (Users[guildUser] != WinRequirement) return;
ShouldStopGame = true;
await channel.SendMessageAsync($":exclamation: We have a winner! It's {guildUser.Mention}.").ConfigureAwait(false);
}
finally { _guessLock.Release(); }
if (!guess) return;
triviaCancelSource.Cancel();
await channel.SendMessageAsync($"☑️ {guildUser.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false);
if (Users[guildUser] != WinRequirement) return;
ShouldStopGame = true;
await channel.SendMessageAsync($":exclamation: We have a winner! It's {guildUser.Mention}.").ConfigureAwait(false);
}
catch { }
catch { }
});
}
public string GetLeaderboard()