Source

AdaCode / elist2.xml

Full commit
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, December 03, 2012, 12:00 PM -->
<!-- MuClient version 4.77 -->

<!-- Plugin "Elist2" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Elist2"
   author="Ada"
   id="bfec5e22c152db0c56821f27"
   language="Python"
   purpose="Vial management"
   date_written="2013-01-04 12:00:00"
   requires="4.62"
   version="1.0"
   >
<description trim="y">
<![CDATA[
While ELIXLIST in Vision is of great utility in itself, a brief summary is often more useful than a raw list. This plugin rewrites the output from ELIXLIST and VENOMLIST and displays a short summary of vials in your inventory. Additionally it also automates the task of pouring old vials into new ones so you can safely feed empty vials to your favorite humgii with good conscience.

This plugin is written in Python, please see this page to setup Python on your computer: http://adayoung.bitbucket.org/pythonsqlite.html

The following aliases are available:

    Elist2 - Display a summary of all vials (except venoms) held in your inventory
    Vlist2 - Display a summary of all venoms held in your inventory
             (Do Elist2 first to let it collect empty vials if you intend to 'repour')

    Elist2:Repour - Pour contents of old and decaying vials into fresh empty vials
    Elist2:Reshift - Re-arrange vials in your inventory in order of decay time

The algorithm in the 'repour' alias makes sure that vials with the longest lifespan have the most amount of any fluid available in them. This ensures you don't lose much even if you do end up with vials decaying before you've had a chance to buy new ones.

The algorithm in the 'reshift' alias makes sure vials are arranged in the order of decay time in your inventory, if you 'repour'red your vials before hitting this alias, you'll have the added benefit of sipping from vials in a sensible order. Not to mention that'll also prevent you from sipping yucky salves due to stupidity since the first vial in your inventory is likely to be empty.
]]>
</description>

</plugin>

<!--  Get our standard constants -->

<include name="constants.pys"/>

<!--  Triggers  -->

<triggers>
  <trigger
   group="Elist2"
   enabled="n"
   keep_evaluating="y"
   match="^Vial\s+Fluid\s+Sips\s+Months Left$"
   name="EListPreamble"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="900"
  >
  <send>
vial_table = []
world.EnableTrigger("EListPreamble", False)
world.EnableTrigger("HorizontalLine", True)
world.EnableTrigger("VialInfo", True)
world.EnableTrigger("PromptCaptureElist2", True)
  </send>
  </trigger>
  <trigger
   group="Elist2"
   enabled="n"
   keep_evaluating="y"
   match="^Vial\s+Venom\s+Doses\s+Months Left$"
   name="VListPreamble"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="900"
  >
  <send>
world.EnableTrigger("VListPreamble", False)
world.EnableTrigger("HorizontalLine", True)
world.EnableTrigger("VialInfo", True)
world.EnableTrigger("PromptCaptureElist2", True)
  </send>
  </trigger>
  <trigger
   group="Elist2"
   enabled="n"
   keep_evaluating="y"
   match="^\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
   name="HorizontalLine"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="900"
  >
  <send>
world.EnableTrigger("HorizontalLine", False)
  </send>
  </trigger>
  <trigger
   group="Elist2"
   enabled="n"
   keep_evaluating="y"
   match="^Vial(\d+)\s+(.+?)\s+(\d+)\s+(\d+)$"
   name="VialInfo"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="900"
  >
  <send>
ProcessVial("%1", "%2", int("%3"), int("%4"))
  </send>
  </trigger>
  <trigger
   group="Elist2"
   enabled="n"
   keep_evaluating="y"
   match="^\d+h(, \d+m)?(, \d+e)?(, \d+w)? [@cexkdb]*(?: Vote)?-"
   name="PromptCaptureElist2"
   regexp="y"
   send_to="12"
   sequence="900"
  >
  <send>
world.EnableTrigger("VialInfo", False)
world.EnableTrigger("PromptCaptureElist2", False)
DisplayVials()
  </send>
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   match="^(E|V)list2$"
   enabled="y"
   group="Elist2"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>
world.EnableTrigger("%sListPreamble" % "%1".upper(), True)
world.SendNoEcho("%sLIST2" % "%1")
  </send>
  </alias>
  <alias
   match="^(E|V)list2:repour$"
   enabled="y"
   group="Elist2"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>
RePourVials()
  </send>
  </alias>
  <alias
   match="^(E|V)list2:reshift$"
   enabled="y"
   group="Elist2"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>
ReShiftVials()
  </send>
  </alias>
  <alias
   match="^(?:E|V)list2:test (.*?)$"
   enabled="y"
   group="Elist2"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>exec("%1")</send>
  </alias>
</aliases>

<!--  Script  -->

<script>
<![CDATA[
def Note(message): # not writing world.Note everywhere ^_^
    world.Note(message)

vial_table = []

def ProcessVial(vial_id, fluid, sips, lifespan):
    vial_table.append((vial_id, fluid, sips, lifespan))
    pass

def DisplayVials():
    vial_summary = {}
    for (vial_id, fluid, sips, lifespan) in vial_table:
        if not vial_summary.has_key(fluid):
            vial_summary[fluid] = {
                'total_sips' : 0,
                'lifespan_min' : 999,
                'lifespan_max' : 0,
                'total_vials' : 0,
            }
        vial_summary[fluid]['total_sips'] += sips
        if vial_summary[fluid]['lifespan_min'] > lifespan:
            vial_summary[fluid]['lifespan_min'] = lifespan
        if vial_summary[fluid]['lifespan_max'] < lifespan:
            vial_summary[fluid]['lifespan_max'] = lifespan
        vial_summary[fluid]['total_vials'] += 1
    fluids = vial_summary.keys()
    fluids.sort()
    Note("----------------------------------------------------------------------")
    Note("Fluid                            Life Span    # of vials    Total sips")
    Note("----------------------------------------------------------------------")
    for i in fluids:
        fluid = i
        lifespan = "%d-%d" % (vial_summary[i]['lifespan_min'], vial_summary[i]['lifespan_max'])
        total_vials = str(vial_summary[i]['total_vials'])
        total_sips = str(vial_summary[i]['total_sips'])

        if len(fluid) < 34:
            fluid += " "*(33 - len(fluid))
        else:
            fluid = fluid[:33] + " "

        if len(lifespan) < 15:
            lifespan += " "*(14 - len(lifespan))
        else:
            lifespan = lifespan[:14] + "   "

        if len(total_vials) < 12:
            total_vials += " "*(11 - len(total_vials))
        else:
            total_vials = total_vials[:11] + " "

        if len(total_sips) < 10:
            total_sips = " "*(9 - len(total_sips)) + total_sips
        else:
            total_sips = " " + total_sips[:9]

        Note("%s %s %s %s" % (fluid, lifespan, total_vials, total_sips))
    Note("----------------------------------------------------------------------")

def RePourVials():
    import sqlite3
    db = sqlite3.connect(':memory:')
    cursor = db.cursor()
    cursor.execute("DROP TABLE IF EXISTS vialdetails") # in case we make a real db to debug
    cursor.execute("""
        CREATE TABLE vialdetails (
            pk INTEGER PRIMARY KEY AUTOINCREMENT,
            id TEXT UNIQUE,
            fluid TEXT,
            sips INTEGER,
            lifespan INTEGER
        )""")
    cursor.executemany("""
        INSERT INTO vialdetails (id, fluid, sips, lifespan) VALUES (?, ?, ?, ?)
        """, vial_table)
    db.commit()

    cursor.execute("SELECT id, fluid, sips, lifespan FROM vialdetails where fluid IS NOT 'empty' ORDER BY lifespan ASC")
    vials = cursor.fetchall()

    for (vial, fluid, sips, lifespan) in vials:
        cursor.execute("SELECT id, fluid, sips FROM vialdetails WHERE (fluid=? or fluid='empty') AND lifespan>? ORDER BY lifespan ASC", (fluid, lifespan))
        o_vials = cursor.fetchall()
        while sips > 0 and len(o_vials) > 0:
            (o_vial, o_fluid, o_sips) = o_vials.pop()
            if o_sips < 200:
                world.Send("POUR %s INTO %s" % (vial, o_vial))

                if o_fluid == 'empty':
                    cursor.execute("UPDATE vialdetails SET fluid=?, sips=? WHERE id=?", (fluid, sips, o_vial))
                    db.commit()

                sips = o_sips + sips - 200

    db.close()

def ReShiftVials():
    Note("Elist2: Oops, this isn't implemented yet.")
]]>
</script>

<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="(E|V)list2:help"
   ignore_case="y"
   regexp="y"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
def OnHelp (a, b, c):
    world.note (world.GetPluginInfo (world.GetPluginID, 3))
]]>
</script>

</muclient>