Page MenuHomePhabricator (Chris)

commandhandler.py
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

commandhandler.py

#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')
lemmesmashList = group_utilities.read_lines('lemmesmash.txt')
blacklist = tinydb.TinyDB('blacklist.json')
dbquery = tinydb.Query()
recentUsers = {} #Recent bot users, used for the cooldown
def lemmesmash(msg, chat_id, bot):
''' /lemmesmash
USAGE: /lemmesmash
RETURNS:
'''
phrase = lemmesmashList[randrange(len(lemmesmashList))] #find a phrase
bot.sendMessage(chat_id, phrase) #send the phrase
group_utilities.logger('command', msg, False, phrase, '/lemmes')
def dab(msg, chat_id, bot):
''' /dab
USAGE: /dab
RETURNS: A terrible sticker of an emoji dabbing
'''
bot.sendSticker(chat_id, 'CAADBAADRwADpnjSCTlOo90rUVSNAg')
try:
bot.deleteMessage((chat_id, msg['message_id']))
except:
print "I need message removal rights for {}!!".format(str(chat_id));
group_utilities.logger('command', msg, False, '*dabs*', '/dab')
def nice(msg, 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
if nices == 0:
nices = randrange(0, 10)
except ValueError:
nices = randrange(0, 10)
else:
nices = randrange(0, 10)
bot.sendMessage(chat_id, "nice"*nices)
group_utilities.logger('command', msg, False, 'nice'*nices, '/nice')
def beemovie(msg, 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)
group_utilities.logger('command', msg, False, output, '/beemovie')
def stfu(msg, 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, 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, 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, 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 rotfl(msg, chat_id, bot):
''' /rotfl
USAGE: /rotfl (text)
RETURNS: rOfTL caT
'''
if 'reply_to_message' in msg:
TEMPVAR = msg['reply_to_message']['text']
else:
if "/rotfl@Jannie_Bot" in msg['text']:
TEMPVAR = msg['text'].split('/rotfl@Jannie_Bot')[1]
else:
TEMPVAR = msg['text'].split('/rotfl')[1]
out = ''
out = out.join([chr(ord(x)-32) if random() > 0.5 and x.isalpha() and x.islower() and x else x for x in TEMPVAR])
bot.sendMessage(chat_id, out)

File Metadata

Mime Type
text/x-script.python
Expires
Sun, Nov 15, 3:02 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
135769
Default Alt Text
commandhandler.py (7 KB)

Event Timeline