# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap
# 
# Path: cardinal/util.py
# def sleep(secs):
#     """Async sleep function"""
#     return deferLater(reactor, secs, lambda: None)


import random
from twisted.internet import defer
from cardinal.decorators import command, help
from cardinal.util import sleep



class Magic8BallPlugin:
    @command(['8', '8ball'])
    @help("Ask the might 8-ball a question.")
    @help("Syntax: .8 <question>")
    @defer.inlineCallbacks
    def answer(self, cardinal, user, channel, msg):
        if not (msg.endswith("?") and len(msg.split()) > 1):
            cardinal.sendMsg(channel, "Was that a question?")
            return

        cardinal.sendMsg(
            channel,
            "Let me dig deep into the waters of life, and find your answer."
        )
        yield sleep(2)
        cardinal.sendMsg(channel, "Hmmm...")
        yield sleep(2)
        cardinal.sendMsg(channel, self._get_random_answer())

    def _get_random_answer(self):
        answers = ['It is certain', 'It is decidedly so', 'Without a doubt',
                   'Yes definitely', 'You may rely on it', 'As I see it, yes',
                   'Most likely', 'Outlook good', 'Yes', 'Signs point to yes',
                   'Reply hazy try again', 'Ask again later',
                   'Better not tell you now', 'Cannot predict now',
                   'Concentrate and ask again', "Don't count on it",
                   'My reply is no', 'My sources say no',

# Path: cardinal/decorators.py
# def command(triggers):
#     if isinstance(triggers, str):
#         triggers = [triggers]
# 
#     if not isinstance(triggers, list):
#         raise TypeError("Command must be a trigger string or list of triggers")
# 
#     def wrap(f):
#         f.commands = triggers
#         return f
# 
#     return wrap
# 
# def help(lines):
#     # For backwards compatibility
#     if isinstance(lines, str):
#         lines = [lines]
# 
#     if not isinstance(lines, list):
#         raise TypeError("Help must be a help string or list of help strings")
# 
#     def wrap(f):
#         # Create help list or prepend to it
#         if not hasattr(f, 'help'):
#             f.help = lines
#         else:
#             f.help = lines + f.help
# 
#         return f
# 
#     return wrap
# 
# Path: cardinal/util.py
# def sleep(secs):
#     """Async sleep function"""
#     return deferLater(reactor, secs, lambda: None)


# Path: plugins/8ball/plugin.py
import random
from twisted.internet import defer
from cardinal.decorators import command, help
from cardinal.util import sleep




class Magic8BallPlugin:
    @command(['8', '8ball'])
    @help("Ask the might 8-ball a question.")
    @help("Syntax: .8 <question>")
    @defer.inlineCallbacks
    def answer(self, cardinal, user, channel, msg):
        if not (msg.endswith("?") and len(msg.split()) > 1):
            cardinal.sendMsg(channel, "Was that a question?")
            return

        cardinal.sendMsg(
            channel,
            "Let me dig deep into the waters of life, and find your answer."
        )
        yield sleep(2)
        cardinal.sendMsg(channel, "Hmmm...")
        yield sleep(2)
        cardinal.sendMsg(channel, self._get_random_answer())

    def _get_random_answer(self):
        answers = ['It is certain', 'It is decidedly so', 'Without a doubt',
                   'Yes definitely', 'You may rely on it', 'As I see it, yes',
                   'Most likely', 'Outlook good', 'Yes', 'Signs point to yes',
                   'Reply hazy try again', 'Ask again later',
                   'Better not tell you now', 'Cannot predict now',
                   'Concentrate and ask again', "Don't count on it",
                   'My reply is no', 'My sources say no',

                   'Outlook not so good', 'Very doubtful']