|
|
@ -1,11 +1,9 @@
|
|
|
|
import discord
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from collections import defaultdict
|
|
|
|
from collections import defaultdict
|
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
from random import randint
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
|
|
|
|
from redbot.core import Config, checks, RedContext
|
|
|
|
import discord
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
from redbot.core import Config, checks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hangman:
|
|
|
|
class Hangman:
|
|
|
@ -20,7 +18,8 @@ class Hangman:
|
|
|
|
|
|
|
|
|
|
|
|
self.config.register_guild(**default_guild)
|
|
|
|
self.config.register_guild(**default_guild)
|
|
|
|
|
|
|
|
|
|
|
|
self.the_data = defaultdict(lambda:{"running": False, "hangman": 0, "guesses": [], "trackmessage": False, "answer": ''})
|
|
|
|
self.the_data = defaultdict(
|
|
|
|
|
|
|
|
lambda: {"running": False, "hangman": 0, "guesses": [], "trackmessage": False, "answer": ''})
|
|
|
|
self.answer_path = "hangman/data/hanganswers.txt"
|
|
|
|
self.answer_path = "hangman/data/hanganswers.txt"
|
|
|
|
self.winbool = defaultdict(lambda: False)
|
|
|
|
self.winbool = defaultdict(lambda: False)
|
|
|
|
|
|
|
|
|
|
|
@ -58,7 +57,7 @@ class Hangman:
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\_________
|
|
|
|
\_________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +68,7 @@ class Hangman:
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\________
|
|
|
|
\________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,11 +76,10 @@ class Hangman:
|
|
|
|
|\___
|
|
|
|
|\___
|
|
|
|
HAN""",
|
|
|
|
HAN""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\_________
|
|
|
|
\_________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
| /|
|
|
|
|
| /|
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,11 +87,10 @@ class Hangman:
|
|
|
|
|\___
|
|
|
|
|\___
|
|
|
|
HANG""",
|
|
|
|
HANG""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\_________
|
|
|
|
\_________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
| /|\
|
|
|
|
| /|\
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -101,12 +98,10 @@ class Hangman:
|
|
|
|
|\___
|
|
|
|
|\___
|
|
|
|
HANGM""",
|
|
|
|
HANGM""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\________
|
|
|
|
\________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
| /|\
|
|
|
|
| /|\
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| /
|
|
|
|
| /
|
|
|
@ -114,11 +109,10 @@ class Hangman:
|
|
|
|
|\___
|
|
|
|
|\___
|
|
|
|
HANGMA""",
|
|
|
|
HANGMA""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""">
|
|
|
|
""">
|
|
|
|
\________
|
|
|
|
\________
|
|
|
|
|/ |
|
|
|
|
|/ |
|
|
|
|
| """+theface+"""
|
|
|
|
| """ + theface + """
|
|
|
|
| /|\
|
|
|
|
| /|\
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| / \
|
|
|
|
| / \
|
|
|
@ -136,7 +130,7 @@ class Hangman:
|
|
|
|
@hangset.command(pass_context=True)
|
|
|
|
@hangset.command(pass_context=True)
|
|
|
|
async def face(self, ctx: commands.Context, theface):
|
|
|
|
async def face(self, ctx: commands.Context, theface):
|
|
|
|
message = ctx.message
|
|
|
|
message = ctx.message
|
|
|
|
#Borrowing FlapJack's emoji validation (https://github.com/flapjax/FlapJack-Cogs/blob/master/smartreact/smartreact.py)
|
|
|
|
# Borrowing FlapJack's emoji validation (https://github.com/flapjax/FlapJack-Cogs/blob/master/smartreact/smartreact.py)
|
|
|
|
if theface[:2] == "<:":
|
|
|
|
if theface[:2] == "<:":
|
|
|
|
theface = [r for r in self.bot.emojis if r.id == theface.split(':')[2][:-1]][0]
|
|
|
|
theface = [r for r in self.bot.emojis if r.id == theface.split(':')[2][:-1]][0]
|
|
|
|
|
|
|
|
|
|
|
@ -152,7 +146,7 @@ class Hangman:
|
|
|
|
await ctx.send("Face has been updated!")
|
|
|
|
await ctx.send("Face has been updated!")
|
|
|
|
|
|
|
|
|
|
|
|
@commands.command(aliases=['hang'], pass_context=True)
|
|
|
|
@commands.command(aliases=['hang'], pass_context=True)
|
|
|
|
async def hangman(self, ctx, guess: str=None):
|
|
|
|
async def hangman(self, ctx, guess: str = None):
|
|
|
|
"""Play a game of hangman against the bot!"""
|
|
|
|
"""Play a game of hangman against the bot!"""
|
|
|
|
if guess is None:
|
|
|
|
if guess is None:
|
|
|
|
if self.the_data[ctx.guild]["running"]:
|
|
|
|
if self.the_data[ctx.guild]["running"]:
|
|
|
@ -170,7 +164,6 @@ class Hangman:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await self._guessletter(guess, ctx.channel)
|
|
|
|
await self._guessletter(guess, ctx.channel)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _startgame(self, guild):
|
|
|
|
def _startgame(self, guild):
|
|
|
|
"""Starts a new game of hangman"""
|
|
|
|
"""Starts a new game of hangman"""
|
|
|
|
self.the_data[guild]["answer"] = self._getphrase().upper()
|
|
|
|
self.the_data[guild]["answer"] = self._getphrase().upper()
|
|
|
@ -191,7 +184,7 @@ class Hangman:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if self.the_data[channel.guild]["hangman"] >= 7:
|
|
|
|
if self.the_data[channel.guild]["hangman"] >= 7:
|
|
|
|
await channel.send("You Lose!\nThe Answer was: **"+self.the_data[channel.guild]["answer"]+"**")
|
|
|
|
await channel.send("You Lose!\nThe Answer was: **" + self.the_data[channel.guild]["answer"] + "**")
|
|
|
|
|
|
|
|
|
|
|
|
self._stopgame(channel.guild)
|
|
|
|
self._stopgame(channel.guild)
|
|
|
|
|
|
|
|
|
|
|
@ -202,7 +195,7 @@ class Hangman:
|
|
|
|
|
|
|
|
|
|
|
|
outphrase = ""
|
|
|
|
outphrase = ""
|
|
|
|
while outphrase == "":
|
|
|
|
while outphrase == "":
|
|
|
|
outphrase = phrases[randint(0, len(phrases)-1)].partition(" (")[0]
|
|
|
|
outphrase = phrases[randint(0, len(phrases) - 1)].partition(" (")[0]
|
|
|
|
return outphrase
|
|
|
|
return outphrase
|
|
|
|
|
|
|
|
|
|
|
|
def _hideanswer(self):
|
|
|
|
def _hideanswer(self):
|
|
|
@ -212,9 +205,9 @@ class Hangman:
|
|
|
|
self.winbool = True
|
|
|
|
self.winbool = True
|
|
|
|
for i in self.the_data["answer"]:
|
|
|
|
for i in self.the_data["answer"]:
|
|
|
|
if i == " " or i == "-":
|
|
|
|
if i == " " or i == "-":
|
|
|
|
out_str += i*2
|
|
|
|
out_str += i * 2
|
|
|
|
elif i in self.the_data["guesses"] or i not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
|
|
|
|
elif i in self.the_data["guesses"] or i not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
|
|
|
|
out_str += "__"+i+"__ "
|
|
|
|
out_str += "__" + i + "__ "
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
out_str += "**\_** "
|
|
|
|
out_str += "**\_** "
|
|
|
|
self.winbool = False
|
|
|
|
self.winbool = False
|
|
|
@ -250,8 +243,6 @@ class Hangman:
|
|
|
|
""" Thanks to flapjack reactpoll for guidelines
|
|
|
|
""" Thanks to flapjack reactpoll for guidelines
|
|
|
|
https://github.com/flapjax/FlapJack-Cogs/blob/master/reactpoll/reactpoll.py"""
|
|
|
|
https://github.com/flapjax/FlapJack-Cogs/blob/master/reactpoll/reactpoll.py"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not self.the_data["trackmessage"]:
|
|
|
|
if not self.the_data["trackmessage"]:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
@ -267,7 +258,6 @@ class Hangman:
|
|
|
|
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[self.letters.index(str(emoji))]
|
|
|
|
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[self.letters.index(str(emoji))]
|
|
|
|
await self._guessletter(letter, message.channel)
|
|
|
|
await self._guessletter(letter, message.channel)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if str(emoji) in self.navigate:
|
|
|
|
if str(emoji) in self.navigate:
|
|
|
|
if str(emoji) == self.navigate[0]:
|
|
|
|
if str(emoji) == self.navigate[0]:
|
|
|
|
await self._reactmessage_am(message)
|
|
|
|
await self._reactmessage_am(message)
|
|
|
@ -275,7 +265,6 @@ class Hangman:
|
|
|
|
if str(emoji) == self.navigate[-1]:
|
|
|
|
if str(emoji) == self.navigate[-1]:
|
|
|
|
await self._reactmessage_nz(message)
|
|
|
|
await self._reactmessage_nz(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _reactmessage_menu(self, message):
|
|
|
|
async def _reactmessage_menu(self, message):
|
|
|
|
"""React with menu options"""
|
|
|
|
"""React with menu options"""
|
|
|
|
await message.clear_reactions()
|
|
|
|
await message.clear_reactions()
|
|
|
@ -287,7 +276,7 @@ class Hangman:
|
|
|
|
await message.clear_reactions()
|
|
|
|
await message.clear_reactions()
|
|
|
|
|
|
|
|
|
|
|
|
for x in range(len(self.letters)):
|
|
|
|
for x in range(len(self.letters)):
|
|
|
|
if x in [i for i,b in enumerate("ABCDEFGHIJKLM") if b not in self._guesslist()]:
|
|
|
|
if x in [i for i, b in enumerate("ABCDEFGHIJKLM") if b not in self._guesslist()]:
|
|
|
|
await message.add_reaction(self.letters[x])
|
|
|
|
await message.add_reaction(self.letters[x])
|
|
|
|
|
|
|
|
|
|
|
|
await message.add_reaction(self.navigate[-1])
|
|
|
|
await message.add_reaction(self.navigate[-1])
|
|
|
@ -296,18 +285,17 @@ class Hangman:
|
|
|
|
await self.bot.clear_reactions(message)
|
|
|
|
await self.bot.clear_reactions(message)
|
|
|
|
|
|
|
|
|
|
|
|
for x in range(len(self.letters)):
|
|
|
|
for x in range(len(self.letters)):
|
|
|
|
if x in [i for i,b in enumerate("NOPQRSTUVWXYZ") if b not in self._guesslist()]:
|
|
|
|
if x in [i for i, b in enumerate("NOPQRSTUVWXYZ") if b not in self._guesslist()]:
|
|
|
|
await message.add_reaction(self.letters[x+13])
|
|
|
|
await message.add_reaction(self.letters[x + 13])
|
|
|
|
|
|
|
|
|
|
|
|
await message.add_reaction(self.navigate[0])
|
|
|
|
await message.add_reaction(self.navigate[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _printgame(self, channel):
|
|
|
|
async def _printgame(self, channel):
|
|
|
|
"""Print the current state of game"""
|
|
|
|
"""Print the current state of game"""
|
|
|
|
cSay = ("Guess this: " + str(self._hideanswer()) + "\n"
|
|
|
|
cSay = ("Guess this: " + str(self._hideanswer()) + "\n"
|
|
|
|
+ "Used Letters: " + str(self._guesslist()) + "\n"
|
|
|
|
+ "Used Letters: " + str(self._guesslist()) + "\n"
|
|
|
|
+ self.hanglist[self.the_data["hangman"]] + "\n"
|
|
|
|
+ self.hanglist[self.the_data["hangman"]] + "\n"
|
|
|
|
+ self.navigate[0]+" for A-M, "+self.navigate[-1]+" for N-Z")
|
|
|
|
+ self.navigate[0] + " for A-M, " + self.navigate[-1] + " for N-Z")
|
|
|
|
|
|
|
|
|
|
|
|
message = await channel.send(cSay)
|
|
|
|
message = await channel.send(cSay)
|
|
|
|
|
|
|
|
|
|
|
@ -321,4 +309,3 @@ def setup(bot):
|
|
|
|
n = Hangman(bot)
|
|
|
|
n = Hangman(bot)
|
|
|
|
bot.add_cog(n)
|
|
|
|
bot.add_cog(n)
|
|
|
|
bot.add_listener(n._on_react, "on_reaction_add")
|
|
|
|
bot.add_listener(n._on_react, "on_reaction_add")
|
|
|
|
|
|
|
|
|
|
|
|