示例#1
0
        private async Task <EmbedBuilder> ShowEventsAsync(EmbedBuilder eb, EmbedAuthorBuilder eab, IEnumerable <EventInfoWrapper> list)
        {
            EventInfoWrapper first = list.First();
            DocsHttpResult   result;
            string           pageUrl = SanitizeDocsUrl($"{first.Parent.TypeInfo.Namespace}.{first.Parent.TypeInfo.Name}");

            try
            {
                result = await GetWebDocsAsync($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html", first);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result = new DocsHttpResult($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html{EventToDocs(first)}");
            }
            eab.Name = $"Event: {first.Parent.TypeInfo.Namespace}.{first.Parent.DisplayName}.{first.Event.Name}";
            eab.Url  = result.Url; //$"{DocsUrlHandler.DocsBaseUrl}api/{first.DeclaringType.Namespace}.{first.DeclaringType.Name}.html{EventToDocs(first)}";
            eb.AddField((x) =>
            {
                x.IsInline = true;
                x.Name     = "Docs:";
                x.Value    = FormatDocsUrl(eab.Url);
            });
            var githubUrl = await GithubRest.GetEventUrlAsync(first);

            if (githubUrl != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = "Source:";
                    x.Value    = FormatGithubUrl(githubUrl);
                });
            }
            if (result.Summary != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Summary:";
                    x.Value    = result.Summary;
                });
            }
            if (result.Example != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Example:";
                    x.Value    = result.Example;
                });
            }
            eb.AddField((x) =>
            {
                x.IsInline = false;
                x.Name     = "Arguments:";
                x.Value    = BuildEvent(first);
            });
            return(eb);
        }
示例#2
0
 public ResultDisplay(SearchResult <BaseInfoWrapper> result, Cache cache, bool isList, GithubRest githubRest)
 {
     _result     = result;
     _cache      = cache;
     _isList     = isList;
     _githubRest = githubRest;
 }
示例#3
0
        public async Task RunAsync()
        {
            string discordToken = await File.ReadAllTextAsync("Tokens/Discord.txt");

            string githubToken = await File.ReadAllTextAsync("Tokens/Github.txt");

            var githubRest = new GithubRest(githubToken);

            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Info,
            });

            _client.Log += (message) =>
            {
                Console.WriteLine(message);
                return(Task.CompletedTask);
            };

            _client.Ready += () =>
            {
                Console.WriteLine("Connected!");
                return(Task.CompletedTask);
            };

            _client.Disconnected += (exception) => //Kills the bot if it doesn't reconnect
            {
                Task.Run(async() =>
                {
                    CancellationTokenSource cts = new CancellationTokenSource();
                    Task ctsTask()
                    {
                        cts.Cancel();
                        return(Task.CompletedTask);
                    }

                    _client.Connected += ctsTask;
                    try { await Task.Delay(30000, cts.Token); } catch { }
                    if (!cts.IsCancellationRequested)
                    {
                        Environment.Exit(1);
                    }
                    _client.Connected -= ctsTask;
                    cts.Dispose();
                });
                return(Task.CompletedTask);
            };

            _client.MessageReceived += (message) =>
            {
                Task.Run(async() =>
                {
                    if (message is IUserMessage userMessage)
                    {
                        if (userMessage.Author.IsBot)
                        {
                            return;
                        }
                        if (userMessage.Channel is ITextChannel tc && tc.GuildId == 81384788765712384 && userMessage.Channel.Name != "dotnet_discord-net" && userMessage.Channel.Name != "testing" && userMessage.Channel.Name != "playground")
                        {
                            return;
                        }
                        MatchCollection matches = _githubRegex.Matches(userMessage.Content);
                        if (matches.Count > 0)
                        {
                            var urls = await githubRest.GetIssuesUrlsAsync(matches.Take(3).Select(x => x.Groups["number"].Value));
                            await userMessage.Channel.SendMessageAsync(string.Join("\n", urls));
                        }
                    }
                });
                return(Task.CompletedTask);
            };

            var services = new ServiceCollection();

            services.AddSingleton(_client);
            services.AddSingleton(new PaginatorService(_client));
            services.AddSingleton(githubRest);

            _mainController = new MainController(_client, services.BuildServiceProvider());
            await _mainController.InitializeEarlyAsync();

            await _client.LoginAsync(TokenType.Bot, discordToken);

            await _client.StartAsync();

            await Task.Delay(-1);
        }
