2017-06-28 13:57:19 +12:00
|
|
|
import rethinkdb as r
|
2016-07-09 13:27:19 +12:00
|
|
|
from discord.ext import commands
|
2016-07-24 04:40:52 +12:00
|
|
|
from discord.ext.commands.cooldowns import BucketType
|
2017-02-18 08:48:45 +13:00
|
|
|
|
|
|
|
from . import utils
|
|
|
|
|
2016-07-09 13:42:33 +12:00
|
|
|
import discord
|
2016-07-09 13:27:19 +12:00
|
|
|
import random
|
2017-05-02 08:57:32 +12:00
|
|
|
import functools
|
2017-06-28 15:01:47 +12:00
|
|
|
import asyncio
|
2016-07-09 13:27:19 +12:00
|
|
|
|
2016-10-03 07:08:20 +13:00
|
|
|
battle_outcomes = \
|
2017-07-31 11:27:19 +12:00
|
|
|
["A meteor fell on {loser}, {winner} is left standing and has been declared the victor!",
|
|
|
|
"{loser} was shot through the heart, and {winner} is to blame",
|
|
|
|
"{winner} has bucked {loser} into a tree, even Big Mac would be impressed at that kick!",
|
|
|
|
"As they were battling, {loser} was struck by lightning! {winner} you lucked out this time!",
|
|
|
|
"{loser} tried to dive at {winner} while fighting, somehow they missed and landed in quicksand."
|
|
|
|
"Try paying more attention next time {loser}",
|
|
|
|
"{loser} got a little...heated during the battle and ended up getting set on fire. {winner} wins by remaining cool",
|
|
|
|
"Princess Celestia came in and banished {loser} to the moon. Good luck getting into any battles up there",
|
|
|
|
"{loser} took an arrow to the knee, they are no longer an adventurer. Keep on adventuring {winner}",
|
|
|
|
"Common sense should make it obvious not to get into battle with {winner}. Apparently {loser} didn't get the memo",
|
|
|
|
"{winner} had a nice cup of tea with {loser} over their conflict, and mutually agreed that {winner} was Best Pony",
|
|
|
|
"{winner} and {loser} had an intense staring contest. "
|
|
|
|
"Sadly, {loser} forgot to breathe and lost much morethan the staring contest",
|
|
|
|
"It appears {loser} is actually a pacifist, they ran away screaming and crying. "
|
2016-10-03 07:08:20 +13:00
|
|
|
"Maybe you should have thought of that before getting in a fight?",
|
2017-07-31 11:27:19 +12:00
|
|
|
"A bunch of parasprites came in and ate up the jetpack while {loser} was flying with it. Those pesky critters...",
|
|
|
|
"{winner} used their charm to seduce {loser} to surrender.",
|
|
|
|
"{loser} slipped on a banana peel and fell into a pit of spikes. That's actually impressive.",
|
|
|
|
"{winner} realized it was high noon, {loser} never even saw it coming.",
|
|
|
|
"{loser} spontaneously combusted...lol rip",
|
|
|
|
"after many turns {winner} summons exodia and {loser} is sent to the shadow realm",
|
|
|
|
"{winner} and {loser} sit down for an intense game of chess, in the heat of the moment {winner} forgot they were playing a "
|
2016-11-29 21:05:22 +13:00
|
|
|
"game and summoned a real knight",
|
2017-07-31 11:27:19 +12:00
|
|
|
"{winner} challenges {loser} to rock paper scissors, unfortunately for {loser}, {winner} chose scissors and stabbed them",
|
|
|
|
"{winner} goes back in time and becomes {loser}'s best friend, winning without ever throwing a punch",
|
|
|
|
"{loser} trips down some stairs on their way to the battle with {winner}",
|
|
|
|
"{winner} books {loser} a one way ticket to Flugendorf prison",
|
|
|
|
"{loser} was already dead",
|
|
|
|
"{loser} was crushed under the weight of expectations",
|
|
|
|
"{loser} was wearing a redshirt and it was their first day",
|
|
|
|
"{winner} and {loser} were walking along when suddenly {loser} got kidnapped by a flying monkey; hope they had water with them",
|
|
|
|
"{winner} brought an army to a fist fight, {loser} never saw their opponent once",
|
|
|
|
"{winner} used multiple simultaneous devestating defensive deep strikes to overwhelm {loser}",
|
|
|
|
"{winner} and {loser} engage in a dance off; {winner} wiped the floor with {loser}",
|
|
|
|
"{loser} tried to hide in the sand to catch {winner} off guard, unfortunately looks like a Giant Antlion had the same "
|
2016-11-29 21:05:22 +13:00
|
|
|
"idea for him",
|
2017-07-31 11:27:19 +12:00
|
|
|
"{loser} was busy playing trash videogames the night before the fight and collapsed before {winner}",
|
|
|
|
"{winner} threw a sick meme and {loser} totally got PRANK'D",
|
|
|
|
"{winner} and {loser} go on a skiing trip together, turns out {loser} forgot how to pizza french-fry",
|
|
|
|
"{winner} is the cure and {loser} is the disease....well {loser} was the disease",
|
|
|
|
"{loser} talked their mouth off at {winner}...literally...",
|
|
|
|
"Looks like {loser} didn't put enough points into kazoo playing, who knew they would have needed it",
|
|
|
|
"{loser} was too scared by the illuminati and extra-dimensional talking horses to show up",
|
|
|
|
"{loser} didn't press x enough to not die",
|
|
|
|
"{winner} and {loser} go fishing to settle their debate, {winner} caught a sizeable fish and {loser} caught a boot older than time",
|
|
|
|
"{winner} did a hero landing and {loser} was so surprised they gave up immediately"]
|
2016-10-03 07:08:20 +13:00
|
|
|
|
|
|
|
hugs = \
|
2017-07-31 11:27:19 +12:00
|
|
|
["*hugs {user}.*",
|
|
|
|
"*tackles {user} for a hug.*",
|
|
|
|
"*drags {user} into her dungeon where hugs ensue*",
|
|
|
|
"*pulls {user} to the side for a warm hug*",
|
|
|
|
"*goes out to buy a big enough blanket to embrace {user}*",
|
|
|
|
"*hard codes an electric hug to {user}*",
|
|
|
|
"*hires mercenaries to take {user} out....to a nice dinner*",
|
|
|
|
"*pays $10 to not touch {user}*",
|
|
|
|
"*clones herself to create a hug pile with {user}*",
|
|
|
|
"*orders an airstrike of hugs {user}*",
|
|
|
|
"*glomps {user}*",
|
|
|
|
"*hears a knock at her door, opens it, finds {user} and hugs them excitedly*",
|
|
|
|
"*goes in for a punch but misses and ends up hugging {user}*",
|
|
|
|
"*hugs {user} from behind*",
|
|
|
|
"*denies a hug from {user}*",
|
|
|
|
"*does a hug to {user}*",
|
|
|
|
"*lets {user} cuddle nonchalantly*",
|
|
|
|
"*cuddles {user}*",
|
|
|
|
"*burrows underground and pops up underneath {user} she hugs their legs.*",
|
|
|
|
"*approaches {user} after having gone to the gym for several months and almost crushes them.*"]
|
2016-10-03 07:08:20 +13:00
|
|
|
|
2016-10-02 15:51:04 +13:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
class Interaction:
|
2016-07-09 13:59:10 +12:00
|
|
|
"""Commands that interact with another user"""
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-08-22 07:37:12 +12:00
|
|
|
self.battles = {}
|
2017-06-28 14:08:25 +12:00
|
|
|
self.bot.br = BattleRankings(self.bot)
|
2017-06-28 15:01:47 +12:00
|
|
|
self.bot.br.update_start()
|
2016-08-31 10:33:46 +12:00
|
|
|
|
2017-05-02 08:57:32 +12:00
|
|
|
def get_battle(self, player):
|
|
|
|
battles = self.battles.get(player.guild.id)
|
|
|
|
|
|
|
|
if battles is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
for battle in battles:
|
|
|
|
if battle['p2'] == player.id:
|
|
|
|
return battle
|
|
|
|
|
2017-05-02 08:45:56 +12:00
|
|
|
def can_battle(self, player):
|
2017-05-02 08:48:29 +12:00
|
|
|
battles = self.battles.get(player.guild.id)
|
2017-05-02 08:45:56 +12:00
|
|
|
|
|
|
|
if battles is None:
|
2016-08-22 07:37:12 +12:00
|
|
|
return True
|
2017-05-02 08:45:56 +12:00
|
|
|
|
|
|
|
for x in battles:
|
2017-05-02 08:46:36 +12:00
|
|
|
if x['p1'] == player.id:
|
2017-05-02 08:45:56 +12:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def can_be_battled(self, player):
|
2017-05-02 08:48:29 +12:00
|
|
|
battles = self.battles.get(player.guild.id)
|
2017-05-02 08:45:56 +12:00
|
|
|
|
|
|
|
if battles is None:
|
2016-08-22 07:37:12 +12:00
|
|
|
return True
|
2017-05-02 08:45:56 +12:00
|
|
|
|
|
|
|
for x in battles:
|
2017-05-02 08:46:59 +12:00
|
|
|
if x['p2'] == player.id:
|
2017-05-02 08:45:56 +12:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2017-05-02 08:48:29 +12:00
|
|
|
def start_battle(self, player1, player2):
|
|
|
|
battles = self.battles.get(player1.guild.id, [])
|
2017-05-02 08:45:56 +12:00
|
|
|
entry = {
|
|
|
|
'p1': player1.id,
|
|
|
|
'p2': player2.id
|
|
|
|
}
|
|
|
|
battles.append(entry)
|
2017-05-02 08:48:29 +12:00
|
|
|
self.battles[player1.guild.id] = battles
|
2016-08-31 10:33:46 +12:00
|
|
|
|
2016-08-22 07:37:12 +12:00
|
|
|
# Handles removing the author from the dictionary of battles
|
2017-05-02 08:57:32 +12:00
|
|
|
def battling_off(self, player1=None, player2=None):
|
2017-05-02 09:01:53 +12:00
|
|
|
if player1:
|
|
|
|
guild = player1.guild.id
|
2017-06-28 13:57:19 +12:00
|
|
|
else:
|
2017-05-02 09:01:53 +12:00
|
|
|
guild = player2.guild.id
|
|
|
|
battles = self.battles.get(guild, [])
|
2017-05-02 08:45:56 +12:00
|
|
|
# Create a new list, exactly the way the last one was setup
|
|
|
|
# But don't include the one start with player's ID
|
2017-05-02 08:57:32 +12:00
|
|
|
new_battles = []
|
|
|
|
for b in battles:
|
|
|
|
if player1 and b['p1'] == player1.id:
|
|
|
|
continue
|
|
|
|
if player2 and b['p2'] == player2.id:
|
|
|
|
continue
|
|
|
|
new_battles.append(b)
|
2017-05-02 09:01:53 +12:00
|
|
|
self.battles[guild] = new_battles
|
2016-08-22 07:37:12 +12:00
|
|
|
|
2017-04-09 15:04:46 +12:00
|
|
|
@commands.command()
|
|
|
|
@commands.guild_only()
|
2017-02-18 08:48:45 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-06-28 12:26:32 +12:00
|
|
|
@utils.check_restricted()
|
2017-08-07 09:16:30 +12:00
|
|
|
async def hug(self, ctx, user = None):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Makes me hug a person!
|
|
|
|
|
|
|
|
EXAMPLE: !hug @Someone
|
|
|
|
RESULT: I hug the shit out of that person"""
|
2017-08-07 09:16:30 +12:00
|
|
|
if ctx.message.mention_everyone:
|
|
|
|
await ctx.send("Your arms aren't big enough")
|
|
|
|
return
|
2016-10-02 15:51:04 +13:00
|
|
|
if user is None:
|
|
|
|
user = ctx.message.author
|
2017-08-07 09:16:30 +12:00
|
|
|
else:
|
|
|
|
converter = commands.converter.MemberConverter()
|
|
|
|
try:
|
2017-08-07 09:26:28 +12:00
|
|
|
user = await converter.convert(ctx, user)
|
2017-08-07 09:16:30 +12:00
|
|
|
except commands.converter.BadArgument:
|
|
|
|
await ctx.send("Error: Could not find user: {}".format(user))
|
|
|
|
return
|
|
|
|
|
2016-10-02 15:51:04 +13:00
|
|
|
|
2017-07-31 11:27:19 +12:00
|
|
|
# Lets get the settings
|
2017-07-31 13:12:36 +12:00
|
|
|
settings = self.bot.db.load('server_settings', key=ctx.message.guild.id) or {}
|
2017-07-31 11:27:19 +12:00
|
|
|
# Get the custom messages we can use
|
|
|
|
custom_msgs = settings.get('hugs')
|
2017-08-09 02:41:52 +12:00
|
|
|
default_on = settings.get('default_hugs')
|
2017-07-31 11:27:19 +12:00
|
|
|
# if they exist, then we want to see if we want to use default as well
|
|
|
|
if custom_msgs:
|
2017-08-09 02:41:52 +12:00
|
|
|
if default_on or default_on is None:
|
|
|
|
msgs = hugs + custom_msgs
|
2017-07-31 11:27:19 +12:00
|
|
|
else:
|
|
|
|
msgs = custom_msgs
|
|
|
|
# Otherwise we simply just want to use the default, no matter what the default setting is
|
|
|
|
else:
|
|
|
|
msgs = hugs
|
|
|
|
|
|
|
|
fmt = random.SystemRandom().choice(msgs)
|
|
|
|
await ctx.send(fmt.format(user=user.display_name))
|
2016-10-02 15:51:04 +13:00
|
|
|
|
2017-07-23 09:42:21 +12:00
|
|
|
@commands.command(aliases=['1v1'])
|
2017-04-09 15:04:46 +12:00
|
|
|
@commands.guild_only()
|
2017-06-07 20:30:19 +12:00
|
|
|
@commands.cooldown(1, 20, BucketType.user)
|
2017-02-18 08:48:45 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-06-28 12:26:32 +12:00
|
|
|
@utils.check_restricted()
|
2017-08-07 09:16:30 +12:00
|
|
|
async def battle(self, ctx, player2 = None):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Challenges the mentioned user to a battle
|
|
|
|
|
|
|
|
EXAMPLE: !battle @player2
|
|
|
|
RESULT: A battle to the death"""
|
2017-08-07 09:16:30 +12:00
|
|
|
# First check if everyone was mentioned
|
|
|
|
if ctx.message.mention_everyone:
|
|
|
|
await ctx.send("You want to battle {} people? Good luck with that...".format(len(ctx.message.channel.members) - 1))
|
|
|
|
return
|
|
|
|
# Then check if nothing was provided
|
|
|
|
if player2 is None:
|
|
|
|
await ctx.send("Who are you trying to battle...?")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# Otherwise, try to convert to an actual member
|
|
|
|
converter = commands.converter.MemberConverter()
|
|
|
|
try:
|
2017-08-07 09:26:28 +12:00
|
|
|
player2 = await converter.convert(ctx, player2)
|
2017-08-07 09:16:30 +12:00
|
|
|
except commands.converter.BadArgument:
|
|
|
|
await ctx.send("Error: Could not find user: {}".format(player2))
|
|
|
|
return
|
|
|
|
# Then check if the person used is the author
|
2016-07-10 00:57:25 +12:00
|
|
|
if ctx.message.author.id == player2.id:
|
2016-09-11 20:30:23 +12:00
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("Why would you want to battle yourself? Suicide is not the answer")
|
2016-07-10 00:57:25 +12:00
|
|
|
return
|
2017-08-07 09:16:30 +12:00
|
|
|
# Check if the person battled is me
|
2016-07-10 00:57:25 +12:00
|
|
|
if self.bot.user.id == player2.id:
|
2016-09-11 20:30:23 +12:00
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("I always win, don't even try it.")
|
2016-07-10 00:57:25 +12:00
|
|
|
return
|
2017-08-07 09:16:30 +12:00
|
|
|
# Next two checks are to see if the author or person battled can be battled
|
2017-05-02 08:45:56 +12:00
|
|
|
if not self.can_battle(ctx.message.author):
|
2016-09-11 20:30:23 +12:00
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-05-02 08:45:56 +12:00
|
|
|
await ctx.send("You are already battling someone!")
|
|
|
|
return
|
|
|
|
if not self.can_be_battled(player2):
|
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-05-06 16:59:16 +12:00
|
|
|
await ctx.send("{} is already being challenged to a battle!".format(player2))
|
2016-07-19 02:26:11 +12:00
|
|
|
return
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Add the author and player provided in a new battle
|
2017-05-02 08:49:26 +12:00
|
|
|
self.start_battle(ctx.message.author, player2)
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-10-18 06:51:02 +13:00
|
|
|
fmt = "{0.message.author.mention} has challenged you to a battle {1.mention}\n" \
|
|
|
|
"{0.prefix}accept or {0.prefix}decline"
|
2016-08-16 15:30:52 +12:00
|
|
|
# Add a call to turn off battling, if the battle is not accepted/declined in 3 minutes
|
2017-05-02 08:57:32 +12:00
|
|
|
part = functools.partial(self.battling_off, player1=ctx.message.author)
|
|
|
|
self.bot.loop.call_later(180, part)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send(fmt.format(ctx, player2))
|
2016-08-07 10:20:23 +12:00
|
|
|
|
2017-04-09 15:04:46 +12:00
|
|
|
@commands.command()
|
|
|
|
@commands.guild_only()
|
2017-02-18 08:48:45 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-06-28 12:26:32 +12:00
|
|
|
@utils.check_restricted()
|
2016-07-11 09:57:52 +12:00
|
|
|
async def accept(self, ctx):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Accepts the battle challenge
|
|
|
|
|
|
|
|
EXAMPLE: !accept
|
|
|
|
RESULT: Hopefully the other person's death"""
|
2016-08-22 07:37:12 +12:00
|
|
|
# This is a check to make sure that the author is the one being BATTLED
|
2016-10-02 14:47:14 +13:00
|
|
|
# And not the one that started the battle
|
2017-05-02 08:57:32 +12:00
|
|
|
battle = self.get_battle(ctx.message.author)
|
|
|
|
if battle is None:
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("You are not currently being challenged to a battle!")
|
2016-07-24 02:20:49 +12:00
|
|
|
return
|
2016-08-07 10:20:23 +12:00
|
|
|
|
2017-05-02 08:58:58 +12:00
|
|
|
battleP1 = discord.utils.find(lambda m: m.id == battle['p1'], ctx.message.guild.members)
|
2017-03-24 16:02:42 +13:00
|
|
|
if battleP1 is None:
|
|
|
|
await ctx.send("The person who challenged you to a battle has apparently left the server....why?")
|
|
|
|
return
|
|
|
|
|
2016-07-19 08:01:07 +12:00
|
|
|
battleP2 = ctx.message.author
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-07-31 11:27:19 +12:00
|
|
|
# Lets get the settings
|
2017-07-31 13:12:36 +12:00
|
|
|
settings = self.bot.db.load('server_settings', key=ctx.message.guild.id) or {}
|
2017-07-31 11:27:19 +12:00
|
|
|
# Get the custom messages we can use
|
|
|
|
custom_msgs = settings.get('battles')
|
2017-08-09 02:41:52 +12:00
|
|
|
default_on = settings.get('default_battles')
|
2017-07-31 11:27:19 +12:00
|
|
|
# if they exist, then we want to see if we want to use default as well
|
|
|
|
if custom_msgs:
|
2017-08-09 02:41:52 +12:00
|
|
|
if default_on or default_on is None:
|
|
|
|
msgs = battle_outcomes + custom_msgs
|
2017-07-31 11:27:19 +12:00
|
|
|
else:
|
2017-08-09 02:41:52 +12:00
|
|
|
msgs = custom_msgs
|
2017-07-31 11:27:19 +12:00
|
|
|
# Otherwise we simply just want to use the default, no matter what the default setting is
|
|
|
|
else:
|
|
|
|
msgs = battle_outcomes
|
|
|
|
|
|
|
|
fmt = random.SystemRandom().choice(msgs)
|
2016-08-22 07:37:12 +12:00
|
|
|
# Due to our previous checks, the ID should only be in the dictionary once, in the current battle we're checking
|
2017-05-02 08:57:32 +12:00
|
|
|
self.battling_off(player2=ctx.message.author)
|
2017-06-28 15:01:47 +12:00
|
|
|
await self.bot.br.update()
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# Randomize the order of who is printed/sent to the update system
|
2016-08-14 07:58:47 +12:00
|
|
|
if random.SystemRandom().randint(0, 1):
|
2017-06-28 15:01:47 +12:00
|
|
|
winner = battleP1
|
|
|
|
loser = battleP2
|
2016-07-24 02:20:49 +12:00
|
|
|
else:
|
2017-06-28 15:01:47 +12:00
|
|
|
winner = battleP2
|
|
|
|
loser = battleP1
|
|
|
|
|
2017-07-31 11:27:19 +12:00
|
|
|
msg = await ctx.send(fmt.format(winner=winner.display_name, loser=loser.display_name))
|
2017-06-28 15:01:47 +12:00
|
|
|
old_winner_rank, _ = self.bot.br.get_server_rank(winner)
|
|
|
|
old_loser_rank, _ = self.bot.br.get_server_rank(loser)
|
|
|
|
|
|
|
|
# Update our records; this will update our cache
|
|
|
|
await utils.update_records('battle_records', self.bot.db, winner, loser)
|
|
|
|
# Now wait a couple seconds to ensure cache is updated
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
await self.bot.br.update()
|
|
|
|
|
|
|
|
# Now get the new ranks after this stuff has been updated
|
|
|
|
new_winner_rank, _ = self.bot.br.get_server_rank(winner)
|
|
|
|
new_loser_rank, _ = self.bot.br.get_server_rank(loser)
|
|
|
|
fmt = msg.content
|
2017-06-29 07:53:28 +12:00
|
|
|
if old_winner_rank:
|
|
|
|
fmt += "\n{} - Rank: {} ( +{} )".format(winner.display_name, new_winner_rank, old_winner_rank - new_winner_rank)
|
|
|
|
else:
|
|
|
|
fmt += "\n{} - Rank: {}".format(winner.display_name, new_winner_rank)
|
|
|
|
if old_loser_rank:
|
|
|
|
fmt += "\n{} - Rank: {} ( -{} )".format(loser.display_name, new_loser_rank, new_loser_rank - old_loser_rank)
|
|
|
|
else:
|
|
|
|
fmt += "\n{} - Rank: {}".format(loser.display_name, new_loser_rank)
|
2017-06-28 15:01:47 +12:00
|
|
|
|
|
|
|
try:
|
2017-06-28 15:02:44 +12:00
|
|
|
await msg.edit(content=fmt)
|
2017-06-28 15:01:47 +12:00
|
|
|
except:
|
|
|
|
pass
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-04-09 15:04:46 +12:00
|
|
|
@commands.command()
|
|
|
|
@commands.guild_only()
|
2017-02-18 08:48:45 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-06-28 12:26:32 +12:00
|
|
|
@utils.check_restricted()
|
2016-07-11 09:57:52 +12:00
|
|
|
async def decline(self, ctx):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Declines the battle challenge
|
|
|
|
|
|
|
|
EXAMPLE: !decline
|
|
|
|
RESULT: You chicken out"""
|
2016-08-22 07:37:12 +12:00
|
|
|
# This is a check to make sure that the author is the one being BATTLED
|
2016-10-02 14:47:14 +13:00
|
|
|
# And not the one that started the battle
|
2017-05-02 08:57:32 +12:00
|
|
|
battle = self.get_battle(ctx.message.author)
|
|
|
|
if battle is None:
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("You are not currently being challenged to a battle!")
|
2016-07-24 02:20:49 +12:00
|
|
|
return
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2017-05-02 08:58:58 +12:00
|
|
|
battleP1 = discord.utils.find(lambda m: m.id == battle['p1'], ctx.message.guild.members)
|
2017-03-24 16:02:42 +13:00
|
|
|
if battleP1 is None:
|
|
|
|
await ctx.send("The person who challenged you to a battle has apparently left the server....why?")
|
|
|
|
return
|
|
|
|
|
2016-07-24 02:20:49 +12:00
|
|
|
battleP2 = ctx.message.author
|
2016-08-17 03:22:32 +12:00
|
|
|
|
2016-08-16 15:30:52 +12:00
|
|
|
# There's no need to update the stats for the members if they declined the battle
|
2017-05-06 16:59:16 +12:00
|
|
|
self.battling_off(player2=battleP2)
|
2017-05-03 08:15:30 +12:00
|
|
|
await ctx.send("{} has chickened out! What a loser~".format(battleP2.mention))
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2017-06-07 20:38:08 +12:00
|
|
|
@commands.command()
|
2017-04-09 15:04:46 +12:00
|
|
|
@commands.guild_only()
|
2017-06-07 20:30:19 +12:00
|
|
|
@commands.cooldown(1, 10, BucketType.user)
|
2017-02-18 08:48:45 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-06-28 12:26:32 +12:00
|
|
|
@utils.check_restricted()
|
2017-03-08 11:35:30 +13:00
|
|
|
async def boop(self, ctx, boopee: discord.Member = None, *, message=""):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Boops the mentioned person
|
|
|
|
|
|
|
|
EXAMPLE: !boop @OtherPerson
|
|
|
|
RESULT: You do a boop o3o"""
|
2016-08-17 03:22:32 +12:00
|
|
|
booper = ctx.message.author
|
2016-09-22 07:16:47 +12:00
|
|
|
if boopee is None:
|
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("You try to boop the air, the air boops back. Be afraid....")
|
2016-09-22 07:16:47 +12:00
|
|
|
return
|
2016-12-02 14:28:13 +13:00
|
|
|
# To keep formatting easier, keep it either "" or the message with a space in front
|
|
|
|
if message is not None:
|
|
|
|
message = " " + message
|
2016-07-10 00:57:25 +12:00
|
|
|
if boopee.id == booper.id:
|
2016-09-11 20:30:23 +12:00
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("You can't boop yourself! Silly...")
|
2016-07-10 00:57:25 +12:00
|
|
|
return
|
|
|
|
if boopee.id == self.bot.user.id:
|
2016-09-11 20:30:23 +12:00
|
|
|
ctx.command.reset_cooldown(ctx)
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send("Why the heck are you booping me? Get away from me >:c")
|
2016-07-10 00:57:25 +12:00
|
|
|
return
|
|
|
|
|
2017-03-08 20:55:22 +13:00
|
|
|
key = str(booper.id)
|
2017-06-07 20:30:19 +12:00
|
|
|
boops = self.bot.db.load('boops', key=key, pluck='boops') or {}
|
|
|
|
amount = boops.get(str(boopee.id), 0) + 1
|
|
|
|
entry = {
|
|
|
|
'member_id': str(booper.id),
|
|
|
|
'boops': {
|
|
|
|
str(boopee.id): amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.bot.db.save('boops', entry)
|
2016-07-18 09:10:12 +12:00
|
|
|
|
2016-12-02 14:28:13 +13:00
|
|
|
fmt = "{0.mention} has just booped {1.mention}{3}! That's {2} times now!"
|
2017-03-06 15:45:44 +13:00
|
|
|
await ctx.send(fmt.format(booper, boopee, amount, message))
|
2016-07-09 13:27:19 +12:00
|
|
|
|
|
|
|
|
2017-06-28 15:01:47 +12:00
|
|
|
# noinspection PyMethodMayBeStatic
|
2017-06-28 13:57:19 +12:00
|
|
|
class BattleRankings:
|
2017-06-28 14:08:25 +12:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.db = bot.db
|
|
|
|
self.loop = bot.loop
|
2017-06-28 13:57:19 +12:00
|
|
|
self.ratings = None
|
|
|
|
|
2017-06-28 15:01:47 +12:00
|
|
|
def build_dict(self, seq, key):
|
|
|
|
return dict((d[key], dict(d, rank=index + 1)) for (index, d) in enumerate(seq[::-1]))
|
2017-06-28 14:08:25 +12:00
|
|
|
|
2017-06-28 15:01:47 +12:00
|
|
|
def update_start(self):
|
|
|
|
self.loop.create_task(self.update())
|
|
|
|
|
|
|
|
async def update(self):
|
2017-06-28 13:57:19 +12:00
|
|
|
ratings = await self.db.query(r.table('battle_records').order_by('rating'))
|
|
|
|
|
|
|
|
# Create a dictionary so that we have something to "get" from easily
|
2017-06-28 15:01:47 +12:00
|
|
|
self.ratings = self.build_dict(ratings, 'member_id')
|
2017-06-28 13:57:19 +12:00
|
|
|
|
2017-06-28 15:56:08 +12:00
|
|
|
def get_record(self, member):
|
2017-06-28 15:58:38 +12:00
|
|
|
data = self.ratings.get(str(member.id), {})
|
2017-06-28 15:56:08 +12:00
|
|
|
fmt = "{} - {}".format(data.get('wins'), data.get('losses'))
|
|
|
|
return fmt
|
|
|
|
|
2017-06-28 13:57:19 +12:00
|
|
|
def get_rating(self, member):
|
2017-06-28 15:58:38 +12:00
|
|
|
data = self.ratings.get(str(member.id), {})
|
2017-06-28 13:57:19 +12:00
|
|
|
return data.get('rating')
|
|
|
|
|
|
|
|
def get_rank(self, member):
|
2017-06-28 15:58:38 +12:00
|
|
|
data = self.ratings.get(str(member.id), {})
|
2017-06-28 13:57:19 +12:00
|
|
|
return data.get('rank'), len(self.ratings)
|
|
|
|
|
|
|
|
def get_server_rank(self, member):
|
2017-06-28 15:48:52 +12:00
|
|
|
# Get the id's of all the members to compare to
|
2017-06-28 13:57:19 +12:00
|
|
|
server_ids = [str(m.id) for m in member.guild.members]
|
2017-06-28 15:48:52 +12:00
|
|
|
# Get all the ratings for members in this server
|
|
|
|
ratings = [x for x in self.ratings.values() if x['member_id'] in server_ids]
|
|
|
|
# Since we went from a dictionary to a list, we're no longer sorted, sort this
|
|
|
|
ratings = sorted(ratings, key=lambda x: x['rating'])
|
|
|
|
# Build our dictionary to get correct rankings
|
|
|
|
server_ratings = self.build_dict(ratings, 'member_id')
|
|
|
|
# Return the rank
|
2017-06-28 15:05:00 +12:00
|
|
|
return server_ratings.get(str(member.id), {}).get('rank'), len(server_ratings)
|
2017-06-28 13:57:19 +12:00
|
|
|
|
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Interaction(bot))
|