async def iron(self, ctx): if not ctx.message.content.endswith("iron"): raise MissingRequiredKey(("send", "top", "local")) money, rank = await self.bot.fetch_iron(ctx.author.id, True) base = "**Dein Speicher:** `{} Eisen`\n**Globaler Rang:** `{}`" await ctx.send(base.format(seperator(money), rank))
async def send_ranking(self, ctx, iterable, guild=False): data = [] for index, record in iterable: if guild is True: ids = (ctx.guild.id, record['id']) member = self.bot.get_guild_member(*ids) else: member = self.bot.get_member(record['id']) if member is None: name = "Unknown" elif guild is True: name = member.display_name else: name = member.name base = "**Rang {}:** `{} Eisen` [{}]" msg = base.format(index, seperator(record['amount']), name) data.append(msg) if len(data) == 5: break if data: embed = discord.Embed(description="\n".join(data)) embed.colour = discord.Color.blue() await ctx.send(embed=embed) else: msg = "Aktuell gibt es keine gespeicherten Scores" await ctx.send(msg)
def show_hand(self, hand, instruction, beginner=False): description = f"**Tribalcard | Deine Hand:**\n\n" for index, player in enumerate(hand): if beginner and index == 0: card = f"Oberste Karte:\n" values = [] for key, value in prop.items(): pval = getattr(player, key) if key in self.format: pval = utils.seperator(pval) pstat = f"**{value}:** `{pval}`" values.append(pstat) result = utils.show_list(values, sep=" | ", line_break=3) card += f"{result}\n\n" base = "Du bist am Zug, wähle eine Eigenschaft mit {}play <property>" instruction = base.format(instruction) else: card = f"**{index + 1}**: {player.name}\n" description += card embed = discord.Embed(description=description) embed.set_footer(text=instruction) return embed
async def send_(self, ctx, amount: int, *, user: MemberConverter): if not 1000 <= amount <= 50000: await ctx.send("Du kannst nur `1000-50.000 Eisen` überweisen") ctx.command.reset_cooldown(ctx) else: await self.bot.subtract_iron(ctx.author.id, amount) await self.bot.update_iron(user.id, amount) base = "Du hast `{}` erfolgreich `{} Eisen` überwiesen (30s Cooldown)" await ctx.send(base.format(user.display_name, seperator(amount)))
async def slots_(self, ctx): await self.bot.subtract_iron(ctx.author.id, 1000) await self.slot_lock.wait() number = random.randint(1, 9999) if number == self.number: self.slot_lock.clear() await self.bot.update_iron(ctx.author.id, self.pot) new_number = random.randint(1, 9999) query = 'INSERT INTO slot(id, amount) VALUES($1, $2);' async with self.bot.ress.acquire() as conn: await conn.execute('TRUNCATE TABLE slot') await conn.execute(query, new_number, 5000) self.pot = 5000 self.number = new_number base = "Glückwunsch, du hast `{} Eisen` gewonnen!\nNeue Gewinnzahl: **{}**" msg = base.format(self.pot, self.number) self.slot_lock.set() else: self.pot += 1000 query = 'INSERT INTO slot(id, amount) VALUES($1, $2) ' \ 'ON CONFLICT (id) DO UPDATE SET amount = slot.amount + $2' arguments = [(ctx.author.id, 1000), (self.number, 1000)] async with self.bot.ress.acquire() as conn: await conn.executemany(query, arguments) base = "Leider die falsche Zahl: **{}**\n" \ "Aktueller Pot: `{}`\nGewinnzahl: **{}**" msg = base.format(number, utils.seperator(self.pot), self.number) async with self.end_game(ctx, time=10): await ctx.send(msg)
async def on_command_error(self, ctx, error): cmd = ctx.invoked_with msg, tip = None, None error = getattr(error, 'original', error) if isinstance(error, self.silenced): return logger.debug(f"command error [{ctx.message.id}]: {error}") if isinstance(error, commands.CommandNotFound): if len(cmd) == cmd.count(ctx.prefix): return else: data = random.choice(self.bot.msg["noCommand"]) await ctx.send(data.format(f"{ctx.prefix}{cmd}")) return elif isinstance(error, commands.MissingRequiredArgument): msg = "Dem Command fehlt ein benötigtes Argument" tip = True elif isinstance(error, utils.MissingRequiredKey): msg = f"`{ctx.prefix}{cmd.lower()} <{'|'.join(error.keys)}>`" tip = True elif isinstance(error, commands.NoPrivateMessage): msg = "Der Command ist leider nur auf einem Server möglich" elif isinstance(error, commands.PrivateMessageOnly): msg = "Der Command ist leider nur per private Message möglich" elif isinstance(error, utils.DontPingMe): msg = "Schreibe anstatt eines Pings den Usernamen oder Nickname" tip = True elif isinstance(error, utils.WorldMissing): msg = "Der Server hat noch keine zugeordnete Welt\n" \ f"Dies kann nur der Admin mit `{ctx.prefix}set world`" elif isinstance(error, utils.UnknownWorld): msg = "Diese Welt existiert leider nicht." tip = True if error.possible_world: msg += f"\nMeinst du möglicherweise: `{error.possible_world}`" elif isinstance(error, utils.InvalidCoordinate): msg = "Du musst eine gültige Koordinate angeben" elif isinstance(error, utils.WrongChannel): if error.type == 'game': channel_id = self.bot.config.get('game', ctx.guild.id) await ctx.send(f"<#{channel_id}>") return elif error.type == 'conquer': msg = "Du befindest dich nicht in einem Eroberungschannel" elif isinstance(error, utils.GameChannelMissing): msg = "Der Server hat keinen Game-Channel\n" \ f"Nutze `{ctx.prefix}set game` um einen festzulegen" elif isinstance(error, utils.MissingGucci): base = "Du hast nur `{} Eisen` auf dem Konto" msg = base.format(utils.seperator(error.purse)) elif isinstance(error, utils.InvalidBet): base = "Der Einsatz muss zwischen {} und {} Eisen liegen" msg = base.format(error.min, error.max) elif isinstance(error, commands.NotOwner): msg = "Diesen Command kann nur der Bot-Owner ausführen" elif isinstance(error, commands.MissingPermissions): msg = "Diesen Command kann nur ein Server-Admin ausführen" elif isinstance(error, commands.CommandOnCooldown): raw = "Command Cooldown: Versuche es in {0:.1f} Sekunden erneut" msg = raw.format(error.retry_after) elif isinstance(error, utils.DSUserNotFound): msg = f"`{error.name}` konnte auf {ctx.world} nicht gefunden werden" elif isinstance(error, utils.MemberNotFound): msg = f"`{error.name}` konnte nicht gefunden werden" elif isinstance(error, commands.BotMissingPermissions): base = "Dem Bot fehlen folgende Rechte auf diesem Server:\n`{}`" msg = base.format(', '.join(error.missing_perms)) elif isinstance(error, commands.ExpectedClosingQuoteError): msg = "Ein Argument wurde mit einem Anführungszeichen begonnen und nicht geschlossen" if msg: try: context = ctx if tip is True else None embed = utils.error_embed(msg, ctx=context) await ctx.send(embed=embed) except discord.Forbidden: msg = "Dem Bot fehlen benötigte Rechte: `Embed Links`" await ctx.safe_send(msg) else: print(f"Command Message: {ctx.message.content}") traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr) logger.warning( f"uncommon error ({ctx.server}): {ctx.message.content}")