Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev committed Feb 5, 2024
1 parent 53a7508 commit eda1516
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
41 changes: 13 additions & 28 deletions src/MacroBot.Core/Services/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ private async Task Ready ()
{
DiscordReady = true;
await _interactionService.RegisterCommandsGloballyAsync();
var guild = _discordSocketClient.GetGuild(MacroBotConfig.GuildId);
if (guild?.GetChannel(MacroBotConfig.MemberScreeningChannelId) is ITextChannel channel)
{
var usersCount = GetUsersCount(guild);
await UpdateMemberScreeningChannelName(channel, usersCount);
}
}

private async Task UserJoined (SocketGuildUser member)
Expand Down Expand Up @@ -231,16 +225,21 @@ private async Task MessageReceived (SocketMessage message)
}

var messageByModerator = member.Roles.Contains(member.Guild.GetRole(MacroBotConfig.ModeratorRoleId));
var imageChannels = MacroBotConfig.ImageOnlyChannelIds;

var anyMentionsOnMsg = message.MentionedUsers.Any(u => message.Content.Contains($"<@{u.Id}>"));

if ((message.MentionedEveryone
|| message.MentionedRoles.Count > 0
|| (message.MentionedUsers.Count > 0 && (anyMentionsOnMsg || message.Type != MessageType.Reply))
&& !(messageByModerator || member.GetPermissions(message.Channel as IGuildChannel).ManageMessages)
&& !(message.MentionedUsers.Count == 1 && message.Content.Contains($"<@{message.Author.Id}>"))))
if (message.MentionedEveryone
|| message.MentionedRoles.Count > 0
|| message.MentionedUsers.Count > 0
|| anyMentionsOnMsg)
{
if (message.Type == MessageType.Reply
|| messageByModerator
|| member.GetPermissions(message.Channel as IGuildChannel).ManageMessages)
{
return;
}

await message.DeleteAsync();
_logger.Information(
"Message containing users/roles/everyone from {AuthorUsername} in {ChannelName} was deleted. Message: {Message}",
Expand Down Expand Up @@ -297,7 +296,8 @@ private async Task MessageReceived (SocketMessage message)
}
}

if (imageChannels.Contains(message.Channel.Id) && !DiscordMessageFilter.FilterForImageChannels(message))
if (MacroBotConfig.ImageOnlyChannelIds.Contains(message.Channel.Id)
&& !DiscordMessageFilter.FilterForImageChannels(message))
{
await message.DeleteAsync();

Expand Down Expand Up @@ -374,7 +374,6 @@ private async Task MemberMovement(IGuildUser member, bool joined)

var usersCount = GetUsersCount(guild);
var botsCount = GetBotsCount(guild);
await UpdateMemberScreeningChannelName(channel, usersCount);
EmbedBuilder embed = new()
{
Color = joined ? Color.Green : Color.Red,
Expand All @@ -395,20 +394,6 @@ private async Task MemberMovement(IGuildUser member, bool joined)
await channel.SendMessageAsync(embed: embed.Build());
}

private async Task UpdateMemberScreeningChannelName (ITextChannel channel, int userCount)
{
// Temporarily disabled because of a rate limit
return;
if (channel is not SocketGuildChannel socketGuildChannel)
{
return;
}
await socketGuildChannel.ModifyAsync(properties =>
{
properties.Name = $"{userCount}_users";
});
}

private int GetUsersCount(SocketGuild guild)
{
return guild.Users.ToArray().Length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand Down

0 comments on commit eda1516

Please sign in to comment.