Page MenuHomePhabricator (Chris)

No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/main.py b/main.py
index b2d9a28..5afb092 100644
--- a/main.py
+++ b/main.py
@@ -1,125 +1,125 @@
import sys
import time
import telepot
import datetime
from commandhandler import *
import group_utilities
import random
import os
#Cooldown length in seconds
COOLDOWN_SEC = 10
#Percentage to ignore command
FAILPERCENTAGE = 1
FAILID = [215620618]
#fetching our BOT_TOKEN
try:
BOT_TOKEN = os.environ['BOT_TOKEN'] #Hosting the bot on Heroku
except KeyError:
BOT_TOKEN = sys.argv[1]
commands = {
'/stfu' : stfu,
'/ask' : ask,
'/roll' : roll,
'/beemovie' : beemovie,
'/nice' : nice,
'/dab' : dab,
'/lemmesmash' : lemmesmash,
'/rotfl' : rotfl
}
def chat_handler(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if 'reply_to_message' in msg:
reply_to_message_handler(msg)
return
if content_type == 'text':
#If the message contains a bot command, go tell command_handler
try:
if msg['entities'][0]['type'] == 'bot_command':
handler(msg, COOLDOWN_SEC, bot)
#If the message contains Hendrik, send a complaint message to sender
except KeyError:
if ' lumber' in (msg['text'].lower()) or 'lumber' == msg['text'].lower()[:len('lumber')]:
if random.randint(0,1) == 1:
bot.sendMessage(chat_id, "LUMBER IS ETERNAL")
else:
bot.sendMessage(chat_id, 'THERE ARE NO BRAKES ON THE LUMBER TRAIN')
def reply_to_message_handler(msg):
if msg['from']['id'] == 164788390:
if msg['text'].lower() == "delet this":
try:
bot.deleteMessage((msg['chat']['id'], msg['message_id']))
bot.deleteMessage((msg['chat']['id'], msg['reply_to_message']['message_id']))
except:
print "I need deleting rights for {}!".format(msg['chat']['id'])
handler(msg, COOLDOWN_SEC, bot)
def edit_handler(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print "edit!!!"
try:
if msg['entities'][0]['type'] == 'bot_command':
bot.sendMessage(chat_id, "Voetsek, don't edit your commands.", reply_to_message_id=msg['message_id'])
except:
if content_type == 'text':
pass
def callback_query_handler(msg):
pass
def handler(msg, cooldown_sec, bot):
content_type, chat_type, chat_id = telepot.glance(msg)
- if 'play' or 'card' in msg['text'].lower():
+ if all(card in msg['text'].lower() for card in ['play', 'card']):
bot.sendMessage(chat_id, "Fuck off")
return
if random.randrange(0,100)==FAILPERCENTAGE and msg['from']['id'] in FAILID:
bot.sendMessage(chat_id, "No, fuck you")
return
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() #Puthis 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
for command in commands:
if msg['text'][:len(command)] == command:
commands[command](msg, chat_id, bot)
if 1==1:
#make our bot and feed it the tokenhend
bot = telepot.Bot(BOT_TOKEN)
#fetch messages and keep script looped
bot.message_loop({'chat' : chat_handler,
'edited_chat' : edit_handler,
'callback_query' : callback_query_handler},
run_forever="Bot Running...")

File Metadata

Mime Type
text/x-diff
Expires
Sat, Feb 7, 3:14 PM (9 h, 42 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55997
Default Alt Text
(4 KB)

Event Timeline