Last active
December 25, 2015 19:09
-
-
Save Kilobyte22/7025342 to your computer and use it in GitHub Desktop.
My Tinychat weechat script
This file contains 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
def weechat_init | |
Weechat.register('tinychat', 'Kilobyte', '1.0', 'GPL3', 'Adds small chat windows for channels. Intended mainly ad widget for small split screen windows', 'gtfo', '') | |
Weechat.hook_command("tinychat", "manages tinychat windows", "[make] || [setmainwindow]", '', "make %(irc_channels)", "cmd_tinychat", '') | |
Weechat.hook_print("", "", "", 0, "hook_print", "") | |
Weechat::WEECHAT_RC_OK | |
end | |
def gtfo | |
Weechat::WEECHAT_RC_OK | |
end | |
@tinychats = {} | |
@mainwin = 1 | |
@lastbuffer | |
def self.debug(message) | |
Weechat.print("", "CP-DEBUG\t#{message}") | |
end | |
def cmd_tinychat(data, buffer, args) | |
cmd = args.split ' ' | |
case cmd[0] | |
when 'make' | |
name = Weechat.buffer_get_string(buffer, 'name') | |
plugin = Weechat.buffer_get_string(buffer, 'plugin') | |
unless plugin == 'irc' and name['.'] | |
Weechat.print(buffer, "ERROR\tInvalid buffer") | |
return Weechat::WEECHAT_RC_ERROR | |
end | |
if @tinychats[buffer] | |
Weechat.print(buffer, "ERROR\tCurrent channel already has a tinychat") | |
return Weechat::WEECHAT_RC_ERROR | |
else | |
_ = name.split '.' | |
server = _[0] | |
channel = _[1] | |
@tinychats[buffer] = Buffer.new server, channel, buffer | |
end | |
#break | |
#when 'setmainwindow' | |
# @mainwin = Weechat.current_window | |
else | |
Weechat.print(buffer, "ERROR\tUnknown subcommand #{cmd[0]}. type /help tinychat") | |
return Weechat::WEECHAT_RC_ERROR | |
end | |
return Weechat::WEECHAT_RC_OK | |
end | |
def hook_print(data, buffer, date, tags, displayed, highlight, prefix, message) | |
return Weechat::WEECHAT_RC_OK unless buf = @tinychats[buffer] | |
t = tags.split(',') | |
case | |
when t.include?('irc_join'), t.include?('irc_part') | |
message = "#{Weechat.color("gray")}#{Weechat.string_remove_color(message.split(' ')[0], '')}" | |
when t.include?('irc_nick') | |
message = "#{Weechat.color("gray")}#{Weechat.string_remove_color(message, '')}" | |
when t.include?('irc_quit') | |
message = "#{Weechat.color("gray")}#{Weechat.string_remove_color(message.split(' ')[0], '')}" | |
prefix = "#{Weechat.color('red')}<<<" | |
end | |
buf.add_line(date.to_i, tags, prefix, message) | |
end | |
def buf_input(data, buffer, text) | |
buf = @tinychats[data] | |
buf.on_input(text) | |
return Weechat::WEECHAT_RC_OK | |
end | |
def buf_close(data, buffer, meh) | |
buf = @tinychats[data] | |
buf.on_close() | |
@tinychats[data] = nil | |
return Weechat::WEECHAT_RC_OK | |
end | |
def buf_buffer_closed(data, signal, buffer) | |
buf = @tinychats[buffer] | |
buf.close if buf | |
return Weechat::WEECHAT_RC_OK | |
end | |
class Buffer | |
def initialize(server, target, buffer) | |
@linked = buffer | |
@name = "tiny:#{server}/#{target}" | |
@me = Weechat.buffer_new(@name, 'buf_input', @linked, 'buf_close', @linked) | |
Weechat.buffer_set(@me, 'title', "Tiny Chat: #{target}@#{server}") | |
end | |
def on_close | |
end | |
def close | |
Weechat.buffer_close(@me) | |
end | |
def on_input(text) | |
if 'text' == '/' | |
Weechat.print(@linked, "tinychat\tOpened linked buffer into main window. use /back to restore old buffer") | |
return Weechat::WEECHAT_RC_OK | |
end | |
Weechat.command(@linked, text) | |
end | |
def add_line(date, tags, prefix, message) | |
msg = "#{prefix}\t#{message}" | |
#Debug.debug ({:linked => @linked, :date => date, :tags => tags, :msg => msg}.inspect) | |
Weechat.print_date_tags(@me, date, tags, msg) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment