···11using Microsoft.EntityFrameworkCore;
22+using Microsoft.Extensions.Logging;
23using NetCord.Rest;
34using StreakBot.Data;
45using StreakBot.Data.Entities;
···1112{
1213 private readonly StreakDbContext _context;
1314 private readonly RestClient _restClient;
1515+ private readonly ILogger<ChannelService> _logger;
14161515- public ChannelService(StreakDbContext context, RestClient restClient)
1717+ public ChannelService(StreakDbContext context, RestClient restClient, ILogger<ChannelService> logger)
1618 {
1719 _context = context;
1820 _restClient = restClient;
2121+ _logger = logger;
1922 }
20232124 public async Task UpdateStreakChannelAsync(ulong serverId, int streakCount, bool endOfDay = false)
···106109 {
107110 if (user1NeedsReminder)
108111 {
109109- var dmChannel = await _restClient.GetDMChannelAsync(user1Id);
110110- var message = new MessageProperties()
111111- .WithContent($"Your streak with <@{user2Id}> will reset in less than an hour! Send a message in the server to keep it alive!");
112112- await _restClient.SendMessageAsync(dmChannel.Id, message);
112112+ try
113113+ {
114114+ var dmChannel = await _restClient.GetDMChannelAsync(user1Id);
115115+ var message = new MessageProperties()
116116+ .WithContent($"Your streak with <@{user2Id}> will reset in less than an hour! Send a message in the server to keep it alive!");
117117+ await _restClient.SendMessageAsync(dmChannel.Id, message);
118118+ }
119119+ catch (RestException)
120120+ {
121121+ _logger.LogWarning("Failed to send streak reminder DM to user {UserId}", user1Id);
122122+ }
113123 }
114124115125 if (user2NeedsReminder)
116126 {
117117- var dmChannel = await _restClient.GetDMChannelAsync(user2Id);
118118- var message = new MessageProperties()
119119- .WithContent($"Your streak with <@{user1Id}> will reset in less than an hour! Send a message in the server to keep it alive!");
120120- await _restClient.SendMessageAsync(dmChannel.Id, message);
127127+ try
128128+ {
129129+ var dmChannel = await _restClient.GetDMChannelAsync(user2Id);
130130+ var message = new MessageProperties()
131131+ .WithContent($"Your streak with <@{user1Id}> will reset in less than an hour! Send a message in the server to keep it alive!");
132132+ await _restClient.SendMessageAsync(dmChannel.Id, message);
133133+ }
134134+ catch (RestException)
135135+ {
136136+ _logger.LogWarning("Failed to send streak reminder DM to user {UserId}", user2Id);
137137+ }
121138 }
122139 }
123140