mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 11:21:47 -05:00
fix a bug
This commit is contained in:
parent
de6d1d15ab
commit
d40c527da1
1 changed files with 25 additions and 29 deletions
|
@ -29,7 +29,7 @@ public static void NotifyFollowers(string uid, string title, string desc, string
|
||||||
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
throw new Exception("Cannot find user with ID " + uid + ".");
|
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);
|
NotifyUser(uid, follower.Follower, title, desc, url);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public static void NotifyEveryone(string uid, string title, string desc, string
|
||||||
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
throw new Exception("Cannot find user with ID " + uid + ".");
|
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);
|
NotifyUser(uid, usr.Id, title, desc, url);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ private static string ComposeHtml(Notification note)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 db = new ApplicationDbContext();
|
||||||
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
||||||
|
@ -117,40 +117,36 @@ internal static void ScreamToDiscord(string title, string desc, string url)
|
||||||
{
|
{
|
||||||
var db = new ApplicationDbContext();
|
var db = new ApplicationDbContext();
|
||||||
var conf = db.Configs.FirstOrDefault();
|
var conf = db.Configs.FirstOrDefault();
|
||||||
if(conf != null)
|
if (conf != null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(conf.WebhookUrl))
|
if (!string.IsNullOrWhiteSpace(conf.WebhookUrl))
|
||||||
{
|
{
|
||||||
var wc = HttpWebRequest.Create(conf.WebhookUrl);
|
var httpWebRequest = (HttpWebRequest)WebRequest.Create(conf.WebhookUrl);
|
||||||
wc.Method = "POST";
|
httpWebRequest.ContentType = "application/json";
|
||||||
wc.ContentType = "application/json";
|
httpWebRequest.Method = "POST";
|
||||||
string json = new JavaScriptSerializer().Serialize(new
|
|
||||||
|
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
|
||||||
{
|
{
|
||||||
content = $@"**{title}**
|
string json = new JavaScriptSerializer().Serialize(new
|
||||||
|
{
|
||||||
|
content = $@"**{title}**
|
||||||
|
|
||||||
{desc}
|
{desc}
|
||||||
|
|
||||||
Visit this URL to see more: {url}"
|
Visit this URL for more info: {url}"
|
||||||
});
|
});
|
||||||
wc.ContentLength = json.Length;
|
|
||||||
using (var s = wc.GetRequestStream())
|
streamWriter.Write(json);
|
||||||
{
|
streamWriter.Flush();
|
||||||
using(var writer = new StreamWriter(s))
|
streamWriter.Close();
|
||||||
{
|
|
||||||
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 httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
|
||||||
|
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
||||||
|
{
|
||||||
|
var result = streamReader.ReadToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue