async def give(self, ctx, *args): giver = ctx.author member = await self.get.get_member(ctx, args[0]) amount = int(args[1]) if self.get.get_user(member.id) is None: return if member is None: return await self.error.get_error(ctx, f"User **{args[0]}** not found", "give") if amount < 1: return await self.error.get_error(ctx, f"You can not transfer less than 1 coin to someone!", "give") if amount > self.get.get_coins(giver.id): return await self.error.get_error(ctx, f"You can not transfer more coins than you own!", "give") try: with db.cursor() as cursor: sql = f"UPDATE players SET coins=%s WHERE user_id=%s" cursor.execute(sql, (self.get.get_coins(member.id) + amount, member.id)) sql = f"UPDATE players SET coins=%s WHERE user_id=%s" cursor.execute(sql, (self.get.get_coins(giver.id)-amount, giver.id)) db.commit() embed = discord.Embed(title=f"Successfully transferred {amount} coins to **{member.name}**", color=discord.Color.from_rgb(130, 234, 255)) await ctx.send(embed=embed) except Exception as e: print(f"Error transferring {amount} coins to {member.name} [{member.id}] from {giver.name} [{giver.id}])\n{e}") return await self.error.get_error(ctx, f"**{member.name}** is not registered!", "addcoins")
async def remove_user_from_db(self, ctx, member): member = await self.get.get_member(ctx, member) if member is None: return await self.error.get_error(ctx, f"user {member} not found") if member.id == 122837007834677251: return await ctx.send("no.") try: with db.cursor() as cursor: sql = f"DELETE players, general_skills, personal_skills, personal_attributes FROM (((players INNER JOIN general_skills ON players.user_id = general_skills.user_id) INNER JOIN personal_attributes ON players.user_id=personal_attributes.user_id) INNER JOIN personal_skills ON players.user_id=personal_skills.user_id) WHERE players.user_id = %s" cursor.execute(sql, (member.id)) db.commit() embed = discord.Embed(title=f"[Successfully removed {member.name} [{member.id}] from the database", color=discord.Color.from_rgb(130, 234, 255)) await ctx.send(embed=embed) except Exception as e: print(f"Error removing {member.name} [{member.id}] from the database\n{e}") return await self.error.get_error(ctx, f"{member.name} is not registered!", "remu")
async def remove_nebula_from_db(self, ctx, inp): nebula = inp if self.nebula.new_nebula(inp) == True: nebula = None try: with db.cursor() as cursor: sql = f"DELETE nebulas, nebula_members FROM nebulas INNER JOIN nebula_members ON nebulas.nebula = nebula_members.nebula WHERE nebulas.nebula = %s" cursor.execute(sql, (nebula)) sql = f"UPDATE players SET nebula=Null WHERE user_id=%s" cursor.execute(sql, (ctx.author.id)) db.commit() embed = discord.Embed(title=f"[Successfully removed nebula [{inp}] from the database", color=discord.Color.from_rgb(130, 234, 255)) await ctx.send(embed=embed) except Exception as e: print(f"Error removing nebula [{inp}] from the database\n{e}") return await self.error.get_error(ctx, f"nebula [{inp}] does not exist!", "remneb")
async def give_gold(self, ctx, *args): if (len(args)) >= 2: member = await self.get.get_member(ctx, args[0]) amount = int(args[1]) if member is None: return await self.error.get_error(ctx, f"user {args[0]} not found", "addcoins") else: member = ctx.author amount = int(args[0]) try: with db.cursor() as cursor: sql = f"UPDATE players SET coins=%s WHERE user_id=%s" cursor.execute(sql, (self.get.get_coins(member.id) + amount, member.id)) db.commit() embed = discord.Embed(title=f"[{self.get.get_user_type(member.id)} **{member.name}** you have obtained __{amount}__ coins!]", color=discord.Color.from_rgb(130, 234, 255)) await ctx.send(embed=embed) except Exception as e: print(f"Error updating coins ({amount} to {member.id} from {ctx.author.name} [{ctx.author.id}])\n{e}") return await self.error.get_error(ctx, f"{member.name} is not registered!", "addcoins")
def sort_members(self, nebula): try: with db.cursor() as cursor: sql = "SELECT member_ids, nebula_rank, contribution, nebula_ranking FROM `nebula_members` WHERE `nebula`=%s" cursor.execute(sql, (nebula,)) data = cursor.fetchone() db.commit() except Exception as e: print(f"Error sorting nebula {nebula}\n{e}") data = list(data.values()) members, ranks, contribution, ranking = data[0].split(", "), data[1].split(", "), data[2].split(", "), data[3].split(", ") sorted_members, sorted_contribution, sorted_ranks, sorted_rankings = "", "", "", "" for i in range(len(members)): idx = i for j in range(i + 1, len(members)): if int(contribution[idx]) < int(contribution[j]): idx = j members[i], members[idx], contribution[i], contribution[idx] = members[idx], members[i], contribution[idx], contribution[i] ranks[i], ranks[idx], ranking[i], ranking[idx] = ranks[idx], ranks[i], ranking[idx], ranking[i] sorted_members += f"{members[i]}" sorted_contribution += f"{contribution[i]}" sorted_ranks += f"{ranks[i]}" sorted_rankings += f"{i + 1}" if i != len(members)-1: sorted_members += ", " sorted_contribution += ", " sorted_ranks += ", " sorted_rankings += ", " try: with db.cursor() as cursor: sql = f"UPDATE nebula_members SET member_ids=%s, nebula_rank=%s, nebula_ranking=%s, contribution=%s WHERE nebula=%s" cursor.execute(sql, (sorted_members, sorted_ranks, sorted_rankings, sorted_contribution, nebula)) db.commit() except Exception as e: print(f"Error sorting nebula members\n{e}")
async def create(self, ctx, *, nebula: str = None): if self.get.get_user(ctx.author.id) is None: return await self.error.not_registered_error(ctx, "nebula") in_nebula = self.get.get_nebula(ctx.author.id) if in_nebula is not None: return await self.error.get_error(ctx, f"{self.get.get_user_type(ctx.author.id)} **{ctx.author.name}**, you are already in a nebula!", "nebula create") if nebula is None: return await self.error.get_error(ctx, "You must enter a name for your nebula", "nebula create") ' '.join(nebula.split()) new_nebula = self.new_nebula(nebula) try: with db.cursor() as cursor: sql = "SELECT `guild_id` FROM `nebulas` WHERE `guild_id`=%s" cursor.execute(sql, (ctx.guild.id,)) result = cursor.fetchone() if not result: guild_has_nebula = False else: guild_has_nebula = True except Exception as e: print(f"Error looking up nebula's in guild {ctx.guild.name}\n{e}") if guild_has_nebula: return await self.error.get_error(ctx, "This guild already has a nebula", "nebula create") if new_nebula is False: return await self.error.get_error(ctx,f"The nebula \"{nebula}\" is already taken", "nebula create") embed = discord.Embed(title="Confirmation", description=f"{self.get.get_user_type(ctx.author.id)}, are you sure you want to create the **{nebula}** nebula for __250,000__ coins?", color=discord.Color.from_rgb(130, 234, 255)) msg = await ctx.send(embed=embed) await msg.add_reaction("✅") await asyncio.sleep(.35) await msg.add_reaction("❌") def check(reaction, user): return ctx.author == user and str(reaction.emoji) in ["✅", "❌"] try: reaction, user = await self.bot.wait_for('reaction_add', timeout=5.0, check=check) except asyncio.TimeoutError: await msg.delete(delay=0) msg = await ctx.send(f"{ctx.author.mention}, you waited too long") await msg.delete(delay=3) else: if str(reaction.emoji) == "✅": coin = self.get.get_coins(ctx.author.id) if coin < 250000: await msg.delete(delay=0) return await self.error.get_error(ctx, f"{self.get.get_user_type(ctx.author.id)}, you do not have enough coins to fund a nebula! You currently have __{format(coin, ',d')}__ coins. Nebulas require __250,000__ coins to fund", "nebula create") try: with db.cursor() as cursor: sql = "INSERT INTO `nebulas` (nebula, guild_id, message, leader, vice_leader) VALUES (%s, %s, %s, %s, %s)" cursor.execute(sql, (nebula, ctx.guild.id, None, ctx.author.id, None,)) sql = "INSERT INTO `nebula_members` (nebula, member_ids, nebula_rank, nebula_ranking, contribution) VALUES (%s, %s, %s, %s, %s)" cursor.execute(sql, (nebula, ctx.author.id, 3, 1, 0)) sql = f"UPDATE players SET nebula=%s, coins=%s WHERE user_id=%s" cursor.execute(sql, (nebula, self.get.get_coins(ctx.author.id)-250000, ctx.author.id)) db.commit() embed = discord.Embed(title="Congratulations 🎉", description=f"{self.get.get_user_type(ctx.author.id)} {ctx.author.mention}, you are responsible for the birth of a nebula. You may now challenge the scenarios with other incarnations and constellations as a nebula.", color=discord.Color.from_rgb(130, 234, 255)) embed.add_field(name="\u200b", value=f"*do `{self.get.get_prefix(ctx)}help nebula` for information on commands regarding nebulas*", inline=False) await msg.delete(delay=0) await ctx.send(embed=embed) except Exception as e: print(f"Error adding Nebula: {e}") elif str(reaction.emoji) == "❌": await msg.delete(delay=0)