summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-05-25 15:17:06 -0400
committerMichael <[email protected]>2017-05-25 15:17:06 -0400
commit3f1236f22eda41e4d7e869d5e7da3802e7419a26 (patch)
tree4382a6dc2e65cd60075ec7b8c78d6fcffddf4551
parent7c3d5156e13a8394350150662faf599d00e83e97 (diff)
downloadproject-unite-3f1236f22eda41e4d7e869d5e7da3802e7419a26.tar.gz
project-unite-3f1236f22eda41e4d7e869d5e7da3802e7419a26.tar.bz2
project-unite-3f1236f22eda41e4d7e869d5e7da3802e7419a26.zip
discord webhooks
-rw-r--r--Project-Unite/Controllers/DeveloperController.cs7
-rw-r--r--Project-Unite/Models/AdminViewModels.cs1
-rw-r--r--Project-Unite/NotificationDaemon.cs45
3 files changed, 52 insertions, 1 deletions
diff --git a/Project-Unite/Controllers/DeveloperController.cs b/Project-Unite/Controllers/DeveloperController.cs
index b635a21..16c7799 100644
--- a/Project-Unite/Controllers/DeveloperController.cs
+++ b/Project-Unite/Controllers/DeveloperController.cs
@@ -145,6 +145,13 @@ namespace Project_Unite.Controllers
//Now we just save to the database...
db.Downloads.Add(download);
+
+ NotificationDaemon.ScreamToDiscord("New release: " + download.Name, $@"A new release of ShiftOS has been made!
+
+Release name: {download.Name}
+Stable: {download.IsStable}
+Released on: {download.PostDate}", Url.Action("ViewRelease", "Downloads", new { id = download.Id }));
+
db.SaveChanges();
return RedirectToAction("Releases");
diff --git a/Project-Unite/Models/AdminViewModels.cs b/Project-Unite/Models/AdminViewModels.cs
index 8a6425e..8f0657c 100644
--- a/Project-Unite/Models/AdminViewModels.cs
+++ b/Project-Unite/Models/AdminViewModels.cs
@@ -75,6 +75,7 @@ namespace Project_Unite.Models
public class Configuration
{
public string Id { get; set; }
+ public string WebhookUrl { get; set; }
public string FeedbackEmail { get; set; }
public string SiteName { get; set; }
public string ReturnEmail { get; set; }
diff --git a/Project-Unite/NotificationDaemon.cs b/Project-Unite/NotificationDaemon.cs
index 0512790..25db0ac 100644
--- a/Project-Unite/NotificationDaemon.cs
+++ b/Project-Unite/NotificationDaemon.cs
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
+using System.Net;
using System.Text;
using System.Web;
+using System.Web.Script.Serialization;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.AspNet.SignalR;
using Project_Unite.Models;
@@ -110,6 +113,46 @@ namespace Project_Unite
SendMessage(target, ComposeHtml(note));
}
-
+ internal static void ScreamToDiscord(string title, string desc, string url)
+ {
+ var db = new ApplicationDbContext();
+ var conf = db.Configs.FirstOrDefault();
+ if(conf != null)
+ {
+ if (!string.IsNullOrWhiteSpace(conf.WebhookUrl))
+ {
+ var wc = HttpWebRequest.Create(conf.WebhookUrl);
+ wc.Method = "POST";
+ wc.ContentType = "application/json";
+ string json = new JavaScriptSerializer().Serialize(new
+ {
+ content = $@"**{title}**
+
+{desc}
+
+Visit this URL to see more: {url}"
+ });
+ wc.ContentLength = json.Length;
+ using (var s = wc.GetRequestStream())
+ {
+ using(var writer = new StreamWriter(s))
+ {
+ writer.Write(json);
+ using(var r = wc.GetResponse())
+ {
+ using(var rs = r.GetResponseStream())
+ {
+ using(var reader = new StreamReader(rs))
+ {
+ string result = reader.ReadToEnd();
+ db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, "Discord webhook sent. Result: " + result));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
} \ No newline at end of file