async def __ranking(self, ctx: SlashContext): topTimeSpentMembers: List[TeinfMember] = db_session.query(TeinfMember).order_by(TeinfMember.timespent).all() i = 1 topkaTitle = "Ranking" topkaDescription = "" for member in topTimeSpentMembers[::-1]: if i > 10: break mention = f"<@{member.discordId}>" topkaDescription += f"{i}. {mention:15} {TimeUtils.getTimeDescFromMinutes(member.timespent)}\n" i += 1 em = discord.Embed( title=topkaTitle, description=topkaDescription, color=discord.Color.gold() ) await ctx.send(embed=em)
async def moneyOverTime(bot): onlineMembers = MembersUtils.get_online_members(bot) onlineMembersIds = [member.id for member in onlineMembers] onlineTeinfMembers: List[TeinfMember] = db_session.query( TeinfMember).filter(TeinfMember.discordId.in_(onlineMembersIds)).all() for onlineTeinfMember in onlineTeinfMembers: LEVEL_MULTIPLIER = 1 level = LevelsUtils.levelFromExp(onlineTeinfMember.exp) onlineTeinfMember.money += level * LEVEL_MULTIPLIER onlineTeinfMember.exp += level * LEVEL_MULTIPLIER
async def on_message(msg: discord.Message): if msg.author.bot: return author_id: int = msg.author.id messageAuthor: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=author_id).first() if messageAuthor: messageAuthor.sentmessages += 1 else: member = TeinfMember(author_id) db_session.add(member)
async def __czas(self, ctx: SlashContext, user: discord.Member = None): user = user or ctx.author teinfMember: TeinfMember = db_session.query(TeinfMember).filter_by(discordId=user.id).first() em = discord.Embed( title="Czas spędzony na serwerze", description=f"{user.display_name} spędził {TimeUtils.getTimeDescFromMinutes(teinfMember.timespent)} na serwerze", color=discord.Colour.green() ) await ctx.send(embed=em)
async def __stan(self, ctx: SlashContext, user: discord.Member = None): if user is None: user = ctx.author teinf_member: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=user.id).first() embd = discord.Embed( title="💵 TEINF BANK 💵", description= f"Stan konta {user.mention}:\n`- {teinf_member.money} chillcoinów`", color=discord.Color.green()) await ctx.send(embed=embd)
async def __level(self, ctx: SlashContext, user: discord.Member = None): user = user or ctx.author teinf_user: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=user.id).first() level = LevelsUtils.levelFromExp(teinf_user.exp) next_level_exp = LevelsUtils.expFromLevel(level + 1) missing_exp_to_lvlup = int(next_level_exp - teinf_user.exp) embed = discord.Embed( title="💎 LEVEL 💎", description= f"Wykres poziomu {user.mention}\n`{level}LVL - {teinf_user.exp}EXP.`\nBrakuje `{missing_exp_to_lvlup}` do kolejnego poziomu.", color=discord.Color.blue()) embed.set_footer(text=str(ctx.author), icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def __ruletka(self, ctx: SlashContext, bet: int): if bet <= 0: return author: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=ctx.author.id).first() if author.money < bet: await ctx.author.send( f"Nie masz wystarczająco pieniędzy - brakuje `{abs(bet - author.money)}` chillcoinów" ) return else: author.money -= bet czarne = [ 2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35 ] czerwone = [ 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36 ] embed = discord.Embed(title=f"🎰 Ruletka 🎰", description=f"Wybierz kolor:", color=discord.Color.gold()) embed.set_footer(text=f"{str(ctx.author)}", icon_url=ctx.author.avatar_url) red_button = create_button(label="Czerwony", style=ButtonStyle.red) black_button = create_button(label="Czarny", style=ButtonStyle.gray) green_button = create_button(label="Zielony", style=ButtonStyle.green) action_row = create_actionrow(red_button, black_button, green_button) message = await ctx.send(embed=embed, components=[action_row]) winning_number = random.randint(0, 36) betWinAmount = 0 button_ctx: ComponentContext = await wait_for_component( self.bot, components=action_row, check=lambda x: x.author_id == ctx.author_id) for component in action_row["components"]: component["disabled"] = True await button_ctx.edit_origin(components=[action_row]) if button_ctx.component_id == red_button["custom_id"]: if winning_number in czerwone: betWinAmount = bet * 2 if button_ctx.component_id == black_button["custom_id"]: if winning_number in czarne: betWinAmount = bet * 2 if button_ctx.component_id == green_button["custom_id"]: if winning_number == 0: betWinAmount = bet * 14 desc = "" if winning_number in czarne: desc += "Czarna\n" elif winning_number in czerwone: desc += "Czerwona\n" elif winning_number == 0: desc += "Zielona" if betWinAmount <= 0: kolor = discord.Color.red() text = "PRZEGRA�EŚ! \U0001F602" else: kolor = discord.Color.green() text = "WYGRA�EŚ!" em = discord.Embed( title=f"\U0001F4B0 Ruletka: {ctx.message.author} \U0001F4B0", colour=kolor) em.add_field(name=f"**{text}**", value=f"Wygrywająca liczba : **{winning_number}**", inline=False) em.add_field(name=f"**INFO O LICZBIE**", value=desc) if betWinAmount > 0: author.money += betWinAmount author.exp += betWinAmount // 10 em.add_field(name="**Profit** :", value=f"**+{betWinAmount}** chillcoinsów", inline=False) em.set_footer( text=str(ctx.author) + f": +{betWinAmount}CC, +{betWinAmount // 10}EXP, BILANS {author.money}", icon_url=ctx.author.avatar_url) else: em.set_footer(text=str(ctx.author) + f":BILANS {author.money}", icon_url=ctx.author.avatar_url) await ctx.send(embed=em)
async def __rr(self, ctx: SlashContext, bet: int): if bet <= 0: return start_embed = discord.Embed( title="Rosyjska ruletka", description= f"Czy podejmiesz się wyzwaniu?\nKliknij 🔫 aby dołączyć\n🏁 aby wystartować\nKoszt wstępu: `{bet}` chillcoinsów", color=discord.Color.red()) start_embed.set_image(url=self.bot.user.avatar_url) start_embed.set_footer( text=f"Komenda wyłołana przez {ctx.author.name}", icon_url=ctx.author.avatar_url) start_message: discord.Message = await ctx.send(embed=start_embed) await start_message.add_reaction("🔫") await start_message.add_reaction("🏁") try: await self.bot.wait_for( "reaction_add", check=lambda react, usr: usr == ctx.author and str(react.emoji) == "🏁" and react.message.id == start_message.id, timeout=120) except asyncio.TimeoutError: await ctx.send(embed=discord.Embed( title="Upływ czasu", description= f"Upłynął czas na dodanie 🏁 przez {ctx.author.name}", color=discord.Color.red()), delete_after=20) await start_message.delete() start_message: discord.Message = await ctx.fetch_message( start_message.id) players: List[Player] = [ Player(player) for player in await start_message.reactions[0].users().flatten() if player.display_name != self.bot.user.display_name ] if len(players) <= 1: return for player in players: member: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=player.id).first() money = member.money if money < bet: players.remove(player) await player.member.send( "Niestety nie możesz zagrać w rosyjską ruletkę - masz za mało pieniędzy! - {}" .format(money)) else: member.money -= bet if len(players) <= 1: return random.shuffle(players) start_players_amount = len(players) revolver = Gun(ctx) while len(players) > 1: for player in players: embed = discord.Embed( title="🤔 Wybór 🤔", description= f"{player.member.mention}\n1. Strzał w siebie\n2. Strzał w innego", color=discord.Color.purple()) embed.set_footer(text=f"{str(player.member)}", icon_url=player.member.avatar_url) msg = await ctx.send(embed=embed, delete_after=20) await EmojiUtils.add_digits(msg, 2) kill_decision = await self.handle_reactions( ctx, msg, player.member) if kill_decision == -1: players.remove(player) elif kill_decision == 1: # strzelanie w siebie target = player target_killed = await player.shot(ctx, target, revolver, self_shot=True) if target_killed: players.remove(target) elif kill_decision == 2: message = await ctx.send(embed=discord.Embed( title="Strzał!", description= f"{player.member.mention} wybierz osobę w którą chcesz strzelić" + self.players_description(players), color=discord.Color.green())) await EmojiUtils.add_digits(message, len(players)) response = await self.handle_reactions( ctx, message, player.member) target = players[response - 1] target_killed = await player.shot(ctx, target, revolver) if not target_killed: await ctx.send(embed=discord.Embed( title="Strzał w siebie", description= f"{player.member.mention} niestety teraz musisz strzelać do siebie...", color=discord.Color.red())) target = player target_killed = await player.shot(ctx, target, revolver, self_shot=True) if target_killed: players.remove(target) else: players.remove(target) winning_player = players[0] embed = discord.Embed( title="🏆 Wygrana! 🏆", description=f"Gratulacje {winning_player} wygrałeś rozgrywkę!", color=discord.Color.green()) money_gained = start_players_amount * bet exp_gained = money_gained // 2 embed.set_footer(text=f"+{money_gained}cc, +{exp_gained}exp") await ctx.send(embed=embed) winning_player: TeinfMember = db_session.query(TeinfMember).filter_by( discordId=winning_player.id).first() winning_player.money += money_gained winning_player.exp += exp_gained