Created
June 26, 2022 14:28
-
-
Save georgestephanis/65f20317df28212c7260ab6c59d5d881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="iso-8859-1" ?> | |
<!DOCTYPE muclient> | |
<muclient> | |
<plugin name="LotJ_Race_Exporter" author="@Daljo" id="d75f227c34fe0f9af2f20f66" language="Lua" purpose="Export race data." requires="4.73" version="0.1" save_state="y"> | |
<description trim="y"> | |
<![CDATA[ | |
-- Race Scraper / Exporter -- | |
]]> | |
</description> | |
</plugin> | |
<triggers> | |
<trigger | |
enabled="n" | |
script="scrapeRaceList" | |
name="scrapeRaceList" | |
lines_to_match="60" | |
keep_evaluating="y" | |
multi_line="y" | |
regexp="y" | |
match="Points\/Dep\. Races\n\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n(?P<races>(.+\n)+)\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n\(S\)yntax\: showrace \<race\>\n To see more details for a specific race\Z" | |
/> | |
<trigger | |
enabled="n" | |
script="scrapeRace" | |
name="scrapeRace" | |
lines_to_match="40" | |
keep_evaluating="y" | |
multi_line="y" | |
regexp="y" | |
match="\(R\)ace\: (?P<name>.+)\n Str Plus\:\s+(?P<str>-?\d+) Dex Plus\:\s+(?P<dex>-?\d+) Wis Plus\:\s+(?P<wis>-?\d+) Int Plus\:\s+(?P<int>-?\d+)\n Con Plus\:\s+(?P<con>-?\d+) Cha Plus\:\s+(?P<cha>-?\d+) Lck Plus\:\s+(?P<lck>-?\d+)\n Hit Pts\:\s+(?P<hp>\d+) AC Mod\:\s+(?P<ac>-?\d+) Frc Plus\:\s+(?P<frc>-?\d+)\n Price\:\s+(?P<price>\d+) Deposit\:\s+(?P<deposit>\d+) App Only\:\s+(?P<apponly>Yes|No)\n\(D\)efined short description\:\s+(?P<shortdesc>.+)\n\(P\)layers of this race can choose any ability as their main\.\n\(D\)efault Language\:\s+(?P<language>.+)\n\(P\)ossible Skincolors\: \n(?P<skincolors>(.+\n)+)\n\(R\)acial Traits\: \n(?P<traits>((.+) \- (.+)\n)*)\n\(L\)evel approximations for .+ by primary class\: \n main\\\/ lvls\-\> COM PIL ENG HUN SMU LEA ESP SLI MED SCI \ncombat (?P<lvl_com>(\d{3}\s){10})\npiloting (?P<lvl_pil>(\d{3}\s){10})\nengineering (?P<lvl_eng>(\d{3}\s){10})\nbounty hunting (?P<lvl_hun>(\d{3}\s){10})\nsmuggling (?P<lvl_smu>(\d{3}\s){10})\nleadership (?P<lvl_lea>(\d{3}\s){10})\nespionage (?P<lvl_esp>(\d{3}\s){10})\nslicer (?P<lvl_sli>(\d{3}\s){10})\nmedical (?P<lvl_med>(\d{3}\s){10})\nscience (?P<lvl_sci>(\d{3}\s){10})\Z" | |
/> | |
</triggers> | |
<aliases> | |
<alias match="scrapeRaces" ignore_case="y" enabled="y" script="scrapeRacesAlias" /> | |
<alias match="dumpRaces" ignore_case="y" enabled="y" script="dumpRaces" /> | |
</aliases> | |
<script> | |
<![CDATA[ | |
require "serialize" | |
json = dofile(GetPluginInfo(GetPluginID(), 20) .. "json.lua") | |
races = {} | |
toScan = {} | |
loadstring( GetVariable('races') or '' ) () | |
function scrapeRacesAlias() | |
EnableTrigger( 'scrapeRaceList', true ) | |
Send( 'showrace' ) | |
end -- dumpRaces | |
-- | |
-- Parse the races list | |
-- | |
function scrapeRaceList( name, output, wildcards ) | |
EnableTrigger( 'scrapeRaceList', false ) | |
local raceString = wildcards.races | |
raceString = raceString:gsub( "(%[.........%]:)", " " ) | |
raceString = raceString:gsub( "(%s%s+)", "|" ) | |
toScan = {} | |
for i in raceString:gmatch( "([^|]+)" ) do | |
table.insert( toScan, i ) | |
end | |
maybeScanRaces() | |
end -- scrapeRaceList | |
function maybeScanRaces() | |
Note( 'Found ' .. #toScan .. ' races left to scan!' ); | |
if ( #toScan > 0 ) then | |
EnableTrigger( 'scrapeRace', true ) | |
Send( 'showrace ' .. table.remove( toScan ) ) | |
else | |
EnableTrigger( 'scrapeRace', false ) | |
end | |
end -- maybeScanRaces | |
-- | |
-- Parse individual races | |
-- | |
function splitLevels( levelString ) | |
local levels = {} | |
for i in levelString:gmatch( "%d%d%d" ) do | |
table.insert( levels, tonumber( i ) ) | |
end | |
return { | |
com = levels[1], | |
pil = levels[2], | |
eng = levels[3], | |
hun = levels[4], | |
smu = levels[5], | |
lea = levels[6], | |
esp = levels[7], | |
sli = levels[8], | |
med = levels[9], | |
sci = levels[10] | |
} | |
end -- splitLevels | |
function splitSkinColors( colorsString ) | |
local colors = {} | |
colorsString = colorsString:gsub( "(%s%s+)", "|" ) | |
for i in colorsString:gmatch( "([^|]+)" ) do | |
table.insert( colors, i ) | |
end | |
return colors | |
end -- splitSkinColors | |
function splitTraits( traitsString ) | |
local traits = {} | |
for i in traitsString:gmatch( "([^\r\n]+)" ) do | |
table.insert( traits, i ) | |
end | |
return traits | |
end -- splitTraits | |
function scrapeRace( name, output, wildcards ) | |
local race = {} | |
race.name = wildcards.name | |
race.shortdesc = wildcards.shortdesc | |
race.language = wildcards.language | |
race.apponly = wildcards.apponly | |
race.price = tonumber( wildcards.price ) | |
race.deposit = tonumber( wildcards.deposit ) | |
-- These will need parsed out! | |
race.skincolors = splitSkinColors( wildcards.skincolors ) | |
race.traits = splitTraits( wildcards.traits ) | |
race.str = tonumber( wildcards.str ) | |
race.dex = tonumber( wildcards.dex ) | |
race.con = tonumber( wildcards.con ) | |
race.int = tonumber( wildcards.int ) | |
race.wis = tonumber( wildcards.wis ) | |
race.cha = tonumber( wildcards.cha ) | |
race.lck = tonumber( wildcards.lck ) | |
race.frc = tonumber( wildcards.frc ) | |
race.hp = tonumber( wildcards.hp ) | |
race.ac = tonumber( wildcards.ac ) | |
race.levels = {} | |
race.levels.com = splitLevels( wildcards.lvl_com ) | |
race.levels.pil = splitLevels( wildcards.lvl_pil ) | |
race.levels.eng = splitLevels( wildcards.lvl_eng ) | |
race.levels.hun = splitLevels( wildcards.lvl_hun ) | |
race.levels.smu = splitLevels( wildcards.lvl_smu ) | |
race.levels.lea = splitLevels( wildcards.lvl_lea ) | |
race.levels.esp = splitLevels( wildcards.lvl_esp ) | |
race.levels.sli = splitLevels( wildcards.lvl_sli ) | |
race.levels.med = splitLevels( wildcards.lvl_med ) | |
race.levels.sci = splitLevels( wildcards.lvl_sci ) | |
-- Store it in the big table! | |
races[ race.name ] = race | |
-- Acknowledge that we got it! | |
ColourNote( 'green', '', 'Scraped ' .. race.name ) | |
maybeScanRaces() | |
SaveState() | |
end -- setTarget | |
function OnPluginSaveState() | |
SetVariable( 'races', serialize.save( 'races' ) ) | |
end -- OnPluginSaveState | |
function dumpRaces() | |
SetClipboard( json.encode( races ) ) | |
ColourNote( 'white', '', 'The JSON for the races is now in your clipboard!' ) | |
end -- dumpRaces | |
]]> | |
</script> | |
</muclient> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment