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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -63,6 +63,8 @@ namespace NadekoBot.Services
} }
private async void MessageReceivedHandler(IMessage msg) private async void MessageReceivedHandler(IMessage msg)
{
try
{ {
var usrMsg = msg as IUserMessage; var usrMsg = msg as IUserMessage;
if (usrMsg == null) if (usrMsg == null)
@ -76,8 +78,7 @@ namespace NadekoBot.Services
var sw = new Stopwatch(); var sw = new Stopwatch();
sw.Start(); sw.Start();
try
{
var guild = (msg.Channel as ITextChannel)?.Guild; var guild = (msg.Channel as ITextChannel)?.Guild;
if (guild != null && guild.OwnerId != usrMsg.Author.Id) 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); var searchResult = _commandService.Search(message, input);
if (!searchResult.IsSuccess) if (!searchResult.IsSuccess)
return new Tuple<Command, PermissionCache, IResult>(null, null, searchResult); return new Tuple<Command, PermissionCache, IResult>(null, null, searchResult);