示例#4
0
 private void portBitIssuesToGit_Click(object sender, RoutedEventArgs e)
 {
     GithubRest git = new GithubRest(gitUsername.Text, gitPassword.Password);
     if (bitMilestones != null && bitMilestones.Count > 0)
     {
         logger.AppendText("This repo has Milestones. Porting them:->\n");
         foreach (Git2Bit.BitModels.Milestone amilestone in bitMilestones)
         {
             Git2Bit.GitModels.MilestonePost gitMilestone = git.PostMilestone(selectedGitRepositiry, amilestone);
             logger.AppendText("Ported closed Milestone: " + gitMilestone.title + "\n");
         }
     }
 }
示例#5
0
        private void gitRepos_Click(object sender, RoutedEventArgs e)
        {
            GithubRest git = new GithubRest(gitUsername.Text, gitPassword.Password);
            GitRepos = git.GetRepos();

            // Create a list of Repos that have issues
            List<string> repos_names = new List<string>();
            foreach (Git2Bit.GitModels.Repository repo in GitRepos)
            {
                if(repo.has_issues) {
                    repos_names.Add(repo.full_name);
                }
            }

            gitRepositories.ItemsSource = repos_names;
        }
示例#6
0
        private void bg_gitIssuesWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            List<String> list = e.Argument as List<String>;
            GithubRest git = new GithubRest(list[0], list[1]);
            gitComments = new Dictionary<int, List<GitModels.Comments>>();
            openGitMilestones = git.GetMilestones(selectedGitRepositiry);
            if (openGitMilestones != null)
            {
                String textData = "The " + selectedGitRepositiry + " has " + openGitMilestones.Count.ToString() + " open milestones.\n";
                Dispatcher.Invoke(new Action(() => logger.AppendText(textData)));

            }
            closedGitMilestones = git.GetMilestones(selectedGitRepositiry, false);
            if (closedGitMilestones != null)
            {
                String textData = ("The " + selectedGitRepositiry + " has " + closedGitMilestones.Count.ToString() + " closed milestones.\n");
                Dispatcher.Invoke(new Action(() => logger.AppendText(textData)));
            }
            openGitIssues = git.GetIssues(selectedGitRepositiry);
            if (openGitIssues != null)
            {
                String textData = ("The " + selectedGitRepositiry + " has " + openGitIssues.Count.ToString() + " open issues.\n");
                Dispatcher.Invoke(new Action(() => logger.AppendText(textData)));
                // Get individual Comments for each open issue
                foreach (Git2Bit.GitModels.Issue issue in openGitIssues)
                {
                    if (issue.comments > 0)
                    {
                        // has comments:
                        List<Git2Bit.GitModels.Comments> comments = git.GetComments(selectedGitRepositiry, issue.number);
                        String textData1 = ("Issue " + issue.number.ToString() + " has " + comments.Count.ToString() + " comments.\n");
                        Dispatcher.Invoke(new Action(() => logger.AppendText(textData1)));
                        gitComments[issue.number] = comments;
                    }
                }
            }
            closedGitIssues = git.GetIssues(selectedGitRepositiry, false);
            if (closedGitIssues != null)
            {
                logger.AppendText("The " + selectedGitRepositiry + " has " + closedGitIssues.Count.ToString() + " closed issues.\n");
                // Get individual Comments for each open issue
                foreach (Git2Bit.GitModels.Issue issue in closedGitIssues)
                {
                    if (issue.comments > 0)
                    {
                        // has comments:
                        List<Git2Bit.GitModels.Comments> comments = git.GetComments(selectedGitRepositiry, issue.number);
                        String textData1 = ("Issue " + issue.number.ToString() + " has " + comments.Count.ToString() + " comments.\n");
                        Dispatcher.Invoke(new Action(() => logger.AppendText(textData1)));
                        gitComments[issue.number] = comments;
                    }
                }
            }
        }
