Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from urllib.parse import urlparse
  4. try: # check if BeautifulSoup4 is installed
  5.     from bs4 import BeautifulSoup
  6.     soupAvailable = True
  7. except:
  8.     soupAvailable = False
  9. import aiohttp
  10.  
  11.  
  12. class starcitizen:
  13.     """Star Citizen Cog For Red!"""
  14.    
  15.     def __init__(self, bot):
  16.         self.bot = bot
  17.  
  18.  
  19.     async def gethandle(self, usertext):
  20.         dodebug = True
  21.         url = 'https://robertsspaceindustries.com/citizens/' + usertext #build the web adress
  22.         return "SyberSects"
  23. #        async with aiohttp.get(url) as response:
  24. #                    soupObject = BeautifulSoup(await response.text(), "html.parser")
  25. #        if soupObject.find(class_='info').find('p').next_sibling.next_sibling.find('strong'):
  26. #            handle = soupObject.find(class_='info').find('p').next_sibling.next_sibling.find('strong').get_text()
  27. #            if dodebug == True:
  28. #                await self.bot.say("Found!")
  29. #            return handle
  30. #        else:
  31. #            return False
  32.  
  33.     @commands.command()
  34.     async def c(self, *text):
  35.         """Search Citizen Profiles!"""
  36.         dodebug = True
  37.         #Your code will go here
  38.              
  39.         try:
  40.             #####GET VARIABLES#####
  41.             usertext = text[0]
  42.             if dodebug == True:
  43.                 await self.bot.say("Gathering what i have found...")
  44.  
  45.             #####PRINT OUTPUT IN DISCORD#####
  46.  
  47.             if dodebug == True:
  48.                 await self.bot.say("checking for handle...")
  49.  
  50.             handle = self.gethandle(usertext)
  51.  
  52.             if handle:
  53.                 if dodebug == True:
  54.                     await self.bot.say("handle is embedding..")
  55.                 await self.bot.say(handle)
  56.                 embed=discord.Embed(title="Results for " + handle, url="https://robertsspaceindustries.com/citizens/" + handle, color=0xbf0000)
  57.                 embed.add_field(name='Handle', value=handle, inline=True)
  58.                 await self.bot.say("handle embedded!")
  59.  
  60.             if handle:
  61.                 await self.bot.say(embed=embed)
  62.             else:
  63.                 await self.bot.say("Citizen Not Found.")
  64.  
  65.  
  66.         except:
  67.             await self.bot.say("Error. And I have no way to know what it is! Good luck to you!")
  68.  
  69.  
  70. def setup(bot):
  71.     bot.add_cog(starcitizen(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement