summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-05-25 15:32:38 -0400
committerMichael <[email protected]>2017-05-25 15:32:38 -0400
commitd40c527da13fd1e1542b785393bd925f4d0bb547 (patch)
treedb723a1298f696d38ca09666c941a12b15bef816
parentde6d1d15ab2f2f770efdb894eac5f1ce683af3fd (diff)
downloadproject-unite-d40c527da13fd1e1542b785393bd925f4d0bb547.tar.gz
project-unite-d40c527da13fd1e1542b785393bd925f4d0bb547.tar.bz2
project-unite-d40c527da13fd1e1542b785393bd925f4d0bb547.zip
fix a bug
-rw-r--r--Project-Unite/NotificationDaemon.cs52
1 files changed, 24 insertions, 28 deletions
diff --git a/Project-Unite/NotificationDaemon.cs b/Project-Unite/NotificationDaemon.cs
index 25db0ac..10fddae 100644
--- a/Project-Unite/NotificationDaemon.cs
+++ b/Project-Unite/NotificationDaemon.cs
@@ -29,7 +29,7 @@ namespace Project_Unite
var user = db.Users.FirstOrDefault(x => x.Id == uid);
if (user == null)
throw new Exception("Cannot find user with ID " + uid + ".");
- foreach(var follower in user.Followers)
+ foreach (var follower in user.Followers)
{
NotifyUser(uid, follower.Follower, title, desc, url);
}
@@ -41,7 +41,7 @@ namespace Project_Unite
var user = db.Users.FirstOrDefault(x => x.Id == uid);
if (user == null)
throw new Exception("Cannot find user with ID " + uid + ".");
- foreach (var usr in db.Users.Where(x=>x.Id!=uid).ToArray())
+ foreach (var usr in db.Users.Where(x => x.Id != uid).ToArray())
{
NotifyUser(uid, usr.Id, title, desc, url);
}
@@ -68,7 +68,7 @@ namespace Project_Unite
}
- public static void NotifyUser(string uid, string target, string title, string desc, string url)
+ public static void NotifyUser(string uid, string target, string title, string desc, string url)
{
var db = new ApplicationDbContext();
var user = db.Users.FirstOrDefault(x => x.Id == uid);
@@ -117,40 +117,36 @@ namespace Project_Unite
{
var db = new ApplicationDbContext();
var conf = db.Configs.FirstOrDefault();
- if(conf != null)
+ 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
+ var httpWebRequest = (HttpWebRequest)WebRequest.Create(conf.WebhookUrl);
+ httpWebRequest.ContentType = "application/json";
+ httpWebRequest.Method = "POST";
+
+ using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
- content = $@"**{title}**
+ 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())
+Visit this URL for more info: {url}"
+ });
+
+ streamWriter.Write(json);
+ streamWriter.Flush();
+ streamWriter.Close();
+ }
+
+ var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
+ using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
- 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));
- }
- }
- }
- }
+ var result = streamReader.ReadToEnd();
}
+
}
}
}