Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from urllib.parse import urlparse
- try: # check if BeautifulSoup4 is installed
- from bs4 import BeautifulSoup
- soupAvailable = True
- except:
- soupAvailable = False
- import aiohttp
- class starcitizen:
- """Star Citizen Cog For Red!"""
- def __init__(self, bot):
- self.bot = bot
- async def gethandle(self, usertext):
- dodebug = True
- url = 'https://robertsspaceindustries.com/citizens/' + usertext #build the web adress
- return "SyberSects"
- # async with aiohttp.get(url) as response:
- # soupObject = BeautifulSoup(await response.text(), "html.parser")
- # if soupObject.find(class_='info').find('p').next_sibling.next_sibling.find('strong'):
- # handle = soupObject.find(class_='info').find('p').next_sibling.next_sibling.find('strong').get_text()
- # if dodebug == True:
- # await self.bot.say("Found!")
- # return handle
- # else:
- # return False
- @commands.command()
- async def c(self, *text):
- """Search Citizen Profiles!"""
- dodebug = True
- #Your code will go here
- try:
- #####GET VARIABLES#####
- usertext = text[0]
- if dodebug == True:
- await self.bot.say("Gathering what i have found...")
- #####PRINT OUTPUT IN DISCORD#####
- if dodebug == True:
- await self.bot.say("checking for handle...")
- handle = self.gethandle(usertext)
- if handle:
- if dodebug == True:
- await self.bot.say("handle is embedding..")
- await self.bot.say(handle)
- embed=discord.Embed(title="Results for " + handle, url="https://robertsspaceindustries.com/citizens/" + handle, color=0xbf0000)
- embed.add_field(name='Handle', value=handle, inline=True)
- await self.bot.say("handle embedded!")
- if handle:
- await self.bot.say(embed=embed)
- else:
- await self.bot.say("Citizen Not Found.")
- except:
- await self.bot.say("Error. And I have no way to know what it is! Good luck to you!")
- def setup(bot):
- bot.add_cog(starcitizen(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement