_adminLogger.Add(
LogType.Chat, LogImpact.Medium,
$"{ToPrettyString(msg.Actor):actor} deleted news article {article.Title} by {article.Author}: {article.Content}"
- );
+ );
articles.RemoveAt(msg.ArticleNum);
_audio.PlayPvs(ent.Comp.ConfirmSound, ent);
if (!ent.Comp.PublishEnabled)
return;
- if (!TryGetArticles(ent, out var articles))
- return;
-
if (!CanUse(msg.Actor, ent.Owner))
return;
var title = msg.Title.Trim();
var content = msg.Content.Trim();
- var article = new NewsArticle
+ if (TryAddNews(ent, title, content, out var article, authorName, msg.Actor))
+ {
+ _audio.PlayPvs(ent.Comp.ConfirmSound, ent);
+
+ _chatManager.SendAdminAnnouncement(Loc.GetString("news-publish-admin-announcement",
+ ("actor", msg.Actor),
+ ("title", article.Value.Title),
+ ("author", article.Value.Author ?? Loc.GetString("news-read-ui-no-author"))
+ ));
+ }
+ }
+
+ /// <summary>
+ /// Set the alert level based on the station's entity ID.
+ /// </summary>
+ /// <param name="uid">Entity on the station to which news will be added.</param>
+ /// <param name="title">Title of the news article.</param>
+ /// <param name="content">Content of the news article.</param>
+ /// <param name="author">Author of the news article.</param>
+ /// <param name="actor">Entity which caused the news article to publish. Used for admin logs.</param>
+ public bool TryAddNews(EntityUid uid, string title, string content, [NotNullWhen(true)] out NewsArticle? article, string? author = null, EntityUid? actor = null)
+ {
+ if (!TryGetArticles(uid, out var articles))
+ {
+ article = null;
+ return false;
+ }
+
+ article = new NewsArticle
{
Title = title.Length <= MaxTitleLength ? title : $"{title[..MaxTitleLength]}...",
Content = content.Length <= MaxContentLength ? content : $"{content[..MaxContentLength]}...",
- Author = authorName,
+ Author = author,
ShareTime = _ticker.RoundDuration()
};
- _audio.PlayPvs(ent.Comp.ConfirmSound, ent);
-
- _adminLogger.Add(
- LogType.Chat,
- LogImpact.Medium,
- $"{ToPrettyString(msg.Actor):actor} created news article {article.Title} by {article.Author}: {article.Content}"
- );
-
- _chatManager.SendAdminAnnouncement(Loc.GetString("news-publish-admin-announcement",
- ("actor", msg.Actor),
- ("title", article.Title),
- ("author", article.Author ?? Loc.GetString("news-read-ui-no-author"))
- ));
+ articles.Add(article.Value);
- articles.Add(article);
+ if (actor != null)
+ {
+ _adminLogger.Add(
+ LogType.Chat,
+ LogImpact.Medium,
+ $"{ToPrettyString(actor):actor} created news article {article.Value.Title} by {article.Value.Author}: {article.Value.Content}");
+ }
+ else
+ {
+ _adminLogger.Add(
+ LogType.Chat,
+ LogImpact.Medium,
+ $"Created news article {article.Value.Title} by {article.Value.Author}: {article.Value.Content}");
+ }
- var args = new NewsArticlePublishedEvent(article);
+ var args = new NewsArticlePublishedEvent(article.Value);
var query = EntityQueryEnumerator<NewsReaderCartridgeComponent>();
+
while (query.MoveNext(out var readerUid, out _))
{
RaiseLocalEvent(readerUid, ref args);
Task.Run(async () => await SendArticleToDiscordWebhook(article));
UpdateWriterDevices();
+
+ return true;
}
#endregion