Extracting certain lines of text out of channels into a text file reddit / irc ---------------------------------------------------------------------- FiesenRotze · 2015-04-07 01:05 Is there a script/plugin for HexChat that allowes scanning for specific words/lines inside of a channel? I'm totally new to this and even would be thankful for a well explained 'no'. ---------------------------------------------------------------------- 24cal · 2015-04-07 04:53 This is easy mode! **Option 1:** Start logging the channel you want to target and then just run a python script to parse out your target string and write to a file. Example: for line in file: if 'string' in line: f.write(line) **Option 2:** Instead of the python you could grep but this is a bit more manual. **Options 3:** Run an IRC bot that monitors the channel and when your desired string is matched, write that to file. Either way works but the bot will do things in real time as opposed to option one which requires you to revisit the chat logs after the fact. Care to share any context on the project you're working on? ---------------------------------------------------------------------- TTSDA · 2015-04-07 08:17 In my opinion the best way would be to simply log everything, and then grep the log files for the word you need. Text doesn't take too much space, and it's much more flexible this way. Using GNU grep you can run something like grep -Pi "\bWORD\b" * (inside the directory with the logs files) to find a word between two boundaries (beginning/end of a phrase, whitespace, punctuation). Read more about regular expressions, you can do some neat stuff. ---------------------------------------------------------------------- FiesenRotze · 2015-04-07 12:32 First of all, thank you very much for your answer. Since a few weeks I like to race my favorite game via SpeedRunsLive, which mainly is based on an IRC. Basically, a bot ('racebot') starts a countdown when all racers in the channel are ready (done through '.ready') and live on Twitch.tv. The thing is, I find the announcement of players finishing/quitting the race not that apparent, so a script scanning the log-file for 'has fortfeit from the race' and 'finished the race' and pasting these lines to another file would be extremely helpful. I did some research and loaded following script ino HexChat: __module_name__ = "Log Search" __module_version__ = "1.0" __module_description__ = "Searches Channel Log" import re, glob, xchat def search_log(word, word_eol, userdata): network = xchat.get_info("network") channel = xchat.get_info("channel") directory = xchat.get_info("xchatdir") filename = directory + "/scrollback/" + network + "/" + channel + ".txt" files = glob.glob(filename) if len(word) > 1: search = re.compile(word[1]).search output = "QUERY -[search]-" xchat.command(output) settab = xchat.find_context(channel='-[search]-') settab.prnt(" ") print "\037\00304SEARCH:", word[1] for file in files: for index, line in enumerate(open(file)): if search(line): output = ":".join((channel, str(index+1), line[:-1])) search_win = xchat.find_context(channel='-[search]-') search_win.prnt(output) return xchat.EAT_NONE xchat.hook_command("s", search_log, help="/s ") This script adds the command '/s', so I could type in '/s finished' or '/s fortfeit' and would get the findings displayed in a new '-[search]-' tab. But what I'm searching for is a command that scans the log file till the race is done/I leave the channel, so while I'm racing I can just look on the printed file and see the current leaderboard. ---------------------------------------------------------------------- 24cal · 2015-04-07 13:55 Aww in this case I think the simplest way would still be to log but then you could tail -f irc.log | grep 'string' That way you filter what you want and its in real time. This is great for glancing at too since it will just populate what you want when it happens. ---------------------------------------------------------------------- 24cal · 2015-04-07 13:56 regex ftw!!! ---------------------------------------------------------------------- FiesenRotze · 2015-04-07 16:15 Is there a homepage that explains how exactly I would have to code this? I'm a total noob at programming and only know the basics, so a sheet with the needed commands would be awesome :) ---------------------------------------------------------------------- 24cal · 2015-04-07 17:12 As long as you have logging configured on your IRC client, you should be able to just tail those logs with the above command. Also, this is a bash command so you will need access to a bash terminal. Assuming you are on Windows. BUT if you are on OSX, this is also possible. (OSX uses bash). If you're on Windows...I'm not sure what the equivalent command is. Maybe power shell could help you out here. ---------------------------------------------------------------------- FiesenRotze · 2015-04-07 17:43 I'm on Windows :/ But isn't it possible to write a script in Python? I really want to have a command in HexChat to start the scanning ---------------------------------------------------------------------- 24cal · 2015-04-07 19:05 I have no exp with writing scripts for HexChat (I use irssi) so I won't be any help on this :/ ---------------------------------------------------------------------- FiesenRotze · 2015-04-08 01:59 Thank you anyway. Helped a lot! ---------------------------------------------------------------------- TingPing · 2015-04-08 02:06 This script will highlight any words you want and change the color of that channels tab so its easy to notice: [wordhl.py](https://github.co m/TingPing/plugins/blob/master/HexChat/wordhl.py) EDIT: And if you want to log these just modify this script with wordhl: [higlight.py](https://github.com/TingPing/plugins/blob/master/ HexChat/highlight.py)