Browse Source

fixed multiple bugs with the scrapper and improved speeds for the reddit cog.

tags/v2.0.0
Roxie Gibson 5 years ago
parent
commit
3b040ad7a7
1 changed files with 2 additions and 5 deletions
  1. +2
    -5
      roxbot/cogs/reddit.py

+ 2
- 5
roxbot/cogs/reddit.py View File

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
""" """
import time


import random import random
import fnmatch import fnmatch
Example: Example:
{command_prefix}subreddit pics {command_prefix}subreddit pics
""" """
start = time.time()
subreddit = subreddit.lower() subreddit = subreddit.lower()
if isinstance(ctx.channel, discord.DMChannel): if isinstance(ctx.channel, discord.DMChannel):
cache_id = ctx.author.id cache_id = ctx.author.id


self.scrapper.cache_refresh(cache_id) self.scrapper.cache_refresh(cache_id)
posts = await self.scrapper.sub_request(subreddit) posts = await self.scrapper.sub_request(subreddit)

if not posts: if not posts:
return await ctx.send("Error ;-; That subreddit probably doesn't exist. Please check your spelling") return await ctx.send("Error ;-; That subreddit probably doesn't exist. Please check your spelling")




choice = await self.scrapper.random(posts["children"], cache_id, nsfw_allowed) choice = await self.scrapper.random(posts["children"], cache_id, nsfw_allowed)


end = time.time()
print("Time Taken: {}s".format(end-start))

if not choice: if not choice:
return await ctx.send("I couldn't find any images from that subreddit.") return await ctx.send("I couldn't find any images from that subreddit.")
elif choice.get("success", True) is False: elif choice.get("success", True) is False:

Loading…
Cancel
Save