コード例 #1
0
        private static async Task Main()
        {
            var client = await DiscordSettings.GetClient();

            var services = DiscordSettings.ConfigureServices(client);
            await DiscordSettings.InstallCommands(client, services);

            SocialScoreWatcher.Bind(client);
            CoronaWatcher.Bind(client);
            MuteWatcher.Bind(client);
            VoiceChat.Bind(client);
            GovernanceVoteWatcher.Bind(client);
            EditWatcher.Bind(client);
            QuickReportWatcher.Bind(client);
            StarboardWatcher.Bind(client);
            QuickChatWatcher.Bind(client);
            SlurWatcher.Bind(client);

            await Task.Delay(10000);

            var crawler = new Crawler(client);

            await Task.WhenAny(Task.Delay(TimeSpan.FromDays(2)), crawler.StartAsync());

            throw new Exception("Restart me!");
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        public async Task Rename([Summary("The short name.")] string shortName)
        {
            var channel = (SocketTextChannel)Context.Channel;
            var type    = channel.GetSuggestionChannelType();

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

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

            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 can rename suggestions.");
            }

            var submissionOld = channel.GetSuggestionChannelName();
            var submissionNew = shortName;
            var editEmbed     = EditWatcher.GetEditEmbed(user, "renamed the suggestion", submissionOld, submissionNew);

            if (editEmbed != null)
            {
                await channel.RenameSuggestionChannel(submissionNew);

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