Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
11 KB
Referenced Files
None
Subscribers
None
diff --git a/commandhandler.py b/commandhandler.py
new file mode 100644
index 0000000..119566b
--- /dev/null
+++ b/commandhandler.py
@@ -0,0 +1,126 @@
+#This is the Command Handler file
+#Handles all bot commands
+import telepot
+from telepot.namedtuple import *
+import group_utilities
+from random import randrange, random
+import datetime
+
+stfu_phrases = group_utilities.read_lines('stfu_phrases.txt')
+response_phrases_y = (group_utilities.read_lines('response_phrases_y.txt'))
+response_phrases_n = (group_utilities.read_lines('response_phrases_n.txt'))
+
+RecentUsers = {}
+
+def stfu(msg, content_type, chat_type, chat_id, bot):
+ ''' /stfu
+ USAGE: /stfu
+ RETURNS: Replies with randomly selected phrase determined in stfu_phrases
+ '''
+ bot.sendMessage(chat_id, stfu_phrases[randrange(len(stfu_phrases))])
+
+def ask(msg, content_type, chat_type, chat_id, bot):
+ ''' /ask
+ USAGE: /ask [question]
+ RETURNS: Replies with randomly selected phrase determined in response_phrases_y and response_phrases_n
+ '''
+ if (("/ask@Jannie_Bot" in msg['text']) and (len(msg['text']) > 15)): #Is there actually a quesiton for /ask@Jannie_Bot
+ if random() > 0.5: #More
+ bot.sendMessage(chat_id, response_phrases_y[randrange(len(response_phrases_y))], reply_to_message_id=msg['message_id'])
+ else:
+ bot.sendMessage(chat_id, response_phrases_n[randrange(len(response_phrases_n))], reply_to_message_id=msg['message_id'])
+ elif (("/ask" in msg['text']) and (len(msg['text']) > 4)) and ("/ask@Jannie_Bot" != msg['text'][:len("/ask@Jannie_Bot")]): #Is there actually a question or is it just /ask@Jannie_Bot
+ if random() > 0.5:
+ bot.sendMessage(chat_id, response_phrases_y[randrange(len(response_phrases_y))], reply_to_message_id=msg['message_id'])
+ else:
+ bot.sendMessage(chat_id, response_phrases_n[randrange(len(response_phrases_n))], reply_to_message_id=msg['message_id'])
+ else: #No question?
+ bot.sendMessage(chat_id, "Give me a question you Heretic", reply_to_message_id=msg['message_id'])
+
+def roll(msg, content_type, chat_type, chat_id, bot):
+ ''' /roll
+ USAGE: /roll
+ RETURNS: Replies with random 9 digit number then if there are trips, dubs, quads etc will also congratulate
+ '''
+ dubzreponses={
+ 0: None,
+ 1: "Nice dubz boi",
+ 2: "You got trips fag, nice",
+ 3: "Quadzz nigga",
+ 4: "Fuck me those are pents",
+ 5: "You got some sexes there boy",
+ 6: "Holy fuck you just rolled for septs",
+ 7: "Jesus christ on a dubzicle those are fucking octs",
+ 8: "You have aquired the respect from Jan, with those ninefolds we can recolonise the whole Universe",
+ }
+ roll_list = []
+
+ roll = str(randrange(10**8, 10**9))
+ bot.sendMessage(chat_id, roll, reply_to_message_id=msg['message_id'])
+ for i in roll:
+ roll_list.append(i)
+ counter = 0
+ for i in range(0,8):
+ if roll_list[i] == roll_list[i+1]:
+ counter +=1
+ else:
+ counter = 0
+ try:
+ bot.sendMessage(chat_id,dub_detector(dubzreponses[counter]))
+ except:
+ pass
+
+def config(msg, content_type, chat_type, chat_id, bot):
+ #bot.sendMessage(chat_id, "Awe Lets Test?", reply_markup=ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='yes'), KeyboardButton(text='no')]]))
+ bot.sendMessage(chat_id, "Awe Lets Test?", reply_markup=InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text='yes', callback_data='yeee'), InlineKeyboardButton(text='no', callback_data='nein')]]))
+def dub_detector(roll): #function for determining if user rolls for dubs, trips, quads etc
+ dubzreponses={
+ 0: None,
+ 1: "Nice dubz boi",
+ 2: "You got trips fag, nice",
+ 3: "Quadzz nigga",
+ 4: "Fuck me those are pents",
+ 5: "You got some sexes there boy",
+ 6: "Holy fuck you just rolled for septs",
+ 7: "Jesus christ on a dubzicle those are fucking octs",
+ 8: "You have aquired the respect from Jan, with those ninefolds we can recolonise the whole Universe",
+ }
+ roll_list = []
+ for i in roll:
+ roll_list.append(i)
+ counter = 0
+ for i in range(0,8):
+ if roll_list[i] == roll_list[i+1]:
+ counter +=1
+ else:
+ counter = 0
+ return dubzreponses[counter]
+
+
+def handler(msg, cooldown_sec, bot):
+ content_type, chat_type, chat_id = telepot.glance(msg)
+ if not msg['from']['username'] in RecentUsers:
+ if not msg['from']['username'] == 'profhiggins':
+ RecentUsers[msg['from']['username']] = datetime.datetime.now()
+
+ else:
+ if (datetime.datetime.now() - RecentUsers[msg['from']['username']]) > datetime.timedelta(0, cooldown_sec):
+ del RecentUsers[msg['from']['username']]
+ RecentUsers[msg['from']['username']] = datetime.datetime.now()
+ pass
+
+ else:
+ print (datetime.datetime.now() - RecentUsers[msg['from']['username']])
+ return
+
+ if msg['text'][:len('/stfu')] == '/stfu':
+ stfu(msg, content_type, chat_type, chat_id, bot)
+
+ if msg['text'][:len('/ask')] == '/ask':
+ ask(msg, content_type, chat_type, chat_id, bot)
+
+ if msg['text'][:len('/roll')] == '/roll':
+ roll(msg, content_type, chat_type, chat_id, bot)
+
+ #if msg['text'][:len('/config')] == '/config':
+ #config(msg, content_type, chat_type, chat_id, bot)
diff --git a/main.py b/main.py
index 27861e2..3dc56ea 100644
--- a/main.py
+++ b/main.py
@@ -1,139 +1,49 @@
- #Todo: Prevent blank /ask
import sys
import time
import telepot
-import group_utilities
-from random import randrange, random
import datetime
-
-#Dict to store recent command users in
-RecentUsers = {}
+import commandhandler
#Cooldown length in seconds
-cooldown_sec =10
-
+cooldown_sec = 10
#fetching our BOT_TOKEN
BOT_TOKEN = sys.argv[1]
-#read phrases for stfu function
-stfu_phrases = group_utilities.read_lines('stfu_phrases.txt')
-response_phrases_y = (group_utilities.read_lines('response_phrases_y.txt'))
-response_phrases_n = (group_utilities.read_lines('response_phrases_n.txt'))
-
-def seth_is_a_faggot(msg):
- content_type, chat_type, chat_id = telepot.glance(msg)
- if msg['from']['username'] == "Seth_Vogler":
- bot.sendMessage(chat_id, "SILENCE, FALSE PROPHET!", reply_to_message_id=msg['message_id'] )
-
- def dub_detector(roll): #function for determining if user rolls for dubs, trips, quads etc
- dubzreponses={
- 0: None,
- 1: "Nice dubz boi",
- 2: "You got trips fag, nice",
- 3: "Quadzz nigga",
- 4: "Fuck me those are pents",
- 5: "You got some sexes there boy",
- 6: "Holy fuck you just rolled for septs",
- 7: "Jesus christ on a dubzicle those are fucking octs",
- 8: "You have aquired the respect from Jan, with those ninefolds we can recolonise the whole Universe",
- }
- roll_list = []
- for i in roll:
- roll_list.append(i)
- counter = 0
- for i in range(0,8):
- if roll_list[i] == roll_list[i+1]:
- counter +=1
- else:
- counter = 0
- return dubzreponses[counter]
-
-def command_handler(msg, content_type, chat_type, chat_id):
-
- if not msg['from']['username'] in RecentUsers:
- RecentUsers[msg['from']['username']] = datetime.datetime.now()
- else:
- if (datetime.datetime.now() - RecentUsers[msg['from']['username']]) > datetime.timedelta(0, cooldown_sec):
- del RecentUsers[msg['from']['username']]
- RecentUsers[msg['from']['username']] = datetime.datetime.now()
- pass
-
- else:
- print (datetime.datetime.now() - RecentUsers[msg['from']['username']])
- return
-
- if msg['text'][:len('/stfu')] == '/stfu':
- ''' /stfu
- USAGE: /stfu
- RETURNS: Replies with randomly selected phrase determined in stfu_phrases
- '''
- bot.sendMessage(chat_id, stfu_phrases[randrange(len(stfu_phrases))])
-
- if msg['text'][:len('/ask')] == '/ask':
- ''' /ask
- USAGE: /ask [question]
- RETURNS: Replies with randomly selected phrase determined in response_phrases_y and response_phrases_n
- '''
-
- if (("/ask@Jannie_Bot" in msg['text']) and (len(msg['text']) > 15)): #Is there actually a quesiton for /ask@Jannie_Bot
- if random() > 0.5: #More
- bot.sendMessage(chat_id, response_phrases_y[randrange(len(response_phrases_y))], reply_to_message_id=msg['message_id'])
- else:
- bot.sendMessage(chat_id, response_phrases_n[randrange(len(response_phrases_n))], reply_to_message_id=msg['message_id'])
-
- elif (("/ask" in msg['text']) and (len(msg['text']) > 4)) and ("/ask@Jannie_Bot" != msg['text'][:len("/ask@Jannie_Bot")]): #Is there actually a question or is it just /ask@Jannie_Bot
- if random() > 0.5:
- bot.sendMessage(chat_id, response_phrases_y[randrange(len(response_phrases_y))], reply_to_message_id=msg['message_id'])
- else:
- bot.sendMessage(chat_id, response_phrases_n[randrange(len(response_phrases_n))], reply_to_message_id=msg['message_id'])
-
- else: #No question?
- bot.sendMessage(chat_id, "Give me a question you Heretic", reply_to_message_id=msg['message_id'])
-
- if msg['text'][:len('/roll')] == '/roll':
- ''' /roll
- USAGE: /roll
- RETURNS: Replies with random 9 digit, calls dub_detector() to see if digits starting from the end of the number are identical and sends a message depending on how many are identical
- '''
- roll = str(randrange(10**8, 10**9))
- bot.sendMessage(chat_id, roll, reply_to_message_id=msg['message_id'])
- try:
- bot.sendMessage(chat_id,dub_detector(roll))
- except:
- pass
-
def chat_handler(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == '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)
+ commandhandler.handler(msg, cooldown_sec, bot)
#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'])
#seth_is_a_faggot(msg)
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']['first_name'])
+def callback_query_handler(msg):
+ pass
#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 },
+ 'edited_chat' : edit_handler,
+ 'callback_query' : callback_query_handler},
run_forever="Bot Running...")

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:22 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
70805
Default Alt Text
(11 KB)

Event Timeline