Join live training with Christoph Glaser
on *:SOCKREAD:jokeapi: { var %data sockread %data while ($sockbr > 0) { if (%data != $null) && (Joke isin %data) { echo -a Joke: %data } sockread %data } sockclose jokeapi } Useful for persistent user data, points, or counters. Example 14: Simple Points System ; Give points: /givepoints Nick 5 ; Show points: /mypoints on *:TEXT:!points:#: { var %user = $nick if ($hget(points,%user) == $null) { hadd points %user 0 } msg $chan %user has $hget(points,%user) points. }
mIRC scripting uses a simple yet powerful language to automate tasks, customize the interface, and interact with channels/users. Scripts are typically written in the Remote ( Alt+R ) or Aliases section. 1. Basic Aliases (Custom Commands) Aliases are shortcuts for commands. Add these in the Aliases tab ( Alt+R → Aliases). Example 1: Simple Greeting ; Usage: /hello /hello { msg $active Hello, $me $+ ! Welcome to $chan } Example 2: Timed Echo with Parameter ; Usage: /remind 60 Take a break /remind { if ($1 isnum) { .timer 1 $1 msg $active Reminder: $2- msg $active Timer set for $1 seconds. } else { echo -a Usage: /remind <seconds> <message> } } Example 3: Random Number Generator ; Usage: /rand 1 100 /rand { var %min = $1, %max = $2 if (%min isnum) && (%max isnum) { var %result = $rand(%min,%max) msg $active Random number between %min and %max: %result } } 2. Remote Events (Listening to IRC) Remote scripts react to IRC events (text, joins, parts, etc.). Add these in the Remote tab ( Alt+R → Remote). Example 4: Auto-Welcome on Join on *:JOIN:#mychannel: { msg $chan Welcome $nick $+ ! Check out our rules at https://example.com/rules .timer 1 10 msg $chan $nick $+ , feel free to ask questions. } Example 5: Anti-Spam (Kick on repeated identical lines) on *:TEXT:*:#: { var %lasttext. [ $+ [ $nick ] ] = $1- if (%lasttext. [ $+ [ $nick ] ] == $1-) { inc %spamcount. [ $+ [ $nick ] ] if (%spamcount. [ $+ [ $nick ] ] >= 3) { kick $chan $nick Please do not repeat the same message. unset %spamcount. [ $+ [ $nick ] ] } } else { set %lasttext. [ $+ [ $nick ] ] $1- set %spamcount. [ $+ [ $nick ] ] 1 } } Example 6: URL Logger to a Text File on *:TEXT:*:#: { if ($regex($1-,/(https?:\/\/[^\s]+)/g)) { var %url = $regml(1) write urls.log [ $+ [ $timestamp ] ] $nick @ $chan : %url echo -a URL logged: %url } } 3. Popups (Right-Click Menus) Add custom items to nick/channel/query popups. Edit in Popups tab ( Alt+R → Popups). Example 7: Nicklist Popup — Whois + Note ; Place in "Nicklist" section Whois &Info: /whois $$1 Add &Note: /note $$1 $$?="Enter note" Example 8: Channel Popup — Quick Topic Change ; Place in "Channel" section Set &Topic: /topic $active $$?="New topic" 4. Timers and Dynamic Actions Timers can execute commands once or repeatedly. Example 9: Auto-Away after 10 minutes idle on *:INPUT:*: { .timeridle off .timeridle 1 600 away Auto-away after 10 min idle } on *:TEXT:*:*: { .timeridle off .timeridle 1 600 away Auto-away after 10 min idle } Example 10: Repeated Channel Greeting (every hour) ; Place in Remote, then run once: /startgreeting alias startgreeting { .timerhour 0 3600 msg #mychannel Don't forget to check our weekly event calendar! } 5. Dialog Examples (Custom Windows) mIRC supports custom modal dialogs with buttons, lists, and inputs. Example 11: Simple Message Box Dialog dialog msgbox { title "Message from Script" size -1 -1 200 100 option dbu text "Hello, this is a custom dialog", 1, 20 20 160 25 button "OK", 2, 75 60 50 20 ok } ; Show dialog with: /showmsg alias showmsg { dialog -m msgbox msgbox } Example 12: Input Dialog (Ask for text) dialog askname { title "Enter your name" size -1 -1 200 80 option dbu text "Name:", 1, 10 20 30 20 edit "", 2, 50 18 130 20 button "OK", 3, 75 50 50 20 ok } alias askname { dialog -m askname askname }
on *:DIALOG:askname:sclick:3: { var %name = $did(2) msg $active Hello %name $+ ! dialog -x askname askname } mIRC can fetch web data using sockets (basic HTTP GET). Example 13: Fetch a Random Joke from API alias getjoke { sockopen jokeapi jokeapi.dev 80 } on *:SOCKOPEN:jokeapi: { sockwrite -n jokeapi GET /api/v1/joke/Any?format=txt HTTP/1.1 sockwrite -n jokeapi Host: jokeapi.dev sockwrite -n jokeapi Connection: close sockwrite -n jokeapi $crlf $+ $crlf }
alias givepoints { if ($hget(points,$1) == $null) { hadd points $1 0 } hadd points $1 $calc($hget(points,$1) + $2) msg $active Gave $2 points to $1 $+ . }