Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
diff --git a/commandhandler.py b/commandhandler.py
index 006e643..ca9cda0 100644
--- a/commandhandler.py
+++ b/commandhandler.py
@@ -1,160 +1,194 @@
#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
import tinydb
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'))
beescript = group_utilities.read_lines('beescript.txt')
blacklist = tinydb.TinyDB('blacklist.json')
dbquery = tinydb.Query()
RecentUsers = {} #Recent bot users, used for the cooldown
-commands = ['/beemovie', '/stfu', '/ask', '/roll']
+commands = ['/beemovie', '/stfu', '/ask', '/roll', '/nice']
+
+def dab(msg, chat_id, bot):
+ ''' /dab
+ USAGE: /dab
+ RETURNS: A terrible photo of an emoji doing a dab
+ '''
+
+ bot.sendPhoto(chat_id, 'http://i.imgur.com/Kcu0Adf.png')
+
+def nice(msg, content_type, chat_type, chat_id, bot):
+ ''' /nice
+ USAGE: /nice [quantity]
+ RETURNS: Random ammount of nices between 1-10 unless a quantity is provided (max 250)
+ '''
+ if (len(msg['text'].split(' '))) > 1:
+ try:
+ nices = int(msg['text'].split(' ')[1])
+ if nices > 250:
+ nices = 250
+
+ except ValueError:
+ nices = randrange(0, 10)
+ else:
+ nices = randrange(0, 10)
+
+ bot.sendMessage(chat_id, "nice"*nices)
+
+
def beemovie(msg, content_type, chat_type, chat_id, bot):
''' /beemovie
USAGE: /beemovie [repalceword]
REUTURS: Three random lines from the bee movie script
If a [replaceword] has been passed it will spit three random lines containing the word bee, but it replaced with [replaceword]
'''
lines = [] # The final list containing the lines
output = '' #The final output that the bot reuturns to the chat_id
args = msg['text'].replace(msg['text'].split(' ')[0],'')[1:] #What is after /beemovie or /beemovie@Jannie_Bot
if args.isspace() or args == '': #Is the command being queried like this /beemovie
lineno = randrange(0, (len(beescript)-2)) #what line number to use from beescript.txt
[lines.append(beescript[lineno+i]) for i in range(0,3)] #find a line and 2 after
output = "\n".join(lines)
else: #Is the command being queryied like this /beemovie [phrase]
while True: #repeat until bee is found in the lines
lines = []
lineno = randrange(0, (len(beescript)-2)) #what line number to use from beescript.txt
[lines.append(beescript[lineno+i]) for i in range(0,3)] #find a line and 2 after
if any('bee' in s for s in lines): #if there is bee in the lines
break #kill the loop
output = "\n".join(lines).replace('bee', args).replace('Bee', args).replace('TOMTOMTOMTOM','been') #replace words with the arg passed. TOMTOMTOMTOM is there because it kept replacing stuff in been
bot.sendMessage(chat_id, output)
def stfu(msg, content_type, chat_type, chat_id, bot):
''' /stfu
USAGE: /stfu
RETURNS: Replies with randomly selected phrase determined in stfu_phrases
'''
phrase = stfu_phrases[randrange(len(stfu_phrases))] #find a phrase
bot.sendMessage(chat_id, phrase) #send the phrase
group_utilities.logger('command', msg, False, phrase, '/stfu') #log it
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 random() > 0.5:
phrase = response_phrases_y[randrange(len(response_phrases_y))]
else:
phrase = response_phrases_n[randrange(len(response_phrases_n))]
if (("/ask@Jannie_Bot" in msg['text']) and (len(msg['text']) > 15)): #Is there actually a quesiton for /ask@Jannie_Bot
bot.sendMessage(chat_id, phrase, 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
bot.sendMessage(chat_id, phrase, reply_to_message_id=msg['message_id'])
else: #No question?
phrase = "Give me a question you Heretic"
bot.sendMessage(chat_id, phrase, reply_to_message_id=msg['message_id'])
group_utilities.logger('command', msg, False, phrase, '/ask')
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)) #generate the roll
bot.sendMessage(chat_id, roll, reply_to_message_id=msg['message_id'])
for i in roll: #basically this whole chunk detects if there are dubs trips etc
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,dubzreponses[counter])
group_utilities.logger('command', msg, False, str(roll)+" ("+dubzreponses[counter]+")", '/roll')
except:
group_utilities.logger('command', msg, False, str(roll), '/roll')
pass
def config(msg, content_type, chat_type, chat_id, bot): #WORK IN PROGRESS
#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 handler(msg, cooldown_sec, bot):
content_type, chat_type, chat_id = telepot.glance(msg)
#for i in commands:
#msg['text'].split(' ')[0]
if not msg['from']['id'] in RecentUsers: #Is the person in the recent users dict
if blacklist.search(dbquery.id == msg['from']['id']) != []:#Is the person in the blacklist
group_utilities.logger('blacklist', msg, False, 0, 0)
return
elif not msg['from']['username'] == 'profhiggins': #If the person isn't profhiggins, save the time the message was sent
RecentUsers[msg['from']['id']] = datetime.datetime.now()
else: #If the person IS in the recent users dict
if blacklist.search(dbquery.id == msg['from']['id']) != []:#Is the person in the blacklist?
group_utilities.logger('blacklist', msg, False, 0, 0)
return
elif (datetime.datetime.now() - RecentUsers[msg['from']['id']]) > datetime.timedelta(0, cooldown_sec): #Was the the timestamp in the dictionary more than cooldown_sec ago
del RecentUsers[msg['from']['id']] #Remvoe the listing in the dict
RecentUsers[msg['from']['id']] = datetime.datetime.now() #Put this message in the dictionary
else: #Was the message sent less than cooldown_sec ago?
group_utilities.logger('cooldown', msg, False, str(datetime.datetime.now() - RecentUsers[msg['from']['id']]), 0)
return
#what command gets handled where
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)
if msg['text'][:len('/beemovie')] == '/beemovie':
try: #catching exceptions here beause sometimes unicode complains and I don't have the effort to fix that
beemovie(msg, content_type, chat_type, chat_id, bot)
except: #just retry beemovie() till it works
beemovie(msg, content_type, chat_type, chat_id, bot)
+
+ if msg['text'][:len('/nice')] == '/nice':
+ nice(msg,content_type, chat_type, chat_id, bot)
+
+ if msg['text'][:len('/dab')] == '/dab':
+ dab(msg, chat_id, bot)

File Metadata

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

Event Timeline