diff --git a/Geekbot.net/Commands/Role.cs b/Geekbot.net/Commands/Role.cs index 579dbc6..851ff02 100644 --- a/Geekbot.net/Commands/Role.cs +++ b/Geekbot.net/Commands/Role.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using AngleSharp; using Discord; using Discord.Commands; +using Discord.Net; using Geekbot.net.Lib; using StackExchange.Redis; @@ -80,6 +81,10 @@ namespace Geekbot.net.Commands } await ReplyAsync("That role doesn't seem to exist"); } + catch (HttpException e) + { + await Context.Channel.SendMessageAsync("Seems like i don't have enough permission to give roles..."); + } catch (Exception e) { _errorHandler.HandleCommandException(e, Context); diff --git a/Geekbot.net/Geekbot.net.csproj b/Geekbot.net/Geekbot.net.csproj index 49779c1..dd62e3a 100755 --- a/Geekbot.net/Geekbot.net.csproj +++ b/Geekbot.net/Geekbot.net.csproj @@ -27,7 +27,7 @@ - + 1.2.6 diff --git a/Geekbot.net/Lib/ErrorHandler.cs b/Geekbot.net/Lib/ErrorHandler.cs index 70a95e2..109ba03 100644 --- a/Geekbot.net/Lib/ErrorHandler.cs +++ b/Geekbot.net/Lib/ErrorHandler.cs @@ -1,6 +1,12 @@ using System; +using System.Runtime.InteropServices.ComTypes; +using System.Security.Principal; using Discord.Commands; +using Nancy.Extensions; using Serilog; +using SharpRaven; +using SharpRaven.Data; +using SharpRaven.Utilities; using Utf8Json; namespace Geekbot.net.Lib @@ -9,11 +15,23 @@ namespace Geekbot.net.Lib { private readonly ILogger _logger; private readonly ITranslationHandler _translation; + private readonly IRavenClient _raven; public ErrorHandler(ILogger logger, ITranslationHandler translation) { _logger = logger; _translation = translation; + + var sentryDsn = Environment.GetEnvironmentVariable("SENTRY"); + if (!string.IsNullOrEmpty(sentryDsn)) + { + _raven = new RavenClient(sentryDsn); + _logger.Information($"Command Errors will be logged to Sentry: {sentryDsn}"); + } + else + { + _raven = null; + } } public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "def") @@ -55,6 +73,20 @@ namespace Geekbot.net.Lib { Context.Channel.SendMessageAsync(errorString); } + + if (_raven == null) return; + + var sentryEvent = new SentryEvent(e) + { + Tags = + { + ["discord_server"] = errorObj.Guild.Name, + ["discord_user"] = errorObj.User.Name + }, + Message = errorObj.Message.Content, + Extra = errorObj + }; + _raven.Capture(sentryEvent); } catch (Exception ex) { diff --git a/Geekbot.net/Lib/LoggerFactory.cs b/Geekbot.net/Lib/LoggerFactory.cs index 8cfabec..988c300 100644 --- a/Geekbot.net/Lib/LoggerFactory.cs +++ b/Geekbot.net/Lib/LoggerFactory.cs @@ -11,13 +11,6 @@ namespace Geekbot.net.Lib var loggerCreation = new LoggerConfiguration() .WriteTo.LiterateConsole() .WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true); - var sentryDsn = Environment.GetEnvironmentVariable("SENTRY"); - if (!string.IsNullOrEmpty(sentryDsn)) - { - loggerCreation.WriteTo.SentryIO(sentryDsn) - .Enrich.FromLogContext(); - Console.WriteLine($"Logging to Sentry Enabled: {sentryDsn}"); - } if (args.Contains("--verbose")) { loggerCreation.MinimumLevel.Verbose(); diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 66d20f8..4382309 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -195,7 +195,7 @@ namespace Geekbot.net { redis.StringSet("botOwner", appInfo.Owner.Id); var req = HttpWebRequest.Create(appInfo.IconUrl); - using (Stream stream = req.GetResponse().GetResponseStream()) + using (var stream = req.GetResponse().GetResponseStream()) { await client.CurrentUser.ModifyAsync(User => { @@ -207,8 +207,8 @@ namespace Geekbot.net } catch (Exception e) { - logger.Warning(e, $"[Setup] Oha, it seems like something went wrong while running the setup"); - logger.Warning(e, $"[Setup] Geekbot will work never the less, some features might be disabled though"); + logger.Warning(e, "[Setup] Oha, it seems like something went wrong while running the setup"); + logger.Warning("[Setup] Geekbot will work never the less, some features might be disabled though"); } return Task.CompletedTask; } diff --git a/Geekbot.net/WebApi/WebConfig.cs b/Geekbot.net/WebApi/WebConfig.cs index 7875ccb..f0b9ca3 100644 --- a/Geekbot.net/WebApi/WebConfig.cs +++ b/Geekbot.net/WebApi/WebConfig.cs @@ -1,4 +1,4 @@ -using System; +using System.Diagnostics; using Nancy; using Nancy.Bootstrapper; using Nancy.TinyIoc; @@ -11,13 +11,12 @@ namespace Geekbot.net.WebApi { //CORS Enable - pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) => + pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => { ctx.Response.WithHeader("Access-Control-Allow-Origin", "*") .WithHeader("Access-Control-Allow-Methods", "GET") .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type") - .WithHeader("Last-Modified", DateTime.Now.ToString()); - + .WithHeader("Last-Modified", Process.GetCurrentProcess().StartTime.ToString()); }); } }