-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.py
executable file
·66 lines (50 loc) · 1.74 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
# Dependencies
import discord
import os
# Local dependencies
from modules.cve import CVE
from modules.csv import CSV
from modules.news import News
from modules.discordhelp import DiscordHelp
from modules.tldr import TLDR
from modules.password_analyzer import Analyze
client = discord.Client()
# set your bot token as an environment variable, e.g.,
# `export JARVIS_TOKEN="<token>"`
token = os.environ['JARVIS_TOKEN']
helpFile = 'docs/bot.md'
def helpMessage():
with open(helpFile, 'r') as fp:
return fp.read()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$help'):
await message.channel.send(helpMessage())
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
if message.content.startswith('$news'):
result = News.getNews(message)
if not DiscordHelp.isValidLength(result):
result = "**Too many articles to list**"
await message.channel.send(result)
if message.content.startswith('$cve'):
result = CVE.cveSearch(message)
await message.channel.send(result)
if message.content.startswith('$tldr'):
result = TLDR.tldr(message)
if isinstance(result, discord.Embed):
await message.channel.send(embed=result)
else:
await message.channel.send(result)
if message.content.startswith('$password'):
result = Analyze.check_password(message)
if isinstance(result, discord.Embed):
await message.channel.send(embed=result)
else:
await message.channel.send(result)
client.run(token)