diff --git a/csharp/Platform.Bot/Program.cs b/csharp/Platform.Bot/Program.cs index 521a6b95..db469bb9 100644 --- a/csharp/Platform.Bot/Program.cs +++ b/csharp/Platform.Bot/Program.cs @@ -95,7 +95,7 @@ private static async Task Main(string[] args) var dbContext = new FileStorage(databaseFilePath?.FullName ?? new TemporaryFile().Filename); Console.WriteLine($"Bot has been started. {Environment.NewLine}Press CTRL+C to close"); var githubStorage = new GitHubStorage(githubUserName, githubApiToken, githubApplicationName); - var issueTracker = new IssueTracker(githubStorage, new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage)); + var issueTracker = new IssueTracker(githubStorage, new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new RubberDuckTrigger(githubStorage), new RubberDuckDialogTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage)); var pullRequenstTracker = new PullRequestTracker(githubStorage, new MergeDependabotBumpsTrigger(githubStorage)); var timestampTracker = new DateTimeTracker(githubStorage, new CreateAndSaveOrganizationRepositoriesMigrationTrigger(githubStorage, dbContext, Path.Combine(Directory.GetCurrentDirectory(), "/github-migrations"))); var cancellation = new CancellationTokenSource(); diff --git a/csharp/Platform.Bot/Triggers/RubberDuckDialogTrigger.cs b/csharp/Platform.Bot/Triggers/RubberDuckDialogTrigger.cs new file mode 100644 index 00000000..6037a209 --- /dev/null +++ b/csharp/Platform.Bot/Triggers/RubberDuckDialogTrigger.cs @@ -0,0 +1,106 @@ +using System; +using System.Threading.Tasks; +using Interfaces; +using Octokit; +using Storage.Remote.GitHub; + +namespace Platform.Bot.Triggers +{ + using TContext = Issue; + /// + /// + /// Represents the rubber duck debugging dialog continuation trigger. + /// + /// + /// + /// + internal class RubberDuckDialogTrigger : ITrigger + { + private readonly GitHubStorage _storage; + + /// + /// + /// Initializes a new instance. + /// + /// + /// + /// + /// A git hub api. + /// + /// + public RubberDuckDialogTrigger(GitHubStorage storage) + { + this._storage = storage; + } + + /// + /// + /// Actions the context. + /// + /// + /// + /// + /// The context. + /// + /// + public async Task Action(TContext context) + { + var debuggingGuide = $@"πŸ¦† **Great! Let's debug together!** + +I'm your rubber duck debugging assistant. Please follow these steps: + +## Step 1: Describe Your Problem +Please tell me: +- **What are you trying to do?** +- **What is happening instead?** +- **What error messages (if any) are you seeing?** + +## Step 2: Show Me The Code +- Share the relevant code snippet +- Include any error messages or unexpected output + +## Step 3: Recent Changes +- **What was the last thing you changed before this problem appeared?** +- Have you tried undoing recent changes? + +## Step 4: Let's Think Through This Together +I'll help you by asking questions like: +- What assumptions are you making about the code? +- Can you trace through the code line by line? +- Have you checked the most obvious things first? + +## Step 5: Problem-Solving Techniques +We can try: +- Adding debug logging/print statements +- Testing with simpler inputs +- Checking documentation +- Looking for similar examples + +**🎯 Often, just explaining your problem step-by-step to me will help you spot the issue!** + +Go ahead and describe your problem in detail. I'm listening! πŸ‘‚"; + + await _storage.CreateIssueComment(context.Repository.Id, context.Number, debuggingGuide); + } + + /// + /// + /// Determines whether this instance condition. + /// + /// + /// + /// + /// The context. + /// + /// + /// + /// The bool + /// + /// + public async Task Condition(TContext context) + { + var title = context.Title.ToLower().Trim(); + return title == "yes" || title == "Π΄Π°"; + } + } +} \ No newline at end of file diff --git a/csharp/Platform.Bot/Triggers/RubberDuckTrigger.cs b/csharp/Platform.Bot/Triggers/RubberDuckTrigger.cs new file mode 100644 index 00000000..c951ec8e --- /dev/null +++ b/csharp/Platform.Bot/Triggers/RubberDuckTrigger.cs @@ -0,0 +1,102 @@ +using System; +using System.Threading.Tasks; +using Interfaces; +using Octokit; +using Storage.Remote.GitHub; + +namespace Platform.Bot.Triggers +{ + using TContext = Issue; + /// + /// + /// Represents the rubber duck debugging trigger. + /// + /// + /// + /// + internal class RubberDuckTrigger : ITrigger + { + private readonly GitHubStorage _storage; + + /// + /// + /// Initializes a new instance. + /// + /// + /// + /// + /// A git hub api. + /// + /// + public RubberDuckTrigger(GitHubStorage storage) + { + this._storage = storage; + } + + /// + /// + /// Actions the context. + /// + /// + /// + /// + /// The context. + /// + /// + public async Task Action(TContext context) + { + var openerQuestion = $@"πŸ¦† **Rubber Duck Debugging Assistant** + +Do you have problem with code? +Π£ вас ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ° с ΠΊΠΎΠ΄ΠΎΠΌ? + +**Instructions:** +- Reply with **""Yes""** or **""Π”Π°""** to start debugging session +- I'll guide you through the problem-solving process step by step +- Explaining your problem to me (the rubber duck) often helps you find the solution yourself! + +**Common debugging steps I can help with:** +1. Understanding the problem clearly +2. Breaking down the problem into smaller parts +3. Checking assumptions +4. Reviewing recent changes +5. Testing hypotheses +6. Finding similar examples + +Ready to debug? πŸ›βž‘οΈβœ¨"; + + await _storage.CreateIssueComment(context.Repository.Id, context.Number, openerQuestion); + } + + /// + /// + /// Determines whether this instance condition. + /// + /// + /// + /// + /// The context. + /// + /// + /// + /// The bool + /// + /// + public async Task Condition(TContext context) + { + var title = context.Title.ToLower().Trim(); + var triggerWords = new[] + { + "help", + "help me", + "sos", + "ΠΏΠΎΠΌΠΎΡ‰ΡŒ", + "ΠΏΠΎΠΌΠΎΠ³ΠΈΡ‚Π΅", + "ΠΏΠΎΠΌΠΎΠ³ΠΈΡ‚Π΅ ΠΌΠ½Π΅", + "спаситС" + }; + + return Array.Exists(triggerWords, trigger => title == trigger); + } + } +} \ No newline at end of file