Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to certain channel based on regular expression #62

Closed
danielo515 opened this issue Feb 18, 2015 · 9 comments
Closed

Move to certain channel based on regular expression #62

danielo515 opened this issue Feb 18, 2015 · 9 comments

Comments

@danielo515
Copy link

Your tool is awesome, but it could be even more awesome with this feature: define some regular expressions that will move the matching clips to certain channel. Let's say I want all my URLs in certain channel, or all the ticket numbers I ever copied on the tickets channel... then this will make channel and clips management automatic. Maybe it can be implemented as a plugin. If it is possible just point me in the good direction and I will try to do it myself.

Regards.

@aviaryan
Copy link
Owner

See the plugin linked here.
It shows how to copy to a different channel other than the current active one. You can use some regex there to auto-determine the destination channel.

But I like the idea and would like to add it as an inbuilt feature. Let's see. I am currently fixing some bugs.

@danielo515
Copy link
Author

Hello @aviaryan ,

I'm trying to write the plugin we were talking about and I'm using your copy2channel plugin as a guide. But there are some things I don't understand that maybe you can explain to me:

plugin_copy2channel(zChannel, zWhat){
    if !zWhat
        zSend := "^{vk43}"
    else zSend := "^{vk58}"

What are those values? seems like key definitions but I can't understand what are they used for

    zoc := CN.NG
    znc := channel_find(zChannel)

Correct me if I'm wrong but I thing those are original channel (zoc) and destination channel (znc)

    changeChannel(znc)
    ONCLIPBOARD := 3 ; any other positive number other than 1
    Send, % zSend

What is this used for? You move to the destination channel and then you set a variable (that I can't understand why) and you send that... keystrokes? Maybe you just copy the content of the clipboard to the selected channel?

    while ( ONCLIPBOARD != 1 )
        sleep 100

    sleep 500
    changeChannel(zoc)
}

Here you wait until ONCLIPBOARD changes, (again, I don't know why) and then you goes back again to the original channel.

Another question not related to your code is: How can I check what is currently on the clipboard in order to run a regular expression check against it? I think I can use getClipAt(0,1,1) but I'm not sure.

Thank you very much.

@danielo515
Copy link
Author

Based on the parameters I think "^{vk43}" means control+c and "^{vk58}" control+x

@danielo515
Copy link
Author

Here is a prototype, that, does not works and I don't know why:

;@Plugin-Name Move to Channel regexp
;@Plugin-Description Use this plugin to move the selected item to a particular channel based on a regular expression
;@Plugin-Author Danielo
;@Plugin-Tags channel move


plugin_move2channel_regex(){
    zSend := "^{vk58}"
    zoc := CN.NG
    clip := getClipAt(0,1,1)
    tooltip, Hello motherfucker
    regexs := Object()
    regexs["N#\d+"] := "tickets"
    for reg, channelName in regexs 
    {
        hasMatch := RegExMatch(clip,reg)
        if ( hasMatch > 0 ){
            destChannel := channel_find(channelName)
            changeChannel(destChannel)
            Send, % zSend
            break
            }
    }

    ONCLIPBOARD := 3 ; any other positive number other than 1

    while ( ONCLIPBOARD != 1 )
        sleep 100

    sleep 500
    changeChannel(zoc)

}

@aviaryan
Copy link
Owner

One problem I see is that ONCLIPBOARD := 3 should be before Send.
The reason is that sending ^x invokes the clipboard and the clipboard then changes the ONCLIPBOARD to 1. If ONCLIPBOARD is made 3 after Sending, then it may happen clipboard runs before ONCLIPBOARD := 3

So it will be better if you put this part inside the if condition

 ONCLIPBOARD := 3 ; any other positive number other than 1
 Send % zSend
    while ( ONCLIPBOARD != 1 )
        sleep 100

@danielo515
Copy link
Author

Hello @aviaryan

Sorry for posting here something that is some kind of support, but it is related with the issue subject.
I changed the code as you described and I added the API. prefix to one API call.

I more or less achieved what I want, but I find what I have done a bit clumsy.
What I do currently is

  • Copy whatever is selected to the clipboard
  • Get the first clip at current channel
  • Process that clip and I found a match move that clip to the matching channel
  • Show a message "Moved to" with API.showTip("Moved to ".channelName,"2000")

The problem with this is that using that approach the tooltip is barely seen. I think it is because it has some conflict with the defautl tooltip. Can you think in a better approach?

@aviaryan
Copy link
Owner

Default tooltip and API's showTip are different. Can you try

API.showTip("Moved to " . channelName, 2000)

Notice the space around "." (period) . Maybe "moved to".channelname is being evaluated as some class property.

@danielo515
Copy link
Author

Ok, the space trick did the job. Now I can see both popups but the second lasts enough to be seen.
Thank you.

@aviaryan
Copy link
Owner

Closing this issue because of #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants