88 lines
3.0 KiB
Python
Executable File
88 lines
3.0 KiB
Python
Executable File
import GoogleApi as google#For read drive
|
|
from slackclient import SlackClient#Obvious
|
|
from SlackUtil import *
|
|
|
|
from WaitonUtil import handleWaitonMsg #For waitons
|
|
|
|
#Read api token from file
|
|
apifile = open("apitoken.txt", 'r')
|
|
SLACK_API = next(apifile).strip()
|
|
apifile.close();
|
|
|
|
#Read killswitch from file
|
|
killswitchfile = open("killswitch.txt", 'r')
|
|
killswitch = next(killswitchfile).strip()
|
|
killswitchfile.close()
|
|
|
|
#Set default username.
|
|
|
|
#Authenticate, get sheets service. Done globally so we dont have to do this
|
|
#every fucking time, which is probably a bad idea
|
|
sheet_credentials = google.get_sheets_credentials()
|
|
sheet_service = google.get_sheets_service(sheet_credentials)
|
|
|
|
|
|
"""
|
|
Insults the scrub who tried to use the bot without setting up slack.
|
|
If for_user is supplied, assumes user was fine and insults for_user
|
|
|
|
Also provides helpful info for how to avoid future disgrace, but thats like, tertiary
|
|
"""
|
|
def handleProfilelessScum(slack, msg, user, for_user=None):
|
|
f_response = None
|
|
if for_user:
|
|
user_name = user['user']['name']
|
|
for_name = for_user['user']['name']
|
|
f_response = "Hey {0}, tell {1} to set up his fucking profile. Like, first and last name, and stuff".format(user_name, for_name)
|
|
else:
|
|
f_response = "Set up your profile before talking to me, scum.\n\nThat is to say, fill out your first and last name in your slack user profile! Please use what would be on the waiton list (IE your proper name, not a nickname)."
|
|
reply(slack, msg, f_response)
|
|
|
|
|
|
def main():
|
|
#Init slack
|
|
slack = SlackClient(SLACK_API)
|
|
print(slack)
|
|
|
|
slack.api_call("chat.postMessage", channel="@jacobhenry", text="I'm back baby!")
|
|
|
|
feed = messageFeed(slack)
|
|
for msg in feed:
|
|
#Check not bot
|
|
if isBotMessage(msg):
|
|
print("Message skipped. Reason: bot")
|
|
continue
|
|
|
|
#get user info
|
|
userid = msg['user']
|
|
user = slack.api_call("users.info", user=userid)
|
|
|
|
#If a mention is found, assign for_user
|
|
for_user = getForUser(slack, msg)
|
|
|
|
#Handle Message
|
|
text = msg['text'].lower()
|
|
if not isValidProfile(user):#invalid profile
|
|
handleProfilelessScum(slack, msg, user)
|
|
elif for_user and not isValidProfile(for_user):#invalid for_user profile
|
|
handleProfilelessScum(slack, msg, user, for_user)
|
|
|
|
elif "waiton" in text:
|
|
handleWaitonMsg(slack, sheet_service, msg, user, for_user)
|
|
|
|
elif "scroll" in text:
|
|
handleScrollMsg(slack, sheet_service, msg)
|
|
|
|
elif "housejob" in text:
|
|
reply(slack, msg, "I cannot do that (yet)", username="sadbot")
|
|
|
|
elif killswitch == msg['text'].lower():
|
|
reply(slack, msg, "as you wish...", username="rip bot")
|
|
break
|
|
|
|
else:
|
|
print("Message skipped. Reason: no command found")
|
|
|
|
#run main
|
|
main()
|