fix: actually store ignored channels/roles
This commit is contained in:
parent
19d9f33454
commit
e12bd6194b
12 changed files with 37 additions and 25 deletions
|
|
@ -45,7 +45,7 @@ public partial class GuildsController
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredChannels.Add(channelId);
|
guildConfig.Messages.IgnoredChannels.Add(channelId);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ public partial class GuildsController
|
||||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredChannels.Remove(channelId);
|
guildConfig.Messages.IgnoredChannels.Remove(channelId);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +75,7 @@ public partial class GuildsController
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredRoles.Add(roleId);
|
guildConfig.Messages.IgnoredRoles.Add(roleId);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,7 @@ public partial class GuildsController
|
||||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredRoles.Remove(roleId);
|
guildConfig.Messages.IgnoredRoles.Remove(roleId);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ public partial class GuildsController
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
guildConfig.IgnoredChannels = [.. guildConfig.IgnoredChannels, channelId];
|
guildConfig.IgnoredChannels = [.. guildConfig.IgnoredChannels, channelId];
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ public partial class GuildsController
|
||||||
var channels = guildConfig.IgnoredChannels.ToList();
|
var channels = guildConfig.IgnoredChannels.ToList();
|
||||||
channels.Remove(channelId);
|
channels.Remove(channelId);
|
||||||
guildConfig.IgnoredChannels = channels.ToArray();
|
guildConfig.IgnoredChannels = channels.ToArray();
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ public partial class GuildsController
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
guildConfig.IgnoredRoles = [.. guildConfig.IgnoredRoles, roleId];
|
guildConfig.IgnoredRoles = [.. guildConfig.IgnoredRoles, roleId];
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ public partial class GuildsController
|
||||||
var roles = guildConfig.IgnoredRoles.ToList();
|
var roles = guildConfig.IgnoredRoles.ToList();
|
||||||
roles.Remove(roleId);
|
roles.Remove(roleId);
|
||||||
guildConfig.IgnoredRoles = roles.ToArray();
|
guildConfig.IgnoredRoles = roles.ToArray();
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public partial class GuildsController
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Channels.Redirects[source.ID.Value] = target.ID.Value;
|
guildConfig.Channels.Redirects[source.ID.Value] = target.ID.Value;
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ public partial class GuildsController
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Channels.Redirects.Remove(channelId, out _);
|
guildConfig.Channels.Redirects.Remove(channelId, out _);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ public partial class GuildsController
|
||||||
return Ok(new IgnoredUser(user.ID.Value, user.Tag()));
|
return Ok(new IgnoredUser(user.ID.Value, user.Tag()));
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredUsers.Add(user.ID.Value);
|
guildConfig.Messages.IgnoredUsers.Add(user.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return Ok(new IgnoredUser(user.ID.Value, user.Tag()));
|
return Ok(new IgnoredUser(user.ID.Value, user.Tag()));
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ public partial class GuildsController
|
||||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredUsers.Remove(userId);
|
guildConfig.Messages.IgnoredUsers.Remove(userId);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,7 +318,7 @@ public partial class GuildsController(
|
||||||
)
|
)
|
||||||
guildConfig.Channels.MessageDeleteBulk = req.MessageDeleteBulk ?? 0;
|
guildConfig.Channels.MessageDeleteBulk = req.MessageDeleteBulk ?? 0;
|
||||||
|
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
return Ok(guildConfig.Channels);
|
return Ok(guildConfig.Channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ public class ChannelCommandsComponents(
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
goto case "return";
|
goto case "return";
|
||||||
case "return":
|
case "return":
|
||||||
var (e, c) = ChannelCommands.BuildRootMenu(guildChannels, guild, guildConfig);
|
var (e, c) = ChannelCommands.BuildRootMenu(guildChannels, guild, guildConfig);
|
||||||
|
|
@ -384,7 +384,7 @@ public class ChannelCommandsComponents(
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
List<IEmbed> embeds =
|
List<IEmbed> embeds =
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public partial class IgnoreMessageCommands : CommandGroup
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredChannels.Add(channel.ID.Value);
|
guildConfig.Messages.IgnoredChannels.Add(channel.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully added {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} to the list of ignored channels."
|
$"Successfully added {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} to the list of ignored channels."
|
||||||
|
|
@ -98,7 +98,7 @@ public partial class IgnoreMessageCommands : CommandGroup
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredChannels.Remove(channel.ID.Value);
|
guildConfig.Messages.IgnoredChannels.Remove(channel.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully removed {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} from the list of ignored channels."
|
$"Successfully removed {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} from the list of ignored channels."
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public partial class IgnoreMessageCommands
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredRoles.Add(role.ID.Value);
|
guildConfig.Messages.IgnoredRoles.Add(role.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully added {role.Name} to the list of ignored roles."
|
$"Successfully added {role.Name} to the list of ignored roles."
|
||||||
|
|
@ -77,7 +77,7 @@ public partial class IgnoreMessageCommands
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredRoles.Remove(role.ID.Value);
|
guildConfig.Messages.IgnoredRoles.Remove(role.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully removed {role.Name} from the list of ignored roles."
|
$"Successfully removed {role.Name} from the list of ignored roles."
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ public partial class IgnoreMessageCommands
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredUsers.Add(user.ID.Value);
|
guildConfig.Messages.IgnoredUsers.Add(user.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully added {user.PrettyFormat()} to the list of ignored users."
|
$"Successfully added {user.PrettyFormat()} to the list of ignored users."
|
||||||
|
|
@ -81,7 +81,7 @@ public partial class IgnoreMessageCommands
|
||||||
);
|
);
|
||||||
|
|
||||||
guildConfig.Messages.IgnoredUsers.Remove(user.ID.Value);
|
guildConfig.Messages.IgnoredUsers.Remove(user.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
return await feedbackService.ReplyAsync(
|
return await feedbackService.ReplyAsync(
|
||||||
$"Successfully removed {user.PrettyFormat()} from the list of ignored users."
|
$"Successfully removed {user.PrettyFormat()} from the list of ignored users."
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class RedirectCommands(
|
||||||
var (_, guildId) = contextInjectionService.GetUserAndGuild();
|
var (_, guildId) = contextInjectionService.GetUserAndGuild();
|
||||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||||
guildConfig.Channels.Redirects[source.ID.Value] = target.ID.Value;
|
guildConfig.Channels.Redirects[source.ID.Value] = target.ID.Value;
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
var output =
|
var output =
|
||||||
$"Success! Edited and deleted messages from {FormatChannel(source)} will now be redirected to <#{target.ID}>.";
|
$"Success! Edited and deleted messages from {FormatChannel(source)} will now be redirected to <#{target.ID}>.";
|
||||||
|
|
@ -101,7 +101,7 @@ public class RedirectCommands(
|
||||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||||
|
|
||||||
var wasSet = guildConfig.Channels.Redirects.Remove(source.ID.Value);
|
var wasSet = guildConfig.Channels.Redirects.Remove(source.ID.Value);
|
||||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
await guildRepository.UpdateConfigAsync(guildId, guildConfig);
|
||||||
|
|
||||||
var output = wasSet
|
var output = wasSet
|
||||||
? $"Removed the redirect for {FormatChannel(source)}! Message logs from"
|
? $"Removed the redirect for {FormatChannel(source)}! Message logs from"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table guilds add column ignored_channels bigint[] not null default array[]::bigint[];
|
||||||
|
alter table guilds add column ignored_roles bigint[] not null default array[]::bigint[];
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
alter table guilds drop column ignored_channels;
|
||||||
|
alter table guilds drop column ignored_roles;
|
||||||
|
|
@ -131,14 +131,22 @@ public class GuildRepository(ILogger logger, DatabaseConnection conn)
|
||||||
new { GuildId = guildId.Value, RoleId = roleId.Value }
|
new { GuildId = guildId.Value, RoleId = roleId.Value }
|
||||||
);
|
);
|
||||||
|
|
||||||
public async Task UpdateChannelConfigAsync(Snowflake id, Guild config) =>
|
public async Task UpdateConfigAsync(Snowflake id, Guild config) =>
|
||||||
await conn.ExecuteAsync(
|
await conn.ExecuteAsync(
|
||||||
"update guilds set channels = @Channels::jsonb, messages = @Messages::jsonb where id = @Id",
|
"""
|
||||||
|
update guilds set channels = @Channels::jsonb,
|
||||||
|
messages = @Messages::jsonb,
|
||||||
|
ignored_channels = @IgnoredChannels,
|
||||||
|
ignored_roles = @IgnoredRoles
|
||||||
|
where id = @Id
|
||||||
|
""",
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = id.Value,
|
Id = id.Value,
|
||||||
config.Channels,
|
config.Channels,
|
||||||
config.Messages,
|
config.Messages,
|
||||||
|
config.IgnoredChannels,
|
||||||
|
config.IgnoredRoles,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue