Skip to content

Commit

Permalink
Merge pull request idooo#4 from shousper/tell-things
Browse files Browse the repository at this point in the history
Tell things + LEGO fixes.
  • Loading branch information
idooo committed Jul 15, 2014
2 parents 3842f7a + 3cc3a80 commit edf5bc9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Simple bot created for fun. + [Campfire version](https://github.com/idooo/pancak
+ get random XKCD comics (http://xkcd.com/xxxx/info.0.json)
+ get random gif by keyword (http://api.giphy.com/)
+ get random LEGO Movie quotes
+ tell users things
+ ask bot a question

Type `/help` to see all available commands and detailed description
Expand Down
38 changes: 19 additions & 19 deletions src/_lego_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

LEGO_QUOTES = [
"He is coming... cover your butt.",
"You've hidden the Kragl well old man. Robots! Destroy him.",
"Your robots are no match for a Master Builder for I see everything.",
"You've hidden the Kragle well old man. Robots! Destroy him.",
"Your robots are no match for a Master Builder, for I see everything!",
"Ahh Haa Haa! Now my evil power will be unlimited. Can you feel me?!",
"One day, a talented lass or fellow, a special one with face of yellow, will make the Piece of Resistance found from it's hiding refuge underground, and with a noble army at the helm, this Master Builder will thwart the Kragle and save the realm, and be the greatest, most interesting, most important person of all times. All this is true because it rhymes.",
"One day a talented lass or fellow, a special one, with face of yellow, will make the Piece of Resistance found, from it's hiding refuge underground. And with a noble army at the helm, this Master Builder will thwart the Kragle and save the realm, and be the greatest, most interesting, most important person of all times. All this is true because it rhymes.",
"All this is true because it rhymes.",
"Ohh! Wow! That was a great inspiring legend that you made up.",
"What a load of hippy dippy baloney.",
"Goooood morning apartment. Good morning doorway, morning wall, morning ceiling, good morning floooorrr. Ready to start the day!",
"Ahh! Here it is. Instructions to fit in, have everybody like and always be happy!",
"Ohh! Wow! That was a great inspiring legend.. that you made up.",
"What a load of hippie dippie baloney.",
"Goooood morning apartment. Good morning doorway, morning wall, morning ceiling, good morning floooorr. Ready to start the day!",
"Ahh, here it is. Instructions to fit in, have everybody like you and always be happy!",
"Step 1: Breathe.",
"Step 2: Greet the day, smile and say: \"Good morning, city!\"",
"Step 3: Exercise. Jumpin' Jacks, hit 'em!.. 1... 2... 3... Haha, I am so pumped up!",
"Step 4: Shower... and always be sure to keep the soap out of yo- AAHHHHH!",
"Wear clothes. Ooops! Almost forgot that one!",
"Hey Planty, what'd you wanna do this morning? Watch TV? Me too!",
"Hi, I'm President Business, president of the Octan corporation and the world. Lets take special care to follow the instructions *whispers* or you'll be put to sleep. And don't forget Taco Tuesday is coming up! That's the day everyone gets a free Taco and my love! You have a great day everyone.",
"Hi, I'm President Business, president of the Octan corporation and the world. Let's take special care to follow the instructions, or you'll be put to sleep. And don't forget Taco Tuesday is coming up! That's the day everyone gets a free taco and my love! You have a great day everyone.",
"You have a great day too President Business. Man, he's such a cool guy, I always wanna hear more of- Wait, did he say put to sleep?!",
"Honey, where are my paaaaannts?",
"What was I just thinkin'? I don't care :D",
"Everything is awesome! Everything is cool when you're part of a team.",
"Everything is awesome! Everything is cool when you're part of a team. Everything is awesooooomme when you're living a dreeeam.",
"Gooooooo sports team!",
"Hey guys, watch me drill this down!",
"I think I heard a whoosh.",
"I think I heard a \"Whoosh\".",
"Hey pal, I hate to tell you this but ahh, I don't think you're supposed to be down here...",
"Yeah, the rules specifically state: work site closes at six, its a hard hat area only, that's not official safety orange...",
"If you see anything weird report it immediately. Well! I guess I'm just going to have to report yoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
Expand All @@ -35,13 +35,13 @@
"You're a LIAR!",
"I watch a lot of cop shows on TV.. isn't there supposed to-... isn't there supposed to be a good cop?",
"Hi buddy! I'm your friendly neighourhood police officer! Would you like a glass of water? TOO BAD!",
"Security cameras picked this up. You were found at the construction site convulsing with a strange piece.",
"Security cameras picked this up. You were found at the construction site, convulsing with a strange piece.",
"It's not my fault! I have no idea how this thing got on my back!",
"Of course buddy, we believe you.",
"I believe you too. You see the quotations I'm making with my claw hands? It means I DOn't believe you.",
"Predsident Business is going to end the world? But he's such a good guy.. and Octan, they make good stuff! Music, dairy products, coffee, TV shows, surveillance systems, all history books, voting machines... wait a minute.",
"That guy is not a criminal mastermind.",
"When you say {} I go HA HA HAHA! When you say the other guy, I go... :|",
"When you say {}, I go HA HA HAHA! When you say the other guy, I go... :|",
"I can't break him, take him to the melting chamber!",
"You're going to melt me?! Am I gonna die?!",
"Yes, we've told him he's going to live, but ahh.. we're lying to him.",
Expand All @@ -60,7 +60,7 @@
"By the way I have a boyfriend. Its super serious and you do not want to mess with him. So don't get any ideas.",
"I never have any ideas.",
"Hey ahh listen do you think you could explain to me like why I'm dressed like this and what those big words in the sky were all about and where we are.. in.. time?",
"Blah, blah, blah proper name, place name, backstory stuff. I'm so pretty, I like you but I'm angry with you for some reason.",
"Blah, blah, blah proper name, place name, back story stuff. I'm so pretty, I like you but I'm angry with you for some reason.",
"Great! I think I got it. But just in case... tell me the whole thing again because I wasn't listening.",
"We're trying to find the fugitive, but his face is so generic it matches every other face in our database.",
"Diabolical.",
Expand All @@ -87,16 +87,16 @@
"Batman huh? Where'd you guys meet?",
"Police to meet you Bad Cop.",
"Guess what you big dumb baby? Your car is a baby carriage.",
"Oh nooo your boyfriends gone..",
"Oh nooo your boyfriend's gone..",
"Hey babe. Let's hold hands.",
"Soo uhhh, hey guys, I think we're about to crash into the sun.",
"Yeah, but it's gonna look really cool.",
"Ahh, is this Cloud Cuckoo Land? I don't see any clouds or.. Cuckoo's..",
"This is Middle Zealand a wonderous land full of knights, castles, mutten, torture weapons, poverty, leeches, illiteracy, and umm... DRAAAGGONNNNSS!!",
"This is Middle Zealand. A wonderous land full of knights, castles, mutten, torture weapons, poverty, leeches, illiteracy, and umm... DRAAAGGONNNNSS!!",
"Yeah, yeah anyway. You guys have gotta checkout these new subwoofers I got installed in the back. I call them \"The Dogs\". Listen to 'em bark!",
"This is a song I wrote for {}. Darkness! It's about how I'm an orphan. No parents!",
"This is real music {}. Batman's a true artist.. dark, brooding.",
"Yeah, well I can be dark and brooding too. Ohh, Look guys a rainbow!",
"Yeah, well I can be dark and brooding too - Ohh, Look guys a rainbow!",
"I just need to give the secret knock...",
"I'm just gonna come right out, I.. have no idea what is going on, or what this place is.. at all.",
"Hiiiii! I am Princess {}, and I welcome you all to Cloud Cuckoo Land!",
Expand All @@ -105,7 +105,7 @@
"I hate this place..",
"Any idea is a good idea, except the not happy ones. Those get pushed down deep inside where you will never, ever, ever, EVER! Fiiind theeem :)",
"D-Didn't Krypton blow up?",
"The special will now give an eloquant speech... Go ahead man, you got this.",
"The special will now give an eloquent speech... Go ahead man, you got this.",
"Really hard?! Wiping your butt with a hook for a hand is REALLY HARD!",
"I had to replace every part of my once strapping, virial pirate body with this useless hunk of junk ye see before ye.",
"Yes, it's true. I may not be a Master Builder.. I may not have a lot of experience, fighting or leading or coming up with plans.. or have ideas in general.",
Expand Down Expand Up @@ -150,11 +150,11 @@
"Acceptable work, {}.",
"You see {}, a corrupted spirit is no match for the purity of imaginat-",
"The prophecy... I made it up. It's not true.",
"You must listen... for what I am about to tell you.. will change the course of histroy...",
"You must listen... for what I am about to tell you.. will change the course of history...",
"As unspecial as I am, you are a thousand billion times more unspecial than me.",
"Must be weird... One minute you're the most special person in the universe... the next minute you're NOBODY.",
"It's not personal. It's just business... Lord Business. Ciao!",
"Don't worry about this big, black, monolith thing that's blocking out the sun. What you need to worry about this question that I'm about to ask you.. Who wants a TACOS?!",
"Don't worry about this big, black, monolith thing that's blocking out the sun. What you need to worry about is this question that I'm about to ask you... Who wants a TACO?!",
"Alright everyone, act normal... Now, FREEZE!",
"Commencing micro-management.",
"{}, you'll... you'll think of something won't you? Just like you always do.",
Expand Down
58 changes: 37 additions & 21 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def __setActions(self):
'action': self.__cmdRoll,
'help': 'Roll a random number 0 - 100'
},
'/tell': {
'action': self.__cmdTell,
'help': 'Tell someone something (/tell name message or /tell name message from name)'
},
'/limit': {
'action': self.__cmdGetLimit,
'help': 'Get current HipChat API limit status'
Expand Down Expand Up @@ -156,7 +160,7 @@ def __getLatestDates(self):

def __getUsers(self, room_name):
if not room_name in self.rooms_users or self.rooms_users[room_name]['time'] + self.get_users_timeout < time():
users = self.hipster.method(
users = self.hipster.method(
'rooms/show',
method='GET',
parameters={'room_id': self.joined_rooms[room_name]}
Expand All @@ -170,7 +174,7 @@ def __getUsers(self, room_name):
return self.rooms_users[room_name]['users']

def __mentionUser(self, username):
return '@' + username.replace(' ','')
return '@' + username.replace(' ', '')

def __getRandomUser(self, room_name):
username = '@here'
Expand All @@ -184,18 +188,16 @@ def __getMentionedUser(self, room_name, message):
message_parts = message.split()
username = None

if len(message_parts) > 1:
# create regexp to find a user
message_parts[1] = re.compile(message_parts[1], re.IGNORECASE)
search = message_parts[0]
if len(message_parts) > 1: # Full message, use second arg.
search = message_parts[1]

users = self.__getUsers(room_name)
usernames = []
for user in users:
if re.search(message_parts[1], user['name']):
usernames.append(user['name'])
search = re.compile(search, re.IGNORECASE)

if usernames:
username = self.__mentionUser(random.choice(usernames))
users = self.__getUsers(room_name)
usernames = [user['name'] for user in users if re.search(search, user['name'])]
if usernames:
username = self.__mentionUser(random.choice(usernames))

return username

Expand All @@ -205,10 +207,8 @@ def __doQuoteAtUser(self, room_name, quoteList, message):
if "{}" not in phrase:
phrase = "{}, " + phrase

# try to get mentioned username
username = self.__getMentionedUser(room_name, message)

# if not - we will get random username
# Default user to random if not found.
if not username:
username = self.__getRandomUser(room_name)

Expand All @@ -227,6 +227,28 @@ def __cmdHelp(self, room_name):

self.postMessage(room_name, message)

def __cmdTell(self, room_name, message):
message_parts = message.split()

recipient = self.__getMentionedUser(room_name, message_parts[1])
if not recipient: # Default to just text.
recipient = message_parts[1]

# Check for "from someone" at the end.
if message_parts[-2].lower() == 'from':
sender = self.__getMentionedUser(room_name, message_parts[-1])
if not sender: # Default to just text.
sender = message_parts[-1]

# Send message as from someone.
message_parts = message_parts
message = ' '.join(message_parts[2:-2])
self.postMessage(room_name, "Hey {}, {} said {}".format(recipient, sender, message))
else:
# Send message as from bot.
message = ' '.join(message_parts[2:])
self.postMessage(room_name, "Hey {}, {}".format(recipient, message))

def __cmdGetRandomChuckPhrase(self, room_name):
message = "Can't connect to Chuck API =("
params = {'limitTo': '[nerdy]'}
Expand Down Expand Up @@ -367,27 +389,21 @@ def postMessage(self, room_name, message):
self.hipster.message_room(self.joined_rooms[room_name], self.name, message)

def start(self):

last_dates = self.__getLatestDates()

while True:

print('.')

for room_name in self.joined_rooms:

try:
messages = self.__getMessages(room_name, last_dates[room_name])

if messages:
last_dates[room_name] = self.__getLatestDate(messages)

for message in messages:

if message['from']['name'] != self.name:

for action_name in self.actions:

fields = set(inspect.getargspec(self.actions[action_name]['action'])[0])
args = {'room_name': room_name}

Expand Down

0 comments on commit edf5bc9

Please sign in to comment.