Initial commit, basic proxying working
This commit is contained in:
@@ -12,10 +12,14 @@ using DSharpPlus.Entities;
|
||||
using DSharpPlus.EventArgs;
|
||||
using DSharpPlus.Exceptions;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
||||
using Permissions = DSharpPlus.Permissions;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
public static class DiscordUtils
|
||||
@@ -190,8 +194,7 @@ namespace PluralKit.Bot
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<IMention> ParseAllMentions(this string input, bool allowEveryone = false,
|
||||
DiscordGuild guild = null)
|
||||
public static IEnumerable<IMention> ParseAllMentions(this string input, Guild guild, bool allowEveryone = false)
|
||||
{
|
||||
var mentions = new List<IMention>();
|
||||
mentions.AddRange(USER_MENTION.Matches(input)
|
||||
@@ -203,7 +206,7 @@ namespace PluralKit.Bot
|
||||
// Original fix by Gwen
|
||||
mentions.AddRange(ROLE_MENTION.Matches(input)
|
||||
.Select(x => ulong.Parse(x.Groups[1].Value))
|
||||
.Where(x => allowEveryone || guild != null && guild.GetRole(x).IsMentionable)
|
||||
.Where(x => allowEveryone || guild != null && (guild.Roles.FirstOrDefault(g => g.Id == x)?.Mentionable ?? false))
|
||||
.Select(x => new RoleMention(x) as IMention));
|
||||
if (EVERYONE_HERE_MENTION.IsMatch(input) && allowEveryone)
|
||||
mentions.Add(new EveryoneMention());
|
||||
|
@@ -4,26 +4,29 @@ using System.Linq;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.EventArgs;
|
||||
|
||||
using Myriad.Gateway;
|
||||
|
||||
using Sentry;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
public interface ISentryEnricher<T> where T: DiscordEventArgs
|
||||
public interface ISentryEnricher<T> where T: IGatewayEvent
|
||||
{
|
||||
void Enrich(Scope scope, DiscordClient shard, T evt);
|
||||
void Enrich(Scope scope, Shard shard, T evt);
|
||||
}
|
||||
|
||||
public class SentryEnricher:
|
||||
ISentryEnricher<MessageCreateEventArgs>,
|
||||
ISentryEnricher<MessageDeleteEventArgs>,
|
||||
ISentryEnricher<MessageUpdateEventArgs>,
|
||||
ISentryEnricher<MessageBulkDeleteEventArgs>,
|
||||
ISentryEnricher<MessageReactionAddEventArgs>
|
||||
public class SentryEnricher //:
|
||||
// TODO!!!
|
||||
// ISentryEnricher<MessageCreateEventArgs>,
|
||||
// ISentryEnricher<MessageDeleteEventArgs>,
|
||||
// ISentryEnricher<MessageUpdateEventArgs>,
|
||||
// ISentryEnricher<MessageBulkDeleteEventArgs>,
|
||||
// ISentryEnricher<MessageReactionAddEventArgs>
|
||||
{
|
||||
// TODO: should this class take the Scope by dependency injection instead?
|
||||
// Would allow us to create a centralized "chain of handlers" where this class could just be registered as an entry in
|
||||
|
||||
public void Enrich(Scope scope, DiscordClient shard, MessageCreateEventArgs evt)
|
||||
public void Enrich(Scope scope, Shard shard, MessageCreateEventArgs evt)
|
||||
{
|
||||
scope.AddBreadcrumb(evt.Message.Content, "event.message", data: new Dictionary<string, string>
|
||||
{
|
||||
@@ -32,7 +35,7 @@ namespace PluralKit.Bot
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
});
|
||||
scope.SetTag("shard", shard.ShardId.ToString());
|
||||
scope.SetTag("shard", shard.ShardInfo?.ShardId.ToString());
|
||||
|
||||
// Also report information about the bot's permissions in the channel
|
||||
// We get a lot of permission errors so this'll be useful for determining problems
|
||||
@@ -40,7 +43,7 @@ namespace PluralKit.Bot
|
||||
scope.AddBreadcrumb(perms.ToPermissionString(), "permissions");
|
||||
}
|
||||
|
||||
public void Enrich(Scope scope, DiscordClient shard, MessageDeleteEventArgs evt)
|
||||
public void Enrich(Scope scope, Shard shard, MessageDeleteEventArgs evt)
|
||||
{
|
||||
scope.AddBreadcrumb("", "event.messageDelete",
|
||||
data: new Dictionary<string, string>()
|
||||
@@ -49,10 +52,10 @@ namespace PluralKit.Bot
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
});
|
||||
scope.SetTag("shard", shard.ShardId.ToString());
|
||||
scope.SetTag("shard", shard.ShardInfo?.ShardId.ToString());
|
||||
}
|
||||
|
||||
public void Enrich(Scope scope, DiscordClient shard, MessageUpdateEventArgs evt)
|
||||
public void Enrich(Scope scope, Shard shard, MessageUpdateEventArgs evt)
|
||||
{
|
||||
scope.AddBreadcrumb(evt.Message.Content ?? "<unknown>", "event.messageEdit",
|
||||
data: new Dictionary<string, string>()
|
||||
@@ -61,10 +64,10 @@ namespace PluralKit.Bot
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()}
|
||||
});
|
||||
scope.SetTag("shard", shard.ShardId.ToString());
|
||||
scope.SetTag("shard", shard.ShardInfo?.ShardId.ToString());
|
||||
}
|
||||
|
||||
public void Enrich(Scope scope, DiscordClient shard, MessageBulkDeleteEventArgs evt)
|
||||
public void Enrich(Scope scope, Shard shard, MessageBulkDeleteEventArgs evt)
|
||||
{
|
||||
scope.AddBreadcrumb("", "event.messageDelete",
|
||||
data: new Dictionary<string, string>()
|
||||
@@ -73,10 +76,10 @@ namespace PluralKit.Bot
|
||||
{"guild", evt.Channel.Id.ToString()},
|
||||
{"messages", string.Join(",", evt.Messages.Select(m => m.Id))},
|
||||
});
|
||||
scope.SetTag("shard", shard.ShardId.ToString());
|
||||
scope.SetTag("shard", shard.ShardInfo?.ShardId.ToString());
|
||||
}
|
||||
|
||||
public void Enrich(Scope scope, DiscordClient shard, MessageReactionAddEventArgs evt)
|
||||
public void Enrich(Scope scope, Shard shard, MessageReactionAddEventArgs evt)
|
||||
{
|
||||
scope.AddBreadcrumb("", "event.reaction",
|
||||
data: new Dictionary<string, string>()
|
||||
@@ -87,7 +90,7 @@ namespace PluralKit.Bot
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
{"reaction", evt.Emoji.Name}
|
||||
});
|
||||
scope.SetTag("shard", shard.ShardId.ToString());
|
||||
scope.SetTag("shard", shard.ShardInfo?.ShardId.ToString());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user