-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
60 lines (48 loc) · 1.89 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
import os
import re
import discord
import requests
from bs4 import BeautifulSoup
def validate_fpl(text):
req = requests.post("http://validation.eurofpl.eu/", data={'freeEntry': text})
data = BeautifulSoup(req.text, features="html.parser")
for span in data.find_all('span', 'ifpuv_result'):
if span.get_text() == 'NO ERRORS':
# print('Success : No Errors')
return True
else:
# print("Error : ", span.get_text())
return span.get_text()
def run():
if not os.environ['DISCORD_TOKEN']:
print('No defined Token in environnement : DISCORD_TOKEN')
exit(0)
TOKEN = os.environ['DISCORD_TOKEN']
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
regex = re.compile(r'\(FPL-(.|\s)*\)')
search = regex.search(message.content)
if search:
print("Received Message from {0.author} with FPL : ".format(message), search[0])
validate = validate_fpl(search[0])
if validate is True:
await client.add_reaction(message, '✅')
else:
await client.add_reaction(message, '❎')
await client.send_message(message.author,
"Le plan de vol que vous venez d'envoyer dans le channel %s"
" est incorrect : %s" % (message.channel.mention, validate))
else:
# print("Didn't parse the message....")
pass
@client.event
async def on_ready():
print('Logged in as %s with ID %s' % (client.user.name, client.user.id))
await client.change_presence(game=discord.Game(name='Vérifier vos plans de vols'))
client.run(TOKEN)
if '__main__' == __name__:
run()