예제 #1
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner,
                      'This bot rolls a random number between 1 and 100')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    roll_command_id = bot.registerCommand('!roll',
                                          'Roll a number between 1 and 100')

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_COMMAND:
            if event.command.id == roll_command_id:
                random_number = random.randrange(1, 101)
                bot.sendArenaMessage(event.player.name + ' rolled ' +
                                     str(random_number) + ' (1-100)')

    print "Bot disconnected"
예제 #2
0
# username/password in our bot files
from Credentials import botowner, botname, botpassword

# import the SubspaceBot class. this is what has all the features we need
from SubspaceBot import *


if __name__ == '__main__':
	# initialize the bot, setting its owner and description, then connecting to the server
	bot = SubspaceBot(botowner, 'This bot rolls a random number between 1 and 100')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	# register two commands, !roll and !about
	roll_command_id = bot.registerCommand('!roll', 'Roll a number between 1 and 100')
	
	# keep looping as long as the bot is connected. at each loop, pull out the next
	# even that is waiting for us to process
	while bot.isConnected():
		event = bot.waitForEvent()
		
		# based on the event type, 
		if event.type == EVENT_COMMAND:
			# based on what type of command this is, handle it accordingly
			if event.command.id == roll_command_id:
				# this command is the !roll command
				random_number = random.randrange(1, 101)
				bot.sendArenaMessage(event.player.name + ' rolled ' + str(random_number) + ' (1-100)')
		
	print "Bot disconnected"
예제 #3
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner, 'This bot sets timers')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    timer_command_id = bot.registerCommand('!timer', 'Set a timer')

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_COMMAND:
            if event.command.id == timer_command_id:
                if len(event.arguments) == 1:
                    bot.setTimer(int(event.arguments[0]), event.player.name)
                    bot.sendPrivateMessage(event.player.name, "Ok")
                else:
                    bot.sendPrivateMessage(event.player.name,
                                           "Usage: !timer <seconds>")
        elif event.type == EVENT_TIMER:
            bot.sendPrivateMessage(event.user_data, "Timer expired")

    print "Bot disconnected"
예제 #4
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner, 'This bot gives you an arena list')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    arena_command_id = bot.registerCommand('!arena',
                                           'List the arenas in the zone')
    requester_names = []

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_COMMAND:
            if event.command.id == arena_command_id:
                requester_names.append(event.player.name)
                bot.sendPublicMessage("?arena")
        elif event.type == EVENT_ARENA_LIST:
            if len(requester_names) > 0:
                player_name = requester_names.pop(0)
                for arena_name, num_players in event.arena_list:
                    bot.sendPrivateMessage(
                        player_name,
                        'Arena: %s - %d' % (arena_name, num_players))
예제 #5
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot changes ship and freq')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	ship_command_id = bot.registerCommand('!ship', 'Change ship')
	freq_command_id = bot.registerCommand('!freq', 'Change ship')
	setposition_command_id = bot.registerCommand('!setposition', 'Change position')
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_COMMAND:
			if event.command.id == ship_command_id:
				if len(event.arguments) == 1:
					bot.requestShipChange(int(event.arguments[0]))
			elif event.command.id == freq_command_id:
				if len(event.arguments) == 1:
					bot.requestFreqChange(int(event.arguments[0]))
			elif event.command.id == setposition_command_id:
				if len(event.arguments) == 4:
					bot.setPosition(int(event.arguments[0]), int(event.arguments[1]), int(event.arguments[2]), int(event.arguments[3]))
		
	print "Bot disconnected"
예제 #6
0
class PlayerInfo:
	def __init__(self):
		self.start_ticks = None
		
if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot rolls a random number between 1 and 100')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	beginning_warpto = (512, 512)
	start = Rectangle(478, 510, 483, 514)
	finish = Rectangle(541, 510, 545, 514)
	
	roll_start_id = bot.registerCommand('!race', 'Start the race')
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_ENTER:
			# initialize player info
			event.player.player_info = PlayerInfo()
		elif event.type == EVENT_POSITION_UPDATE:
			if event.player.player_info.start_ticks is None and start.containsPlayer(event.player):
				# the players start ticks is empty and hes entered the start area
				# start the race off and set his tick stamp
				event.player.player_info.start_ticks = GetTickCountHs()
				bot.sendArenaMessage('%s has started the race!' % event.player.name)
			if event.player.player_info.start_ticks is not None and finish.containsPlayer(event.player):
				# the player has a start tick stamp, and hes entered the finish area
				race_time = TickDiff(GetTickCountHs(), event.player.player_info.start_ticks) / 100.0
예제 #7
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot gives you an arena list')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	arena_command_id = bot.registerCommand('!arena', 'List the arenas in the zone')
	requester_names = []
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_COMMAND:
			if event.command.id == arena_command_id:
				requester_names.append(event.player.name)
				bot.sendPublicMessage("?arena")
		elif event.type == EVENT_ARENA_LIST:
			if len(requester_names) > 0:
				player_name = requester_names.pop(0)
				for arena_name, num_players in event.arena_list:
					bot.sendPrivateMessage(player_name, 'Arena: %s - %d' % (arena_name, num_players))
		
	print "Bot disconnected"
예제 #8
0
파일: TimerBot.py 프로젝트: cycad/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot sets timers')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	timer_command_id = bot.registerCommand('!timer', 'Set a timer')
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_COMMAND:
			if event.command.id == timer_command_id:
				if len(event.arguments) == 1:
					bot.setTimer(int(event.arguments[0]), event.player.name)
					bot.sendPrivateMessage(event.player.name, "Ok")
				else:
					bot.sendPrivateMessage(event.player.name, "Usage: !timer <seconds>")
		elif event.type == EVENT_TIMER:
			bot.sendPrivateMessage(event.user_data, "Timer expired")
		
	print "Bot disconnected"
예제 #9
0
class PlayerInfo:
    def __init__(self):
        self.start_ticks = None


if __name__ == "__main__":
    bot = SubspaceBot(botowner, "This bot rolls a random number between 1 and 100")
    bot.connectToServer("66.235.184.102", 7900, botname, botpassword, "#python")

    print "Bot connected to server"

    beginning_warpto = (512, 512)
    start = Rectangle(478, 510, 483, 514)
    finish = Rectangle(541, 510, 545, 514)

    roll_start_id = bot.registerCommand("!race", "Start the race")

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_ENTER:
            # initialize player info
            event.player.player_info = PlayerInfo()
        elif event.type == EVENT_POSITION_UPDATE:
            if event.player.player_info.start_ticks is None and start.containsPlayer(event.player):
                # the players start ticks is empty and hes entered the start area
                # start the race off and set his tick stamp
                event.player.player_info.start_ticks = GetTickCountHs()
                bot.sendArenaMessage("%s has started the race!" % event.player.name)
            if event.player.player_info.start_ticks is not None and finish.containsPlayer(event.player):
                # the player has a start tick stamp, and hes entered the finish area
                race_time = TickDiff(GetTickCountHs(), event.player.player_info.start_ticks) / 100.0