Skip to content

Commit

Permalink
Add message inviting user to Discord after 10 usages
Browse files Browse the repository at this point in the history
  • Loading branch information
gememma committed May 20, 2024
1 parent 989029d commit 906c521
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/250.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Users will be invited to join the Discord server after 10 usages
20 changes: 20 additions & 0 deletions modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ private class SafeParser {
*/
private const val FEEDBACK_COUNTER_REVIEW_AFTER = 100

/**
* How many times mirrord can be run before inviting the user to Discord.
*/
private const val DISCORD_COUNTER_INVITE_AFTER = 10


/**
* Interact with mirrord CLI using this API.
*/
Expand Down Expand Up @@ -273,6 +279,7 @@ class MirrordApi(private val service: MirrordProjectService, private val project
*/
fun exec(cli: String, target: String?, configFile: String?, executable: String?, wslDistribution: WSLDistribution?): MirrordExecution {
bumpFeedbackCounter()
checkDiscordCounter()

val task = MirrordExtTask(cli, projectEnvVars).apply {
this.target = target
Expand Down Expand Up @@ -302,6 +309,19 @@ class MirrordApi(private val service: MirrordProjectService, private val project

service.notifier.notification("Enjoying mirrord? Don't forget to leave a review or star us on GitHub!", NotificationType.INFORMATION).withLink("Review", "https://plugins.jetbrains.com/plugin/19772-mirrord/reviews").withLink("Star us on GitHub", GITHUB_URL).withDontShowAgain(MirrordSettingsState.NotificationId.PLUGIN_REVIEW).fire()
}

/**
* Invite user to MetalBear Discord server after a few usages.
*/
private fun checkDiscordCounter() {
val currentRuns = MirrordSettingsState.instance.mirrordState.runsCounter

if ((currentRuns - DISCORD_COUNTER_INVITE_AFTER) != 0) {
return
}

service.notifier.notification("Need any help with mirrord? Come chat with our team on Discord!", NotificationType.INFORMATION).withLink("Join us", "https://discord.gg/metalbear").withDontShowAgain(MirrordSettingsState.NotificationId.DISCORD_INVITE).fire()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ open class MirrordSettingsState : PersistentStateComponent<MirrordSettingsState.
ACTIVE_CONFIG_MOVED("active mirrord config is moved"),
AGENT_VERSION_MISMATCH("agent version does not match version of the local mirrord installation"),
PLUGIN_REVIEW("mirrord occasionally asks for plugin review"),
DISCORD_INVITE("mirrord offers a Discord server invitation"),
MIRRORD_FOR_TEAMS("mirrord occasionally informs about mirrord for Teams")
}

Expand Down

0 comments on commit 906c521

Please sign in to comment.