Posted by
| Nick Gammon
Australia (23,100 posts) Bio
Forum Administrator |
Message
| As a demonstration of how you might use the new array features (discussed elsewhere) I have written a plugin that uses them.
This shows some of the new script calls. For example, in the "plugin install" section we load up an array ...
ArrayCreate "gags"
ArrayImport "gags", GetVariable ("gags"), "|"
Then when the number of gagged players changes we save it back to the variable ...
SetVariable "gags", ArrayExport ("gags", "|")
We can see if a player is in the gag array like this:
If Not ArrayKeyExists ("gags", who) Then
ColourNote "white", "red", who & " is not gagged."
...
We can add them with ArraySet. Note that the "key is the data" here, so the "value" is just the empty string ...
We can delete them with ArrayDeleteKey ...
ArrayDeleteKey "gags", who
We can get a list of the gagged players with ArrayExportKeys ...
ArrayExportKeys ("gags", ",")
The full plugin is below. Note that you need version 3.46 to use this, which is not released at the present moment.
<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, March 19, 2004, 12:02 PM -->
<!-- MuClient version 3.46 -->
<!-- Plugin "Gag" generated by Plugin Wizard -->
<muclient>
<plugin
name="Gag"
author="Nick Gammon"
id="36e75e5c438fcd6f6c9f994d"
language="VBscript"
purpose="Gags annoying players"
save_state="y"
date_written="2004-03-19 11:58:21"
requires="3.46"
version="1.0"
>
<description trim="y">
<![CDATA[
This plugin will automatically customise a trigger to gag players who are annoying you.
You need to specify the regular expression that matches the text to be gagged,
where "!!" represents the list of players whose names are to be gagged.
Usage
-----
gagsetmatch (regular expression)
eg. gagsetmatch (!!) (says|whispers|tells you).*$
gag (player) <-- gags a player
eg. gag turkey
ungag (player) <-- ungags a player
eg. ungag turkey
gagshow <-- shows list of gagged players
gaginfo <-- shows information about the gag plugin
gaghelp <-- show this information
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.vbs"/>
<!-- Triggers -->
<triggers>
<trigger
custom_colour="1"
enabled="n"
match="will be replaced when you gag someone"
name="gags"
omit_from_output="y"
regexp="y"
sequence="100"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
script="OnUnGag"
match="ungag *"
enabled="y"
echo_alias="y"
sequence="100"
>
</alias>
<alias
script="OnGag"
match="gag *"
enabled="y"
echo_alias="y"
sequence="100"
>
</alias>
<alias
script="OnShowGags"
match="gagshow"
enabled="y"
sequence="100"
>
</alias>
<alias
script="OnGagInfo"
match="gaginfo"
enabled="y"
sequence="100"
>
</alias>
<alias
script="OnGagSetMatch"
match="gagsetmatch *"
enabled="y"
sequence="100"
>
</alias>
</aliases>
<!-- Variables -->
<variables>
<variable name="regexp">(!!) (says|tells you).*$</variable>
</variables>
<!-- Script -->
<script>
<![CDATA[
Sub OnPluginInstall
ArrayCreate "gags"
ArrayImport "gags", GetVariable ("gags"), "|"
'
' Set up trigger after install
'
Call MakeTrigger
ColourNote "white", "maroon", "Gag plugin installed."
Call OnShowGags "","",""
End Sub
Sub OnGag (name, line, wildcards)
dim who
who = Trim (Lcase (wildcards (1)))
If ArrayKeyExists ("gags", who) Then
ColourNote "white", "red", who & " is already gagged."
Else
ArraySet "gags", who, "" ' add to array of gagged players
ColourNote "white", "blue", who & " added to list of gagged players."
Call MakeTrigger
End If
End Sub
Sub OnUnGag (name, line, wildcards)
dim who
who = Trim (Lcase (wildcards (1)))
If Not ArrayKeyExists ("gags", who) Then
ColourNote "white", "red", who & " is not gagged."
Else
ArrayDeleteKey "gags", who ' remove from array of gagged players
ColourNote "white", "blue", who & " removed from list of gagged players."
Call MakeTrigger
End If
End Sub
Sub MakeTrigger
'
' remember gag list in variable for plugin state save
'
SetVariable "gags", ArrayExport ("gags", "|")
'
' enable/disable trigger depending on whether we have gagged players
'
EnableTrigger "gags", ArraySize ("gags") <> 0
'
' change the trigger match text - replace !! by the gag list
'
If SetTriggerOption ("gags", "match", _
Replace (GetVariable ("regexp"), "!!", _
ArrayExportKeys ("gags", "|"))) = eBadRegularExpression Then
ColourNote "white", "red", _
"Could not set trigger - check regular expression syntax"
ColourNote "white", "red", "Regular expression is currently: " _
& GetVariable ("regexp")
End If
End Sub
Sub OnShowGags (name, line, wildcards)
dim gaglist
If ArraySize ("gags") = 0 Then
ColourNote "white", "blue", "No gagged players."
Else
gaglist = Replace (ArrayExportKeys ("gags", ","), ",", ", ")
ColourNote "white", "maroon", "You have gagged: " & gaglist
End If
End Sub
Sub OnGagSetMatch (name, line, wildcards)
SetVariable "regexp", wildcards (1)
Call MakeTrigger
End Sub
Sub OnGagInfo (name, line, wildcards)
ColourNote "white", "blue", "Number of gagged players = " & _
ArraySize ("gags")
ColourNote "white", "blue", "Gagging regular expression = " & _
GetVariable ("regexp")
ColourNote "white", "blue", "(""!!"" will be replaced by gagged player names)"
ColourNote "white", "blue", "Number of times gag trigger matched = " & _
GetTriggerInfo ("gags", 21)
End Sub
]]>
</script>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="gaghelp"
enabled="y"
>
</alias>
</aliases>
<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
world.Note world.GetPluginInfo (world.GetPluginID, 3)
End Sub
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|