-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
69 lines (56 loc) · 2.44 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import discord
from config.secret_credentials import discordSecret, sheetName
from config.checkin_keywords import keywordLogin, keywordBreak, keywordReturn, keywordOffline, AllKeywords
from lib.sheetsFunctions import initializeSheet
from lib.message_condition import msgCondition
from localization.channel_names import channelNames
from localization.message_translations import translations
from lib.shiftClass import Shift
# Initialize discord client
client = discord.Client()
# Declare globals so that they can be used by the shift class
# global sheet
inFrame, employees, sheet, dummy = initializeSheet(sheetName)
shift = Shift()
@client.event
async def on_ready():
# Informs that discord client is connected to Discord.
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
# whenever message is in the check in channel and it is not in the keyword set
if str(message.channel) == channelNames['checkInChannel']:
validMessage = msgCondition(AllKeywords, message)
if not validMessage[0]:
if message.author.name != channelNames['botName']:
await message.channel.send(str(message.author.name) + ' ' +
translations['incorrectKeyword'] + ' ' +
translations['usageScreenShot'] + ' ' +
translations['usageScreenShot2']
)
# Checks that keyword is in the message
online = msgCondition(keywordLogin, message)
if online[0]:
msg = shift.login(online, message.channel)
await message.channel.send(msg)
# break mechanism. Called 'break_' to avoid conflict with Python's native function.
break_ = msgCondition(keywordBreak, message)
if break_[0]:
msg = shift.takeABreak(break_)
await message.channel.send(msg)
# return from break
breakReturn = msgCondition(keywordReturn, message)
# check, timeStamp, author
if breakReturn[0]:
msg = shift.returnFromBreak(breakReturn)
await message.channel.send(msg)
# offline mechanism
offline = msgCondition(keywordOffline, message)
# check, timeStamp, author
if offline[0]:
msg = shift.logOut(offline, sheetName)
if msg is None:
print('message is empty')
await message.channel.send(msg)
inFrame[offline[2]] = dummy
client.run(discordSecret)