Ejemplo n.º 1
0
    def test_trigger_disable(self):
        group = triggers.create_group('test', app='sage')

        make_triggers(group, 10, 'dis_')

        group.disable('dis_2')

        self.assertEqual(self._trigger_in_enabled('dis_2'), False)
Ejemplo n.º 2
0
    def test_create_group(self):

        group = triggers.create_group('test_create', app='sage')

        self.assertIn('test_create', triggers.groups)

        group.create_group('test_subgroup')

        self.assertIn('test_subgroup', group.groups)
Ejemplo n.º 3
0
    def test_destroy(self):
        group = triggers.create_group('test', app='sage')

        make_triggers(group, 1)

        trigger = group['test_0']

        trigger.destroy()

        self.assertNotIn(trigger, triggers.enabled)
Ejemplo n.º 4
0
    def test_remove(self):

        group = triggers.create_group('test', app='sage')

        make_triggers(group, 1)

        trigger = group['test_0']

        group.remove('test_0')

        self.assertNotIn('test_0', group.matchables)
        self.assertNotIn(trigger, triggers.enabled)
Ejemplo n.º 5
0
from sage import triggers

dg = triggers.create_group('dummy', app='dummyapp')


@dg.exact('test')
def decorator_trigger(trigger):
    pass


def api_trigger(trigger):
    pass

dg.create(
    name='api_trigger',
    pattern='test',
    mtype='exact',
    methods=[api_trigger]
)

sg = dg.create_group('subdummy')


@sg.substring('test')
def sg_trigger(trigger):
    pass
Ejemplo n.º 6
0
~~~~~~~~~~~~

This is a rudimentary health and mana sipper only intended to be an example.

"""
from __future__ import division
import sage
from sage import player, triggers
from sage.contrib import Balance
from sage.signals import post_prompt

# create a new balance called player.sip
player.sip = Balance()

# create an app-level trigger group
ss = triggers.create_group('simplesipper', app='simplesipper')


def sip(vial):
    """ Takes a sip of health or mana """

    # Don't try to sip if we are off sip balance
    if player.sip == False:
        return

    # turn on the sip group
    sip_group.enable()

    # set the balance to the wait-state
    player.sip.wait()
Ejemplo n.º 7
0
        db.commit()
        db.close()


smap = SkillMap()


def shutdown(**kwargs):
    smap.save()


skill_info.connect(smap.show_skill_info)
skills.connect(smap.skills_update)
pre_shutdown.connect(shutdown)

skill_triggers = triggers.create_group('skill', app='skills')
skill_aliases = aliases.create_group('skill', app='skills')
track_shortnames = False


@skill_aliases.exact(pattern="skillsup", intercept=True)
def updateskills(alias):
    gmcp.get_skills()


@skill_aliases.exact(pattern="skills load", intercept=True)
def loadstuff(alias):
    smap.load()


@skill_aliases.exact(pattern="skills save", intercept=True)
Ejemplo n.º 8
0
~~~~~~~~~~~~

This is a rudimentary health and mana sipper only intended to be an example.

"""
from __future__ import division
import sage
from sage import player, triggers
from sage.contrib import Balance
from sage.signals import post_prompt

# create a new balance called player.sip
player.sip = Balance()

# create an app-level trigger group
ss = triggers.create_group('simplesipper', app='simplesipper')


def sip(vial):
    """ Takes a sip of health or mana """

    # Don't try to sip if we are off sip balance
    if player.sip == False:
        return

    # turn on the sip group
    sip_group.enable()

    # set the balance to the wait-state
    player.sip.wait()
Ejemplo n.º 9
0


smap = SkillMap()

def shutdown(**kwargs):
    smap.save()



skill_info.connect(smap.show_skill_info)
skills.connect(smap.skills_update)
pre_shutdown.connect(shutdown)


skill_triggers = triggers.create_group('skill', app='skills')
skill_aliases  = aliases.create_group('skill', app='skills')
track_shortnames = False

