poshbotio / PoshBot

Powershell-based bot framework
MIT License
537 stars 108 forks source link

Changes to plugins aren't picked up after bot restart #117

Closed Tadas closed 5 years ago

Tadas commented 5 years ago

While working on a plugin I've added a new function to the plugin module. I've restarted PoshBot but the new function isn't detected. Changes to existing functions seem to get picked up.

Expected Behavior

If I make changes to a plugin module and restart the bot I'd expect the changes to become live

Current Behavior

Possible Solution

Add -Force to Import-Module ? https://github.com/poshbotio/PoshBot/blob/d1fba821896d58a01656b01a5224e6be0171ea06/PoshBot/Classes/PluginManager.ps1#L467

Steps to Reproduce (for bugs)

  1. Create a new plugin module, install
  2. !help and observe functions in our plugin
  3. Add new function to plugin module
  4. Restart bot without restarting PowerShell session
  5. !help and observe functions in our plugin

Context

Your Environment

gkingston commented 5 years ago

I don't know if there is an official/better way, but I don't restart the bot. I make changes to my plugins and then I run !rp sompluginname to remove it, followed by !ip somepluginname to install it again. There is also the command !updateplugin somepluginname to update the existing plugin.

If you are just restarting the bot, it will keep the same plugin version you've already loaded.

My standard workflow when changing/updating a plugin is to update the code in the psm1 file, update the version in the psd1 file and then remove/(re)install or update the plugin. I never stop the bot

Tadas commented 5 years ago

Yeah !rp would work since https://github.com/poshbotio/PoshBot/issues/100 has been fixed

Still, it's kind of surprising that restarting something doesn't completely re-initialise the state, it's one of the core tenets of IT :)

devblackops commented 5 years ago

@Tadas Adding -Force here will probably work. I suspect that is why your changes to a plugin/module without changing the version is why they aren't being picked up. https://github.com/poshbotio/PoshBot/blob/d1fba821896d58a01656b01a5224e6be0171ea06/PoshBot/Classes/PluginManager.ps1#L467

When you say you're restarting the bot, are you running it interactively, as a job, or as a service? Depending on what you're doing, the PS session isn't closing and therefore the plugin/module is still loaded. Adding -Force to Import-Module should fix that.