示例#7
0
        private async Task <EmbedBuilder> ShowTypesAsync(EmbedBuilder eb, EmbedAuthorBuilder eab, IEnumerable <TypeInfoWrapper> list)
        {
            TypeInfoWrapper first = list.First();
            DocsHttpResult  result;
            string          pageUrl = SanitizeDocsUrl($"{first.TypeInfo.Namespace}.{first.TypeInfo.Name}");

            try
            {
                result = await GetWebDocsAsync($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html", first);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result = new DocsHttpResult($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html");
            }
            eab.Name = $"{(first.TypeInfo.IsInterface ? "Interface" : (first.TypeInfo.IsEnum ? "Enum" : "Type"))}: {first.TypeInfo.Namespace}.{first.DisplayName}";
            eab.Url  = result.Url;//$"{DocsUrlHandler.DocsBaseUrl}api/{first.Namespace}.{first.Name}.html";
            eb.AddField((x) =>
            {
                x.IsInline = true;
                x.Name     = "Docs:";
                x.Value    = FormatDocsUrl(eab.Url);
            });
            var githubUrl = await GithubRest.GetTypeUrlAsync(first);

            if (githubUrl != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = "Source:";
                    x.Value    = FormatGithubUrl(githubUrl);
                });
            }
            if (result.Summary != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Summary:";
                    x.Value    = result.Summary;
                });
            }
            if (result.Example != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Example:";
                    x.Value    = result.Example;
                });
            }
            CacheBag cb = _cache.GetCacheBag(first);

            if (cb.Methods.Count != 0)
            {
                int i       = 1;
                var methods = cb.Methods.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some methods ({methods.Count()}/{cb.Methods.Count}):";
                    x.Value    = String.Join("\n", methods.Select(y => $"``{i++}-``{(IsInherited(new MethodInfoWrapper(first, y)) ? " (i)" : "")} {y.Name}(...)"));
                });
            }
            if (cb.Properties.Count != 0)
            {
                int i          = 1;
                var properties = cb.Properties.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some properties ({properties.Count()}/{cb.Properties.Count}):";
                    x.Value    = String.Join("\n", properties.Select(y => $"``{i++}-``{(IsInherited(new PropertyInfoWrapper(first, y)) ? " (i)" : "")} {y.Name}"));
                });
            }
            if (first.TypeInfo.IsEnum)
            {
                var enumValues = first.TypeInfo.GetEnumNames();
                int i          = 1;
                var fields     = enumValues.RandomShuffle().Take(3);
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = $"Some fields ({fields.Count()}/{enumValues.Length}):";
                    x.Value    = String.Join("\n", fields.Select(y => $"``{i++}-`` {y}"));
                });
            }
            return(eb);
        }
示例#8
0
        private async Task <EmbedBuilder> ShowMethodsAsync(EmbedBuilder eb, EmbedAuthorBuilder eab, IEnumerable <MethodInfoWrapper> list)
        {
            MethodInfoWrapper first = list.First();
            DocsHttpResult    result;
            string            pageUrl = SanitizeDocsUrl($"{first.Parent.TypeInfo.Namespace}.{first.Parent.TypeInfo.Name}");

            try
            {
                result = await GetWebDocsAsync($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html", first);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result = new DocsHttpResult($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html{MethodToDocs(first)}");
            }
            eab.Name = $"Method: {first.Parent.TypeInfo.Namespace}.{first.Parent.DisplayName}.{first.Method.Name}";
            eab.Url  = result.Url;
            eb.AddField((x) =>
            {
                x.IsInline = true;
                x.Name     = "Docs:";
                x.Value    = FormatDocsUrl(eab.Url);
            });
            var githubUrl = await GithubRest.GetMethodUrlAsync(first);

            if (githubUrl != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = "Source:";
                    x.Value    = FormatGithubUrl(githubUrl);
                });
            }
            if (result.Summary != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Summary:";
                    x.Value    = result.Summary;
                });
            }
            if (result.Example != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Example:";
                    x.Value    = result.Example;
                });
            }
            int i = 1;

            eb.AddField((x) =>
            {
                x.IsInline = false;
                x.Name     = "Overloads:";
                x.Value    = String.Join("\n", list.OrderBy(y => IsInherited(y)).Select(y => $"``{i++}-``{(IsInherited(y) ? " (i)" : "")} {BuildMethod(y)}"));
            });
            return(eb);
        }
示例#9
0
 public QueryHandler(GithubRest githubRest)
 {
     Cache      = new Cache();
     GithubRest = githubRest;
 }
        private void portBitIssuesToGit_Click(object sender, RoutedEventArgs e)
        {
            GithubRest git = new GithubRest(gitUsername.Text, gitPassword.Password);
            string raw = string.Empty;

            foreach (var bitIssue in BitIssues)
            {
                try
                {
                    git.PostIssue(selectedGitRepositiry, bitIssue,null, out raw);
            #if DEBUG
                    logger.AppendText("raw response portBitIssuesToGit : " + raw + Environment.NewLine);
            #endif
                    logger.AppendText(string.Format("Ported bit issue {0} to git", bitIssue.title) + Environment.NewLine);
                }
                catch (Exception ex)
                {
                    logger.AppendText(string.Format("An error occured while trying to migrate issue {0}. Error: {1}." + Environment.NewLine, bitIssue.title, ex.Message));
                }
            }
        }
        private void gitGetIssuesButton_Click(object sender, RoutedEventArgs e)
        {
            GithubRest git = new GithubRest(gitUsername.Text, gitPassword.Password);
            gitComments = new Dictionary<int, List<GitModels.Comments>>();
            openGitMilestones = git.GetMilestones(selectedGitRepositiry);
            logger.AppendText("The " + selectedGitRepositiry + " has " + openGitMilestones.Count.ToString() + " open milestones.\n");
            closedGitMilestones = git.GetMilestones(selectedGitRepositiry, false);
            logger.AppendText("The " + selectedGitRepositiry + " has " + closedGitMilestones.Count.ToString() + " closed milestones.\n");
            openGitIssues = git.GetIssues(selectedGitRepositiry);
            logger.AppendText("The " + selectedGitRepositiry + " has " + openGitIssues.Count.ToString() + " open issues.\n");
            closedGitIssues = git.GetIssues(selectedGitRepositiry, false);
            logger.AppendText("The " + selectedGitRepositiry + " has " + closedGitIssues.Count.ToString() + " closed issues.\n");

            // Get individual Comments for each open issue
            foreach (Git2Bit.GitModels.Issue issue in openGitIssues)
            {
                if (issue.comments > 0)
                {
                    // has comments:
                    List<Git2Bit.GitModels.Comments> comments = git.GetComments(selectedGitRepositiry, issue.number);
                    logger.AppendText("Issue " + issue.number.ToString() + " has " + comments.Count.ToString() + " comments.\n");
                    gitComments[issue.number] = comments;
                }
            }

            // Get individual Comments for each open issue
            foreach (Git2Bit.GitModels.Issue issue in closedGitIssues)
            {
                if (issue.comments > 0)
                {
                    // has comments:
                    List<Git2Bit.GitModels.Comments> comments = git.GetComments(selectedGitRepositiry, issue.number);
                    logger.AppendText("Issue " + issue.number.ToString() + " has " + comments.Count.ToString() + " comments.\n");
                    gitComments[issue.number] = comments;
                }
            }

            gitIssuesButton.IsEnabled = false;
        }
示例#12
0
        private async Task <EmbedBuilder> ShowPropertiesAsync(EmbedBuilder eb, EmbedAuthorBuilder eab, IEnumerable <PropertyInfoWrapper> list)
        {
            PropertyInfoWrapper first = list.First();
            DocsHttpResult      result;
            string pageUrl = SanitizeDocsUrl($"{first.Parent.TypeInfo.Namespace}.{first.Parent.TypeInfo.Name}");

            try
            {
                result = await GetWebDocsAsync($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html", first);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                result = new DocsHttpResult($"{DocsUrlHandler.DocsBaseUrl}api/{pageUrl}.html{PropertyToDocs(first)}");
            }
            eab.Name = $"Property: {first.Parent.TypeInfo.Namespace}.{first.Parent.DisplayName}.{first.Property.Name} {(IsInherited(first) ? "(i)" : "")}";
            eab.Url  = result.Url;//$"{DocsUrlHandler.DocsBaseUrl}api/{first.Parent.Namespace}.{first.Parent.Name}.html{PropertyToDocs(first)}";
            eb.AddField((x) =>
            {
                x.IsInline = true;
                x.Name     = "Docs:";
                x.Value    = FormatDocsUrl(eab.Url);
            });
            var githubUrl = await GithubRest.GetPropertyUrlAsync(first);

            if (githubUrl != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = true;
                    x.Name     = "Source:";
                    x.Value    = FormatGithubUrl(githubUrl);
                });
            }
            if (result.Summary != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Summary:";
                    x.Value    = result.Summary;
                });
            }
            if (result.Example != null)
            {
                eb.AddField((x) =>
                {
                    x.IsInline = false;
                    x.Name     = "Example:";
                    x.Value    = result.Example;
                });
            }
            eb.AddField((x) =>
            {
                x.IsInline = false;
                x.Name     = "Return type:";
                x.Value    = Utils.BuildType(first.Property.PropertyType);
            });

            /*eb.AddField((x) =>
             * {
             *  x.IsInline = true;
             *  x.Name = "Get & Set:";
             *  x.Value = $"Can write: {first.Property.CanWrite}\nCan read: {first.Property.CanRead}";
             * });*/
            return(eb);
        }