Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
diff --git a/commandhandler.py b/commandhandler.py
index 2bccea2..61134e0 100644
--- a/commandhandler.py
+++ b/commandhandler.py
@@ -1,141 +1,143 @@
#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'))
-blacklist = ['Seth_Vogler']
+blacklist = ['215620618', '164788390']
RecentUsers = {}
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))]
bot.sendMessage(chat_id, phrase)
group_utilities.logger('command', msg, False, phrase, '/stfu')
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))
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,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):
#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']['id'] in RecentUsers: #Is the person in the recent users dict
- if msg['from']['username'] in blacklist: #Is the person in the blacklist
+ if str(msg['from']['id']) in blacklist: #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 msg['from']['username'] in blacklist: #Is the person in the blacklist?
+ if str(msg['from']['id']) in blacklist: #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
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/group_utilities.py b/group_utilities.py
index 4f5ed9f..8df35da 100644
--- a/group_utilities.py
+++ b/group_utilities.py
@@ -1,29 +1,32 @@
def read_lines(filename):
lines = []
try:
with open(filename, 'r') as f:
for line in f:
lines.append(line[:-1])
except IOError:
print 'Failed to open {}'.format(filename)
return lines
def logger(logtype, msg, edited, reply, command):
try:
senderusername = "{} ({})".format(msg['from']['id'], msg['from']['username'])
except:
senderusername = "No Username"
if msg['chat']['type'] == 'private':
chattitle = "Private Message with {}".format(senderusername)
else:
chattitle = msg['chat']['title']
if logtype == 'hendrik':
print "HENDRIK: \n Message Text: {} \n Sender: {} \n Chat: {} \n Edited: {} \n".format(msg['text'], senderusername, chattitle, edited)
if logtype == 'command':
print "COMMAND: \n Command: {} \n Message Text: {} \n Sender: {} \n Chat: {} \n Reply: {} \n".format(command, msg['text'], senderusername, chattitle, reply)
if logtype == 'cooldown':
print "COOLDOWN: \n Message Text: {} \n Sender: {} \n Chat: {} \n Time Elapsed: {} \n".format(msg['text'], senderusername, chattitle, reply)
+
+ if logtype == 'blacklist':
+ print "BLACKLIST: \n Message Text: {} \n Sender: {} \n Chat: {} \n".format(msg['text'], senderusername, chattitle)

File Metadata

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

Event Timeline