Created
March 10, 2014 19:31
-
-
Save Ninjex/9472511 to your computer and use it in GitHub Desktop.
A Weechat plugin coded in Ruby. This plugin allows you to run command on your machine from IRC, additionally you may choose to directly post the messages to all users in IRC with the -p option. For example: /exec -p echo 'hi'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| def weechat_init | |
| Weechat.register('exec', 'Ninjex', '1.0', 'GPL3', 'Execute a terminal command via /exec <command>', '', '') | |
| Weechat.hook_command('exec', 'Execute a terminal command from chat', '', '', '', 'exec', '') | |
| return Weechat::WEECHAT_RC_OK | |
| end | |
| def exec(data, buffer, args) | |
| to = nil | |
| buffer = Weechat.current_buffer | |
| explode = args.split('-p') | |
| if explode.size > 1 | |
| query = explode.drop(1).join.strip | |
| to = :current_buffer | |
| else | |
| query = explode.join.strip | |
| to = :main_buffer | |
| end | |
| cmd_thread = Thread.new { data = `#{query} 2>&1` } | |
| cmd_thread.join | |
| if data.nil? || data.empty? || data.include?('Permission denied') | |
| Weechat.print("", "Permission was denied or an invalid query was given.") | |
| elsif to == :current_buffer | |
| Weechat.command(buffer, data) | |
| else | |
| Weechat.print("", data) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment