Jump to content

AutoResponse creator


Recommended Posts

This is a Powershell script you might run in the background while you are playing the game. It will monitor your log file for keywords (such as "DFB" or "Posi") and when found will create the text for a tell and place it on your clipboard.

 

In game, theoretically, when you see someone advertise a DFB (one of the keywords you've defined in line 28), you can quickly hit ENTER to start a new message, Control V to paste from your clipboard, and then ENTER again to send the message. This would allow you to quickly respond to new postings by sending a tell directly to the organizer.

 

Note that the script doesn't differentiate between "I am forming a DFB" and "I would like to join a DFB" - so long as the keyword is found in a new LFG post, the clipboard will be populated. Also, since log files are for 1 day only, if you play across midnight you will want to close and restart this for the new day.

 

Here's the script if you prefer to look at it that way:

 

Spoiler

#COH AutoResponse - 9/28/22 (2nd version)
#Original code written by @Oklahoman
#NOTE: In game, you must turn on chat logs - MENU -> Options -> Windows -> Log Chat (Enabled)
#NOTE: This will create text files in your COH install directory -> username -> logs folder
#NOTE: Periodically, you may want to archive or delete these files as they will pile up, one file for each day you play!
#NOTE: Please share alterations to this code to the Homecoming forums (https://forums.homecomingservers.com/) in the
#NOTE: "Tools, Utilities, and Downloads" forum
#NOTE: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.1
#NOTE: You will need to set execution policy for local user to Unrestricted, and understand the consequences of that
#NOTE: Save this file with a .ps1 extension. Right click and select "Run with Powershell" to execute. YMMV
#The intent is to monitor LFG for keywords, and when found create a request to join and place it in the players clipboard
#In game, when you see something advertised you are tracking below, you can hit ENTER, CTRL-V, ENTER to send a request for invitation

#Opens a file picker window
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$FileBrowser.filter = "Txt (*.txt)| *.txt"
[void]$FileBrowser.ShowDialog()
#TODO: Gracefully handle user hitting cancel

#Open selected file so we can read it while COH continues to write to it
$File = [System.io.File]::Open($FileBrowser.FileName, 'Open', 'Read', 'ReadWrite')

#only include lines in output that have these keywords in them
#Array is Filter, WhereToSubstringFrom - we do not use WhereToSubstringFrom in this script, but too lazy to remove everything associated with it right now!
#Add any and all keywords here, following this same pattern

$keywords = @("DFB", "Posi", "ASF")

$newstreamreader = New-Object System.IO.StreamReader($File)

#TODO: maybe some code that compares the date data in $newstreamreader to todays date, and alerts when you have passed midnight. As it stands now, you need to close and rerun this immediately after midnight or it will continue to monitor the now-previous days log file.

$bFlag = 1;

While ($bFlag -eq 1) {
    #Are we at the end of the file?
    if (($readeachline = $newstreamreader.ReadLine()) -ne $null) {

        #remove HTML from line
        $a = $readeachline -replace '<[^>]+>',''

        #Ignore lines not coming from a chat channel at all, such as influence gained, who killed what, etc.
        if ($a.Substring(20,4) -eq "[Loo") {
            if ($a.Substring(20,19) -eq "[Looking For Group]") {
                #Ignore any line that does not have [Looking For Group] in a specific spot.
                foreach ($keyword in $keywords) { 


                    #Looking for any of the filter words occuring after the date and time info
                    if ($a.IndexOf($keyword) -gt 1 ) {
                        #We found a keyword from the $keywords list above
                        $b = $a.Substring(20)
                        #So $b now consists of all the text in the line AFTER the date and timestamp
                    
                        #Within $b, find the first ":" which indicates the end of the PlayerName
                        $PlayerColon = $b.IndexOf(":")
                        $PlayerNameLength = $PlayerColon - 20
                        $PlayerName = $b.Substring(20, $PlayerNameLength)
                    
                        $Plea = "/t " + $PlayerName + ", Can I join that " + $keyword + " you are forming, please?"
                        Write-Host $Plea
                        #Adds to clipboard
                        Set-Clipboard -Value $Plea
                    }
                }
            }
        }
    }
}
#You're going to hit Control-C or close the window before this hits, but whatevs
$newstreamreader.Dispose()

 

DISCLAIMER: I am not a coder (obviously) but I was at one time until I took an arrow to the knee. I dabble now, and I am confident any half-skilled coder could do a much better job with this, even creating something that doesn't require Powershell. Please share if you do!

COH AutoResponse.ps1

Edited by Oklahoman
  • Like 1
  • Thumbs Up 1
Link to comment
Share on other sites

Decided to try this in real time. If you have dual monitor capabilities, you can have the powershell running on one monitor while you play on the other (see pic). I decided to change the code on my end slightly - I changed the output on line 62 to act more as an alert, rather than just telling me what just got placed on my clipboard. I inserted line 63 after that to make a beep, too, so if I was playing and something popped up I wanted to join I'd have both an audio and visual alert.

 

Spoiler

#COH AutoResponse - 9/28/22 (2nd version)
#Original code written by @Oklahoman
#NOTE: In game, you must turn on chat logs - MENU -> Options -> Windows -> Log Chat (Enabled)
#NOTE: This will create text files in your COH install directory -> username -> logs folder
#NOTE: Periodically, you may want to archive or delete these files as they will pile up, one file for each day you play!
#NOTE: Please share alterations to this code to the Homecoming forums (https://forums.homecomingservers.com/) in the
#NOTE: "Tools, Utilities, and Downloads" forum
#NOTE: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.1
#NOTE: You will need to set execution policy for local user to Unrestricted, and understand the consequences of that
#NOTE: Save this file with a .ps1 extension. Right click and select "Run with Powershell" to execute. YMMV
#The intent is to monitor LFG for keywords, and when found create a request to join and place it in the players clipboard
#In game, when you see something advertised you are tracking below, you can hit ENTER, CTRL-V, ENTER to send a request for invitation

#Opens a file picker window
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
$FileBrowser.filter = "Txt (*.txt)| *.txt"
[void]$FileBrowser.ShowDialog()
#TODO: Gracefully handle user hitting cancel

#Open selected file so we can read it while COH continues to write to it
$File = [System.io.File]::Open($FileBrowser.FileName, 'Open', 'Read', 'ReadWrite')

#only include lines in output that have these keywords in them
#Array is Filter, WhereToSubstringFrom - we do not use WhereToSubstringFrom in this script, but too lazy to remove everything associated with it right now!
#Add any and all keywords here, following this same pattern

$keywords = @("DFB", "Posi", "Numina")

$newstreamreader = New-Object System.IO.StreamReader($File)

#TODO: maybe some code that compares the date data in $newstreamreader to todays date, and alerts when you have passed midnight. As it stands now, you need to close and rerun this immediately after midnight or it will continue to monitor the now-previous days log file.

$bFlag = 1;

While ($bFlag -eq 1) {
    #Are we at the end of the file?
    if (($readeachline = $newstreamreader.ReadLine()) -ne $null) {

        #remove HTML from line
        $a = $readeachline -replace '<[^>]+>',''

        #Ignore lines not coming from a chat channel at all, such as influence gained, who killed what, etc.
        if ($a.Substring(20,4) -eq "[Loo") {
            if ($a.Substring(20,19) -eq "[Looking For Group]") {
                #Ignore any line that does not have [Looking For Group] in a specific spot.
                foreach ($keyword in $keywords) { 


                    #Looking for any of the filter words occuring after the date and time info
                    if ($a.IndexOf($keyword) -gt 1 ) {
                        #We found a keyword from the $keywords list above
                        $b = $a.Substring(20)
                        #So $b now consists of all the text in the line AFTER the date and timestamp
                    
                        #Within $b, find the first ":" which indicates the end of the PlayerName
                        $PlayerColon = $b.IndexOf(":")
                        $PlayerNameLength = $PlayerColon - 20
                        $PlayerName = $b.Substring(20, $PlayerNameLength)
                    
                        $Plea = "/t " + $PlayerName + ", Can I join that " + $keyword + " you are forming, please?"
                        Write-Host "Looks like a $keyword may be forming!"
                        [console]::beep(1000,500)
                        #Adds to clipboard
                        Set-Clipboard -Value $Plea
                    }
                }
            }
        }
    }
}
#You're going to hit Control-C or close the window before this hits, but whatevs
$newstreamreader.Dispose()

 

IMG_0494.jpg

Link to comment
Share on other sites

I find it interesting, given your post about wanting people to ask for invites in broadcast rather than tells (hey, it's right there in your signature!), that this script sends a tell by default.  Maybe you could add another keyword check to see if the message includes the words "tell," "PST," "broadcast," or "shout" to determine whether the text to paste is formatted as a tell or a broadcast?

Edited by Zhym
  • Like 1
Link to comment
Share on other sites

45 minutes ago, Zhym said:

I find it interesting, given your post about wanting people to ask for invites in broadcast rather than tells (hey, it's right there in your signature!), that this script sends a tell by default.  Maybe you could add another keyword check to see if the message includes the words "tell," "PST," "broadcast," or "shout" to determine whether the text to paste is formatted as a tell or a broadcast?

 

I can see that. Personally, I only ask for stuff to be posted in Broadcast for MSRs and Hamis (if I ever run one again) for the reasons outlined in that link, but I also understand other leaders may have different thoughts on the matter. If someone had "MSR" as a keyword and tried to respond with this tool, I wouldn't respond, honestly. All other times it would be fine, though.

 

But, yeah, I imagine the code could try to guess how best to respond. The code could look for the other keywords you suggest and then change it from a tell to a broadcast based on what it finds. You'd have to prioritize somehow for posts like "DFB - send me a tell or holler in broadcast" - perhaps the first option mentioned in the ad? You'd have a hiccup with some ads like "DFB looking for stellar people, BROADCAST ONLY!"

 

The sound could be changed to other audio files rather than a beep, and even customize that by keyword so a BAF plays "Tiny Bubbles" while an MoDD might play "Enter Sandman."

 

If there's interest, and perhaps something noticeably north of zero downloads, I could probably give some examples. Hopefully the young folk with all their computerizing skills will do it for me, though.

Link to comment
Share on other sites

1 hour ago, Oklahoman said:

If there's interest, and perhaps something noticeably north of zero downloads, I could probably give some examples. Hopefully the young folk with all their computerizing skills will do it for me, though.

I'd try it out myself, but I'm on a Mac, so I'd have to rewrite the whole thing in Automator or something anyway (I almost said "AppleScript"; that's how old I am).

Edited by Zhym
Link to comment
Share on other sites

21 hours ago, Zhym said:

I'd try it out myself, but I'm on a Mac, so I'd have to rewrite the whole thing in Automator or something anyway (I almost said "AppleScript"; that's how old I am).

 

I'm sure I have Hypercard on the G4 if you'd like me to order a Zip disk for you.

  • Haha 2

OG Server: Pinnacle  <||>  Current Primary Server: Torchbearer  ||  Also found on the others if desired


Installing CoX:  Windows  ||  MacOS  ||  MacOS for M1  <||>  Migrating Data from an Older Installation


Clubs: Mid's Hero Designer  ||  PC Builders  ||  HC Wiki  ||  Jerk Hackers


Old Forums  <||>  Titan Network  <||>  Heroica! (by @Shenanigunner)

 

Link to comment
Share on other sites

On 9/29/2022 at 5:25 PM, WanderingAries said:

 

I'm sure I have Hypercard on the G4 if you'd like me to order a Zip disk for you.

 

If we're getting a group together to buy Zip disks in bulk, count me in.

 

I had fun explaining to a group the other day that the predecessor to the internet was SneakerNet.

Link to comment
Share on other sites

5 hours ago, Oklahoman said:

 

If we're getting a group together to buy Zip disks in bulk, count me in.

 

I had fun explaining to a group the other day that the predecessor to the internet was SneakerNet.

 

Heh, sadly, I sold what I had ages ago. The USB 2.0 add-on card works for me IF I ever need to move data.

OG Server: Pinnacle  <||>  Current Primary Server: Torchbearer  ||  Also found on the others if desired


Installing CoX:  Windows  ||  MacOS  ||  MacOS for M1  <||>  Migrating Data from an Older Installation


Clubs: Mid's Hero Designer  ||  PC Builders  ||  HC Wiki  ||  Jerk Hackers


Old Forums  <||>  Titan Network  <||>  Heroica! (by @Shenanigunner)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...