@skill_aliases.exact(pattern="skillsup", intercept=True)
def updateskills(alias):
    gmcp.get_skills()

@skill_aliases.exact(pattern="skills load", intercept=True)
def loadstuff(alias):
    smap.load()


@skill_aliases.exact(pattern="skills save", intercept=True)
def savestuff(alias):
    smap.save()
Ejemplo n.º 10
0

    def add(self, line):
        db = mysql.connect(host=self.login[0], user=self.login[1],passwd=self.login[2],
                db='achaea',cursorclass=MySQLdb.cursors.DictCursor)
        cur=db.cursor()
        cur.execute('INSERT into achaea.filter'
                ' (rawtxt,count) '
                ' VALUES '
                ' (%s, %s) '
                ' ON DUPLICATE KEY UPDATE rawtxt=rawtxt, count=count+1'
                ';',(line, 1))
        cur.close()
        db.commit()
        db.close()



filter_triggers = triggers.create_group('filter', app='filter')

filt = FilterMap()

@filter_triggers.regex("^(.*)$",enabled=True)
def all_match(trigger):
    (rescount, gag) = filt.check(trigger.groups[0])
    if(rescount == 0):
        filt.add(trigger.groups[0])
    elif gag:
        trigger.line.gag()
 
Ejemplo n.º 11
0
"""
    http://spicerack.github.io/sage/html/quickstart.html
"""

from sage import triggers, aliases, ansi, send
from sage.signals.gmcp import room as room_signal

room_triggers = triggers.create_group('room', app='quickstart')

room_aliases = aliases.create_group('room', app='quickstart')


# interception to False means the original command passes through
@room_aliases.exact(pattern="ql", intercept=False)
def ql(alias):

    # enable the exits trigger
    room_triggers('exits').enable()

    # send to Achaea
    #send('ql')


@room_triggers.regex(
    "^You see (a single exit leading|exits leading) ([a-z, \(\)]+)\.$",
    enabled=False)
def exits(trigger):
    exit_str = trigger.groups[1]
    exit_str = exit_str.replace('and', '')
    exits = [ansi.bold_white(e.strip()) for e in exit_str.split(',')]
    new_str = ', '.join(exits)
Ejemplo n.º 12
0
    def setUp(self):
        self.group = triggers.create_group('test_get', app='sage')
        make_triggers(self.group)

        self.subgroup = self.group.create_group('subgroup')
        make_triggers(self.subgroup)
Ejemplo n.º 13
0
 def setUp(self):
     self.l1 = triggers.create_group('level_1', app='sage')
     self.l2 = self.l1.create_group('level_2', enabled=False)
     self.l3 = self.l2.create_group('level_3')
Ejemplo n.º 14
0
 def setUp(self):
     group = triggers.create_group('test_hooks', app='sage')
     make_triggers(group, 1)
Ejemplo n.º 15
0
    add_items(**kwargs)

    def ql_info(room, new):
        for line in sage.buffer:
            if line[:-1] == room.name:
                line.output += ansi.grey(' (%s) (%s)' % (room.area, room.id))
                if new:
                    line.output += ansi.grey(' [new]')



    sage.defer_to_prompt(ql_info, room, new)



room_triggers = triggers.create_group('room', app='mapper')
room_aliases  = aliases.create_group('room', app='mapper')
track_shortnames = False

@room_aliases.exact(pattern="imap shorton", intercept=True)
def short_on(alias):
    global track_shortnames
    track_shortnames = True

@room_aliases.exact(pattern="imap save", intercept=True)
def isave(alias):
    itemdata.write_to_db()
    mapdata.write_to_db()

@room_aliases.exact(pattern="imap load", intercept=True)
def iload(alias):
Ejemplo n.º 16
0
def action_loop():
    global do_loop
    if player.health.value == 0:
        sage.send('qq')
        return
    if do_loop:
        explr.on_begin()
        explr.scope_it_out()
        explr.room_actions()
        explr.quest_actions()
        explr.attacks()
        explr.other()
        #explr.on_end()
        sage.delay(0.1, action_loop)

xplr_triggers = triggers.create_group('xplr', app='explorer')
xplr_aliases  = aliases.create_group('xplr', app='explorer')
vial_triggers = triggers.create_group('vials', app='explorer')

@xplr_triggers.regex('^You determine that there is a ([a-z]+) lode of ([a-z ]+) here. Approximately ([0-9]+)% has been mined.$', enabled=True)
def xplr_lode_partial(trigger):
    #entry=(type, size, percent, location, area, owner)
    entry=[trigger.groups[1].lower(), trigger.groups[0].lower(), trigger.groups[2],
            player.room.id, player.room.area, time.time(), "NONE"]
    explr.all_mines.append(entry)
    print player.room.id 
    print trigger.line


@xplr_triggers.regex('^You determine that there is a ([a-z]+) lode of ([a-z ]+) here.$', enabled=True)
def xplr_lode(trigger):
Ejemplo n.º 17
0
                {int(v): k
                 for k, v in room.exits.items()}, room.coords, room.details,
                room.map, new)
    add_items(**kwargs)

    def ql_info(room, new):
        for line in sage.buffer:
            if line[:-1] == room.name:
                line.output += ansi.grey(' (%s) (%s)' % (room.area, room.id))
                if new:
                    line.output += ansi.grey(' [new]')

    sage.defer_to_prompt(ql_info, room, new)


room_triggers = triggers.create_group('room', app='mapper')
room_aliases = aliases.create_group('room', app='mapper')
track_shortnames = False


@room_aliases.exact(pattern="imap shorton", intercept=True)
def short_on(alias):
    global track_shortnames
    track_shortnames = True


@room_aliases.exact(pattern="imap save", intercept=True)
def isave(alias):
    itemdata.write_to_db()
    mapdata.write_to_db()
Ejemplo n.º 18
0
    def test_create(self):

        group = triggers.create_group('test_create', app='sage')
        make_triggers(group)

        self.assertEqual(100, len(group.matchables))
Ejemplo n.º 19
0
        if d_mana > 0:
            self.cur_mana_gain = self.cur_mana_gain + d_mana
                
        if d_mana < 0:
            self.cur_mana_loss = self.cur_mana_loss - d_mana

        self.last_health = cur_health.value
        self.last_mana = cur_mana.value
            
    def update_health_gain(self, trigger):
        self.ema_health_gain = self.ema_health_gain *.1 + self.cur_health_gain
        self.ema_health_loss = max(self.ema_health_loss *.1 + .9 * self.cur_health_loss,
                self.cur_health_loss)
        self.cur_health_gain = 0
        self.cur_health_loss = 0

        self.ema_mana_gain = self.ema_mana_gain *.5 + self.cur_mana_gain
        self.ema_mana_loss = self.ema_mana_loss *.5 + self.cur_mana_loss
        self.cur_mana_gain = 0
        self.cur_mana_loss = 0

tracker = HealthTracker()

health_trigs = triggers.create_group('health', app='explorer')                                       
health_trigs.enable()                                                                                
@health_trigs.exact("You may drink another health or mana elixir.")                         
def snap_health(trigger):
    tracker.update_health_gain(trigger)
vitals.connect(tracker.update_health_stats)

Ejemplo n.º 20
0
	else:
		osys.system_echo("Invalid sipping type! Health and mana are both valid.")

@sipper_aliases.regex("^hh$", enabled=True)
def toggleSipPriority(alias):
	if overwatch.priority == "health":
		overwatch.priority = "mana"
		osys.system_echo("Sipping priority changed to " + overwatch.priority)
	else:
		overwatch.priority = "health"
		osys.system_echo("Sipping priority changed to " + overwatch.priority)


""" Triggers """

ss = triggers.create_group('sipping', app='overwatch_sipper', enabled=True)

@ss.exact('You may drink another health or mana elixir or tonic.', enabled=True)
def sip_balance(trigger):
	player.sip.on()

@ss.exact('The elixir flows down your throat without effect.', enabled=True)
def off_sip_balance(trigger):
	if player.sip.balance is False:
		player.sip.off()

@ss.exact(name='sip_noneleft', pattern='What is it that you wish to drink?', enabled=True)
def no_SipLeft(trigger):
	if overwatch.currently_sipping is True:
		osys.system_echo('SIPPING: Run out of elixir to sip! Trying again in 4 seconds')
		sage.delay(4, lambda: doSip(overwatch.last_siptype))
Ejemplo n.º 21
0
            sage.echo(self.text)
            self.text = ""

        if self.echo_aff:
            sage.echo(ansi.bold_yellow(self.aff_str))
            self.echo_aff = False
        if len(self.cures) > 0:
            for cure in self.cures:
                sage.echo(cure[1])
            self.cures = []
        self.venoms = []


tracker = AffTracker()

combat_trigs = triggers.create_group('combat', app='combat')


@combat_trigs.regex(
    pattern="You remove 1 [a-z]+, bringing the total in the Rift to [0-9]+.",
    enabled=True)
def orift(trigger):
    trigger.line.gag()
    trigger.gag_prompt = True


@combat_trigs.exact(pattern="You are already wielding that.", enabled=True)
def prewield(trigger):
    trigger.line.gag()

Ejemplo n.º 22
0
            return
        sage.echo(re.sub('"','',re.sub('.*, "','',text)))
        sage.echo(talker)
        sage.echo(channel)
        response = response + ' ' + val['bot'].ask(text)

        last_response = max(time.time(), last_response)
        time_to_type = len(response)/5.0
        last_response = last_response + time_to_type
        sage.delay(last_response-time.time(), sage.send, response)

comms.connect(echo_comms)
comms.connect(chatstuff)
pull_comms()

comm_triggers = triggers.create_group('comm', app='communication')
comm_aliases  = aliases.create_group('comm', app='communication')

@comm_aliases.startswith (pattern="talkon", intercept=True)
def talkon(alias):
    global talkon
    talkon = True
    sage.echo("Enabling chatter")

@comm_aliases.startswith (pattern="talkoff", intercept=True)
def talkoff(alias):
    global talkon
    talkon = False
    sage.echo("Disabling chatter")

@comm_aliases.startswith (pattern="comm do ", intercept=True)
Ejemplo n.º 23
0
import time

from sage.signals.gmcp import room
from sage.signals import pre_shutdown
import meta
from maplib import Map
from sage import echo, ansi, send, aliases, triggers, player, delay, loopdelay
import sage

mapper_aliases = aliases.create_group('mapper', app='mapper')
mapper_triggers = triggers.create_group('mapper', app='mapper')
mapdata = Map(meta.path + '/mapdata.json.gz')

def room_info(**kwargs):
    new = False
    room = kwargs['room']
    room.name = room.name.replace("Flying above ","").replace("In the trees above ","")
    if room.id not in mapdata.rooms:
        new = True
    mapdata.add(
            room.id,
            room.name,
            room.area,
            room.environment,
            {int(v):k for k, v in room.exits.items()},
            room.coords,
            room.details,
            room.map,
            new
        )
Ejemplo n.º 24
0
        sage.echo(re.sub('"', '', re.sub('.*, "', '', text)))
        sage.echo(talker)
        sage.echo(channel)
        response = response + ' ' + val['bot'].ask(text)

        last_response = max(time.time(), last_response)
        time_to_type = len(response) / 5.0
        last_response = last_response + time_to_type
        sage.delay(last_response - time.time(), sage.send, response)


comms.connect(echo_comms)
comms.connect(chatstuff)
pull_comms()

