import random

from hamper.interfaces import ChatPlugin
from hamper.utils import ude

platitudes = [
    "Analysis without numbers is only an opinion.",
    "This is why it's a good idea to design them to operate when some things are wrong .",
    "This is true at any point in time.",
    "Learn to live with the disappointment.",
    "Three points determine a curve.",
    "Everything is linear if plotted log-log with a fat magic marker.",
    "At the start of any design effort, the person who most wants to be team leader is least likely to be capable of it.",
    "Distrust assertions that the optimum is at an extreme point.",
    "Not having all the information you need is never a satisfactory excuse for not starting the analysis.",
    "But be sure to go back and clean up the mess when the real numbers come along.",
    "Sometimes, the fastest way to get to the end is to throw everything out and start over.",
    "There are always multiple wrong ones, though.",
    "There's no justification for designing something one bit better than the requirements dictate.",
    "Better is the enemy of good.",
    "This is also the prime location for screwing it up.",
    "There is especially no reason to present their analysis as yours.",
    "The fact that an analysis appears in print has no relationship to the likelihood of its being correct.",
    "Too much reality can doom an otherwise worthwhile design, though.",
    "If your analysis says your terminal velocity is twice the speed of light, you may have invented warp drive, but the chances are a lot better that you've screwed up.",
    "A good design with a bad presentation is doomed immediately.",
    "Education is figuring out which half is which.",
    "Documentation requirements will reach a maximum shortly after the termination of a program.",
    "The schedule you develop will seem like a complete work of fiction up until the time your customer fires you for not meeting it.",
    "It's called a Work Breakdown Structure because the Work remaining will grow until you have a Breakdown, unless you enforce some Structure on it.",
    "Following a testing failure, it's always possible to refine the analysis to show that you really had negative margins all along.",
    "Don't do nuthin' dumb.",
    "Schedules only move in one direction.",
    "There ain't no such thing as a free launch.",
    "To get an accurate estimate of final program requirements, multiply the initial time estimates by pi, and slide the decimal point on the cost estimates one place to the right.",
    "Engineers always wind up designing the vehicle to look like the initial artist's concept.",
    "You can't get to the moon by climbing successively taller trees.",
    "When the hardware is working perfectly, the really important visitors don't show up.",
    "A good plan violently executed now is better than a perfect plan next week.",
    "Do what you can, where you are, with what you have.",
    "A designer knows that he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.",
    "A great engineer designs them to be effective.",
    "One key to success in a mission is establishing clear lines of blame.",
    "Capabilities drive requirements, regardless of what the systems engineering textbooks say.",
    "Any exploration program which just happens to include a new launch vehicle is, de facto, a launch vehicle program.",
    "You can't make it better until you make it work.",
    "There's never enough time to do it right, but somehow, there's always enough time to do it over.",
    "If you screw up the engineering, somebody dies (and there's no partial credit because most of the analysis was right...)",
    "A waste of time",
    "All for one, and one for all",
    "All is fair in love and war",
    "All’s well that ends well",
    "And they all lived happily ever after",
    "At least you're not homeless.",
    "At the speed of light",
    "Better out than in",
    "Brevity is the soul of wit.",
    "Cat got your tongue?",
    "Do as I say,not as I do.",
    "Don't dwell on it.",
    "Don't let it bother you.",
    "Don't let it eat at you.",
    "Don't let it get you down.",
    "Don't let life get you down.",
    "Don't linger on the past.",
    "Don’t cry over spilt milk",
    "Don’t get your knickers in a twist",
    "Every cloud has a silver lining",
    "Everything happens for a reason.",
    "Everything's going to be OK.",
    "Frightened to death",
    "Get on with your life.",
    "Good things come to people who wait.",
    "Good things happen to those who wait.",
    "Gut-wrenching pain",
    "Happiness is a choice.",
    "Haste makes waste",
    "He has his tail between his legs",
    "Head over heels in love",
    "Heart-stopping fear",
    "I feel your pain.",
    "I share your pain.",
    "I understand this is difficult for you.",
    "If at first you don't succeed, try, try again.",
    "If life gives you lemons, make lemonade.",
    "If you can't say something nice, don't say anything at all.",
    "If you knew what I knew, you'd think differently.",
    "In a jiffy ",
    "In the nick of time",
    "It all comes out in the wash.",
    "It can't be that bad.",
    "It could be worse.",
    "It is what it is.",
    "It was just their time to go.",
    "It was meant to be.",
    "It wasn't meant to be.",
    "It will all be worth it in the end.",
    "It's God's will.",
    "It's OK.",
    "It's for your own good.",
    "It's in the past.",
    "It's not rocket science.",
    "Just a matter of time",
    "Just be yourself.",
    "Just don't think about it.",
    "Just follow your heart.",
    "Just give it time.",
    "Just think positive.",
    "Just try harder next time.",
    "Karma's a hunter2.",
    "Keep a stiff upper lip.",
    "Kiss and make up",
    "Lasted an eternity",
    "Laughter is the best medicine",
    "Let it slide off your back.",
    "Life doesn't give you things you can't handle.",
    "Live and let live.",
    "Look on the bright side.",
    "Lost track of time",
    "Love you more than life itself",
    "Maybe your heart just isn't in to it.",
    "No good deed goes unpunished.",
    "No matter what you do, it's always something.",
    "Not all that glitters is gold",
    "Nothing is impossible.",
    "One day you'll see things differently.",
    "Only time will tell",
    "Opposites attract",
    "Other people go through this every day.",
    "Our hearts go out to them",
    "Our thoughts and prayers go out to them",
    "Own it and move on.",
    "Patience is a virtue.",
    "Perception is reality.",
    "Read between the lines",
    "Rushed for time",
    "Scared out of my wits",
    "Someone woke up on the wrong side of the bed",
    "Something will turn up.",
    "Such is life.",
    "Take it one day at a time.",
    "The best revenge is to have a fulfilling life.",
    "The calm before the storm",
    "The only thing to fear is fear itself.",
    "The time of my life",
    "The writing's on the wall",
    "There is someone worse off than you.",
    "There's plenty of fish in the sea.",
    "There's somebody out there for everyone.",
    "They don't deserve you.",
    "They weren't right for you anyway.",
    "They're in a better place.",
    "Things will get easier.",
    "Things will work out.",
    "Things would be better if you were more positive.",
    "This is just a bump in the road.",
    "This is life.",
    "This too shall pass.",
    "Time heals all wounds",
    "Time heals all wounds.",
    "Time will tell.",
    "Tomorrow will be better.",
    "Tomorrow's another day.",
    "We all have problems.",
    "We all have to do things we don't want to do.",
    "We're not laughing at you we’re laughing with you",
    "What doesn't kill you makes you stronger.",
    "What goes around comes around",
    "What's done is done.",
    "When life gives you lemons, make lemonade",
    "You can be anything you want to be.",
    "You can do so much better.",
    "You did the best you could.",
    "You did this to yourself.",
    "You don't need people like that in your life.",
    "You gotta do what you gotta do.",
    "You have to know your limitations.",
    "You have to move on.",
    "You have your whole life ahead of you.",
    "You just have to try a little harder.",
    "You just haven't met the right person yet.",
    "You just need some sleep.",
    "You just need to believe in yourself.",
    "You just need to get over it.",
    "You look OK.",
    "You still have your health.",
    "You'll be OK.",
    "You'll be back in the game before you know it.",
    "You'll be better off for this.",
    "You'll be fine.",
    "You'll get better at it.",
    "You'll get over it.",
    "You'll get through it.",
    "You'll get used to it.",
    "You'll thank me for this one day.",
    "You're better off without them.",
    "You're better than this.",
    "You're lucky to be alive.",
    "You're making a mountain out of a molehill.",
    "You're paddling against the current.",
    "Your negativity is your only hurdle.",
    "Your time will come.",
    "Between a rock and a hard place",
    "Absence makes the heart grow fonder",
    "The way to someone's heart is between the third and fourth ribs",
    "Darned if you do, darned if you don't.",
]

class PlatitudesPlugin(ChatPlugin):
    """If you can't say something nice, don't say anything at all."""

    name = 'platitudes'
    priority = -3

    def setup(self, *args):
        pass

    def contemplate(self, bot, comm):
        resp = random.choice(platitudes)
        bot.reply(comm, resp)
        return True

    def inform(self, bot, comm):
        resp = random.choice(platitudes)
        bot.reply(comm, '{0}: {1}'.format(comm['user'], resp))
        return True

    def message(self, bot, comm):
        msg = ude(comm['message'].strip())
        if comm['directed']:
            if not '?' in msg:
                if random.random() < .3:
                    self.inform(bot, comm)
                else:
                    self.contemplate(bot, comm)
                return True
        elif random.random() < .0001:
            # Occasionally pipe up
            if random.random() < .2:
                self.inform(bot, comm)
            else:
                self.contemplate(bot, comm)
            return True
        return False


