async def on_message(self, message): if not 'pcpartpicker' in message.content: return if message.author.id in (769886576321888256, 785613577066119229): return elif message.guild != None and message.guild.id in self.bot.autopcpp_disabled: return elif 'updatebuild' in message.content or 'createbuild' in message.content: return matches = get_list_links(message.content) urls = [] for match in matches: if not 'pcpartpicker.com' in match and not '/list' in match: continue if match.endswith("/list") or match.endswith("/list/"): if len(matches) > 1: continue embed_msg = discord.Embed( title= "You copied the wrong link for your PCPartPicker list!", colour=green) embed_msg.set_image( url= "https://images-ext-2.discordapp.net/external/d_524-5pqtAyimIrQTDWPumbJ-rB5JmglIR1UD9G8hI/https/i.imgur.com/zQrtYKAh.jpg" ) await message.reply(embed=embed_msg) continue urls.append((match, message)) if len(urls) == 0: return for url in urls: self.bot.queued_lists.append(url)
async def createbuild(self, ctx, *, _list=None): async with aiosqlite.connect("bot.db") as conn: cursor = await conn.execute( "SELECT * from builds WHERE userid IS (?)", (ctx.author.id, )) info = await cursor.fetchall() message_content = _list if len(info) > 0: embed_msg = discord.Embed( title="You already have a build saved!", description= "To update your build, do `,updatebuild (content or pcpartpicker link)`.", timestamp=datetime.utcnow(), colour=red) await ctx.send(embed=embed_msg) return if _list is None: embed_msg = discord.Embed( title="What would you like the contents of your Build to be?", description= "Send your PCPartPicker list link or the raw text for your build's contents.", timestamp=datetime.utcnow(), colour=red) sent_message = await ctx.message.reply(embed=embed_msg) check = lambda message: message.author == ctx.author and message.content != "" try: message = await self.bot.wait_for('message', check=check, timeout=30) except asyncio.TimeoutError: embed_msg = discord.Embed( title= "What would you like the contents of your Build to be?", description="Timed out. You took too long to respond!", timestamp=datetime.utcnow(), colour=red) await sent_message.edit(embed=embed_msg) return message_content = message.content matches = get_list_links(message_content) build_content = message_content build_url = "None" pcpp = Scraper() if len(matches) > 0: for url in matches: pcpp_list = pcpp.fetch_list(url) description = '\n'.join([ f"**{part.type}** - [{part.name}]({part.url})" if part.url != None else f"**{part.type}** - {part.name}" for part in pcpp_list.parts ]) + '\n' if len(description) > 1950: description = '\n'.join([ f"**{part.type}** - {part.name}" for part in pcpp_list.parts ])[:1950] + '\n' if description == "": build_content = url else: build_content = description build_url = pcpp_list.url break async with aiosqlite.connect("bot.db") as conn: cursor = await conn.execute( "INSERT INTO builds VALUES (?, ?, ?)", (ctx.author.id, build_content, build_url)) await conn.commit() embed_msg = discord.Embed( title="Successfully saved build", description= "Check it out using `,build`. You can edit this build using `,updatebuild`.", colour=red) await ctx.send(embed=embed_msg) return