Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/main.py b/main.py
index 3f15637..4d083be 100644
--- a/main.py
+++ b/main.py
@@ -1,34 +1,57 @@
+#Todo: Prevent blank /ask
import sys
import time
import telepot
+import group_utilities
+from random import randrange, randint
#fetching our BOT_TOKEN
BOT_TOKEN = sys.argv[1]
+#read phrases for stfu function
+stfu_phrases = group_utilities.read_lines('stfu_phrases.txt')
+janrepsonsephrases = group_utilities.read_lines('janresponse.txt')
+
+def command_handler(msg, content_type, chat_type, chat_id):
+
+ if msg['text'][:len('/stfu')] == '/stfu':
+ bot.sendMessage(chat_id, stfu_phrases[randrange(len(stfu_phrases))])
+
+ if msg['text'][:len('/ask')] == '/ask':
+
+ bot.sendMessage(chat_id, janrepsonsephrases[randrange(len(janrepsonsephrases))], reply_to_message_id=msg['message_id'])
def chat_handler(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'text':
- if "hendrik" in (msg['text'].lower()):
- bot.sendMessage(chat_id, 'Who the fuck is Hendrik?', reply_to_message_id=msg['message_id'])
- print "Trigger Phrase Detected: \n Message Text: {}".format(msg['text'])
+ #If the message contains a bot command, go tell command_handler
+ try:
+ if msg['entities'][0]['type'] == 'bot_command':
+ command_handler(msg, content_type, chat_type, chat_id)
+
+ #If the message contains Hendrik, send a complaint message to sender
+ except KeyError:
+ if "hendrik" in (msg['text'].lower()):
+ bot.sendMessage(chat_id, 'Who the fuck is Hendrik?', reply_to_message_id=msg['message_id'])
+ print "Trigger Phrase Detected: \n Message Text: {} \n Sender: {} \n ".format(msg['text'], msg['from']['first_name'])
+
def edit_handler(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'text':
if "hendrik" in (msg['text'].lower()):
bot.sendMessage(chat_id, 'Your sneaky edits do not work on me. Who the fuck is Hendrik?', reply_to_message_id=msg['message_id'])
- print "Trigger Phrase Detected (EDITED MESSAGE): \n Message Text: {} \n Sender: {} \n ".format(msg['text'], msg['from'])
+ print "Trigger Phrase Detected (EDITED MESSAGE): \n Message Text: {} \n Sender: {} \n ".format(msg['text'], msg['from']['first_name'])
#make our bot and feed it the token
bot = telepot.Bot(BOT_TOKEN)
#fetch messages and keep script looped
bot.message_loop({'chat' : chat_handler,
'edited_chat' : edit_handler },
run_forever="Bot Running...")

File Metadata

Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:06 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69730
Default Alt Text
(2 KB)

Event Timeline