public IlModule( CodePasteService pasteService, IAutoRemoveMessageService autoRemoveMessageService, IHttpClientFactory httpClientFactory) { _pasteService = pasteService; _autoRemoveMessageService = autoRemoveMessageService; _httpClientFactory = httpClientFactory; }
public IlModule( CodePasteService pasteService, IAutoRemoveMessageService autoRemoveMessageService, IHttpClientFactory httpClientFactory, IOptions <ModixConfig> modixConfig) { _pasteService = pasteService; _autoRemoveMessageService = autoRemoveMessageService; _httpClientFactory = httpClientFactory; _ilUrl = string.IsNullOrWhiteSpace(modixConfig.Value.IlUrl) ? DefaultIlRemoteUrl : modixConfig.Value.IlUrl; }
public TagModule( ITagService tagService, CodePasteService codePasteService, IUserService userService, IOptions <ModixConfig> config) { TagService = tagService; CodePasteService = codePasteService; UserService = userService; Config = config.Value; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostEnvironment env, CodePasteService codePasteService) { var options = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }; app.UseForwardedHeaders(options); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseResponseCompression(); //Static redirect for invite link app.Map("/invite", builder => { builder.Run(handler => { //TODO: Maybe un-hardcode this? //handler.Response.StatusCode = StatusCodes handler.Response.Redirect("https://aka.ms/csharp-discord"); return(Task.CompletedTask); }); }); //Map to static files when not hitting the API app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder => { //Tiny middleware to redirect invalid requests to index.html, //this ensures that our frontend routing works on fresh requests builder.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index.html"; await next(); } }) .UseDefaultFiles() .UseStaticFiles(); }); //Defer to MVC for anything that doesn't match (and ostensibly //starts with /api) app.UseMvcWithDefaultRoute(); }
private async Task <Embed> BuildEmbedAsync(IReadOnlyCollection <TagSummary> tags, IUser ownerUser = null, IGuild ownerGuild = null, IRole ownerRole = null) { var orderedTags = tags.OrderBy(x => x.Name); var ownerName = ownerUser?.Username ?? ownerGuild?.Name ?? ownerRole?.Name; var ownerImage = ownerUser?.GetDefiniteAvatarUrl() ?? ownerGuild?.IconUrl; var builder = new EmbedBuilder(); builder .WithAuthor(ownerName, ownerImage) .WithColor(Color.DarkPurple) .WithDescription(tags.Count > 0 ? null : "No tags.") .WithTimestamp(DateTimeOffset.Now) .WithTitle("Tags"); const int tagsToDisplay = 5; foreach (var tag in orderedTags.Take(tagsToDisplay)) { builder.AddField(x => x.WithName(tag.Name) .WithValue($"{tag.Uses} uses")); } if (tags.Count > tagsToDisplay) { var pasteContent = BuildPaste(orderedTags); var fieldName = $"and {tags.Count - tagsToDisplay} more"; try { var pasteLink = await CodePasteService.UploadCodeAsync(pasteContent, "txt"); builder.AddField(x => x.WithName(fieldName) .WithValue($"[View at {pasteLink}]({pasteLink})")); } catch (WebException ex) { builder.AddField(x => x.WithName(fieldName) .WithValue(ex.Message)); } } return(builder.Build()); }
public void Emit(LogEvent logEvent) { const int DiscordStringTruncateLength = 1000; var formattedMessage = logEvent.RenderMessage(_formatProvider); var webhookClient = new DiscordWebhookClient(_webhookId, _webhookToken); var message = new EmbedBuilder() .WithAuthor("DiscordLogger") .WithTitle("Modix") .WithTimestamp(DateTimeOffset.UtcNow) .WithColor(Color.Red); try { var messagePayload = $"{formattedMessage}\n{logEvent.Exception?.Message}"; message.AddField(new EmbedFieldBuilder() .WithIsInline(false) .WithName($"LogLevel: {logEvent.Level}") .WithValue(Format.Code(messagePayload.TruncateTo(DiscordStringTruncateLength)))); var eventAsJson = JsonConvert.SerializeObject(logEvent, _jsonSerializerSettings); var url = CodePasteService.UploadCodeAsync(eventAsJson, "json").GetAwaiter().GetResult(); message.AddField(new EmbedFieldBuilder() .WithIsInline(false) .WithName("Full Log Event") .WithValue($"[view on paste.mod.gg]({url})")); } catch (Exception ex) { Console.WriteLine($"Unable to upload log event. {ex}"); var stackTracePayload = $"{formattedMessage}\n{logEvent.Exception?.ToString().TruncateTo(DiscordStringTruncateLength)}".TruncateTo(DiscordStringTruncateLength); message.AddField(new EmbedFieldBuilder() .WithIsInline(false) .WithName("Stack Trace") .WithValue(Format.Code(stackTracePayload))); message.AddField(new EmbedFieldBuilder() .WithIsInline(false) .WithName("Upload Failure Exception") .WithValue(Format.Code($"{ex.ToString().TruncateTo(DiscordStringTruncateLength)}"))); } webhookClient.SendMessageAsync(string.Empty, embeds: new[] { message.Build() }, username: "******"); }
public DiscordWebhookSink( ulong webhookId, string webhookToken, IFormatProvider formatProvider, CodePasteService codePasteService) { _codePasteService = codePasteService; _discordWebhookClient = new DiscordWebhookClient(webhookId, webhookToken); _formatProvider = formatProvider; _jsonSerializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new ExceptionContractResolver() }; }
public static async Task UploadToServiceIfBiggerThan(this EmbedBuilder embed, string content, string contentType, uint size, CodePasteService service) { if (content.Length > size) { try { var resultLink = await service.UploadCodeAsync(content, contentType); embed.AddField(a => a.WithName("More...").WithValue($"[View on Hastebin]({resultLink})")); } catch (WebException we) { embed.AddField(a => a.WithName("More...").WithValue(we.Message)); } } }
public AutoCodePasteBehavior(CodePasteService service) { _service = service; }
public CodePasteModule(CodePasteService service) { _service = service; }
public PopularityContestService(DiscordSocketClient client, CodePasteService pasteService, IAuthorizationService authorizationService) { _client = client; _pasteService = pasteService; _authorizationService = authorizationService; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostEnvironment env, CodePasteService codePasteService) { var options = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }; app.UseForwardedHeaders(options); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseResponseCompression(); //Static redirect for invite link app.Map("/invite", builder => { builder.Run(handler => { //TODO: Maybe un-hardcode this? //handler.Response.StatusCode = StatusCodes handler.Response.Redirect("https://aka.ms/csharp-discord"); return(Task.CompletedTask); }); }); // Serve up log files for maintainers only app.MapWhen(x => x.Request.Path.Value.StartsWith(_logFilesRequestPath), builder => { var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "logs")); builder .UseMiddleware <LogFilesAuthorizationMiddleware>() .UseDirectoryBrowser(new DirectoryBrowserOptions() { FileProvider = fileProvider, RequestPath = _logFilesRequestPath }) .UseStaticFiles(new StaticFileOptions() { FileProvider = fileProvider, RequestPath = _logFilesRequestPath, ServeUnknownFileTypes = true }); }); //Map to static files when not hitting the API app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder => { //Tiny middleware to redirect invalid requests to index.html, //this ensures that our frontend routing works on fresh requests builder.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) { context.Request.Path = "/index.html"; await next(); } }) .UseDefaultFiles() .UseStaticFiles(); }); //Defer to MVC for anything that doesn't match (and ostensibly //starts with /api) app.UseMvcWithDefaultRoute(); }
public IlModule(ModixConfig config, CodePasteService pasteService) { _pasteService = pasteService; _config = config; _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", config.ReplToken); }
public TagModule(ITagService tagService, CodePasteService codePasteService, IUserService userService) { TagService = tagService; CodePasteService = codePasteService; UserService = userService; }
public static LoggerConfiguration DiscordWebhookSink(this LoggerSinkConfiguration config, ulong id, string token, LogEventLevel minLevel, CodePasteService codePasteService) { return(config.Sink(new DiscordWebhookSink(id, token, null, codePasteService), minLevel)); }
public StreamingModule(CampingService campingService, LyricaContext db, CodePasteService paste) { _campingService = campingService; _db = db; _paste = paste; }