public static async Task getTicket(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 (m[0].Groups.Count != 3) { c.Response.StatusCode = 400; c.Response.Close(); return; } // Fetch them the html! var uid = m[0].Groups[1].Value; var timestamp = m[0].Groups[2].Value; var ts = TranscriptHandler.GetTranscript(uid, timestamp); if (ts == null) { c.Response.StatusCode = 404; c.Response.Close(); return; } c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(ts)); c.Response.ContentEncoding = Encoding.UTF8; c.Response.ContentType = "text/html"; c.Response.StatusCode = 200; c.Response.Close(); }
public async Task StartAsync() { WebSocketServer.Create(); Global.systemSlash = "/"; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[" + DateTime.Now.TimeOfDay + "] - " + "Welcome, " + Environment.UserName); Global.ReadConfig(); _t = new TranscriptHandler(); await DiscordAuthKeeper.Init(); _client = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Debug, AlwaysDownloadUsers = true, }); _client.Log += Log; await _client.LoginAsync(TokenType.Bot, Global.Token); await _client.StartAsync(); Global.Client = _client; _commands = new CustomCommandService(new Settings() { DefaultPrefix = Global.Preflix, HasPermissionMethod = HasPerms, CustomGuildPermissionMethod = new Dictionary <ulong, Func <SocketCommandContext, bool> >() { { 592458779006730264, HasPerms }, { 622150031092350976, (SocketCommandContext c) => { return(true); } }, { 726857672942420070, (SocketCommandContext c) => { return(false); } }, { 706397254000443392, (SocketCommandContext c) => { return(true); } } }, AllowCommandExecutionOnInvalidPermissions = true, DMCommands = false }); handlerService = new HandlerService(_client); _handler = new CommandHandler(_client, _commands, handlerService); Global.ConsoleLog("Creating Server..."); _server = new HttpServer(3000); Global.ConsoleLog("Server running!"); await Task.Delay(-1); //jabibot }
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 getTicket(HttpListenerContext c, MatchCollection m) { var user = c.GetSwissbotAuth(); if (user == null) { return; } if (m[0].Groups.Count != 3) { c.Response.StatusCode = 400; c.Response.Close(); return; } // Fetch them the html! var uid = m[0].Groups[1].Value; var timestamp = m[0].Groups[2].Value; var ts = TranscriptHandler.GetTranscript(uid, timestamp); if (ts == null) { c.Response.StatusCode = 404; c.Response.Close(); return; } c.Response.OutputStream.Write(Encoding.UTF8.GetBytes(ts)); c.Response.ContentEncoding = Encoding.UTF8; c.Response.ContentType = "text/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(); } }