Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #78 from yannickgloster/small-features
Browse files Browse the repository at this point in the history
Added some small features
  • Loading branch information
lexesj authored Nov 1, 2020
2 parents 70dc3bd + dc5012b commit c64e39b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
2 changes: 2 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, config: dict, startup_extensions: List[str]):
self.bot_IP: str = config['bot_IP']
self.steam_web_api_key = config['steam_web_API_key']
self.servers: List[CSGOServer] = []
# Will need to change for when there is multiple server queue
self.users_not_ready: List[discord.Member] = []
for i, server in enumerate(config['servers']):
self.servers.append(
CSGOServer(i, server['server_address'], server['server_port'], server['server_password'],
Expand Down
74 changes: 48 additions & 26 deletions cogs/csgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def __init__(self, bot: Discord_10man, veto_image):
self.veto_image = veto_image
self.readied_up: bool = False

@commands.command(hidden=True)
async def test(self, ctx: commands.Context, *args):
print('test')

@commands.command(aliases=['10man', 'setup'],
help='This command takes the users in a voice channel and selects two random '
'captains. It then allows those captains to select the members of their '
Expand All @@ -45,30 +49,32 @@ def __init__(self, bot: Discord_10man, veto_image):
@commands.check(checks.ten_players)
@commands.check(checks.linked_accounts)
@commands.check(checks.available_server)
async def pug(self, ctx: commands.Context, arg0: str = None, arg1: str = None):
async def pug(self, ctx: commands.Context, *args):
random_teams: bool = False
map_arg: str = None
if arg0 is not None:
if arg0 == 'random':
team1_captain_arg: discord.Member = None
team2_captain_arg: discord.Member = None
for arg in args:
if arg == 'random':
random_teams = True
if arg1 is not None:
if arg1.startswith('de_'):
map_arg = arg1
if map_arg not in current_map_pool:
raise commands.CommandError(message=f'`{map_arg}` is not in Map Pool')
else:
raise commands.CommandError(message=f'Invalid Argument: `{arg1}`')
elif arg0.startswith('de_'):
map_arg = arg0
elif arg.startswith('de_'):
map_arg = arg
if map_arg not in current_map_pool:
raise commands.CommandError(message=f'`{map_arg}` is not in Map Pool')
if arg1 is not None:
if arg1 == 'random':
random_teams = True
else:
raise commands.CommandError(message=f'Invalid Argument: `{arg1}`')
else:
raise commands.CommandError(message=f'Invalid Argument: `{arg0}`')
member: discord.Member = await commands.MemberConverter().convert(ctx, arg)
if member in ctx.author.voice.channel.members:
if team1_captain_arg is None:
team1_captain_arg = member
elif team2_captain_arg is None and member is not team1_captain_arg:
team2_captain_arg = member
else:
if member is team1_captain_arg:
raise commands.CommandError(message=f'One user cannot be captain of 2 teams.')
else:
raise commands.CommandError(message=f'You can only set 2 captains.')
else:
raise commands.CommandError(message=f'Invalid Argument: `{arg}`')

# TODO: Refactor this mess
db = Database('sqlite:///main.sqlite')
Expand Down Expand Up @@ -102,10 +108,17 @@ async def pug(self, ctx: commands.Context, arg0: str = None, arg1: str = None):
emojis_selected = []
team1 = []
team2 = []
team1_captain = players[randint(0, len(players) - 1)]
if team1_captain_arg is not None:
team1_captain = team1_captain_arg
else:
team1_captain = players[randint(0, len(players) - 1)]
team1.append(team1_captain)
players.remove(team1_captain)
team2_captain = players[randint(0, len(players) - 1)]

if team2_captain_arg is not None:
team2_captain = team2_captain_arg
else:
team2_captain = players[randint(0, len(players) - 1)]
team2.append(team2_captain)
players.remove(team2_captain)

Expand Down Expand Up @@ -274,7 +287,8 @@ async def pug(self, ctx: commands.Context, arg0: str = None, arg1: str = None):
'players': team2_steamIDs
},
'cvars': {
'get5_event_api_url': f'http://{bot_ip}:{self.bot.web_server.port}/'
'get5_event_api_url': f'http://{bot_ip}:{self.bot.web_server.port}/',
'get5_print_damage': 1
}
}

Expand Down Expand Up @@ -344,6 +358,8 @@ async def get_chosen_map_embed(self, chosen_map, session=aiohttp.ClientSession()
session: :class:`aiohttp.ClientSession`
Current aiohttp client session
'''
if session.closed:
session = aiohttp.ClientSession()
veto_image_fp = 'result.png'
base_url = f'http://{self.bot.bot_IP}:{self.bot.web_server.port}'

Expand Down Expand Up @@ -488,6 +504,7 @@ async def queue_check(self):
ready_up_message = await self.bot.queue_ctx.send(embed=embed)
await ready_up_message.add_reaction('✅')
self.ready_up.start(message=ready_up_message, members=self.bot.queue_voice_channel.members)
self.bot.users_not_ready = self.bot.queue_voice_channel.members
self.queue_check.stop()

@tasks.loop(seconds=1.0, count=60)
Expand All @@ -501,12 +518,13 @@ async def ready_up(self, message: discord.Message, members: List[discord.Member]
check_emoji = reaction
break

users = await check_emoji.users().flatten()
user_reactions = await check_emoji.users().flatten()
ready = True
for member in members:
if member not in users:
if member not in user_reactions:
ready = False
break
else:
self.bot.users_not_ready.remove(member)

if ready:
self.readied_up = True
Expand All @@ -518,8 +536,12 @@ async def ready_up_cancel(self):
self.readied_up = False
await self.pug(self.bot.queue_ctx)
else:
# TODO: Kick people who haven't readied up
await self.bot.queue_ctx.send('Not everyone readied up')
not_ready_text: List[str] = []
for member in self.bot.users_not_ready:
not_ready_text.append(f'<@{member.id}>')
await member.move_to(None, reason='You did not ready up')
await self.bot.queue_ctx.send(f'{", ".join(map(str, not_ready_text))} did not ready up')
self.bot.users_not_ready = []
self.queue_check.start()

@commands.command(help='This command creates a URL that people can click to connect to the server.',
Expand Down
2 changes: 1 addition & 1 deletion cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def check_update(self):
await owner.send(embed=embed)
await session.close()

@commands.command(aliases=['version'], help='This command gets the bot information and version')
@commands.command(aliases=['version', 'v', 'a'], help='This command gets the bot information and version')
async def about(self, ctx: commands.Context):
embed = discord.Embed(color=0xff0000)
embed.add_field(name=f'Discord 10 Man Bot v{self.bot.version}',
Expand Down
2 changes: 1 addition & 1 deletion utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def _handler(self, request: web.Request) -> web.Response:
score_embed.set_footer(text="🟢 Live")
await server.score_message.edit(embed=score_embed)

elif get5_event['event'] == 'series_end' or get5_event['event'] == 'series_cancel':
elif get5_event['event'] == 'series_end' or get5_event['event'] == 'series_cancel' or get5_event['event'] == 'map_end':
if get5_event['event'] == 'series_end':
await server.score_message.edit(content='Game Over')
elif get5_event['event'] == 'series_cancel':
Expand Down

0 comments on commit c64e39b

Please sign in to comment.