Compare commits
2 commits
9b8d00d184
...
ae8a63eeac
Author | SHA1 | Date | |
---|---|---|---|
ae8a63eeac | |||
4549b1f4e4 |
2 changed files with 8 additions and 8 deletions
src/EllieBot/Modules/Utility/LiveChannel
|
@ -13,7 +13,7 @@ public partial class Utility
|
||||||
[BotPerm(GuildPerm.ManageChannels)]
|
[BotPerm(GuildPerm.ManageChannels)]
|
||||||
public async Task LiveChAdd(IChannel channel, [Leftover] string template)
|
public async Task LiveChAdd(IChannel channel, [Leftover] string template)
|
||||||
{
|
{
|
||||||
if (!await svc.AddLiveChannelAsync(ctx.Guild.Id, channel, template))
|
if (!await svc.AddLiveChannelAsync(ctx.Guild.Id, channel.Id, template))
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Error(strs.livechannel_limit(LiveChannelService.MAX_LIVECHANNELS))
|
.Error(strs.livechannel_limit(LiveChannelService.MAX_LIVECHANNELS))
|
||||||
|
|
|
@ -119,16 +119,16 @@ public class LiveChannelService(
|
||||||
/// Adds a new live channel configuration to the specified guild.
|
/// Adds a new live channel configuration to the specified guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guildId">ID of the guild</param>
|
/// <param name="guildId">ID of the guild</param>
|
||||||
/// <param name="channel">Channel to set as live</param>
|
/// <param name="channelId">ID of the channel</param>
|
||||||
/// <param name="template">Template text to use for the channel</param>
|
/// <param name="template">Template text to use for the channel</param>
|
||||||
/// <returns>True if successfully added, false otherwise</returns>
|
/// <returns>True if successfully added, false otherwise</returns>
|
||||||
public async Task<bool> AddLiveChannelAsync(ulong guildId, IChannel channel, string template)
|
public async Task<bool> AddLiveChannelAsync(ulong guildId, ulong channelId, string template)
|
||||||
{
|
{
|
||||||
var guildDict = _liveChannels.GetOrAdd(
|
var guildDict = _liveChannels.GetOrAdd(
|
||||||
guildId,
|
guildId,
|
||||||
_ => new());
|
_ => new());
|
||||||
|
|
||||||
if (guildDict.Count >= MAX_LIVECHANNELS)
|
if (!guildDict.ContainsKey(channelId) && guildDict.Count >= MAX_LIVECHANNELS)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
await using var uow = db.GetDbContext();
|
await using var uow = db.GetDbContext();
|
||||||
|
@ -136,7 +136,7 @@ public class LiveChannelService(
|
||||||
.InsertOrUpdateAsync(() => new()
|
.InsertOrUpdateAsync(() => new()
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
ChannelId = channel.Id,
|
ChannelId = channelId,
|
||||||
Template = template
|
Template = template
|
||||||
},
|
},
|
||||||
(_) => new()
|
(_) => new()
|
||||||
|
@ -146,18 +146,18 @@ public class LiveChannelService(
|
||||||
() => new()
|
() => new()
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
ChannelId = channel.Id
|
ChannelId = channelId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add to in-memory cache
|
// Add to in-memory cache
|
||||||
var newConfig = new LiveChannelConfig
|
var newConfig = new LiveChannelConfig
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
ChannelId = channel.Id,
|
ChannelId = channelId,
|
||||||
Template = template
|
Template = template
|
||||||
};
|
};
|
||||||
|
|
||||||
guildDict[channel.Id] = newConfig;
|
guildDict[channelId] = newConfig;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue