Skip to content

Commit

Permalink
Merge pull request #55 from SahneeDEV/next
Browse files Browse the repository at this point in the history
Added: Changelog permission logging
  • Loading branch information
Patrick Sachs authored Apr 28, 2022
2 parents 648aa78 + 48a97f9 commit 1c984e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions SahneeBot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 1.0.1

The Sahnee-Bot is currently generating an increased amount of errors related to changelog permissions.
Functionality may be impacted while we work on a solution. Thank you for your patience.

## 1.0.0

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!
Expand Down
7 changes: 0 additions & 7 deletions SahneeBot/SahneeBotDiscordError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ private ISuccess<T> GetMissingRolePermissionsError<T>(string prefix)
{
var inviteUrl = _cfg["BotSettings:InviteUrl"];
return new Error<T>("The Sahnee-Bot does not have enough permissions on your server.\n" +
"-----------------\n" +
$"**Due to the update of the Sahnee-Bot on {_release.StartedAt.ToShortDateString()} " +
"the bot does not have all permissions required.\n" +
$"Please kick the bot and re-invite it using [this link]({inviteUrl}).**\n" +
"**Please note that since a lot of people are currently updating the bot you may need to " +
"wait a minute or two after the bot has been invited for commands to appear. If nothing " +
"happens after 15 minutes feel free to join the support server.**\n" +
"-----------------\n" +
"Please drag the Sahnee-Bot role above all other roles starting with " +
$"\"{prefix.TrimEnd()}\" in your Server Settings and make sure that it has the \"Manage " +
Expand Down
23 changes: 18 additions & 5 deletions SahneeBot/Tasks/SahneeBotPostChangelogsToGuildTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SahneeBot.Formatter;
using Microsoft.Extensions.Logging;
using SahneeBot.Formatter;
using SahneeBotController;
using SahneeBotController.Tasks;

Expand All @@ -11,23 +12,27 @@ public class SahneeBotPostChangelogsToGuildTask : PostChangelogsToGuildTask
private readonly Bot _bot;
private readonly SahneeBotDiscordError _discordError;
private readonly GetBoundChannelTask _boundChannelTask;
private readonly ILogger<SahneeBotPostChangelogsToGuildTask> _logger;

public SahneeBotPostChangelogsToGuildTask(Changelog changelog
, ChangelogVersionDiscordFormatter fmt
, GetBoundChannelTask boundChannelTask
, Bot bot
, SahneeBotDiscordError discordError)
, SahneeBotDiscordError discordError
, ILogger<SahneeBotPostChangelogsToGuildTask> logger)
{
_changelog = changelog;
_fmt = fmt;
_bot = bot;
_discordError = discordError;
_logger = logger;
_boundChannelTask = boundChannelTask;
}

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

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

try
{
if (await _fmt.FormatAndSendMany(changelogs, channel.SendMessageAsync))
{
_logger.LogDebug("Sent the changelog to guild {Guild}", guildId);
return new Success<uint>((uint) changelogs.Count);
}
}
catch(Exception exception)
{
var error = await _discordError.TryGetError<uint>(
ctx, new SahneeBotDiscordError.ErrorOptions {Exception = exception, GuildId = guildId});
_logger.LogWarning(exception, "Failed to post changelogs in guild {Guild} due to error", guildId);
var error = await _discordError.TryGetError<uint>(ctx
, new SahneeBotDiscordError.ErrorOptions {
Exception = exception
, GuildId = guildId
});
if (error != null)
{
return error;
Expand All @@ -66,6 +78,7 @@ public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
throw;
}

_logger.LogDebug("No changelogs to post to {Guild}", guildId);
return new Error<uint>("No changelogs to post.");
}
}
}
2 changes: 1 addition & 1 deletion SahneeBotController/Tasks/UpdateGuildChangelogTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected UpdateGuildChangelogTask(IServiceProvider provider)
if (!post.IsSuccess)
{
_logger.LogWarning(EventIds.Changelog
, "Failed to post warnings to guild {Guild}: {Error}"
, "Failed to post changelog to guild {Guild}: {Error}"
, arg.GuildId, post.Message);
success = new Error<Version?>(post.Message);
}
Expand Down

0 comments on commit 1c984e7

Please sign in to comment.