Skip to content

Instantly share code, notes, and snippets.

@bradland
Created January 20, 2011 21:03
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 bradland/788667 to your computer and use it in GitHub Desktop.
Save bradland/788667 to your computer and use it in GitHub Desktop.
Colloquy script for welcoming 5by5 web IRC client users.
# modified from http://colloquy.info/extras/details.php?file=8
property prefs : missing value
property prefsPath : missing value
script prefsTemplate
property knownNames : {}
property allowedRooms : {}
end script
on loadPrefs()
if prefs is missing value then
set prefsPath to (path to preferences folder from user domain as Unicode text) & "Welcome WebIRC Script Preferences"
try
set prefs to load script alias prefsPath
on error
set prefs to prefsTemplate
end try
end if
end loadPrefs
on savePrefs()
if prefs is not missing value then store script prefs in file prefsPath replacing yes
end savePrefs
using terms from application "Colloquy"
on build contextual menu for item obj in view
if class of obj is member then return {"Welcome WebIRC User", "-"}
my loadPrefs()
set checkedBool to view's name is in prefs's allowedRooms
if class of obj is chat room panel then return {title:"Automatically Welcome WebIRC Users", checked:checkedBool}
end build contextual menu for item
on handle clicked contextual menu item title for obj within submenu
if title is "Welcome WebIRC User" then
tell obj's chat room panel to send message "Hello, " & obj's name & "! Welcome to the " & name of obj's chat room panel & " chat room. Type '/nick newnick' to change your nickname."
my loadPrefs()
if prefs's knownNames does not contain obj's name then
set prefs's knownNames to prefs's knownNames & {obj's name}
my savePrefs()
end if
else if title is "Automatically Welcome WebIRC Users" then
my loadPrefs()
if obj's name is in prefs's allowedRooms then
set allowedRooms to {}
repeat with i from 1 to number of items in prefs's allowedRooms
set room to item i of prefs's allowedRooms
if room is not obj's name then set allowedRooms to allowedRooms & {room}
end repeat
set prefs's allowedRooms to allowedRooms
tell obj to add event message "No longer welcoming new WebIRC users to the room." with name "welcomeScriptStatus"
my savePrefs()
else
set prefs's allowedRooms to prefs's allowedRooms & {obj's name}
tell obj to add event message "Welcoming new WebIRC users to the room." with name "welcomeScriptStatus"
my savePrefs()
end if
end if
end handle clicked contextual menu item
on member joined m in room
my loadPrefs()
if room's name is in prefs's allowedRooms and prefs's knownNames does not contain m's name and m's name contains "qwebirc" then
tell room to send message "Hello, " & m's name & "! Welcome to the " & room's name & " chat room. Type '/nick newnick' to change your nickname."
set prefs's knownNames to prefs's knownNames & {m's name}
my savePrefs()
end if
end member joined
on process user command c for view with args
if c is not "welcome" or view's class is not chat room panel then return false
if args is in {"auto", "on", "", missing value} then
my loadPrefs()
if view's name is not in prefs's allowedRooms then
set prefs's allowedRooms to prefs's allowedRooms & {view's name}
tell view to add event message "Welcoming new WebIRC users to the room." with name "welcomeScriptStatus"
my savePrefs()
end if
else if args is "off" then
my loadPrefs()
if view's name is in prefs's allowedRooms then
set allowedRooms to {}
repeat with i from 1 to number of items in prefs's allowedRooms
set room to item i of prefs's allowedRooms
if room is not view's name then set allowedRooms to allowedRooms & {room}
end repeat
set prefs's allowedRooms to allowedRooms
tell view to add event message "No longer welcoming new WebIRC users to the room." with name "welcomeScriptStatus"
my savePrefs()
end if
else if args is "reset" then
my loadPrefs()
set prefs to prefsTemplate
my savePrefs()
else if args is "names" then
my loadPrefs()
set AppleScript's text item delimiters to ", "
display dialog prefs's knownNames as string
end if
return true
end process user command
end using terms from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment