/// <summary>
        /// Updates a proposal linked to a given ID, by setting its status and relevant information, modifying the linked embed.
        /// </summary>
        /// <param name="EventID">The ID of the target event to update.</param>
        /// <returns>A <c>Task</c> object, which can be awaited until the method completes successfully.</returns>

        public async Task UpdateEventProposal(int EventID)
        {
            CommunityEvent Event = GetEvent(EventID);

            if (Event == null)
            {
                return;
            }

            if (Event.EventType == EventType.Official)
            {
                return;
            }

            SocketChannel ProposalChannel = DiscordSocketClient.GetChannel(CommunityConfiguration.EventsNotificationsChannel);

            IUserMessage Proposal = null;

            if (ProposalChannel is SocketTextChannel TextChannel)
            {
                try {
                    Proposal = await TextChannel.GetMessageAsync(Event.EventProposal) as IUserMessage;
                }
                catch (HttpException) {
                    await BuildEmbed(EmojiEnum.Annoyed)
                    .WithTitle("Failed to update event proposal")
                    .WithDescription("The message doesn't exist anymore! Perhaps it was deleted?")
                    .AddField("Message ID", Event.EventProposal)
                    .SendEmbed(Context.Channel);
                }
            }

            if (Proposal == null)
            {
                return;
            }

            string ProposalText = Event.Status switch {
                EventStatus.Pending => $"**New Event Proposal >>>** {CommunityConfiguration.EventsNotificationMention}",
                EventStatus.Approved => $"**Upcoming Event [{DateTimeOffset.FromUnixTimeSeconds(Event.DateTimeRelease).ToOffset(TimeSpan.FromHours(BotConfiguration.StandardTimeZone)):MMM M 'at' h:mm tt}] >>>**",
                EventStatus.Released => $"**Released Event**",
                _ => $"**{Event.Status} Event Proposal >>>**"
            };

            if (Event.Status is EventStatus.Pending or EventStatus.Approved or EventStatus.Released)
            {
                string Link = Event.Description.GetHyperLinks().FirstOrDefault();
                if (Link != null && Link.Length > 0)
                {
                    ProposalText += $"\n{Link}";
                }
            }

            await Proposal.ModifyAsync(Properties => {
                Properties.Content = ProposalText;
                Properties.Embed   = CreateEventProposalEmbed(Event).Build();
            });
        }
Exemple #2
0
        public async Task UserDMCommand(string Token, [Remainder] string Message)
        {
            ModMail ModMail = ModMailDB.ModMail.Find(Token);

            IUser User = null;

            if (ModMail != null)
            {
                User = DiscordSocketClient.GetUser(ModMail.UserID);
            }

            if (ModMail == null || User == null)
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Could Not Find Token!")
                .WithDescription("Haiya! I couldn't find the modmail for the given token. Are you sure this exists in the database? " +
                                 "The token should be given as the footer of the embed. Make sure this is the token and not the modmail number.")
                .WithCurrentTimestamp()
                .SendEmbed(Context.Channel);
            }
            else
            {
                SocketChannel SocketChannel = DiscordSocketClient.GetChannel(ModerationConfiguration.ModMailChannelID);

                if (SocketChannel is SocketTextChannel TextChannel)
                {
                    IMessage MailMessage = await TextChannel.GetMessageAsync(ModMail.MessageID);

                    if (MailMessage is IUserMessage MailMSG)
                    {
                        try {
                            await MailMSG.ModifyAsync(MailMSGs => MailMSGs.Embed = MailMessage.Embeds.FirstOrDefault().ToEmbedBuilder()
                                                      .WithColor(Color.Green)
                                                      .AddField($"Replied By: {Context.User.Username}", Message.Length > 300 ? $"{Message.Substring(0, 300)} ..." : Message)
                                                      .Build()
                                                      );
                        } catch (InvalidOperationException) {
                            IMessage Messaged = await MailMSG.Channel.SendMessageAsync(embed : MailMSG.Embeds.FirstOrDefault().ToEmbedBuilder().Build());

                            ModMail.MessageID = Messaged.Id;
                            ModMailDB.SaveChanges();
                        }
                    }
                    else
                    {
                        throw new Exception($"Woa, this is strange! The message required isn't a socket user message! Are you sure this message exists? ModMail Type: {MailMessage.GetType()}");
                    }
                }
                else
                {
                    throw new Exception($"Eek! The given channel of {SocketChannel} turned out *not* to be an instance of SocketTextChannel, rather {SocketChannel.GetType().Name}!");
                }

                await BuildEmbed(EmojiEnum.Love)
                .WithTitle("Modmail User DM")
                .WithDescription(Message)
                .AddField("Sent By", Context.User.GetUserInformation())
                .SendDMAttachedEmbed(Context.Channel, BotConfiguration, User,
                                     BuildEmbed(EmojiEnum.Unknown)
                                     .WithTitle($"Modmail From {Context.Guild.Name}")
                                     .WithDescription(Message)
                                     .WithCurrentTimestamp()
                                     .WithFooter(Token)
                                     );
            }
        }