This commit is contained in:
Kwoth 2016-12-28 07:56:44 +01:00
parent 3a68a8b4f6
commit aa49c5608b
10 changed files with 172 additions and 154 deletions

View File

@ -81,7 +81,10 @@ namespace NadekoBot.Modules.Administration
{
_log = LogManager.GetCurrentClassLogger();
NadekoBot.Client.MessageReceived += (imsg) =>
NadekoBot.Client.MessageReceived += async (imsg) =>
{
try
{
var msg = imsg as IUserMessage;
if (msg == null || msg.Author.IsBot)
@ -90,11 +93,6 @@ namespace NadekoBot.Modules.Administration
var channel = msg.Channel as ITextChannel;
if (channel == null)
return;
var t = Task.Run(async () =>
{
try
{
AntiSpamSetting spamSettings;
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings))
return;
@ -112,8 +110,6 @@ namespace NadekoBot.Modules.Administration
}
}
catch { }
});
return;
};
NadekoBot.Client.UserJoined += async (usr) =>

View File

@ -45,7 +45,8 @@ namespace NadekoBot.Modules.Administration
else
{
usr.MessageCount++;
var t = Task.Run(async () => {
var t = Task.Run(async () =>
{
try
{
await Task.Delay(PerSeconds * 1000, cancelSource.Token);
@ -63,9 +64,9 @@ namespace NadekoBot.Modules.Administration
{
_log = LogManager.GetCurrentClassLogger();
NadekoBot.Client.MessageReceived += (umsg) =>
NadekoBot.Client.MessageReceived += async (umsg) =>
{
var t = Task.Run(async () =>
try
{
var usrMsg = umsg as IUserMessage;
var channel = usrMsg.Channel as ITextChannel;
@ -77,9 +78,9 @@ namespace NadekoBot.Modules.Administration
return;
if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
});
return;
await usrMsg.DeleteAsync();
}
catch (Exception ex) { _log.Warn(ex); }
};
}

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NLog;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -73,9 +74,12 @@ namespace NadekoBot.Modules.Games
//text, votes
private readonly ConcurrentDictionary<string, int> votes = new ConcurrentDictionary<string, int>();
private readonly Logger _log;
public AcrophobiaGame(ITextChannel channel, int time)
{
this._log = LogManager.GetCurrentClassLogger();
this.channel = channel;
this.time = time;
this.source = new CancellationTokenSource();
@ -253,7 +257,10 @@ namespace NadekoBot.Modules.Games
}
}
catch { }
catch (Exception ex)
{
_log.Warn(ex);
}
}
public async Task End()

View File

@ -2,6 +2,7 @@
using NadekoBot.Extensions;
using NadekoBot.Services;
using Newtonsoft.Json;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
@ -70,6 +71,8 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
public class HangmanGame
{
private readonly Logger _log;
public IMessageChannel GameChannel { get; }
public HashSet<char> Guesses { get; } = new HashSet<char>();
public HangmanObject Term { get; private set; }
@ -97,6 +100,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
public HangmanGame(IMessageChannel channel, HangmanTermPool.HangmanTermType type)
{
_log = LogManager.GetCurrentClassLogger();
this.GameChannel = channel;
this.TermType = type;
}
@ -126,6 +130,11 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
private async void PotentialGuess(IMessage msg)
{
try
{
if (!(msg is IUserMessage))
return;
if (msg.Channel != GameChannel)
return; // message's channel has to be the same as game's
if (msg.Content.Length != 1) // message must be 1 char long
@ -147,8 +156,6 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
return;
var guess = char.ToUpperInvariant(msg.Content[0]);
try
{
if (Guesses.Contains(guess))
{
MessagesSinceLastPost = 0;
@ -193,7 +200,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
}
}
catch { }
catch (Exception ex) { _log.Warn(ex); }
}
public string GetHangman() => $@"\_\_\_\_\_\_\_\_\_

View File

@ -58,6 +58,8 @@ namespace NadekoBot.Modules.Games
}
private static async void PotentialFlowerGeneration(IMessage imsg)
{
try
{
var msg = imsg as IUserMessage;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
@ -81,18 +83,18 @@ namespace NadekoBot.Modules.Games
if (num > 100)
{
lastGenerations.AddOrUpdate(channel.Id, DateTime.Now, (id, old) => DateTime.Now);
try
{
var sent = await channel.SendFileAsync(
GetRandomCurrencyImagePath(),
$"❗ A random { Gambling.Gambling.CurrencyName } appeared! Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`")
.ConfigureAwait(false);
plantedFlowers.AddOrUpdate(channel.Id, new List<IUserMessage>() { sent }, (id, old) => { old.Add(sent); return old; });
}
catch { }
}
}
catch { }
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]

View File

@ -125,6 +125,8 @@ namespace NadekoBot.Modules.Games
}
private async void Vote(IMessage imsg)
{
try
{
// has to be a user message
var msg = imsg as IUserMessage;
@ -137,8 +139,7 @@ namespace NadekoBot.Modules.Games
return;
if (vote < 1 || vote > answers.Length)
return;
try
{
IMessageChannel ch;
if (isPublic)
{

View File

@ -106,14 +106,15 @@ namespace NadekoBot.Modules.Games
}
private async void AnswerReceived(IMessage imsg)
{
try
{
if (imsg.Author.IsBot)
return;
var msg = imsg as IUserMessage;
if (msg == null)
return;
try
{
if (this.Channel == null || this.Channel.Id != this.Channel.Id) return;
var guess = msg.Content;

View File

@ -143,6 +143,8 @@ namespace NadekoBot.Modules.Games.Trivia
}
private async void PotentialGuess(IMessage imsg)
{
try
{
if (imsg.Author.IsBot)
return;
@ -150,8 +152,7 @@ namespace NadekoBot.Modules.Games.Trivia
var umsg = imsg as IUserMessage;
if (umsg == null)
return;
try
{
var textChannel = umsg.Channel as ITextChannel;
if (textChannel == null || textChannel.Guild != guild)
return;

View File

@ -29,6 +29,8 @@ namespace NadekoBot.Modules.Searches
UserLanguages = new ConcurrentDictionary<UserChannelPair, string>();
NadekoBot.Client.MessageReceived += async (msg) =>
{
try
{
var umsg = msg as IUserMessage;
if (umsg == null)
@ -47,8 +49,6 @@ namespace NadekoBot.Modules.Searches
if (!UserLanguages.TryGetValue(key, out langs))
return;
try
{
var text = await TranslateInternal(umsg, langs, umsg.Resolve(UserMentionHandling.Ignore), true)
.ConfigureAwait(false);
if (autoDelete)

View File

@ -63,6 +63,8 @@ namespace NadekoBot.Services
}
private async void MessageReceivedHandler(IMessage msg)
{
try
{
var usrMsg = msg as IUserMessage;
if (usrMsg == null)
@ -76,8 +78,7 @@ namespace NadekoBot.Services
var sw = new Stopwatch();
sw.Start();
try
{
var guild = (msg.Channel as ITextChannel)?.Guild;
if (guild != null && guild.OwnerId != usrMsg.Author.Id)
@ -208,7 +209,8 @@ namespace NadekoBot.Services
}
}
public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best)
{
var searchResult = _commandService.Search(message, input);
if (!searchResult.IsSuccess)
return new Tuple<Command, PermissionCache, IResult>(null, null, searchResult);