Beispiel #1
0
        public async Task Draft([Summary("The short name.")] string shortName)
        {
            var suggestionChannel = await CreateSuggestionChannel(SuggestionType.Draft, shortName, Context.User,
                                                                  channel => GetSuggestionFromUserAsync(channel, Context.User));

            if (suggestionChannel != null)
            {
                await GovernanceSubscriptionFeed.OnSuggestAsync(Context.Client, suggestionChannel.Id);
            }
        }
        public async Task Edit()
        {
            var channel = (SocketTextChannel)Context.Channel;

            if (!channel.IsSuggestionChannelByName())
            {
                throw new InvalidOperationException("Wrong channel!");
            }

            if (channel.GetSuggestionChannelType() == SuggestionType.Vote)
            {
                throw new Exception("Finalized suggestions cannot be edited.");
            }

            var user = (IGuildUser)Context.User;
            var vote = await Database.UNSAFE_GetGovernanceVoteAsync(channel.Id);

            if (vote == null)
            {
                throw new Exception("Cannot find information about this suggestion in database!");
            }

            if (vote.UserId != user.Id && !user.IsStaff())
            {
                throw new Exception("Only the owner or staff can edit suggestions.");
            }

            var message = (IUserMessage)await channel.GetMessageAsync(vote.MessageId);

            var author = Context.Client.GetUser(vote.UserId);

            await Context.Message.DeleteAsync();

            var suggestionMessage = await GetSuggestionFromUserAsync(channel, author);

            await(suggestionMessage?.DeleteAsync() ?? Task.CompletedTask);
            if (suggestionMessage != null)
            {
                var submissionOld = message.Embeds.OfType <Embed>().FirstOrDefault();
                var submissionNew = suggestionMessage.Embeds.OfType <Embed>().FirstOrDefault();
                var editEmbed     = EditWatcher.GetEditEmbed(user, "edited their suggestion", submissionOld.Description,
                                                             submissionNew.Description);
                if (editEmbed != null)
                {
                    await message.ModifyAsync(props => props.Embed = submissionNew);

                    await channel.ModifyAsync(props => props.Topic = submissionNew.Description);

                    await channel.SendMessageAsync(string.Empty, embed : editEmbed);

                    await GovernanceSubscriptionFeed.OnEditAsync(Context.Client, channel.Id);
                }
            }
        }
Beispiel #3
0
        public async Task Upgrade(ulong messageId, string shortName)
        {
            var message = await Context.Channel.GetMessageAsync(messageId);

            if (message == null)
            {
                throw new Exception("Message with the given ID was not found in this channel.");
            }

            var suggestionChannel = await CreateSuggestionChannel(SuggestionType.Draft, shortName, message.Author,
                                                                  async channel =>
            {
                await channel.SendMessageAsync(
                    $"Suggestion upgraded by {MentionUtils.MentionUser(Context.User.Id)}.");
                return(await ConfirmSuggestionFromUserAsync(channel, message.Author, message.Content));
            });

            if (suggestionChannel != null)
            {
                await GovernanceSubscriptionFeed.OnUpgradeAsync(Context.Client, suggestionChannel.Id);
            }
        }
Beispiel #4
0
        public async Task Finalize(bool force = false)
        {
            var channel = Context.Channel;
            var oldType = channel.GetSuggestionChannelType();

            if (!channel.IsSuggestionChannelByName())
            {
                throw new InvalidOperationException("Wrong channel!");
            }

            var user = (IGuildUser)Context.User;
            var vote = await Database.UNSAFE_GetGovernanceVoteAsync(channel.Id);

            var age       = DateTimeOffset.UtcNow - channel.CreatedAt;
            var ageInDays = age.TotalDays;
            var ageLeft   = TimeSpan.FromTicks((channel.CreatedAt.AddDays(3) - DateTimeOffset.UtcNow).Ticks);


            if (vote == null)
            {
                throw new Exception("Cannot find information about this suggestion in database!");
            }

            if (!user.IsStaff() && ageInDays < 10)
            {
                throw new Exception("Only the staff can finalize suggestions.");
            }

            if (oldType == SuggestionType.RFC)
            {
                throw new Exception("RFCs cannot be finalized.");
            }

            if (oldType == SuggestionType.Vote)
            {
                throw new Exception("Finalized suggestions cannot be finalized.");
            }

            if (ageInDays < 3 && (!force || !user.IsServerOwner()))
            {
                throw new Exception("Suggestion too young. " +
                                    $"{ToHumanCounter(ageLeft.Days, "day")}, {ToHumanCounter(ageLeft.Hours, "hour")}, {ToHumanCounter(ageLeft.Minutes, "minute")} left.");
            }

            var textChannel = (SocketTextChannel)channel;
            var message     = (IUserMessage)await Context.Channel.GetMessageAsync(vote.MessageId);

            await textChannel.ConvertSuggestionChannelType(SuggestionType.Vote);

            await message.AddReactionsAsync(new[] { new Emoji("👍"), new Emoji("👎") });

            await UpdateBillboardAsync(Context.Guild, message, channel, vote, SuggestionType.Vote);

            var finalizeMsg = await channel.SendMessageAsync("", embed : new EmbedBuilder()
                                                             .WithTitle(":white_check_mark: Suggestion was finalized. You may now vote!")
                                                             .WithDescription($"[Click here to vote]({message.GetJumpUrl()})")
                                                             .Build());

            await finalizeMsg.PinAsync();

            await GovernanceSubscriptionFeed.OnFinalizeAsync(Context.Client, message.Channel.Id);
        }