From 5c1316ae8c1e6b413afc7e179aa4d3a9f0c8002f Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 4 Mar 2019 13:46:41 -0800 Subject: [PATCH 1/5] (GH-1) Initial implementation --- .gitignore | 1 + PoshBot.Soon/PoshBot.Soon.psd1 | 125 +++++++++++++++++++++++++++++++++ PoshBot.Soon/PoshBot.Soon.psm1 | 50 +++++++++++++ README.md | 19 +++++ appveyor.yml | 13 ++++ build.ps1 | 33 +++++++++ psake.ps1 | 81 +++++++++++++++++++++ requirements.psd1 | 9 +++ 8 files changed, 331 insertions(+) create mode 100644 .gitignore create mode 100644 PoshBot.Soon/PoshBot.Soon.psd1 create mode 100644 PoshBot.Soon/PoshBot.Soon.psm1 create mode 100644 README.md create mode 100644 appveyor.yml create mode 100644 build.ps1 create mode 100644 psake.ps1 create mode 100644 requirements.psd1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fec32c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tmp/ diff --git a/PoshBot.Soon/PoshBot.Soon.psd1 b/PoshBot.Soon/PoshBot.Soon.psd1 new file mode 100644 index 0000000..50fbb1b --- /dev/null +++ b/PoshBot.Soon/PoshBot.Soon.psd1 @@ -0,0 +1,125 @@ +# +# Module manifest for module 'PoshBot.Soon' +# +# Generated by: Gary Ewan Park +# +# Generated on: 3/4/2019 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'PoshBot.Soon.psm1' + +# Version number of this module. +ModuleVersion = '0.1.0' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = 'bd719e1d-b82c-44ff-8852-6c21458fbcba' + +# Author of this module +Author = 'Gary Ewan Park' + +# Company or vendor of this module +CompanyName = 'Community' + +# Copyright statement for this module +Copyright = '(c) 2019 Gary Ewan Park. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'A soon plugin for PoshBot' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '5.0.0' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +RequiredModules = @('PoshBot') + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @( + 'Get-Soon' +) + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +VariablesToExport = @() + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @('PoshBot', 'Soon', 'ChatOps') + + # A URL to the license for this module. + LicenseUri = 'https://raw.githubusercontent.com/gep13/PoshBot.Soon/develop/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/gep13/PoshBot.Soon' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + ReleaseNotes = 'https://raw.githubusercontent.com/gep13/PoshBot.Soon/develop/CHANGELOG.md' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + diff --git a/PoshBot.Soon/PoshBot.Soon.psm1 b/PoshBot.Soon/PoshBot.Soon.psm1 new file mode 100644 index 0000000..746299f --- /dev/null +++ b/PoshBot.Soon/PoshBot.Soon.psm1 @@ -0,0 +1,50 @@ +function Get-Soon { + [PoshBot.BotCommand( + Command = $false, + TriggerType = 'regex', + Regex = 'soon' + )] + [cmdletbinding()] + param( + [object[]]$Arguments + ) + + $imageArray = "https://i.imgur.com/TVxNL84.png", + "https://i.imgur.com/bFb5qZt.jpg", + "https://i.imgur.com/qNiLQz3.png", + "https://i.imgur.com/8niosvC.gif", + "https://i.imgur.com/qX5jkRi.jpg", + "https://i.imgur.com/Rqe94Xw.jpg", + "https://i.imgur.com/i2leGDn.jpg", + "https://i.imgur.com/QdnGKdY.jpg", + "https://i.imgur.com/bkox94P.jpg", + "https://i.imgur.com/hdG9IOk.jpg", + "https://i.imgur.com/ne6T0UP.png", + "https://i.imgur.com/41vZ1zP.png", + "https://i.imgur.com/yweXMrA.jpg", + "https://i.imgur.com/GcnzEjU.jpg", + "https://i.imgur.com/J0PLa1k.jpg", + "https://i.imgur.com/GHHLFqK.jpg", + "https://i.imgur.com/o25zB5O.jpg", + "https://i.imgur.com/6yyeCBR.jpg", + "https://i.imgur.com/GKSdoAm.png", + "https://i.imgur.com/3L0UQ8A.jpg", + "https://i.imgur.com/7WhKHPh.gif", + "https://i.imgur.com/xZuKr9v.gif", + "https://i.imgur.com/GWSQBxx.jpg", + "https://i.imgur.com/eCvTcTQ.jpg", + "https://i.imgur.com/0ypfizN.jpg", + "https://i.imgur.com/JyaroGd.jpg", + "https://i.imgur.com/xUgmD93.jpg", + "https://i.imgur.com/ftGheRE.jpg", + "https://i.imgur.com/Y4ExtS5.gif", + "https://i.imgur.com/pDXRVjp.jpg", + "https://i.imgur.com/L2SZuzG.gif" + + $randomlySelectedImage = Get-Random -InputObject $imageArray + + # @devblackops - You could also use the New-PoshBotCardResponse -ImageUrl + if ($randomlySelectedImage) { + "![img]($($randomlySelectedImage))" + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dbbc1a2 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# PoshBot.Soon + +A simple [PoshBot](https://github.com/poshbotio/PoshBot) plugin to show random images any time someone writes the word `soon`. + +## Install Module + +To install the module from the [PowerShell Gallery](https://www.powershellgallery.com/): + +``` +PS C:\> Install-Module -Name PoshBot.Soon -Repository PSGallery +``` + +## Install Plugin + +To install the plugin from within PoshBot: + +``` +!install-plugin --name poshbot.soon +``` \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..dd4a83e --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,13 @@ +version: 1.0.{build} + +image: WMF 5 + +build: off + +# Uncomment this block to enable RDP access to the AppVeyor test instance for +# debugging purposes. +# on_finish: +# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + +test_script: +- ps: . .\build.ps1 -Task Test diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..8c9beb0 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,33 @@ + + +[cmdletbinding(DefaultParameterSetName = 'task')] +param( + [parameter(ParameterSetName = 'task', Position = 0)] + [string[]]$Task = 'default', + + [parameter(ParameterSetName = 'help')] + [switch]$Help +) + +Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null +Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + +if (-not (Get-Module -Name PSDepend -ListAvailable)) { + Install-module -Name PSDepend -Repository PSGallery +} +Import-Module -Name PSDepend +Invoke-PSDepend -Path .\requirements.psd1 -Install -Import -Force +if (-not (Get-Module -Name BuildHelpers -ListAvailable)) { + Install-Module -Name BuildHelpers -AllowClobber +} +Import-Module -Name BuildHelpers + +if ($PSBoundParameters.ContainsKey('help')) { + Get-PSakeScriptTasks -buildFile "$PSScriptRoot\psake.ps1" | + Format-Table -Property Name, Description, Alias, DependsOn +} else { + Set-BuildEnvironment -Force + + Invoke-psake -buildFile "$PSScriptRoot\psake.ps1" -taskList $Task -nologo + exit ( [int]( -not $psake.build_success ) ) +} diff --git a/psake.ps1 b/psake.ps1 new file mode 100644 index 0000000..318beb7 --- /dev/null +++ b/psake.ps1 @@ -0,0 +1,81 @@ +properties { + $projectRoot = $ENV:BHProjectPath + if(-not $projectRoot) { + $projectRoot = $PSScriptRoot + } + + $sut = "$projectRoot\$env:BHProjectName" + $tests = "$projectRoot\Tests" + $manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest + + $psVersion = $PSVersionTable.PSVersion.Major +} + +task default -depends Test + +task Init { + "`nSTATUS: Testing with PowerShell $psVersion" + "Build System Details:" + Get-Item ENV:BH* +} -description 'Initialize build environment' + +task Test -Depends Init, Analyze, Pester -description 'Run test suite' + +task Analyze -Depends Init { + $analysis = Invoke-ScriptAnalyzer -Path $sut -Recurse -Verbose:$false + $errors = $analysis | Where-Object {$_.Severity -eq 'Error'} + $warnings = $analysis | Where-Object {$_.Severity -eq 'Warning'} + if (@($errors).Count -gt 0) { + Write-Error -Message 'One or more Script Analyzer errors were found. Build cannot continue!' + $errors | Format-Table + } + + if (@($warnings).Count -gt 0) { + Write-Warning -Message 'One or more Script Analyzer warnings were found. These should be corrected.' + $warnings | Format-Table + } +} -description 'Run PSScriptAnalyzer' + +task Pester -Depends Init { + Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue -Verbose:$false + Import-Module -Name $env:BHPSModuleManifest -Force -Verbose:$false + + # Prep for testing + $PesterParams = @{} + $testResultFile = '' + switch ($ENV:BHBuildSystem) { + 'AppVeyor' { + $testResultFile = Join-Path -Path $projectRoot -ChildPath 'pester.xml' + $PesterParams = @{ + OutputFile = $testResultFile + OutputFormat = 'NUnitXML' + } + break + } + Default {} + } + + # Run tests + if (Test-Path -Path $tests) { + $testResults = Invoke-Pester -Path $tests -PassThru @PesterParams + + # Post test results + switch ($ENV:BHBuildSystem) { + 'AppVeyor' { + (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $testResultFile) + break + } + Default {} + } + } + + if ($testResults.FailedCount -gt 0) { + throw "$($testResults.FailedCount) tests failed!" + } + +} -description 'Run Pester tests' + +Task Publish -Depends Test { + " Publishing version [$($manifest.ModuleVersion)] to PSGallery..." + Publish-Module -Path $sut -NuGetApiKey $env:PSGalleryApiKey -Repository PSGallery +} diff --git a/requirements.psd1 b/requirements.psd1 new file mode 100644 index 0000000..90854d9 --- /dev/null +++ b/requirements.psd1 @@ -0,0 +1,9 @@ +@{ + PSDependOptions = @{ + Target = 'CurrentUser' + } + psake = 'latest' + pester = 'latest' + psscriptanalyzer = 'latest' + poshbot = 'latest' +} From d973b24d85387a9aeef442f5100308180001c769 Mon Sep 17 00:00:00 2001 From: Maurice Kevenaar Date: Mon, 2 Sep 2019 14:27:49 +0200 Subject: [PATCH 2/5] (GH-2) Switch to New-PoshBotCardResponse --- PoshBot.Soon/PoshBot.Soon.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PoshBot.Soon/PoshBot.Soon.psm1 b/PoshBot.Soon/PoshBot.Soon.psm1 index 746299f..ac8d98c 100644 --- a/PoshBot.Soon/PoshBot.Soon.psm1 +++ b/PoshBot.Soon/PoshBot.Soon.psm1 @@ -45,6 +45,6 @@ function Get-Soon { # @devblackops - You could also use the New-PoshBotCardResponse -ImageUrl if ($randomlySelectedImage) { - "![img]($($randomlySelectedImage))" + New-PoshBotCardResponse -ImageUrl $randomlySelectedImage } } \ No newline at end of file From 5c0bb1e9fab020bc238e4f726da9cf06f2c1a5dc Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 2 Sep 2019 15:46:28 +0100 Subject: [PATCH 3/5] (maint) Formatting --- PoshBot.Soon/PoshBot.Soon.psm1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PoshBot.Soon/PoshBot.Soon.psm1 b/PoshBot.Soon/PoshBot.Soon.psm1 index ac8d98c..a3b1d1f 100644 --- a/PoshBot.Soon/PoshBot.Soon.psm1 +++ b/PoshBot.Soon/PoshBot.Soon.psm1 @@ -43,8 +43,7 @@ function Get-Soon { $randomlySelectedImage = Get-Random -InputObject $imageArray - # @devblackops - You could also use the New-PoshBotCardResponse -ImageUrl if ($randomlySelectedImage) { - New-PoshBotCardResponse -ImageUrl $randomlySelectedImage + New-PoshBotCardResponse -ImageUrl $randomlySelectedImage } -} \ No newline at end of file +} From 8b354665d4b1ff8c4f20d32d032f408d04f0913b Mon Sep 17 00:00:00 2001 From: Maurice Kevenaar Date: Mon, 2 Sep 2019 20:15:43 +0200 Subject: [PATCH 4/5] (GH-4) PoshBot.Soon should depend on PoshBot v0.11.8 or higher In versions older than 0.11.8, a bug was discovered that shows an empty string above the image --- PoshBot.Soon/PoshBot.Soon.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PoshBot.Soon/PoshBot.Soon.psd1 b/PoshBot.Soon/PoshBot.Soon.psd1 index 50fbb1b..724f85b 100644 --- a/PoshBot.Soon/PoshBot.Soon.psd1 +++ b/PoshBot.Soon/PoshBot.Soon.psd1 @@ -51,7 +51,7 @@ PowerShellVersion = '5.0.0' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -RequiredModules = @('PoshBot') +RequiredModules = @(@{ModuleName='PoshBot'; ModuleVersion='0.11.8'; Guid='7bfb126c-b432-4921-989a-9802f525693f'}) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() From bf87d43038910bfa11171a1f94b6501d0b3a93b2 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 2 Sep 2019 12:13:56 -0700 Subject: [PATCH 5/5] (build) Change AppVeyor Build Image --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index dd4a83e..21056a7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: 1.0.{build} -image: WMF 5 +image: Visual Studio 2015 build: off