async def give_product(): info = await request.get_json() try: giveproduct(info["userid"], info["productname"]) userinfo = getuser(info["userid"]) member = nextcord.utils.get(sbot.users, id=userinfo["discordid"]) if member != None: # Try to prevent it from returning an error product = getproduct(info["productname"]) productname = info["productname"] if product != None: embed = Embed( title="Thanks for your purchase!", description=f"Thank you for your purchase of **{productname}** please get it by using the links below.", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ) await member.send(embed=embed) if product["attachments"] != None or product["attachments"] != []: for attachment in product["attachments"]: await member.send(attachment) return dumps(userinfo) except: return {"errors": [{"message": "Unable to give product"}]}
async def giveproduct(self, ctx, members: Greedy[Member], *, product: str): if not len(members): await ctx.send( f"You left out a vital argument, use {self.bot.PREFIX}help to see all the required arguments.", refrence=ctx.message, ) elif not getproduct(product): await ctx.send(f"You inputted a incorrect product.", refrence=ctx.message) else: for member in members: data = getuserfromdiscord(member.id) if data: try: giveproduct(data["_id"], product) try: embed = Embed( title="Thanks for your purchase!", description= f"Thank you for your purchase of {product} please get it by using the links below.", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ) if not member.dm_channel: await member.create_dm() await member.dm_channel.send(embed=embed) for attachment in getproduct( product)["attachments"]: await member.dm_channel.send(attachment) except: await ctx.send( f"I was unable to DM {member.mention} there product.", reference=ctx.message, ) except: await ctx.send( f"I was unable to give {member.mention} {product}.", reference=ctx.message, ) members.remove(member) else: await ctx.send( f"I was unable to give {member.mention} {product}.", reference=ctx.message, ) members.remove(member) if members: await ctx.send( "Gave " + "".join([member.mention for member in members]) + f" {product}.", reference=ctx.message, )
async def transfer(self, ctx, member: Member): await ctx.send( embed=Embed( title="Transfer Product", description="Please select the product you want to transfer.", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ), view=TransferView(ctx, member), reference=ctx.message, )
async def update_select(self, _, interaction: Interaction): product = str(interaction.data["values"])[2:-2] embed = Embed( title=f"Update {product}", description=f"What would you like to change?", colour=Colour.blue(), timestamp=nextcord.utils.utcnow(), ) embed.set_footer(text="Redon Tech RPH • By: parker02311") await interaction.message.edit( "", embed=embed, view=WhatUpdateView(self.context, product, self.bot) )
async def unlink(self, ctx): view = AreYouSureView(ctx) message = await ctx.send( embed=Embed( title="Are you sure?", description= "Are you sure you want to unlink your Roblox account?", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ), view=view, reference=ctx.message, ) await view.wait() if view.Return == None: await message.edit("Timed Out", embed=None, view=None) elif view.Return == False: await message.edit("Cancelled", embed=None, view=None) elif view.Return == True: try: user = getuserfromdiscord(ctx.author.id) if not user: raise UserNotVerified unlinkuser(user["_id"]) await message.edit("Your Roblox account has been unlinked.", embed=None, view=None) except UserNotVerified: await message.edit("You are not verified.", embed=None, view=None) except: await message.edit("I was unable to unlink your account.", embed=None, view=None)
async def retrieveproduct(self, ctx, *, product: str): userinfo = getuserfromdiscord(ctx.author.id) if userinfo: if product in userinfo["purchases"]: embed = Embed( title="Thanks for your purchase!", description=f"Thank you for your purchase of {product} please get it by using the links below.", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ) try: if not ctx.author.dm_channel: await ctx.author.create_dm() await ctx.author.dm_channel.send(embed=embed) for attachment in getproduct(product)["attachments"]: await ctx.author.dm_channel.send(attachment) except Forbidden: await ctx.send( "Please open your DM's and try again.", reference=ctx.message )
async def callback(self, interaction: Interaction): product = str(interaction.data["values"])[2:-2] view = AreYouSureView(self.context) await interaction.message.delete() message = await interaction.channel.send( embed=Embed( title="Are you sure?", description= f"Are you sure you want to transfer **{product}** to **{self.whoto.mention}**?", colour=Colour.from_rgb(255, 255, 0), timestamp=nextcord.utils.utcnow(), ), view=view, reference=self.context.message, ) await view.wait() if view.Return == None: await message.edit("Timed Out", embed=None, view=None) elif view.Return == False: await message.edit("Canceled Transfer", embed=None, view=None) elif view.Return == True: await message.edit( embed=Embed( title="Transferring...", description= f"Please wait while we transfer your **{product}**.", colour=Colour.from_rgb(255, 255, 255), timestamp=nextcord.utils.utcnow(), ), view=None, ) try: interactor = getuserfromdiscord(self.user.id) goingto = getuserfromdiscord(self.whoto.id) if not goingto: raise UserNotVerified if product in goingto["purchases"]: raise UserOwnsProduct revokeproduct(interactor["_id"], product) giveproduct(goingto["_id"], product) await message.edit(embed=Embed( title="Transfer Complete", description= f"Your **{product}** has been transferred to the selected account.", colour=Colour.from_rgb(0, 255, 0), timestamp=nextcord.utils.utcnow(), )) except UserNotVerified: await message.edit(embed=Embed( title="Transfer Failed", description=f"**{self.whoto.mention}** is not verified.", colour=Colour.from_rgb(255, 0, 0), timestamp=nextcord.utils.utcnow(), )) except UserOwnsProduct: await message.edit(embed=Embed( title="Transfer Failed", description= f"**{self.whoto.mention}** already owns **{product}**.", colour=Colour.from_rgb(255, 0, 0), timestamp=nextcord.utils.utcnow(), )) except: await message.edit(embed=Embed( title="Transfer Failed", description= f"An error occured while transferring your **{product}**.", colour=Colour.from_rgb(255, 0, 0), timestamp=nextcord.utils.utcnow(), ))
async def update_name(self, _, interaction: Interaction): embed = Embed( title=f"Update {self.product['name']}", description=f"What would you like to change the name to?", colour=Colour.blue(), timestamp=nextcord.utils.utcnow(), ) embed.set_footer( text='Redon Tech RPH • Say "Cancel" to cancel. • By: parker02311' ) view = CancelView(self.context) await interaction.message.edit("", embed=embed, view=None) def check(m): return m.content and m.author == self.context.author try: message = await self.bot.wait_for("message", timeout=600.0, check=check) except TimeoutError: await interaction.message.delete() await interaction.response.send_message("Timed Out", ephemeral=True) self.stop() if not message is None and view.canceled is False: if message.content.lower() == "cancel": await interaction.message.delete() await interaction.response.send_message("Canceled", ephemeral=True) self.stop() else: await interaction.message.delete() view = AreYouSureView(self.context) message = await self.context.send( f"Are you sure you would like to change {self.product['name']} to {message.content}?", view=view, reference=self.context.message, ) await view.wait() if view.Return == None: await message.delete() await interaction.response.send_message("Timed out", ephemeral=True) elif view.Return == False: await message.delete() await interaction.response.send_message("Canceled update", ephemeral=True) elif view.Return == True: try: updateproduct( self.product["name"], message.content, self.product["description"], self.product["price"], self.product["attachments"] ) await interaction.message.delete() name = self.product["name"] await interaction.response.send_message( f"Updated {name}.", ephemeral=True, ) except: await interaction.message.delete() await interaction.response.send_message( f"Failed to update {self.args[0]}.", ephemeral=True, )
async def update_attachments(self, _, interaction: Interaction): embed = Embed( title=f"Update {self.product['name']}", description=f'Please post the attachments now. Say "Done" when you are done.', colour=Colour.blue(), timestamp=nextcord.utils.utcnow(), ) embed.set_footer( text='Redon Tech RPH • Say "Cancel" to cancel. • By: parker02311' ) fields = [ ( "Attachments", "None", False, ) ] for name, value, inline in fields: embed.add_field(name=name, value=value, inline=inline) view = CancelView(self.context) await interaction.message.edit("", embed=embed, view=None) def check(m): return m.author == self.context.author attachments = [] while True: try: message = await self.bot.wait_for("message", timeout=600.0, check=check) except TimeoutError: await interaction.message.delete() await interaction.response.send_message("Timed Out", ephemeral=True) self.stop() if message.content.lower() == "cancel": await interaction.message.delete() await self.context.send( "Canceled", reference=self.context.message, delete_after=5.0 ) break if message.content.lower() == "done": break elif not message.attachments == [] and message.attachments: for attachment in message.attachments: attachments.append(attachment.url) embed = Embed( title=f"Update {self.product['name']}", description=f'Please post the attachments now. Say "Done" when you are done.', colour=Colour.blue(), timestamp=nextcord.utils.utcnow(), ) embed.set_footer( text='Redon Tech RPH • Say "Cancel" to cancel. • By: parker02311' ) fields = [ ( "Attachments", "\n".join([attachment for attachment in attachments]), False, ) ] for name, value, inline in fields: embed.add_field(name=name, value=value, inline=inline) embed.set_footer(text="Pembroke Bot • By: parker02311") await interaction.message.edit("", embed=embed, view=None) await self.context.send( "It is recommended to not delete this message unless needed.", reference=message, ) if attachments: await interaction.message.delete() view = AreYouSureView(self.context) await self.context.send( f"Are you sure you would like to change {self.product['attachments']} to {attachments}?", view=view, reference=self.context.message, ) await view.wait() if view.Return == None: await message.delete() await interaction.response.send_message("Timed out", ephemeral=True) elif view.Return == False: await message.delete() await interaction.response.send_message("Canceled update", ephemeral=True) elif view.Return == True: try: updateproduct( self.product["name"], self.product["name"], self.product["description"], self.product["price"], attachments ) await interaction.message.delete() name = self.product["name"] await interaction.response.send_message( f"Updated {name}.", ephemeral=True, ) except: await interaction.message.delete() await interaction.response.send_message( f"Failed to update {self.args[0]}.", ephemeral=True, )