public static async Task listTicket(HttpListenerContext c, MatchCollection m) { var user = c.GetSwissbotAuth(); if (user == null) { return; } if (c.Request.QueryString.Count == 0) { // List our tickets var html = TranscriptHandler.CreateTicketListHtml(user); c.Response.ContentType = "text/html"; c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(html)); c.Response.ContentEncoding = Encoding.UTF8; c.Response.StatusCode = 200; c.Response.Close(); } else { // Get the uid and dt var uid = c.Request.QueryString["uid"]; var dt = c.Request.QueryString["dt"]; // Get the user string username = "******"; string avatar = "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTjA0Lpsg840JNGLaPgVWM9QofkvAYdFPLb-g&usqp=CAU"; var ticketAuthor = Global.Client.GetUser(ulong.Parse(uid)); if (ticketAuthor != null) { username = ticketAuthor.ToString(); avatar = ticketAuthor.GetAvatarUrl(Discord.ImageFormat.Jpeg, 256); if (avatar == null) { avatar = ticketAuthor.GetDefaultAvatarUrl(); } } // Create the item var html = Resources.ticketItem.Replace("{item.profile}", avatar) .Replace("{item.username}", username) .Replace("{item.id}", uid) .Replace("{item.date}", DateTime.FromFileTimeUtc(long.Parse(dt)).ToString("R")) .Replace("{item.url}", $"/apprentice/v1/tickets/{uid}/{dt}"); c.Response.ContentEncoding = Encoding.UTF8; c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(html)); c.Response.StatusCode = 200; c.Response.Close(); } }
public static async Task listTicket(HttpListenerContext c, MatchCollection m) { // Check if they have the discord auth if (!c.Request.Cookies.Any(x => x.Name == "csSessionID")) { c.Response.Redirect($"https://discord.com/api/oauth2/authorize?client_id=772314985979969596&redirect_uri=https%3A%2F%2Fapi.swissdev.team%2Fapprentice%2Fv1%2Fauth&response_type=code&scope=identify&state={UrlEncoder.Default.Encode(c.Request.RawUrl)}"); c.Response.Close(); return; } var sesh = c.Request.Cookies["csSessionID"]; if (!DiscordAuthKeeper.IsValidUser(sesh)) { c.Response.StatusCode = 401; c.Response.Close(); return; } var user = DiscordAuthKeeper.GetUser(sesh.Value); if (!user.HasPermissions()) { c.Response.StatusCode = 403; c.Response.Close(); return; } if (c.Request.QueryString.Count == 0) { // List our tickets var html = TranscriptHandler.CreateTicketListHtml(user); c.Response.ContentType = "text/html"; c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(html)); c.Response.ContentEncoding = Encoding.UTF8; c.Response.StatusCode = 200; c.Response.Close(); } else { // Get the uid and dt var uid = c.Request.QueryString["uid"]; var dt = c.Request.QueryString["dt"]; // Get the user string username = "******"; string avatar = "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTjA0Lpsg840JNGLaPgVWM9QofkvAYdFPLb-g&usqp=CAU"; var ticketAuthor = Global.Client.GetUser(ulong.Parse(uid)); if (ticketAuthor != null) { username = ticketAuthor.ToString(); avatar = ticketAuthor.GetAvatarUrl(Discord.ImageFormat.Jpeg, 256); if (avatar == null) { avatar = ticketAuthor.GetDefaultAvatarUrl(); } } // Create the item var html = Resources.ticketItem.Replace("{item.profile}", avatar) .Replace("{item.username}", username) .Replace("{item.id}", uid) .Replace("{item.date}", DateTime.FromFileTimeUtc(long.Parse(dt)).ToString("R")) .Replace("{item.url}", $"/apprentice/v1/tickets/{uid}/{dt}"); c.Response.ContentEncoding = Encoding.UTF8; c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(html)); c.Response.StatusCode = 200; c.Response.Close(); } }