Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit b3f4cfd

Browse files
committed
revamped !attack command
lots of cool stuff, adds unlimited attack pairs.
1 parent 1a95797 commit b3f4cfd

File tree

2 files changed

+79
-61
lines changed

2 files changed

+79
-61
lines changed

tapir bot.py

+33-24
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,40 @@ async def on_message(message): #when someone sends a message
2626
if len(message) >= 1: #must have atleast one character in the message
2727
message = message.split(' ') #message is made into a list split at every ' '
2828
if message[0].startswith('!'): #prefix is defined as '!'
29-
if message[0] in tapir.commands: #if not tapir checks if command in the the command dictionary
30-
await tapir.print_message(message[0], raw_message) #gets the console stuff
31-
await client.send_message(raw_message.channel, tapir.commands[message[0]]) #says the commands text
32-
elif message[0] == '!tapir' or message[0] == '!taper': #the tapir command!
33-
await tapir.print_message(message[0], raw_message) #gets the console stuff
34-
await tapir.tapir(raw_message, client) #gets the tapir image
35-
elif message[0] == '!attack' and raw_message.channel.id != '82210263440306176': #attack command! It doesn't go to /r/starcitizen's general channel
36-
try: #caususe index errors happen
37-
await tapir.attack(message[1], raw_message, client)
29+
try:
30+
if message[0] in tapir.commands: #if not tapir checks if command in the the command dictionary
3831
await tapir.print_message(message[0], raw_message) #gets the console stuff
39-
except IndexError: #if someone is dumb and forgets the character to play as
40-
await client.send_message(raw_message.channel, "Whoops, you forgot to specify a character!")
41-
await tapir.print_message("Attack_list_error", raw_message)
42-
elif message[0] == '!add_tapir' and raw_message.author.id == '149281074437029890': #add tapirs to the text if you are me :)
43-
new_tapir = raw_message.content.split(' ')[1]
44-
tapir.tapirs_text.write(new_tapir + "\n") #adds the link and a line ender thing (can't remember name)
45-
tapir.tapirs.append(new_tapir) #also puts the link in the list for immediate usage
46-
tapir.images = len(tapir.tapirs) #allows to use instantly
47-
await tapir.print_message(message[0], raw_message) #prints on console
48-
await client.send_message(raw_message.channel, "Got it! :thumbsup:") #confirms the tapir
49-
elif message[0] == '!reply' and raw_message.author.id == '149281074437029890': #can communicate through tapir-bot
50-
await tapir.send_message(raw_message, client)
51-
elif message[0] == '!close' and raw_message.author.id == '149281074437029890': #if you're me you can close tapir-bot
52-
tapir.tapirs_text.close() #closes the tapir.txt
53-
await client.logout() #logs tapir-bot out
32+
await client.send_message(raw_message.channel, tapir.commands[message[0]]) #says the commands text
33+
elif message[0] == '!tapir' or message[0] == '!taper': #the tapir command!
34+
await tapir.print_message(message[0], raw_message) #gets the console stuff
35+
await tapir.tapir(raw_message, client) #gets the tapir image
36+
elif message[0] == '!add_tapir' and raw_message.author.id == '149281074437029890': #add tapirs to the text if you are me :)
37+
new_tapir = raw_message.content.split(' ')[1]
38+
tapir.tapirs_text.write(new_tapir + "\n") #adds the link and a line ender thing (can't remember name)
39+
tapir.tapirs.append(new_tapir) #also puts the link in the list for immediate usage
40+
tapir.images = len(tapir.tapirs) #allows to use instantly
41+
await tapir.print_message(message[0], raw_message) #prints on console
42+
await client.send_message(raw_message.channel, "Got it! :thumbsup:") #confirms the tapir
43+
elif message[0] == '!reply' and raw_message.author.id == '149281074437029890': #can communicate through tapir-bot
44+
await tapir.send_message(raw_message, client)
45+
elif message[0] == '!close' and raw_message.author.id == '149281074437029890': #if you're me you can close tapir-bot
46+
tapir.tapirs_text.close() #closes the tapir.txt
47+
await client.logout() #logs tapir-bot out
48+
elif message[0] == '!attack' and message[1] == 'define' and raw_message.channel.id != '82210263440306176': #to define a attacking pair
49+
await tapir.print_message(message[1], raw_message) #prints to the console
50+
await tapir.define(message[2:5:2], raw_message, client) #calls the define function
51+
elif message[0] == '!attack' and message[1] == 'reset' and raw_message.channel.id != '82210263440306176': #the reset function of attack
52+
await tapir.print_message(message[1], raw_message)
53+
await tapir.reset(raw_message, client)
54+
elif message[0] == '!attack' and raw_message.channel.id != '82210263440306176': #attack command! It doesn't go to /r/starcitizen's general channel
55+
try: #caususe index errors happen
56+
await tapir.attack(message[1:4:2], raw_message, client) #does the attacking
57+
await tapir.print_message(message[0], raw_message) #gets the console stuff
58+
except IndexError: #if someone is dumb and forgets the character to play as
59+
await client.send_message(raw_message.channel, "Whoops, you forgot did something wrong!")
60+
await tapir.print_message("Attack_list_error", raw_message)
61+
except:
62+
pass
5463
elif raw_message.channel.is_private and not raw_message.author.id == '173648334479687681': #if it has no command but is PMed to tapir-bot it will tell me
5564
print(raw_message.author.name + ' private message')
5665
await tapir.private_message_recieved(raw_message, client)

tapir_module.py

+46-37
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ def __init__(self):
1313

1414
self.images = len(self.tapirs) #sets the length to the length of the list
1515

16-
self.current_game = "say \"!?\" for help" #the current game messsage
16+
self.current_game = "say \"!?\" for help" #the current game message
1717

18-
self.georgie = 100 #health of georgie
19-
self.pennywise = 100 #health of pennywise
18+
self.pairs = [
19+
['georgie', 'pennywise']
20+
]
21+
22+
self.pair_health = [
23+
[100, 100]
24+
]
2025

2126
self.commands = { #command dictioinary
2227
'!?' : 'Hello! I am a bot made by <@149281074437029890> . \n say `!tapir` to get a random tapir image! \n say `!carrack` for a Carrack picture. \n say `!azwe` for @Azwethinkweiz\'s beautiful mocap animation. \n say `!ben` to get Ben\'s beautiful dancing. \n say `!2.4` to get an update on the new 2.4 update. \n say `!scam` to know the truth of Star Citizen. \n say `!attack <pennywise or georgie>` to play the attacking minigame. say `!attack help` for more information. \n say `!source` for my Github!',
@@ -46,14 +51,14 @@ async def print_message(self, message, raw_message): #prints the name of author
4651

4752
async def private_message_recieved(self, raw_message, client): #when tapir-bot recieves a private message
4853
"""sends me a private message of the channel ID and the author name and content"""
49-
await client.send_message(client.get_channel('173957638302728192'), raw_message.channel.id + ' : ' + raw_message.author.name + '\n' + raw_message.content)
54+
await client.send_message(client.get_channel('173957638302728192'), '{} : {} \n {}'.format(raw_message.channel.id, raw_message.author.name, raw_message.content))
5055

5156
async def send_message(self, raw_message, client):
5257
"""I send a message, through tapir-bot"""
5358
message = raw_message.content.split(' ') #makes the message a list of the words
5459
receiver = message[1] #the channel is the ID I send
5560
receiver = client.get_channel(receiver) #it makes that into a channel class
56-
del message[0:2] #in messsage it deletes thee first two indexes
61+
del message[0:2] #in message it deletes thee first two indexes
5762
message = ' '.join(message) #joins the list back together with a space inbeetween the indexes
5863
print(str(receiver) + ' : ' + message) #on consol it prints the channel and the message
5964
await client.send_message(receiver, message) #send the message
@@ -63,36 +68,40 @@ async def tapir(self, message, client): #when someone calls the !tapir command
6368
"""the tapir command function"""
6469
taper = self.tapirs[random.randrange(self.images)] #generates the tapir
6570
await client.send_message(message.channel, taper) #sends the tapir
71+
72+
async def define(self, pair, raw_message, client):
73+
"""will define a new pair for attack"""
74+
if pair not in self.pairs and pair[::-1] not in self.pairs: #if it's not defined
75+
self.pairs.append(pair) #puts the pair in
76+
self.pair_health.append([100, 100]) #appends the health to the health list
77+
await client.send_message(raw_message.channel, '{} vs. {} is ready!'.format(pair[0], pair[1])) #confirms they are added
78+
else: #if it's already defined
79+
await client.send_message(raw_message.channel, '{} vs. {} is already defined.'.format(pair[0], pair[1])) #says they are already defined
6680

67-
async def attack(self, character, message, client):
68-
"""does the pennywise vs. georgie attack minigame, for now at least"""
69-
if character == "pennywise": #if you play ass pennywise
70-
if self.pennywise > 0: #and he isn't dead
71-
damage = random.randrange(10, 21) #you get a damage value
72-
self.georgie -= damage #and damage the other charcter with it
73-
if self.georgie <= 0: #if georgie gets dead
74-
await client.send_message(message.channel, "Georgie is dead!") #he is rekt
75-
else: #if georgie is still alive after being beat down
76-
await client.send_message(message.channel, "Pennywise did {} points of damage to Georgie, he only has {} left!".format(damage, self.georgie)) #you get told
77-
else: #if pennywise was dead
78-
await client.send_message(message.channel, "Pennywise is dead dummy!") #your dumb, reset
79-
elif character == "georgie": #if you want to play as georgie
80-
if self.georgie > 0: #and he's not dead
81-
damage = random.randrange(10, 21) #he gets a damage value
82-
self.pennywise -= damage #applies it to pennywise
83-
if self.pennywise <= 0: #if he gets rekt
84-
await client.send_message(message.channel, "Pennywise is dead!") #then he is dead, and you are told
85-
else: #if he is still alive
86-
await client.send_message(message.channel, "Georgie did {} points of damage to Pennywise, he only has {} left!".format(damage, self.pennywise)) #you are told his health
87-
else: #if georgie is dead
88-
await client.send_message(message.channel, "Georgie is dead dummy!") #ur dumb reset
89-
elif character == "reset": #resets the game
90-
self.georgie = 100 #health back to 100
91-
self.pennywise = 100
92-
await client.send_message(message.channel, "Healths have been reset") #notified that it is reset
93-
elif character == "health": #if you want to know the health of the characters
94-
await client.send_message(message.channel, "Pennywise has: {} \n Georgie has {}".format(self.pennywise, self.georgie)) #it tells you the health!
95-
elif character == "help":
96-
await client.send_message(message.channel, "This is the Pennywise vs. Georgie game. It can be used to settle conflicts if needed. \n say `!attack pennywise` to play as pennywise, and say `!attack georgie` to play as georgie. \n say `!attack health` to get an update on the character's health. \n say `attack reset` to reset everything")
97-
else:
98-
await client.send_message(message.channel, "That isn't a recognized attacking character, say `!attack help` for help")
81+
async def reset(self, raw_message, client):
82+
"""resets all of the healths to 100"""
83+
for pair in range(len(self.pair_health)): #for the pair in the health list
84+
for character in range(len(self.pair_health[pair])): #for every character in the pair
85+
self.pair_health[pair][character] = 100 #their health is 100
86+
await client.send_message(raw_message.channel, 'All healths reset!')
87+
88+
async def attack(self, pair, raw_message, client):
89+
"""attack command, with unlimited pairs"""
90+
if pair in self.pairs or pair[::-1] in self.pairs: #if they are in the list
91+
attacker = pair[0] #makes sure to define which is the attacker
92+
defender = pair[1] #and the defender
93+
if pair not in self.pairs: #if the base isn't in, it reverse the two
94+
pair = pair[::-1]
95+
pair_index = self.pairs.index(pair) #finds the index of the pair in the pairs list
96+
attacker_index = self.pairs[pair_index].index(attacker) #finds the index of the attacker
97+
defender_index = self.pairs[pair_index].index(defender) #and the defender
98+
if self.pair_health[pair_index][attacker_index] > 0: #if the attacker is still alive
99+
damage = random.randrange(10, 21) #he damages the defender
100+
self.pair_health[pair_index][defender_index] -= damage #applies the damage
101+
if self.pair_health[pair_index][defender_index] > 0: #if the defender is still alive
102+
await client.send_message(raw_message.channel, '{} did {} damage to {}, who has {} health left'.format(attacker, damage, defender, self.pair_health[pair_index][defender_index])) #says how much health is left of defender and such
103+
else: #if the defender has 0 or less health after being damaged
104+
await client.send_message(raw_message.channel, '{} is dead!'.format(defender)) #if the defender dies it says so
105+
else: #if the attacker is dead
106+
await client.send_message(raw_message.channel, '{} is dead, they can\'t attack!'.format(attacker)) #says so
107+

0 commit comments

Comments
 (0)