public async Task SetLogChannel(Context ctx) { ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); DiscordChannel channel = null; if (!ctx.HasNext()) { throw new PKSyntaxError("You must pass a #channel to set."); } var channelString = ctx.PeekArgument(); channel = await ctx.MatchChannel(); if (channel == null || channel.GuildId != ctx.Guild.Id) { throw Errors.ChannelNotFound(channelString); } var patch = new GuildPatch { LogChannel = channel?.Id }; await _db.Execute(conn => conn.UpsertGuild(ctx.Guild.Id, patch)); if (channel != null) { await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name}."); } else { await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared."); } }
public async Task SetLogEnabled(Context ctx, bool enable) { ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); var affectedChannels = new List <DiscordChannel>(); if (ctx.Match("all")) { affectedChannels = (await ctx.Guild.GetChannelsAsync()).Where(x => x.Type == ChannelType.Text).ToList(); } else if (!ctx.HasNext()) { throw new PKSyntaxError("You must pass one or more #channels."); } else { while (ctx.HasNext()) { var channelString = ctx.PeekArgument(); var channel = await ctx.MatchChannel(); if (channel == null || channel.GuildId != ctx.Guild.Id) { throw Errors.ChannelNotFound(channelString); } affectedChannels.Add(channel); } } ulong?logChannel = null; await using (var conn = await _db.Obtain()) { var config = await conn.QueryOrInsertGuildConfig(ctx.Guild.Id); logChannel = config.LogChannel; var blacklist = config.LogBlacklist.ToHashSet(); if (enable) { blacklist.ExceptWith(affectedChannels.Select(c => c.Id)); } else { blacklist.UnionWith(affectedChannels.Select(c => c.Id)); } var patch = new GuildPatch { LogBlacklist = blacklist.ToArray() }; await conn.UpsertGuild(ctx.Guild.Id, patch); } await ctx.Reply( $"{Emojis.Success} Message logging for the given channels {(enable ? "enabled" : "disabled")}." + (logChannel == null ? $"\n{Emojis.Warn} Please note that no logging channel is set, so there is nowhere to log messages to. You can set a logging channel using `pk;log channel #your-log-channel`." : "")); }
public async Task SetBlacklisted(Context ctx, bool shouldAdd) { ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); var affectedChannels = new List <DiscordChannel>(); if (ctx.Match("all")) { affectedChannels = (await ctx.Guild.GetChannelsAsync()).Where(x => x.Type == ChannelType.Text).ToList(); } else if (!ctx.HasNext()) { throw new PKSyntaxError("You must pass one or more #channels."); } else { while (ctx.HasNext()) { var channelString = ctx.PeekArgument(); var channel = await ctx.MatchChannel(); if (channel == null || channel.GuildId != ctx.Guild.Id) { throw Errors.ChannelNotFound(channelString); } affectedChannels.Add(channel); } } await using (var conn = await _db.Obtain()) { var guild = await conn.QueryOrInsertGuildConfig(ctx.Guild.Id); var blacklist = guild.Blacklist.ToHashSet(); if (shouldAdd) { blacklist.UnionWith(affectedChannels.Select(c => c.Id)); } else { blacklist.ExceptWith(affectedChannels.Select(c => c.Id)); } var patch = new GuildPatch { Blacklist = blacklist.ToArray() }; await conn.UpsertGuild(ctx.Guild.Id, patch); } await ctx.Reply($"{Emojis.Success} Channels {(shouldAdd ? "added to" : "removed from")} the proxy blacklist."); }
public async Task SetLogChannel(Context ctx) { ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server"); if (await ctx.MatchClear("the server log channel")) { await _db.Execute(conn => _repo.UpsertGuild(conn, ctx.Guild.Id, new GuildPatch { LogChannel = null })); await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared."); return; } if (!ctx.HasNext()) { throw new PKSyntaxError("You must pass a #channel to set, or `clear` to clear it."); } Channel channel = null; var channelString = ctx.PeekArgument(); channel = await ctx.MatchChannel(); if (channel == null || channel.GuildId != ctx.Guild.Id) { throw Errors.ChannelNotFound(channelString); } var patch = new GuildPatch { LogChannel = channel.Id }; await _db.Execute(conn => _repo.UpsertGuild(conn, ctx.Guild.Id, patch)); await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name}."); }