Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csharp/Platform.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static async Task<int> 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 WelcomeMessageTrigger(githubStorage, dbContext), 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 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();
Expand Down
88 changes: 88 additions & 0 deletions csharp/Platform.Bot/Triggers/WelcomeMessageTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Threading.Tasks;
using Interfaces;
using Octokit;
using Storage.Local;
using Storage.Remote.GitHub;

namespace Platform.Bot.Triggers
{
using TContext = Issue;
/// <summary>
/// <para>
/// Represents the welcome message trigger for new users.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="ITrigger{TContext}"/>
internal class WelcomeMessageTrigger : ITrigger<TContext>
{
private readonly GitHubStorage _storage;
private readonly FileStorage _fileStorage;

/// <summary>
/// <para>
/// Initializes a new <see cref="WelcomeMessageTrigger"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="storage">
/// <para>A GitHub storage.</para>
/// <para></para>
/// </param>
/// <param name="fileStorage">
/// <para>A file storage.</para>
/// <para></para>
/// </param>
public WelcomeMessageTrigger(GitHubStorage storage, FileStorage fileStorage)
{
this._storage = storage;
this._fileStorage = fileStorage;
}

/// <summary>
/// <para>
/// Actions the context.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
public async Task Action(TContext context)
{
var welcomeMessage = @"👋 Welcome to the platform!

Thank you for creating your first issue. Here are some things you can do to get started:

🌐 **Set up your languages list**: Let us know which programming languages you're interested in by mentioning them in your issues or profile.

🔗 **Set up your GitHub link**: Make sure your GitHub profile is properly linked and accessible.

❓ **Need help?**: Use the `help` command or create an issue with ""help"" in the title to get assistance with available commands and features.

We're glad to have you here! Feel free to explore and don't hesitate to ask questions.";

await _storage.CreateIssueComment(context.Repository.Id, context.Number, welcomeMessage);

// Mark user as welcomed
_fileStorage.MarkUserAsWelcomed(context.User.Login);
}

/// <summary>
/// <para>
/// Determines whether this instance condition.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>The bool</para>
/// <para></para>
/// </returns>
public async Task<bool> Condition(TContext context) => _fileStorage.IsNewUser(context.User.Login);
}
}
44 changes: 44 additions & 0 deletions csharp/Storage/LocalStorage/FileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,50 @@ public List<File> GetFilesFromSet(string set)

// public void SetLastGithubMigrationTimeStamp()

/// <summary>
/// <para>
/// Checks if a user has been welcomed before.
/// </para>
/// <para></para>
/// </summary>
/// <param name="username">
/// <para>The username to check.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>True if user is new (not welcomed), false if already welcomed</para>
/// <para></para>
/// </returns>
public bool IsNewUser(string username)
{
var userMarker = CreateString($"welcomed_user:{username}");
try
{
var existingUser = _synchronizedLinks.SearchOrDefault(userMarker, _synchronizedLinks.Constants.Itself);
return existingUser == _synchronizedLinks.Constants.Null;
}
catch
{
return true; // Assume new user if there's any error
}
}

/// <summary>
/// <para>
/// Marks a user as welcomed.
/// </para>
/// <para></para>
/// </summary>
/// <param name="username">
/// <para>The username to mark as welcomed.</para>
/// <para></para>
/// </param>
public void MarkUserAsWelcomed(string username)
{
var userMarker = CreateString($"welcomed_user:{username}");
_synchronizedLinks.GetOrCreate(userMarker, _synchronizedLinks.Constants.Itself);
}

protected override void Dispose(bool manual, bool wasDisposed)
{
_disposableLinks.Dispose();
Expand Down
Loading