Skip to content

Instantly share code, notes, and snippets.

@AndrioCelos
Last active February 28, 2021 00:28
Show Gist options
  • Save AndrioCelos/2fb23f270f50dd9dd0b9 to your computer and use it in GitHub Desktop.
Save AndrioCelos/2fb23f270f50dd9dd0b9 to your computer and use it in GitHub Desktop.
In IRC, there is a limit on how long a line can be. This limit is 512 bytes, including the command name and the CR+LF at the end, though some servers enforce it differently. This mIRC script will show you how much space you have left for your message, including channel topics. I have two versions: one that uses the toolbar for the display, the o…
; Length limit display script
; by Andrio Celos
; This script creates a floating window that shows how long your text line is, and the maximum length.
; It also works when you're entering a /topic command.
dialog length {
title " "
size 0 0 80 16
text "Length: ---/---", 1, 0 0 80 16
}
on *:START:showlength
alias showlength {
dialog -m length length
dialog -s length %length_x %length_y 80 16
set -e %wmaxlength ---
.timerLengthCheck -o 0 1 checklength
}
alias checklength {
if ($dialog(length)) {
var %maxlength = %wmaxlength
scid $activecid
var %length = $len($editbox($active)), %text = $editbox($active)
if (/topic* iswm %text) {
if ($gettok(%text, 3-, 32)) %length = $len($v1)
else %length = ---
%maxlength = %topiclen_ [ $+ [ $activecid ] ]
}
did -o length 1 1 Length: %length $+ / $+ %maxlength
set %length_x $dialog(length).x
set %length_y $dialog(length).y
}
else .timerLengthCheck off
}
on *:ACTIVE:*:{
if ($window($active).type == channel) set -e %wmaxlength $calc(498 - $len($address($me, 5)) - $len($chan))
else if ($window($active).type == query) set -e %wmaxlength $calc(498 - $len($address($me, 5)) - $len($active))
else set -e %wmaxlength ---
checklength
}
on *:APPACTIVE:{
if ($appactive) .timerLengthCheck -r
else .timerLengthCheck -p
}
raw 005:*:{
var %i = 2
while (%i < $0) {
if (TOPICLEN=* iswm $ [ $+ [ %i ] ]) set -e %topiclen_ [ $+ [ $cid ] ] $gettok($ [ $+ [ %i ] ], 2, 61)
if (NICKLEN=* iswm $ [ $+ [ %i ] ]) set -e %nicklen_ [ $+ [ $cid ] ] $gettok($ [ $+ [ %i ] ], 2, 61)
inc %i
}
}
; Length limit display script
; by Andrio Celos
; This script adds a display at the end of the toolbar, that shows how much space you have left for your text line.
; It also works when you're entering a /topic command.
; For the script to work, digits.png (such as the one provided with this Gist) must be in the mIRC data folder.
on *:START:{
toolbar -as lengthsep
toolbar -a length1 "Characters remaining" digits.png 160 0 16 16
toolbar -a length2 "Characters remaining" digits.png 160 0 16 16
toolbar -a length3 "Characters remaining" digits.png 160 0 16 16
set -e %wmaxlength ---
.timerLengthCheck -o 0 1 checklength
}
alias checklength {
var %maxlength = %wmaxlength
scid $activecid
var %length = $len($editbox($active)), %text = $editbox($active)
if (/topic* iswm %text) {
if ($gettok(%text, 3-, 32)) %length = $len($v1)
else %length = ---
%maxlength = %topiclen_ [ $+ [ $activecid ] ]
}
; Update the toolbar.
if (%length == ---) {
toolbar -p length1 digits.png 160 0 16 16
toolbar -p length2 digits.png 160 0 16 16
toolbar -p length3 digits.png 160 0 16 16
}
else {
if (%maxlength == ---) var %alength = %length
else var %alength = $abs($calc(%maxlength - %length))
toolbar -p length1 digits.png $calc(($int($calc(%alength / 100)) % 10) * 16) $iif((%maxlength == ---) || (%length <= %maxlength), 0, 16) 16 16
toolbar -p length2 digits.png $calc(($int($calc(%alength / 10)) % 10) * 16) $iif((%maxlength == ---) || (%length <= %maxlength), 0, 16) 16 16
toolbar -p length3 digits.png $calc((%alength % 10) * 16) $iif((%maxlength == ---) || (%length <= %maxlength), 0, 16) 16 16
}
}
on *:ACTIVE:*:{
if ($window($active).type == channel) set -e %wmaxlength $calc(498 - $len($address($me, 5)) - $len($chan))
else if ($window($active).type == query) set -e %wmaxlength $calc(498 - $len($address($me, 5)) - $len($active))
else set -e %wmaxlength ---
checklength
}
on *:APPACTIVE:{
if ($appactive) .timerLengthCheck -r
else .timerLengthCheck -p
}
raw 005:*:{
var %i = 2
while (%i < $0) {
if (TOPICLEN=* iswm $ [ $+ [ %i ] ]) set %topiclen_ [ $+ [ $cid ] ] $gettok($ [ $+ [ %i ] ], 2, 61)
if (NICKLEN=* iswm $ [ $+ [ %i ] ]) set %nicklen_ [ $+ [ $cid ] ] $gettok($ [ $+ [ %i ] ], 2, 61)
inc %i
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment