<config>


//////////////
//
//  Wikipedia v0.2a by Pri (15th of May 2010)
//
//////////////
//
//  Commands Included that you can use:
//  !Wiki [Query] - Perform a query to locate information about something from Wikipedia.org
//  !PrivateWiki - Typing this will set Wikipedia to only give results privately to those who use the command
//  !PublicWiki - Typing this will set Wikipedia to give results to the entire room when someone uses the command
//  !SetWikiColour [Number] - Set the menu colours to something other than the default Green (#c4#) to better fit your room
//
//////////////


<usergroup name="Wiki_Admin_Users" case="0">
// This usergroup is only for your admins so that they can control some of the special commands.
// Everyone even if they are not in this usergroup will be able to type !Wiki [Query] and see the results
*  ®ÊN  Pri  *
</usergroup>

<command type="script">
<in>!wiki %PARAM%</in>
// Filter input so it cannot be activated mid-sentance
<out type="push" extdata="req">%TRIGGER%</out>
<out type="push" extdata="req"><operator type="strleft" lvalue="$req$" rvalue="6"/></out>
<out type="break" condition="!_?" lvalue="$req$" rvalue="!wiki "></out>
// Check that the scripts folder and settings file has been setup. If it hasn't do it.
<out type="push" extdata="Wiki_Setup_Check"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\.Wikipedia.ini" lvalue="l" rvalue="1"/></out>
<out condition="==" lvalue="$Wiki_Setup_Check$" rvalue="" type="exec" extdata="1">cmd.exe /c MD C:\Pri.Script.Dependencies\Wikipedia</out>
<out condition="==" lvalue="$Wiki_Setup_Check$" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Wikipedia.ini" mode="t">1</out>
// Download some special characters required for this to function (Metis by itself doesn't allow these characters inside the code so they have to be loaded as varibles)
<out type="push" extdata="Special_2" condition="==" lvalue="$Special_2$" rvalue=""><operator type="readweb" nvalue="http://wiki.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="2"/></out>
<out type="push" extdata="Special_1" condition="==" lvalue="$Special_1$" rvalue=""><operator type="readweb" nvalue="http://wiki.mxpulse.com/metis.assistant.txt" lvalue="l" rvalue="1"/></out>
// Load in the menucolour selected by the admins, if nothing found default is #c4#
<out type="push" extdata="Menu_Colour"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\.Menu.Colour.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Menu_Colour" condition="!?" lvalue="$Menu_Colour$" rvalue="#c"></out>
// Check if the script has been set to Public or Private Mode
<out type="push" extdata="Private_Public_Setting"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Server_Private_Command" condition="==" lvalue="$Private_Public_Setting$" rvalue="1"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini" lvalue="l" rvalue="2"/></out>
// If the user has selected to use private commands formulate how it should look for this query
<out type="push" extdata="Server_Private_Command"><operator type="strrep" nvalue="$Server_Private_Command$" lvalue=":@:RAWNAME:@:" rvalue="%RAWNAME%"/></out>
<out type="push" extdata="Server_Private_Command"><operator type="strrep" nvalue="$Server_Private_Command$" lvalue=":@:SPACE:@:" rvalue=" "/></out>
// Check if there is a Cache for this Wikipedia Entry already and if there is, out put it to the room/user
<out type="push" extdata="searchrequest">%PARAM%</out>
<out type="push" extdata="searchrequest"><operator type="strlwr" lvalue="%USERVAR[searchrequest]%"/></out>
<out type="push" extdata="Cache_Version"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="LOOKEDUPTODAYDATE"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="2"/></out>
// If this cache was made with an earlier version of this script then don't use the cache and use a new query instead
<out type="push" extdata="LOOKEDUPTODAYDATE" condition="!=" lvalue="$Cache_Version$" rvalue="v0.2a">00-00-00</out>
// If the cache is within 1 month old then display that to the room
<out type="push" extdata="LOOKEDUPTODAY1" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="3"/></out>
<out type="push" extdata="LOOKEDUPTODAY2" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="4"/></out>
<out type="push" extdata="LOOKEDUPTODAY3" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="5"/></out>
<out type="push" extdata="LOOKEDUPTODAY4" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="6"/></out>
<out type="push" extdata="LOOKEDUPTODAY5" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\%USERVAR[searchrequest]%.txt" lvalue="l" rvalue="7"/></out>
<out condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%">%USERVAR[Server_Private_Command]%%USERVAR[LOOKEDUPTODAY1]% #c63#(#c62#Cache#c63#)</out>
<out condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%">%USERVAR[Server_Private_Command]%%USERVAR[LOOKEDUPTODAY2]%</out>
<out condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%">%USERVAR[Server_Private_Command]%%USERVAR[LOOKEDUPTODAY3]%</out>
<out condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%">%USERVAR[Server_Private_Command]%%USERVAR[LOOKEDUPTODAY4]%</out>
<out condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%">%USERVAR[Server_Private_Command]%%USERVAR[LOOKEDUPTODAY5]%</out>
<out type="break" condition="==" lvalue="$LOOKEDUPTODAYDATE$" rvalue="%MONTH%"></out>
// Check for an updated version of this script
<out type="push" extdata="Version_Info">v0.2a</out>
<out type="pop" extdata="Version_Release_Message"/>
<out type="push" extdata="Version_Check_Date"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\.Version.Check.Date.txt" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Info" condition="!=" lvalue="%USERVAR[Version_Check_Date]%" rvalue="%DATE%"><operator type="readweb" nvalue="http://wiki.mxpulse.com/version.ini" lvalue="l" rvalue="1"/></out>
<out type="push" extdata="Version_Release_Message" condition="!=" lvalue="%USERVAR[Version_Info]%" rvalue="v0.2a"><operator type="readweb" nvalue="http://wiki.mxpulse.com/version.ini" lvalue="l" rvalue="2"/></out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c9#%USERVAR[Version_Release_Message]%</out>
<out condition="!=" lvalue="%USERVAR[Version_Release_Message]%" rvalue="" type="file" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Version.Check.Date.txt" mode="t">%DATE%</out>
// Push Paramater in to the Link
<out type="push" extdata="PARAMTHING">%PARAM%</out>
<out type="push" extdata="QUERY">http://en.wikipedia.org/w/api.php?action=opensearch%USERVAR[Special_1]%search=%USERVAR[PARAMTHING]%%USERVAR[Special_1]%format=xml</out>
// Query the Link, only line 1 is supposed to contain data but sometimes line 2 and maybe more can aswell, so take first 20 lines anyway
<out type="push" extdata="XMLDATA"><operator type="readweb" nvalue="$QUERY$" lvalue="c" rvalue="20"/></out>
// Swap tags inside the data with a Newline to Seperate data parts
<out type="push" extdata="XMLDATA"><operator type="strrep" nvalue="$XMLDATA$" lvalue=">" rvalue="\n"/></out>
<out type="push" extdata="XMLDATA"><operator type="strrep" nvalue="$XMLDATA$" lvalue="<" rvalue="\n"/></out>
// Swap around data in the XMLDATA for things like Quotes and stuff
<out type="push" extdata="XMLDATA"> <operator type="strrep" nvalue="$XMLDATA$" lvalue="â€™" rvalue="'"/> </out>
<out type="push" extdata="XMLDATA"> <operator type="strrep" nvalue="$XMLDATA$" lvalue="$Special_1$amp;" rvalue="$Special_1$"/> </out>
<out type="push" extdata="XMLDATA"> <operator type="strrep" nvalue="$XMLDATA$" lvalue="$Special_1$quot;" rvalue="$Special_2$"/> </out>
<out type="push" extdata="XMLDATA"> <operator type="strrep" nvalue="$XMLDATA$" lvalue="â€“" rvalue="--"/> </out>
<out type="push" extdata="XMLDATA"> <operator type="strrep" nvalue="$XMLDATA$" lvalue=" " rvalue=" "/> </out>
<out type="push" extdata="XMLDATA"><operator type="strrem" lvalue="$XMLDATA$" rvalue=", ; "/></out>
<out type="push" extdata="XMLDATA"><operator type="strrem" lvalue="$XMLDATA$" rvalue="Â"/></out>
// Write the XMLDATA to a file so we can read back individual pieces
<out type="file" mode="t" extdata="C:\Pri.Script.Dependencies\Wikipedia\Wiki.Cache.txt">$XMLDATA$\n</out>
// Read in the Page Name
<out type="push" extdata="Name"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\Wiki.Cache.txt" lvalue="l" rvalue="15"/></out>
// Read in the Content for the User
<out type="push" extdata="Content"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\Wiki.Cache.txt" lvalue="l" rvalue="19"/></out>
// Load a 2nd line of Content if the first one is inconclusive
<out type="push" extdata="Content" condition="?" lvalue="$Content$" rvalue="may refer to:"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\Wiki.Cache.txt" lvalue="l" rvalue="35"/></out>
// Read in the Page Address
<out type="push" extdata="PageAddress"><operator type="readfile" nvalue="C:\Pri.Script.Dependencies\Wikipedia\Wiki.Cache.txt" lvalue="l" rvalue="23"/></out>
// Output to the user if no DATA was found and Break thread
<out condition="==" lvalue="$Content$" rvalue="">%USERVAR[Server_Private_Command]%#c1# · #c9#No Page Exists for this at Wikipedia, Why not create one?</out>
<out type="break" condition="==" lvalue="$Content$" rvalue=""></out>
// Send the user the above data!
<out>%USERVAR[Server_Private_Command]%#c62# &lt;· #c4#%USERVAR[Menu_Colour]%%USERVAR[Name]% #c63#(#c62#Web#c63#)</out>
<out>%USERVAR[Server_Private_Command]%#c1# #c1# #c1# #c1# #c1# %USERVAR[PageAddress]% #c62#·&gt;</out>
<out>%USERVAR[Server_Private_Command]%#c1# #c62#</out>
<out>%USERVAR[Server_Private_Command]%#c62# &lt;· #c4#%USERVAR[Menu_Colour]%Summary</out>
<out>%USERVAR[Server_Private_Command]%#c1# #c1# #c1# #c1# #c1# %USERVAR[Content]% #c62#·&gt;</out>
// Create a local cache of this data so that it can later be read back. This cache can last a maximum of 1 month.
<out type="file" mode="t" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">v0.2a\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">%MONTH%\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">#c62# &lt;· #c4#%USERVAR[Menu_Colour]%%USERVAR[Name]%\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">#c1# #c1# #c1# #c1# #c1# %USERVAR[PageAddress]% #c62#·&gt;\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">#c1# #c62#\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">#c62# &lt;· #c4#%USERVAR[Menu_Colour]%Summary\n</out>
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\%PARAM%.txt">#c1# #c1# #c1# #c1# #c1# %USERVAR[Content]% #c62#·&gt;\n</out>
</command>

<command type="script" usergroup="Wiki_Admin_Users">
<in>!privatewiki</in>
<in>!publicwiki</in>
// Check if the command was typed at the start of a sentence, if not break
<out type="push" extdata="Wiki_CMD_REQ">%TRIGGER%</out>
<out type="push" extdata="Wiki_CMD_REQ"><operator type="strleft" lvalue="$Wiki_CMD_REQ$" rvalue="1"/></out>
<out type="break" condition="!_?" lvalue="$Wiki_CMD_REQ$" rvalue="!"></out>
// Process which command the user typed
<out type="file" mode="t" condition="_?" lvalue="%TRIGGER%" rvalue="!privatewiki" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini">1\n</out>
<out type="file" mode="t" condition="_?" lvalue="%TRIGGER%" rvalue="!publicwiki" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini">0</out>
// Output to the Admins if it was set to Public Mode
<out condition="_?" lvalue="%TRIGGER%" rvalue="!publicwiki">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c1#Wikipedia Has been set to Public Mode</out>
<out condition="_?" lvalue="%TRIGGER%" rvalue="!publicwiki">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c62#When this is set to Public, all Wikipedia results will be shown to the entire room</out>
// Break if the user selected to use Public
<out type="break" condition="_?" lvalue="%TRIGGER%" rvalue="!publicwiki"></out>
// If the user selected PrivateWiki, work out which server is in use
<out type="push" extdata="Server_Private_Command">0</out>
<out type="push" extdata="Server_Private_Command" condition="?" lvalue="%SERVER%" rvalue="WCS">/hidecmd /privnotice :@:RAWNAME:@::@:SPACE:@:</out>
<out type="push" extdata="Server_Private_Command" condition="?" lvalue="%SERVER%" rvalue="RCS">/hidecmd /privnotice :@:RAWNAME:@::@:SPACE:@:</out>
<out type="push" extdata="Server_Private_Command" condition="?" lvalue="%SERVER%" rvalue="FXServer">/message :@:RAWNAME:@::@:SPACE:@:</out>
<out type="push" extdata="Server_Private_Command" condition="?" lvalue="%SERVER%" rvalue="Ouka">#private :@:RAWNAME:@: #message:@:SPACE:@:</out>
// Because ZCS does not report itself as ZCS and instead as WinMX we are just going to assume that WinMX = ZCS
<out type="push" extdata="Server_Private_Command" condition="?" lvalue="%SERVER%" rvalue="WinMX">/privnotice :@:RAWNAME:@::@:SPACE:@:</out>
// Save the command for later use
<out type="file" mode="a" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini">%USERVAR[Server_Private_Command]%</out>
// Server not recognised Message
<out condition="==" lvalue="$Server_Private_Command$" rvalue="0">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c9#Wikipedia cannot be set to Private in your room as the Server #c63#(#c62#%SERVER%#c63#)#c9# is not supported by the script currently</out>
<out type="file" mode="t" condition="==" lvalue="$Server_Private_Command$" rvalue="0" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Public.Private.Server.Settings.ini">0</out>
<out type="break" condition="==" lvalue="$Server_Private_Command$" rvalue="0"></out>
// Output to the Admins if it was set to Private Mode
<out condition="_?" lvalue="%TRIGGER%" rvalue="!privatewiki">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c1#Wikipedia Has been set to Private Mode</out>
<out condition="_?" lvalue="%TRIGGER%" rvalue="!privatewiki">/opmsg #c4#%USERVAR[Menu_Colour]%Wikipedia #c63#(#c62#v0.2a#c63#): #c62#When this is set to Private, only those who use the !Wiki command will see results</out>
</command>

<command type="script" usergroup="Wiki_Admin_Users">
<in>!setwikicolour %PARAM%</in>
<in>!setwikicolor %PARAM%</in>
// Check if the command was typed at the start of a sentence, if not break
<out type="push" extdata="Wiki_CMD_REQ">%TRIGGER%</out>
<out type="push" extdata="Wiki_CMD_REQ"><operator type="strleft" lvalue="$Wiki_CMD_REQ$" rvalue="12"/></out>
<out type="break" condition="!_?" lvalue="$Wiki_CMD_REQ$" rvalue="!setwikicolo"></out>
// Encapsulate parameter with colour tags if none are present and save to file
<out type="file" mode="t" condition="?" lvalue="%PARAM%" rvalue="#c" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Menu.Colour.ini">%PARAM%\n</out>
<out type="file" mode="t" condition="!?" lvalue="%PARAM%" rvalue="#c" extdata="C:\Pri.Script.Dependencies\Wikipedia\.Menu.Colour.ini">#c%PARAM%#\n</out>
// Output to the Admins what colour it has been set to
<out condition="?" lvalue="%PARAM%" rvalue="#c">/opmsg #c4#%PARAM%Wikipedia #c63#(#c62#v0.2a#c63#): #c1#Wikipedia Has set its colours to#c63#: %PARAM% |||||</out>
<out condition="!?" lvalue="%PARAM%" rvalue="#c">/opmsg #c4##c%PARAM%#Wikipedia #c63#(#c62#v0.2a#c63#): #c1#Wikipedia Has set its colours to#c63#: #c%PARAM%# |||||</out>
</command>

</config>