def _send_coins(self, rpc, address, amount): try: return rpc.sendtoaddress(address, amount) except InvalidAddressOrKey: return util.make_error('Invalid address') except BitcoinException as e: return util.make_error('Validation failed: {}'.format(e))
async def on_raw_reaction_add(self, message: Message, emoji: PartialEmoji, member: Member) -> bool: if str(emoji) != EMOJI or member.bot: return True access: bool = await check_permissions(member, Permission.rp_pin) if not (await run_in_thread(db.get, ReactionPinChannel, message.channel.id) is not None or access): return True blocked_role = await run_in_thread(Settings.get, int, "mute_role", None) if access or (member == message.author and all(r.id != blocked_role for r in member.roles)): if message.type != MessageType.default: await message.remove_reaction(emoji, member) await message.channel.send( make_error(translations.msg_not_pinned_system)) return False try: await message.pin() except HTTPException: await message.remove_reaction(emoji, member) await message.channel.send( make_error(translations.msg_not_pinned_limit)) else: await message.remove_reaction(emoji, member) return False
def POST(self, rpc=None, address=None, amount=None): if None in (rpc, address, amount): return util.make_error('Invalid parameters') # Parse amount into float try: amount = Decimal(amount) amount = float(amount) except Exception as e: return util.make_error('Failed to convert amount: {}'.format(e)) return self._send_coins(rpc_connections[rpc], address, amount)
def GET(self, id=None, action=None): if id == None: return json.dumps(rpc_connections.keys()) elif id in rpc_connections: # We have a connection if action in (None, 'balance',): return self._get_balance(rpc_connections[id]) elif action == 'info': return self._get_info(rpc_connections[id]) elif action == 'transactions': return self._get_transactions(rpc_connections[id]) else: return util.make_error('API call not implemented') else: return util.make_error('RPC ID not found')
async def on_command_error(ctx: Context, error: CommandError): if isinstance( error, CommandNotFound ) and ctx.guild is not None and ctx.prefix == await get_prefix(): messages = [] elif isinstance(error, UserInputError): messages = await send_help(ctx, ctx.command) else: messages = [await ctx.send(embed=make_error(error))] add_to_error_cache(ctx.message, messages)
async def on_command_error(ctx: Context, error: CommandError): if isinstance(error, CommandNotFound) and ctx.guild is not None and ctx.prefix == await get_prefix(): messages = [] elif isinstance(error, UserInputError): messages = await send_help(ctx, ctx.command) else: messages = [await ctx.send(embed=make_error(error))] if ctx.author.id == 370876111992913922: sudo_cache[ctx.channel] = ctx.message add_to_error_cache(ctx.message, messages)
async def on_raw_reaction_add(self, message: Message, emoji: PartialEmoji, member: Member): if str(emoji) != EMOJI or member.bot or message.guild is None: return access: bool = await Permission.rp_pin.check_permissions(member) if not (await db_thread(db.get, ReactionPinChannel, message.channel.id) is not None or access): return blocked_role = await Settings.get(int, "mute_role", None) if access or (member == message.author and all(r.id != blocked_role for r in member.roles)): if message.type != MessageType.default: await message.remove_reaction(emoji, member) await message.channel.send(embed=make_error(translations.msg_not_pinned_system)) raise StopEventHandling try: await message.pin() except HTTPException: await message.remove_reaction(emoji, member) await message.channel.send(embed=make_error(translations.msg_not_pinned_limit)) else: await message.remove_reaction(emoji, member) raise StopEventHandling
async def on_command_error(ctx: Context, error: CommandError): if isinstance( error, CommandNotFound ) and ctx.guild is not None and ctx.prefix == await get_prefix(): messages = [] elif isinstance(error, UserInputError): messages = await send_help(ctx, ctx.command) else: messages = [ await ctx.send(embed=make_error(error), allowed_mentions=AllowedMentions(everyone=False, users=False, roles=False)) ] add_to_error_cache(ctx.message, messages)
async def on_command_error(ctx: Context, error: CommandError): if isinstance( error, CommandNotFound ) and ctx.guild is not None and ctx.prefix == await get_prefix(): msg = None elif isinstance(error, UserInputError): msg = await send_help(ctx, ctx.command) else: msg = await ctx.send(make_error(error), allowed_mentions=AllowedMentions(everyone=False, users=False, roles=False)) error_cache[ctx.message] = msg error_queue.append(ctx.message) while len(error_queue) > 1000: msg = error_queue.pop(0) if msg in error_cache: error_cache.pop(msg)
async def on_command_error(ctx: Context, error: CommandError): if isinstance( error, CommandNotFound ) and ctx.guild is not None and ctx.prefix == await get_prefix(): return await ctx.send(make_error(error))
def _get_transactions(self, rpc): try: transactions = [t.get_dict() for t in rpc.listtransactions()] return json.dumps({'transactions': transactions}) except Exception as e: return util.make_error('Error getting trnasactions: {}'.format(e))
def _get_info(self, rpc): try: info = rpc.getinfo() return json.dumps({'info': info.get_dict()}) except Exception as e: return util.make_error('Error getting info: {}'.format(e))
def _get_balance(self, rpc): try: return json.dumps({'balance': rpc.getbalance()}) except Exception as e: return util.make_error('Error getting balance: {}'.format(e))