1
0
Fork 0
mirror of synced 2024-06-29 11:40:20 +12:00

Merge pull request #9 from Phxntxm/dev

Dev
This commit is contained in:
Dan Hess 2016-09-29 02:41:05 -05:00 committed by GitHub
commit 975d352c7e
3 changed files with 23 additions and 17 deletions

View file

@ -38,7 +38,7 @@ class Interaction:
self.battles[ctx.message.server.id] = {p1: p2 for p1, p2 in battles.items() if
not p2 == player_id and not p1 == player_id}
@commands.group(pass_context=True, no_pm=True, invoke_without_command=True)
@commands.group(pass_context=True, no_pm=True, invoke_without_command=True, enabled=False)
@commands.cooldown(1, 180, BucketType.user)
@checks.custom_perms(send_messages=True)
async def battle(self, ctx, player2: discord.Member):

View file

@ -6,6 +6,7 @@ import discord
import aiohttp
import random
import re
import math
class Links:
@ -90,15 +91,17 @@ class Links:
await self.bot.say("No results with that search term, {0}!".format(ctx.message.author.mention))
return
# Find a random image based on the first page of results.
# Currently derpibooru provides no way to change how many results can be shown on one page
# Nor anyway to see how many pages are returned by a certain query
# Due to the fact that a query may only return one page
# We cannot try to check more than one as it might fail
# So this is the best that we can do at the moment
# The first request we've made ensures there are results
# Now we can get the total count from that, and make another request based on the number of pages as well
if len(results) > 0:
pages = math.ceil(data['total'] / len(results))
url += '&page={}'.format(random.SystemRandom().randint(1, pages))
async with self.session.get(url, headers=self.headers) as r:
data = await r.json()
results = data['search']
index = random.SystemRandom().randint(0, len(results) - 1)
image_link = 'http://{}'.format(results[index].get('representations').get('full')[2:].strip())
image_link = 'https://derpibooru.org/{}'.format(results[index])
else:
await self.bot.say("No results with that search term, {0}!".format(ctx.message.author.mention))
return

View file

@ -108,11 +108,14 @@ async def update_records(key, winner, loser):
winner_stats = {}
loser_stats = {}
for stat in matches:
if stat.get('member_id') == winner.id:
winner_stats = stat
elif stat.get('member_id') == loser.id:
loser_stats = stat
try:
for stat in matches:
if stat.get('member_id') == winner.id:
winner_stats = stat
elif stat.get('member_id') == loser.id:
loser_stats = stat
except TypeError:
pass
winner_rating = winner_stats.get('rating') or 1000
loser_rating = loser_stats.get('rating') or 1000
@ -138,10 +141,10 @@ async def update_records(key, winner, loser):
loser_rating -= 16 + rating_change
# Just increase wins/losses for each person, making sure it's at least 0
winner_wins = winner_stats.get('wins') or 0
winner_losses = winner_stats.get('losses') or 0
loser_wins = loser_stats.get('wins') or 0
loser_losses = loser_stats.get('losses') or 0
winner_wins = winner_stats.get('wins', 0)
winner_losses = winner_stats.get('losses', 0)
loser_wins = loser_stats.get('wins', 0)
loser_losses = loser_stats.get('losses', 0)
winner_wins += 1
loser_losses += 1