Last active
March 13, 2016 19:39
-
-
Save FredrikAugust/67a8d979d6afb8dcf836 to your computer and use it in GitHub Desktop.
Weechat read mentions and privmsgs
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 | |
# set username here! | |
NICK = "" # irc nick | |
IP = "" # computer on which to exec espeak | |
USER = "" # user on said computer | |
# this is all wizardry | |
# don't touch | |
def say(nick, text) | |
# execute espeak over ssh | |
system "ssh #{USER}@#{IP} \"espeak '#{nick} said #{text}'\"" | |
end | |
def mention_cb(data, modifier, modifier_data, string) | |
# parse the command string to a hash | |
content = Weechat.info_get_hashtable("irc_message_parse", {"message" => string}) | |
# remove | |
content["text"] = content["arguments"].sub(/^#?.+ :/, '') | |
# print to the main buffer | |
Weechat.print('', "Content: #{content.to_s}") | |
# if msg is to you, or the message contains your nick | |
if content["channel"] == NICK or content["text"] =~ /#{NICK}/i | |
# remove the nick when someone tags you at beginning of msg | |
say(content["nick"], content["text"].sub(/^#{NICK}.?\s?/i, '').gsub(/[\\\'\"\`\$\{\}]/, '')) | |
end | |
return string | |
end | |
def weechat_init | |
Weechat.register("read_aloud", "FredrikAugust", "1.0", "GPL3", "Read mentions and privmsgs aloud", "", "") | |
Weechat.hook_modifier("irc_in_privmsg", "mention_cb", "") | |
return Weechat::WEECHAT_RC_OK | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment