Skip to content

Commit

Permalink
SlapChop no longer talks to other bots infinitely, an issue noticed w…
Browse files Browse the repository at this point in the history
…hile adding Retests.
  • Loading branch information
= committed Apr 17, 2024
1 parent 5660717 commit f38100c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/run/message_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def clean_up_and_split_message_text(self, message_text):

return clean_split

def get_self_mention(self, ):
def get_self_mention(self):
return self.client.user.mention

async def process_guild_message_text_from_player(self, channel, message):
Expand Down Expand Up @@ -379,7 +379,7 @@ async def on_ready(self, ):
print(f'We have logged in as {self.client.user}')

async def on_message(self, message):
if message.author == self.client.user:
if message.author.bot:
return
await self.expire_challenges()
if message.channel.guild is not None:
Expand Down
2 changes: 2 additions & 0 deletions src/test/framework/spoofer_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, users, guild_channels, new_client):
class Client:
def __init__(self, user):
self.user = user
user.bot = True

class Message:
def __init__(self, author, channel, content, mentions):
Expand All @@ -36,6 +37,7 @@ def __init__(self, display_name):
self.display_name = display_name
self.mention = "<" + str(int(hash(display_name))) + ">"
player_mention_map[self.mention] = self
self.bot = False

async def send(self, message):
await self.channel.send(message)
Expand Down
17 changes: 14 additions & 3 deletions src/test/test_message_responder_statics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ async def set_up_spoof():
async def responder_test_basic_static():
beckett = spoof.users[0]
channel = spoof.guild_channels[0]
message = Message(beckett, channel, spoof.client.user.mention + " static", [spoof.client.user]) #We don't actually spoof mentions correctly... I'll update that later if needed.
message = Message(beckett, channel, spoof.client.user.mention + " static", [spoof.client.user])
await channel.spoof_send(message, responder)
expect(len(channel.message_history) >= 2, "A message back was not received.")
expect(channel.message_history[1].content.startswith(beckett.mention + ", you"), "Something other than a static occurred. Message: " + channel.message_history[1].content)

@test
async def responder_test_static_from_bot():
channel = spoof.guild_channels[0]
channel.message_history = []
beckett = spoof.users[0]
beckett.bot = True #oh no robo beckett
message = Message(beckett, channel, spoof.client.user.mention + " static", [spoof.client.user])
await channel.spoof_send(message, responder)
expect(len(channel.message_history) == 1, "Robots shouldn't get a response - even if they're Gangrel.")

@test
async def responder_test_statistical_bias():
wins = 0
losses = 0
ties = 0

tries = 0
beckett = spoof.users[0]
beckett.bot = False #he's cured :)
while tries < 1000:
tries += 1
beckett = spoof.users[0]
channel = spoof.guild_channels[0]
message = Message(beckett, channel, spoof.client.user.mention + " static", [spoof.client.user])
await channel.spoof_send(message, responder)
Expand All @@ -50,4 +60,5 @@ async def responder_test_statistical_bias():
async def run_tests():
await set_up_spoof()
await responder_test_basic_static()
await responder_test_static_from_bot()
await responder_test_statistical_bias()

0 comments on commit f38100c

Please sign in to comment.