Skip to content

Instantly share code, notes, and snippets.

@KulaGGin
Created February 17, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KulaGGin/e8bd34f6065ef3f306c364b93fd74801 to your computer and use it in GitHub Desktop.
Save KulaGGin/e8bd34f6065ef3f306c364b93fd74801 to your computer and use it in GitHub Desktop.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
#MaxHotkeysPerInterval 200
SetBatchLines -1 ; decrease delay between lines
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive ahk_exe Discord.exe ; script works only in Discord
!sc01E::Wrap("**") ; Alt+A, bold
!sc01F::Wrap("*") ; Alt+S, italic
!sc020::Wrap("***") ; Alt+D, bold italic
!sc02D::Wrap("~~") ; Alt+X, strikeout
!sc02E::Wrap("__") ; Alt+C, underline
Alt & Q:: ; ALT + Q to quote selected text in input box
if !(GetKeyState("LCtrl", "p"))
{
Wrap("`n```````n")
}
Return
CTRL & Q:: ; quote selected text from chat
{
if !(GetKeyState("LAlt", "p")) ; Quote only selected text from chat
{
;Clear Clipboard
Clipboard=
;Copy selected text to clipboard
Send ^c
ClipWait
SelectedText := Clipboard
; Form changed text
ChangedText := "```````r`n" SelectedText "`r`n```````r`n"
Clipboard:=ChangedText
Send {Tab}^v
}
else ; Complex quote from chat with notifier
{
ComplexQuote()
}
}
Return
Wrap(tag) {
OldClipboard := Clipboard
Clipboard := ""
sleep, 100
send, ^c
sleep, 100
if (Clipboard = "") {
Clipboard := OldClipboard
return
}
Clipboard := tag . Clipboard . tag
send, ^v
Clipboard := OldClipboard
}
ComplexQuote() {
;Clear Clipboard
Clipboard=
;Copy selected text to clipboard
Send ^c
ClipWait
SelectedText := Clipboard
;Get nickname
RegExMatch(SelectedText, "^.*(?=\x20\x2d\x20.*\x0d)", Nickname)
;Form RegEx to get text after nickname
RegExTextAfterNickname := "(?<=^" Nickname ")" ".+?" "(?=\x0d)"
;Get text after nickname
RegExMatch(SelectedText, RegExTextAfterNickname, TextAfterNickname)
;Get text in first line
RegExMatch(SelectedText, "^.+?(?=\x0d)", FirstLine)
;Get everything else after first line
EverythingElse := RegExReplace(SelectedText, "^(.*)(\x0d)(\x0a)", "")
; Form changed text
ChangedText := "***" TextAfterNickname " Said:***" "`r`n" "``````" "`r`n" EverythingElse "`r`n" "``````" "`r`n"
;Send tab to switch to input box
Send {Tab}@
Sleep, 10
;Send nickname character after character to notify person
i:=1
NicknameLength := StrLen(Nickname)
while(i<=NicknameLength)
{
thisChar := SubStr(Nickname, i, 1)
Send {%thisChar%}
Sleep, 10
i++
}
;Send tab again to notify
Send {Tab}
;put changed text into clipboard
Clipboard := ChangedText
;Send CTRL+V to paste changed text
Send ^v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment