Skip to content

Commit

Permalink
Merge pull request #164 from Tortoise-Community/dev
Browse files Browse the repository at this point in the history
Merge dev stable release
  • Loading branch information
Ryuga authored Oct 22, 2021
2 parents 7524c7a + 584719a commit f56d8e3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
28 changes: 10 additions & 18 deletions bot/cogs/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async def remove(self, player):
await player.message.clear_reactions()
player.game.participants.pop(player.user_id)
self.reactable_messages.pop(player.message.id)
await self.check_active_session(player)
del player

async def hit(self, player):
Expand All @@ -76,18 +75,15 @@ async def hit(self, player):
await self.check_active_session(player.game)

async def check_active_session(self, player):
active_game_session = False
participants = player.game.participants
for person in participants:
if participants[person].stay is False:
active_game_session = True
if not active_game_session:
await self.dealers_play(player.game)
else:
me = self.bot.get_user(player.user_id)
embed = black_jack_embed(me, player)
embed.description = "**Status: **Waiting for other players..."
await player.message.edit(embed=embed)
if participants[person].stay:
me = self.bot.get_user(player.user_id)
embed = black_jack_embed(me, player)
embed.description = "**Status: **Waiting for other players..."
await player.message.edit(embed=embed)
return
await self.dealers_play(player.game)

async def stay(self, player):
player.stay = True
Expand All @@ -109,8 +105,8 @@ async def init_blackjack(self, ctx, bet_amount):
self.live_games[ctx.channel.id] = game

if not len(game.participants) == blackjack_player_limit:
player = Player(ctx.author.id, bet_amount, game)
if ctx.author.id not in game.participants:
player = Player(ctx.author.id, bet_amount, game)
game.participants[ctx.author.id] = player
game.deck.give_random_card(player, 2)
embed = black_jack_embed(ctx.author, player)
Expand Down Expand Up @@ -143,13 +139,9 @@ async def on_raw_reaction_add(self, payload):
reaction = self.bot.get_emoji(payload.emoji.id)
user = self.bot.get_user(payload.user_id)
player = self.reactable_messages.get(payload.message_id)
if user is not self.bot.user:
if payload.user_id == player.user_id:
await player.message.remove_reaction(reaction, user)
try:
if payload.user_id == player.user_id:
await self.reaction_options[payload.emoji.id](player) # noqa
except Exception as e:
logger.critical(e)
await self.reaction_options[payload.emoji.id](player) # noqa


def setup(bot):
Expand Down
6 changes: 6 additions & 0 deletions bot/cogs/invite_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ async def on_member_join(self, member: Member):
member=member,
title=""
))
else:
await self.log_channel.send(embed=embed_handler.info(
f"New member {member} joined through discord Discovery",
member=member,
title=""
))


def setup(bot):
Expand Down
6 changes: 1 addition & 5 deletions bot/cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async def google(self, ctx, *, query):

await ctx.trigger_typing()
results = await self.google_client.search(query)
page_number = 1

for result in results:
page_embed = discord.Embed(color=self.utility_embed_color)
Expand All @@ -33,13 +32,10 @@ async def google(self, ctx, *, query):
page_embed.url = result.url

page_embed.set_thumbnail(url=result.image_url)
# TODO should be handled by paginator..
page_embed.set_footer(text=f"Page {page_number}/{len(results)}", icon_url=google_icon)

page_list.append(page_embed)
page_number += 1

paginator = ListPaginator(ctx, page_list)
paginator = ListPaginator(ctx, page_list, footer_icon=google_icon)
await paginator.start()

@commands.command(aliases=["sof", "stack"])
Expand Down
14 changes: 10 additions & 4 deletions bot/utils/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from asyncio import TimeoutError

from discord.abc import Messageable
from discord import ClientUser, User, Member, HTTPException
from discord import ClientUser, User, Member, HTTPException, Embed
from discord.ext import commands

from bot.utils.embed_handler import info
Expand Down Expand Up @@ -224,19 +224,25 @@ async def update_message(self):
class ListPaginator:
"""Constructs a Paginator when provided a list of Embeds/Messages"""
def __init__(
self, ctx: commands.Context, page_list, footer,
self, ctx: commands.Context, page_list,
footer: bool = True,
footer_icon=Embed.Empty,
restart_button="⏮",
back_button="◀",
forward_button="⏭",
next_button="▶",
pause_button="⏸",
stop_button="⏹"
):
"""
:param footer: bool if paginator footer to be included.
:param footer_icon: string url for icon used in footer.
"""
self.pages = page_list
self.ctx = ctx
self.bot = ctx.bot
self.footer = footer

self.footer_icon = footer_icon
self.restart_button = restart_button
self.back_button = back_button
self.pause_button = pause_button
Expand Down Expand Up @@ -270,7 +276,7 @@ async def start(self):

if self.footer:
for index, page in enumerate(pages):
page.set_footer(text=f"Page {index+1}/{len(pages)}")
page.set_footer(text=f"Page {index+1}/{len(pages)}", icon_url=self.footer_icon)

embed = pages[0]

Expand Down

0 comments on commit f56d8e3

Please sign in to comment.