Пример #1
0
def get_response(command, channel, userid, username):
    """
        Executes bot command if the command is known
    """

    # This is where you start to implement more commands!
    if command.startswith('home'):
        webbrowser.open('http://127.0.0.1:5000/', new=2)
    if command.startswith('open'):
        openString = command.split(' ')[1]

        favUrl = persist.getSavedRecipe(openString)
        if favUrl is None:
            url = openString[1:-1]
            if check_url.check_url(url):
                open_browser(url, channel, userid, username, None)
                return "Opening, {}!".format(url)

            return "I don't recognise {}".format(openString)
        else:
            open_browser(favUrl, channel, userid, username, openString)
            return "ok, opening {}".format(openString)
    if command.startswith('save'):
        parts = command.split(' ')
        print(parts)
        name = parts[1]
        url = parts[2][1:-1]
        if check_url.check_url(url):
            saved = persist.saveRecipe(name, url)
            if saved:
                return "Saving {} as `{}`!".format(url, name)
            else:
                return "I cannot save this since you already have a saved recipe named `{}`".format(
                    name)
        else:
            return "Cannot set invalid url"
    if command.startswith('get recent'):
        return recent.pretty_print()
    if command.startswith('get saved'):
        return persist.pretty_print()
    if command.startswith('clear recent'):
        recent.clear()
        return 'Done!'
    if command.startswith('add custom'):
        name = command[11:]
        canadd = custom.begin(name)
        if canadd:
            return 'ok...'
        else:
            return 'already exists'
    if command.startswith('add item '):
        item_to_add = command[9:]
        custom.add(item_to_add)
        return ''
    if command.startswith('custom done'):
        custom.done()
        return 'done'

    # Default response is help text for the user
    return "Not sure what you mean. Try *{}*.".format('hi bot')
	campaign=None
	for c in clist:
		#print "Checking campaign "+str(c.name)
		if c.name == args[0]:
			campaign = c
	if not campaign:
		return ["failure", 'Campaign '+str(args[0])+' does not exit'];
	else:
		queued_cmds.append((campaign,args[1],args[2:]))
		if VS.isserver():
			return handle_queued_cmds(-1)
		import Base
		if Base.GetNumRoom()>0:
			return handle_queued_cmds(default_room)

custom.add("campaign", handle_campaign_message)

def handle_campaign_readsave_message(local,cmd,args,id):
	clist = getCampaignList()
	for c in clist:
		c.setDocked(True)
		c.getCurrentNode(-1)
	return ["success"]
custom.add("campaign_readsave", handle_campaign_readsave_message)

def undock_campaigns():
	clist = getCampaignList()
	for c in clist:
		c.setDocked(False)

Пример #3
0
    items += ["endrow"]
    return items


def alert(message, callback=None, width=1.0, buttonText='OK'):
    def dbcallback(db, data):
        db.undraw()
        custom.respond(["close"], None, db.id)
        if callback:
            return callback()

    dialog(["width", width, "text", message] + button_row(width, buttonText),
           dbcallback)


def confirm(message, callback, width=1.0, buttons=('Cancel', 'OK')):
    def dbcallback(db, data):
        db.undraw()
        custom.respond(["close"], None, db.id)
        arg = False
        if data[0] != buttons[0] and data[0] != "Cancel":
            arg = data[0]
        if callback:
            return callback(arg)

    dialog(["width", width, "text", message] + button_row(width, *buttons),
           dbcallback)


custom.add("dialog_box", custom_run_dialog)
Пример #4
0
                "button",buttons[2]]
    else:
        for b in buttons:
            items += ["button",b]
    items += ["endrow"]
    return items

def alert(message, callback=None, width=1.0, buttonText='OK'):
    def dbcallback(db,data):
        db.undraw()
        custom.respond(["close"],None,db.id)
        if callback:
            return callback()

    dialog(["width",width, "text",message] + button_row(width, buttonText), dbcallback)

def confirm(message, callback, width=1.0, buttons=('Cancel','OK')):
    def dbcallback(db,data):
        db.undraw()
        custom.respond(["close"],None,db.id)
        arg = False
        if data[0]!=buttons[0] and data[0]!="Cancel":
            arg = data[0]
        if callback:
            return callback(arg)

    dialog(["width",width, "text",message] + button_row(width, *buttons), dbcallback)


custom.add("dialog_box",custom_run_dialog)
Пример #5
0
                      briefing_vars)
    elif args[0] == 'LoadLastMission':
        which = args[1]
        LoadLastMission(which)
    elif args[0] == 'CreateFixerMissions':
        ret = CreateFixerMissions()
        vals = [0]
        for m in ret:
            if isinstance(m, tuple):
                vals += m
                vals[0] += 1
        return vals


import custom
custom.add('mission_lib', mission_lib_custom)


class missionhook:
    def __init__(self, amentry):
        self.amentry_id = AddActiveMissionEntry(amentry)
        debug.debug("New Mission entry: %s (%s)" %
                    (self.amentry_id, amentry.get('MISSION_SHORTDESC', '')))

    def __del__(self):
        RemoveActiveMissionEntry(self.amentry_id)
        debug.debug("Mission entry %s destroyed." % self.amentry_id)


def SetMissionHookArgs(args):
    players[getMissionPlayer()].hookargs = args
Пример #6
0
def handle_guilds_message(local, cmd, args, id):
    un = VS.getPlayer()
    plr = un.isPlayerStarship()
    if VS.isserver():
        import server
        if not server.getDocked(un):
            return ["failure", 'Not currently docked']
    guildinfo = guilds.get(args[0], None)
    if not guildinfo:
        return ["failure", 'Guild ' + str(args[0]) + ' does not exit']
    else:
        return guildinfo.handle_server_cmd(args[1], args[2:])


custom.add("guilds", handle_guilds_message)


class Button:
    """A button that you can click on."""
    def __init__(self, spritefile, x, y, wid, hei, room, linkdesc, index,
                 pythonstr):
        """Initializes the button (but does not draw it; use drawobjs())"""
        self.sprite = spritefile
        self.x = x
        self.y = y
        self.wid = wid
        self.hei = hei
        self.room = room
        self.linkdesc = linkdesc
        self.index = index
Пример #7
0
	#		dialog_box.confirm("Test message 2 "+str(result),c)
	#	dialog_box.confirm("Test message",b,buttons=('A','B','C','D','E',"F",'G','H','I','J'))
	#dialog_box.alert("TEST\nALERT\nBox",callback=a)
	
	def callback(dialog,result):
		print 'id is: ',id
		action,inputs = dialog_box.fromValues(result)
		if action=='Test':
			print 'test clicked!!!!'
		if action=='Bounty Hunt':
			print 'hunting bounty'
			runBountyMenu(cp)
		if action=='OK' or action=="Exit Menu" or action=="Cancel":
			dialog.undraw()
			custom.respond(['close'],None,id)
			return False
		return True
	
	items=['width', 1.0,
		'text', 'Public Computer Menu',
		'space', 0., .1,
		'button', 'Test',
		'button', 'View Score',
		'button', 'Bounty Hunt',
		'button', 'Exit Menu']
	id = dialog_box.dialog(items,callback)
	print 'id is set to: ',id

custom.add("computer",runComputer)

Пример #8
0

def handle_guilds_message(local, cmd, args, id):
	un = VS.getPlayer()
	plr = un.isPlayerStarship()
	if VS.isserver():
		import server
		if not server.getDocked(un):
			return ["failure", 'Not currently docked']
	guildinfo = guilds.get(args[0],None)
	if not guildinfo:
		return ["failure", 'Guild '+str(args[0])+' does not exit'];
	else:
		return guildinfo.handle_server_cmd(args[1], args[2:])

custom.add("guilds", handle_guilds_message)

class Button:
	"""A button that you can click on."""
	def __init__(self,spritefile,x,y,wid,hei,room,linkdesc,index,pythonstr):
		"""Initializes the button (but does not draw it; use drawobjs())"""
		self.sprite=spritefile
		self.x=x
		self.y=y
		self.wid=wid
		self.hei=hei
		self.room=room
		self.linkdesc=linkdesc
		self.index=index
		self.pythonstr=pythonstr
		self.state=0
Пример #9
0
            briefing_vars[args[i*2+5]] = args[i*2+6]
        AddNewMission(which, None, None, brief0, brief1, briefing_vars, briefing_vars)
    elif args[0] == 'LoadLastMission':
        which = args[1]
        LoadLastMission(which)
    elif args[0] == 'CreateFixerMissions':
        ret = CreateFixerMissions()
        vals = [0]
        for m in ret:
            if isinstance(m,tuple):
                vals += m
                vals[0] += 1
        return vals

import custom
custom.add('mission_lib', mission_lib_custom)

class missionhook:
    def __init__(self,amentry):
        self.amentry_id = AddActiveMissionEntry(amentry)
        debug.debug("New Mission entry: %s (%s)" % (self.amentry_id,amentry.get('MISSION_SHORTDESC','')))
    def __del__(self):
        RemoveActiveMissionEntry(self.amentry_id)
        debug.debug("Mission entry %s destroyed." % self.amentry_id)

def SetMissionHookArgs(args):
    players[getMissionPlayer()].hookargs = args

def AddMissionHooks(director):
    hookargs = players[getMissionPlayer()].hookargs
    doMissionHooks=True
Пример #10
0
    #		def c(result):
    #			dialog_box.alert(result)
    #		dialog_box.confirm("Test message 2 "+str(result),c)
    #	dialog_box.confirm("Test message",b,buttons=('A','B','C','D','E',"F",'G','H','I','J'))
    #dialog_box.alert("TEST\nALERT\nBox",callback=a)

    def callback(dialog, result):
        print 'id is: ', id
        action, inputs = dialog_box.fromValues(result)
        if action == 'Test':
            print 'test clicked!!!!'
        if action == 'Bounty Hunt':
            print 'hunting bounty'
            runBountyMenu(cp)
        if action == 'OK' or action == "Exit Menu" or action == "Cancel":
            dialog.undraw()
            custom.respond(['close'], None, id)
            return False
        return True

    items = [
        'width', 1.0, 'text', 'Public Computer Menu', 'space', 0., .1,
        'button', 'Test', 'button', 'View Score', 'button', 'Bounty Hunt',
        'button', 'Exit Menu'
    ]
    id = dialog_box.dialog(items, callback)
    print 'id is set to: ', id


custom.add("computer", runComputer)