Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent mode #76

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open

Silent mode #76

wants to merge 2 commits into from

Conversation

ObserverHerb
Copy link

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]

…to check for environment variable

SILENT_MODE before private messaging the user.

Included SILENT_MODE in .env.example
@rikai
Copy link
Owner

rikai commented Dec 3, 2016

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
Copy link
Author

ObserverHerb commented Dec 3, 2016

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
Copy link
Owner

rikai commented Dec 3, 2016

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
Copy link
Owner

rikai commented Mar 28, 2017

Any update on this? :)

@ObserverHerb
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants