poshbotio / PoshBot

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

New-ScheduledCommand works but shows an error #173

Closed pauby closed 4 years ago

pauby commented 5 years ago

When you use the New-Schedule command it does add a command to the schedule but also shows an error.

Expected Behavior

I expect no error to be shows.

Current Behavior

If I run !newschedule --command 'somecommand' --value 1 --interval days --startafter '7:00am' I get a green tick to say the command is scheduled. I also get an error that says:

Sorry :( PoshBot has been configured to not allow that command in this channel. Please contact your bot administrator.

image

But if I run !somecommand in the same channel it works fine (there are also no commands restricted in this channel).

The logs show this:

{"DataTime":"2019-08-22 13:33:06Z","Class":"Command","Method":"TriggerMatch","Severity":"Normal","LogLevel":"Debug","Message":"Parsed command [somecommand] matched to command trigger [somecommand] on command [somecommand]","Data":{}}
{"DataTime":"2019-08-22 13:33:06Z","Class":"PluginManager","Method":"MatchCommand","Severity":"Normal","LogLevel":"Info","Message":"Matched parsed command [:somecommand] to plugin command [module.name:somecommand]","Data":{}}
{"DataTime":"2019-08-22 13:33:06Z","Class":"Bot","Method":"HandleMessage","Severity":"Normal","LogLevel":"Debug","Message":"Igoring message. Command not approved in channel","Data":"module.name:somecommand:0.0.2"}

Your Environment

devblackops commented 5 years ago

@pauby I think something in your channel rules in tripping this up. This is the test I did that worked. I ran this in private-channel.

ChannelRules = @(
    @{
      Channel = 'private-channel1'
      IncludeCommands = @('*')
      ExcludeCommands = @()
    },
    @{
      Channel = 'private-channel2'
      IncludeCommands = @('Builtin:Get-CommandHelp:*')
      ExcludeCommands = @()
    }
    @{
      IncludeCommands = @('*')
      Channel = '*'
      ExcludeCommands = @()
    }
  )

image

devblackops commented 5 years ago

@pauby In #172, you has this in your channel rules. Notice the backtick. That will cause the command to not be allowed since the fully qualified command name <modulename>.<commandname>.<version> won't match that (PoshBot uses -Like to match the names).

'module:command1`:*',
pauby commented 5 years ago

@pauby In #172, you has this in your channel rules. Notice the backtick. That will cause the command to not be allowed since the fully qualified command name <modulename>.<commandname>.<version> won't match that (PoshBot uses -Like to match the names).

'module:command1`:*',

That backtick was a formatting error when I was editing the names for that issue @devblackops - apologies. I've amended it now in that issue as it wasn't actually there in the config on the server. Im happy to send exactly what I have to you through private channels (no pun intended 😃)?

pauby commented 5 years ago

The command that was scheduled to run (in both provate channels - so one with the '*' as included commands and the other with the restricted commands) didn't actually run. At the scheduled time I got this in both channels:

image

The command is one of those that is allowed to run in private-channel2. Logs show this (for both channels its the same errors):

{"DataTime":"2019-08-23 07:00:00Z","Class":"Command","Method":"TriggerMatch","Severity":"Normal","LogLevel":"Debug","Message":"Parsed command [somecommand] matched to command trigger [somecommand] on command [somecommand]","Data":{}}
{"DataTime":"2019-08-23 07:00:00Z","Class":"PluginManager","Method":"MatchCommand","Severity":"Normal","LogLevel":"Info","Message":"Matched parsed command [:somecommand] to plugin command [module.name:somecommand]","Data":{}}
{"DataTime":"2019-08-23 07:00:00Z","Class":"Bot","Method":"HandleMessage","Severity":"Normal","LogLevel":"Debug","Message":"Igoring message. Command not approved in channel","Data":"module.name:somecommand:0.0.2"}

Again, if the command somecommand is run manually in the channel it works as expected.

pauby commented 5 years ago

I think something in your channel rules in tripping this up.

Okay. I was drifting between it's something stupid I'm doing wrong or it's a bug. I keep thinking it's one, move forward and then think it's the other 😄

The only difference between my configuration and yours is I don't have this at the end:

    @{
      IncludeCommands = @('*')
      Channel = '*'
      ExcludeCommands = @()
    }

Is it needed?

UPDATE:

I actually added that code to the end of the ChannelRules and it works. The commands are executed but the side effect from this is that any channel POshBot is invited into is allowed to execute any command. What I was looking for is to restrict channel explicitly so any channel PoshBot is invited into has to be configured for commands or nothing works for it. I've confirmed that is the case by adding this line.

So I'm still wavering between 'its a bug' (in matching commands) and 'its my config'. The fact it works when run manually but doesn't work when run as a scheduled command is making me lean mnore towards it's a bug? Thoughts?

Can you actually try the ChannelRules config you had with only private-channel1 and private-channel2?

Thank you for all your help with this by the way!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

pauby commented 4 years ago

@devblackops Did you manage to look at this based on my comments?

devblackops commented 4 years ago

Sorry @pauby. Got distracted with other stuff. I'll take a look at this again.

devblackops commented 4 years ago

@pauby Can you build from master and try this out? This commit should hopefully fix it.

tl;dr; Scheduled commands weren't getting the ToName and FromName resolved because that is a function of the backend and scheduled commands don't really come from the backend, they get shoehorned into the bot message queue as if they came from the backend. Now those messages will call methods in the backend to resolve the names.

pauby commented 4 years ago

@devblackops That's cool - I really did it because of the bot trying to shut us down! 😃

Leave this with me and I'll have a look at it. Likely after Ignite. Thanks for looking at it and sorting it.

pauby commented 4 years ago

@devblackops It's been a while but I've come back to this. I've upgraded PoshBot to the commit version and it appears to be working (it's only been half an hour but still). The scheduled commands are working and the restricted commands are not. Just as it should be.

Would like to keep this open for a few more days just to be sure and then I'll come back and close it?

devblackops commented 4 years ago

@pauby Glad it's working! Feel free to close the issue whenever you're comfortable.