Skip to content

Commit 1c984e7

Browse files
author
Patrick Sachs
authored
Merge pull request #55 from SahneeDEV/next
Added: Changelog permission logging
2 parents 648aa78 + 48a97f9 commit 1c984e7

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

SahneeBot/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 1.0.1
4+
5+
The Sahnee-Bot is currently generating an increased amount of errors related to changelog permissions.
6+
Functionality may be impacted while we work on a solution. Thank you for your patience.
7+
38
## 1.0.0
49

510
Sahnee-Bot 1.0.0 is a complete rewrite of the Sahnee-Bot using the new Discord slash commands, with a more modern and stable architecture that will allow us to implement even more & better features in the future!

SahneeBot/SahneeBotDiscordError.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ private ISuccess<T> GetMissingRolePermissionsError<T>(string prefix)
107107
{
108108
var inviteUrl = _cfg["BotSettings:InviteUrl"];
109109
return new Error<T>("The Sahnee-Bot does not have enough permissions on your server.\n" +
110-
"-----------------\n" +
111-
$"**Due to the update of the Sahnee-Bot on {_release.StartedAt.ToShortDateString()} " +
112-
"the bot does not have all permissions required.\n" +
113-
$"Please kick the bot and re-invite it using [this link]({inviteUrl}).**\n" +
114-
"**Please note that since a lot of people are currently updating the bot you may need to " +
115-
"wait a minute or two after the bot has been invited for commands to appear. If nothing " +
116-
"happens after 15 minutes feel free to join the support server.**\n" +
117110
"-----------------\n" +
118111
"Please drag the Sahnee-Bot role above all other roles starting with " +
119112
$"\"{prefix.TrimEnd()}\" in your Server Settings and make sure that it has the \"Manage " +

SahneeBot/Tasks/SahneeBotPostChangelogsToGuildTask.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SahneeBot.Formatter;
1+
using Microsoft.Extensions.Logging;
2+
using SahneeBot.Formatter;
23
using SahneeBotController;
34
using SahneeBotController.Tasks;
45

@@ -11,23 +12,27 @@ public class SahneeBotPostChangelogsToGuildTask : PostChangelogsToGuildTask
1112
private readonly Bot _bot;
1213
private readonly SahneeBotDiscordError _discordError;
1314
private readonly GetBoundChannelTask _boundChannelTask;
15+
private readonly ILogger<SahneeBotPostChangelogsToGuildTask> _logger;
1416

1517
public SahneeBotPostChangelogsToGuildTask(Changelog changelog
1618
, ChangelogVersionDiscordFormatter fmt
1719
, GetBoundChannelTask boundChannelTask
1820
, Bot bot
19-
, SahneeBotDiscordError discordError)
21+
, SahneeBotDiscordError discordError
22+
, ILogger<SahneeBotPostChangelogsToGuildTask> logger)
2023
{
2124
_changelog = changelog;
2225
_fmt = fmt;
2326
_bot = bot;
2427
_discordError = discordError;
28+
_logger = logger;
2529
_boundChannelTask = boundChannelTask;
2630
}
2731

2832
public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
2933
{
3034
var (guildId, enumerable) = arg;
35+
_logger.LogDebug("Will now send changelogs to guild {Guild}", guildId);
3136
var set = new HashSet<Version>(enumerable);
3237
var changelogs = _changelog.Versions
3338
.Where(v => set.Contains(v.Version))
@@ -36,6 +41,7 @@ public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
3641
var guild = await _bot.Client.GetGuildAsync(guildId);
3742
if (guild == null)
3843
{
44+
_logger.LogWarning("Could not found the guild {GuildId}", guildId);
3945
return new Error<uint>("Could not find the server.");
4046
}
4147

@@ -44,20 +50,26 @@ public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
4450
: await guild.GetDefaultChannelAsync();
4551
if (channel == null)
4652
{
53+
_logger.LogWarning("Could not find a channel to post the changelogs in {GuildId}", guildId);
4754
return new Error<uint>("Could not find a channel to post the changelogs in.");
4855
}
4956

5057
try
5158
{
5259
if (await _fmt.FormatAndSendMany(changelogs, channel.SendMessageAsync))
5360
{
61+
_logger.LogDebug("Sent the changelog to guild {Guild}", guildId);
5462
return new Success<uint>((uint) changelogs.Count);
5563
}
5664
}
5765
catch(Exception exception)
5866
{
59-
var error = await _discordError.TryGetError<uint>(
60-
ctx, new SahneeBotDiscordError.ErrorOptions {Exception = exception, GuildId = guildId});
67+
_logger.LogWarning(exception, "Failed to post changelogs in guild {Guild} due to error", guildId);
68+
var error = await _discordError.TryGetError<uint>(ctx
69+
, new SahneeBotDiscordError.ErrorOptions {
70+
Exception = exception
71+
, GuildId = guildId
72+
});
6173
if (error != null)
6274
{
6375
return error;
@@ -66,6 +78,7 @@ public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
6678
throw;
6779
}
6880

81+
_logger.LogDebug("No changelogs to post to {Guild}", guildId);
6982
return new Error<uint>("No changelogs to post.");
7083
}
71-
}
84+
}

SahneeBotController/Tasks/UpdateGuildChangelogTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected UpdateGuildChangelogTask(IServiceProvider provider)
5050
if (!post.IsSuccess)
5151
{
5252
_logger.LogWarning(EventIds.Changelog
53-
, "Failed to post warnings to guild {Guild}: {Error}"
53+
, "Failed to post changelog to guild {Guild}: {Error}"
5454
, arg.GuildId, post.Message);
5555
success = new Error<Version?>(post.Message);
5656
}

0 commit comments

Comments
 (0)