mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Refactor permission utils to properly account for lack of channel access
This commit is contained in:
parent
f97ceac1fb
commit
ee9c87a29f
3 changed files with 54 additions and 33 deletions
|
|
@ -9,6 +9,7 @@ using Autofac;
|
|||
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.Exceptions;
|
||||
|
||||
using PluralKit.Bot.Utils;
|
||||
using PluralKit.Core;
|
||||
|
|
@ -281,14 +282,27 @@ namespace PluralKit.Bot
|
|||
throw new PKError("You do not have permission to access this information.");
|
||||
}
|
||||
|
||||
public DiscordChannel MatchChannel()
|
||||
public async Task<DiscordChannel> MatchChannel()
|
||||
{
|
||||
if (!MentionUtils.TryParseChannel(PeekArgument(), out var channel)) return null;
|
||||
var discordChannel = _rest.GetChannelAsync(channel).GetAwaiter().GetResult();
|
||||
if (discordChannel.Type != ChannelType.Text) return null;
|
||||
|
||||
PopArgument();
|
||||
return discordChannel;
|
||||
if (!MentionUtils.TryParseChannel(PeekArgument(), out var channel))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var discordChannel = await _shard.GetChannelAsync(channel);
|
||||
if (discordChannel.Type != ChannelType.Text) return null;
|
||||
|
||||
PopArgument();
|
||||
return discordChannel;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (UnauthorizedException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue