rikai / Showbot

🤖 An omnipresent multi-platform bot who's goal in life is become Skynet 🤖
MIT License
40 stars 18 forks source link

Silent mode #76

Open ObserverHerb opened 7 years ago

ObserverHerb commented 7 years ago

Possibly resolves #64.

I've added a SILENT_MODE environment variable and included it in the example file.

Added extensions.rb with the monkey patches. Was able to just call super with Cinch::User since send() is from the Target base class.

reply() and action_reply() are actually members of Cinch::Message, so the patch overwrites them and I had to copy the implementation into the extension. This could be problematic if the implementation changes in the future. Is there possibly a better way or another way to patch the class without changing the API?

Output when in silent mode is in the format: SILENT MODE: Type of message to [user nick] = [message that would have been sent]

rikai commented 7 years ago

So I was actually thinking of a slightly different approach with this than what you've gone with here. This is 95% of what i wanted but...

For maximum debugging ability, I was thinking rather than intercepting the events by overriding the send, that instead intercepting them after sending them would be closer to normal functionality. As in, sending the messages as you normally would, but those messages being sent to a sort of /dev/null (or some sort of mini-server that only does logging or something) rather than to the IRC server.

My goal with this feature is to keep it as close to vanilla functionality as humanly possible while still intercepting the messages, so the less monkeypatching of cinch that is done, the better.

ObserverHerb commented 7 years ago

If I'm understanding correctly, then I can dig a little deeper into the framework. It sounds like you want to capture at the last possible moment before the message is actually sent.

I could redirect in the base send function in irc.rb...

    # Send a message to the server.
    # @param [String] msg
    # @return [void]
    def send(msg)
      @queue.queue(msg)   <--- redirect instead of pushing to queue to be sent to socket
    end

Or I could redirect in message_queue.rb right before it's written to the socket...

       begin
          to_send = Cinch::Utilities::Encoding.encode_outgoing(message, @bot.config.encoding)
          @socket.write to_send + "\r\n"   <-- Redirect to another output rather than socket
          @log << Time.now
          @bot.loggers.outgoing(message)

          @time_since_last_send = Time.now
        rescue IOError
          @bot.loggers.error "Could not send message (connectivity problems): #{message}"
        end

Do either of those put us closer to the same page?

rikai commented 7 years ago

The latter seems like the last possible point to catch it, so that'd probably be optimal. It would also allow us to catch everything going out without having to do special cases for each type of output if I understand correctly, no?

The only other potential problem I can see relating to doing things this way is that we may want to have a way to set an override for the silent mode with specific plugins. For example, cinch-identify would stop functioning in silent mode and therefore break identification as messages from the bot wouldn't be sent to the server.

rikai commented 7 years ago

Any update on this? :)

ObserverHerb commented 7 years ago

Jeebus, I forgot all about JBot! I've been tied up with qtwebkit stuff lately, but as soon as I get a chance to revisit this I'll let you know.

ObserverHerb commented 7 years ago

Hey man, I don't want to leave you hanging. I want to finish this but I have to accept I'm just not able to make it a priority. My apologies.