@@ -9,6 +9,7 @@ namespace DiscordBot.Services;
99
1010public class FeedService
1111{
12+ private const string ServiceName = "FeedService" ;
1213 private readonly DiscordSocketClient _client ;
1314
1415 private readonly BotSettings _settings ;
@@ -72,13 +73,12 @@ private async Task<SyndicationFeed> GetFeedData(string url)
7273 var client = new HttpClient ( ) ;
7374 var response = await client . GetStringAsync ( url ) ;
7475 response = Utils . Utils . SanitizeXml ( response ) ;
75- XmlReader reader = new XmlTextReader ( new StringReader ( response ) ) ;
76+ var reader = XmlReader . Create ( new StringReader ( response ) ) ;
7677 feed = SyndicationFeed . Load ( reader ) ;
7778 }
7879 catch ( Exception e )
7980 {
80- LoggingService . LogToConsole ( e . ToString ( ) , LogSeverity . Error ) ;
81- await _logging . LogAction ( $ "Feed Service Error: { e . ToString ( ) } ", true , true ) ;
81+ LoggingService . LogToConsole ( $ "[{ ServiceName } Feed failure: { e . ToString ( ) } ", ExtendedLogSeverity . LowWarning ) ;
8282 }
8383
8484 // Return the feed, empty feed if null to prevent additional checks for null on return
@@ -97,8 +97,8 @@ private async Task HandleFeed(FeedData feedData, ForumNewsFeed newsFeed, ulong c
9797 var channel = _client . GetChannel ( channelId ) as IForumChannel ;
9898 if ( channel == null )
9999 {
100- await _logging . LogAction ( $ "Feed Service Error: Channel { channelId } not found", true , true ) ;
101- LoggingService . LogToConsole ( $ "Feed Service Error: Channel { channelId } not found", LogSeverity . Error ) ;
100+ await _logging . LogAction ( $ "[ { ServiceName } ] Error: Channel { channelId } not found", true , true ) ;
101+ LoggingService . LogToConsole ( $ "[ { ServiceName } ] Error: Channel { channelId } not found", LogSeverity . Error ) ;
102102 return ;
103103 }
104104 foreach ( var item in feed . Items . Take ( MaximumCheck ) )
@@ -110,7 +110,7 @@ private async Task HandleFeed(FeedData feedData, ForumNewsFeed newsFeed, ulong c
110110 // Title
111111 var newsTitle = string . Format ( newsFeed . TitleFormat , item . Title . Text ) ;
112112 if ( newsTitle . Length > 90 )
113- newsTitle = newsTitle . Substring ( 0 , 95 ) + "..." ;
113+ newsTitle = newsTitle [ .. 90 ] + "..." ;
114114
115115 // Confirm we haven't posted this title before
116116 if ( _postedFeeds . Contains ( newsTitle ) )
@@ -126,8 +126,8 @@ private async Task HandleFeed(FeedData feedData, ForumNewsFeed newsFeed, ulong c
126126 var summary = Utils . Utils . RemoveHtmlTags ( item . Summary . Text ) ;
127127 newsContent = "**__Summary__**\n " + summary ;
128128 // Unlikely to be over, but we need space for extra local info
129- if ( newsContent . Length > Constants . MaxLengthChannelMessage - 100 )
130- newsContent = newsContent . Substring ( 0 , Constants . MaxLengthChannelMessage - 100 ) + "..." ;
129+ if ( newsContent . Length > Constants . MaxLengthChannelMessage - 400 )
130+ newsContent = newsContent [ .. ( Constants . MaxLengthChannelMessage - 400 ) ] + "..." ;
131131 }
132132 // If a role is provided we add to end of title to ping the role
133133 var role = _client . GetGuild ( _settings . GuildId ) . GetRole ( roleId ?? 0 ) ;
@@ -140,7 +140,7 @@ private async Task HandleFeed(FeedData feedData, ForumNewsFeed newsFeed, ulong c
140140 // The Post
141141 var post = await channel . CreatePostAsync ( newsTitle , ForumArchiveDuration , null , newsContent , null , null , AllowedMentions . All ) ;
142142 // If any tags, include them
143- if ( newsFeed . IncludeTags != null && newsFeed . IncludeTags . Count > 0 )
143+ if ( newsFeed . IncludeTags is { Count : > 0 } )
144144 {
145145 var includedTags = new List < ulong > ( ) ;
146146 foreach ( var tag in newsFeed . IncludeTags )
@@ -157,7 +157,7 @@ private async Task HandleFeed(FeedData feedData, ForumNewsFeed newsFeed, ulong c
157157 catch ( Exception e )
158158 {
159159 LoggingService . LogToConsole ( e . ToString ( ) , LogSeverity . Error ) ;
160- await _logging . LogAction ( $ "Feed Service Error: { e . ToString ( ) } ", true , true ) ;
160+ await _logging . LogAction ( $ "[ { ServiceName } ] Error: { e . ToString ( ) } ", true , true ) ;
161161 }
162162 }
163163
0 commit comments