comm_triggers = triggers.create_group('comm', app='communication')
comm_aliases = aliases.create_group('comm', app='communication')


@comm_aliases.startswith(pattern="talkon", intercept=True)
def talkon(alias):
    global talkon
    talkon = True
    sage.echo("Enabling chatter")


@comm_aliases.startswith(pattern="talkoff", intercept=True)
def talkoff(alias):
    global talkon
    talkon = False
    sage.echo("Disabling chatter")
Ejemplo n.º 25
0
            sage.echo(self.text)
            self.text = ""

        if self.echo_aff:
            sage.echo(ansi.bold_yellow(self.aff_str))
            self.echo_aff = False
        if len(self.cures) > 0:
            for cure in self.cures:
                sage.echo(cure[1])
            self.cures=[]
        self.venoms=[]


tracker=AffTracker()

combat_trigs = triggers.create_group('combat', app='combat')

@combat_trigs.regex(pattern="You remove 1 [a-z]+, bringing the total in the Rift to [0-9]+.", enabled=True)
def orift(trigger):
    trigger.line.gag()
    trigger.gag_prompt=True

@combat_trigs.exact(pattern="You are already wielding that.", enabled=True)
def prewield(trigger):
    trigger.line.gag()

@combat_trigs.exact(pattern="The attack rebounds back onto you!", enabled=True)
def hit_rebounding(trigger):
    tracker.hit_rebounding()
    trigger.line.gag()
Ejemplo n.º 26
0
from sage import triggers

dg = triggers.create_group('dummy', app='dummyapp')


@dg.exact('test')
def decorator_trigger(trigger):
    pass


def api_trigger(trigger):
    pass


dg.create(name='api_trigger',
          pattern='test',
          mtype='exact',
          methods=[api_trigger])

sg = dg.create_group('subdummy')


@sg.substring('test')
def sg_trigger(trigger):
    pass
Ejemplo n.º 27
0
    global do_loop
    if player.health.value == 0:
        sage.send('qq')
        return
    if do_loop:
        explr.on_begin()
        explr.scope_it_out()
        explr.room_actions()
        explr.quest_actions()
        explr.attacks()
        explr.other()
        #explr.on_end()
        sage.delay(0.1, action_loop)


xplr_triggers = triggers.create_group('xplr', app='explorer')
xplr_aliases = aliases.create_group('xplr', app='explorer')
vial_triggers = triggers.create_group('vials', app='explorer')


@xplr_triggers.regex(
    '^You determine that there is a ([a-z]+) lode of ([a-z ]+) here. Approximately ([0-9]+)% has been mined.$',
    enabled=True)
def xplr_lode_partial(trigger):
    #entry=(type, size, percent, location, area, owner)
    entry = [
        trigger.groups[1].lower(), trigger.groups[0].lower(),
        trigger.groups[2], player.room.id, player.room.area,
        time.time(), "NONE"
    ]
    explr.all_mines.append(entry)
Ejemplo n.º 28
0
"""
    http://spicerack.github.io/sage/html/quickstart.html
"""

from sage import triggers, aliases, ansi, send
from sage.signals.gmcp import room as room_signal

room_triggers = triggers.create_group('room', app='quickstart')

room_aliases = aliases.create_group('room', app='quickstart')


# interception to False means the original command passes through
@room_aliases.exact(pattern="ql", intercept=False)
def ql(alias):

    # enable the exits trigger
    room_triggers('exits').enable()

    # send to Achaea
    #send('ql')


@room_triggers.regex("^You see (a single exit leading|exits leading) ([a-z, \(\)]+)\.$", enabled=False)
def exits(trigger):
    exit_str = trigger.groups[1]
    exit_str = exit_str.replace('and', '')
    exits = [ansi.bold_white(e.strip()) for e in exit_str.split(',')]
    new_str = ', '.join(exits)
    trigger.line.output = "Exits: " + new_str