public static async Task CreateReactionsBulk(this DiscordApiClient rest, Message msg, string[] reactions) { foreach (var reaction in reactions) { await rest.CreateReaction(msg.ChannelId, msg.Id, new() { Name = reaction }); } }
public async Task ReproxyMessage(Context ctx) { var msg = await GetMessageToEdit(ctx, ReproxyTimeout, true); if (ctx.System.Id != msg.System?.Id) { throw new PKError("Can't reproxy a message sent by a different system."); } // Get target member ID var target = await ctx.MatchMember(restrictToSystem : ctx.System.Id); if (target == null) { throw new PKError("Could not find a member to reproxy the message with."); } // Fetch members and get the ProxyMember for `target` List <ProxyMember> members; using (_metrics.Measure.Timer.Time(BotMetrics.ProxyMembersQueryTime)) members = (await _repo.GetProxyMembers(ctx.Author.Id, msg.Message.Guild !.Value)).ToList(); var match = members.Find(x => x.Id == target.Id); if (match == null) { throw new PKError("Could not find a member to reproxy the message with."); } try { await _proxy.ExecuteReproxy(ctx.Message, msg.Message, match); if (ctx.Guild == null) { await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success }); } if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages)) { await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id); } } catch (NotFoundException) { throw new PKError("Could not reproxy message."); } }
public async Task EditMessage(Context ctx) { var msg = await GetMessageToEdit(ctx); if (ctx.System.Id != msg.System?.Id) { throw new PKError("Can't edit a message sent by a different system."); } if (!ctx.HasNext()) { throw new PKSyntaxError("You need to include the message to edit in."); } var newContent = ctx.RemainderOrNull().NormalizeLineEndSpacing(); if (newContent.Length > 2000) { throw new PKError("PluralKit cannot proxy messages over 2000 characters in length."); } var originalMsg = await _rest.GetMessageOrNull(msg.Message.Channel, msg.Message.Mid); if (originalMsg == null) { throw new PKError("Could not edit message."); } try { var editedMsg = await _webhookExecutor.EditWebhookMessage(msg.Message.Channel, msg.Message.Mid, newContent); if (ctx.Guild == null) { await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success }); } if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages)) { await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id); } await _logChannel.LogMessage(ctx.MessageContext, msg.Message, ctx.Message, editedMsg, originalMsg !.Content !); } catch (NotFoundException) { throw new PKError("Could not edit message."); } }
public async Task EditMessage(Context ctx) { var msg = await GetMessageToEdit(ctx); if (!ctx.HasNext()) { throw new PKSyntaxError("You need to include the message to edit in."); } if (ctx.Author.Id != msg.Sender) { throw new PKError("Can't edit a message sent from a different account."); } var newContent = ctx.RemainderOrNull(); var originalMsg = await _rest.GetMessage(msg.Channel, msg.Mid); try { await _webhookExecutor.EditWebhookMessage(msg.Channel, msg.Mid, newContent); if (ctx.Guild == null) { await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new() { Name = Emojis.Success }); } if (ctx.BotPermissions.HasFlag(PermissionSet.ManageMessages)) { await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id); } await _logChannel.LogEditedMessage(ctx.MessageContext, msg, ctx.Message, originalMsg !, newContent); } catch (NotFoundException) { throw new PKError("Could not edit message."); } }