-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclevercord.py
142 lines (113 loc) · 4.44 KB
/
clevercord.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'''
Discord bot to chat with Cleverbot. Uses the cleverbotfree library to
communicate via a headless Firefox browser.
Just message "&chat" to chat with Cleverbot.
Copyright (C) 2018 plasticuproject@pm.me
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
'''
import os
import discord
from discord.ext import commands
from cleverbotfree.cbfree import Cleverbot
import re
from random import randint
from modules.cve import CVE
from modules.discordhelp import DiscordHelp
from modules.password_analyzer import Analyze
bot = commands.Bot(command_prefix='&')
sendCb = Cleverbot().single_exchange
# Discord Bot Token variable
token = os.environ['CLEVERCORD_TOKEN']
# Discord Client ID
clientID = os.environ['CLEVERCORD_CLIENT_ID']
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
# uses cleverbotfree to communicate with Cleverbot
@bot.command()
async def chat(ctx, *args):
# print(ctx.message.author)
# print(ctx.message.content)
userInput = ' '.join(args)
try:
response = sendCb(userInput)
await ctx.send(response)
except:
embed = discord.Embed(title='ERROR: Could not connect. Please try again', color=0xff0000)
await ctx.send(embed=embed)
# search NVD for CVE info
@bot.command()
async def cve(ctx, *args):
try:
if len(args) == 0:
message = '&cve'
else:
message = '&cve ' + ' '.join(args)
result = CVE.cveSearch(message)
await ctx.send(result)
except:
embed = discord.Embed(title='ERROR: Could not connect. Please try again', color=0xff0000)
await ctx.send(embed=embed)
# analyze password strength
@bot.command()
async def password(ctx, *args):
try:
if len(args) == 0:
message = '&password'
else:
message = '&password ' + ' '.join(args)
result = Analyze.check_password(message)
if isinstance(result, discord.Embed):
await ctx.send(embed=result)
else:
await ctx.send(result)
except:
embed = discord.Embed(title='ERROR: Could not connect. Please try again', color=0xff0000)
await ctx.send(embed=embed)
# grab a quote from Uncle Ted!
@bot.command()
async def ted(ctx):
try:
with open('bomb.txt', 'r') as bomb:
text = bomb.read()
r = randint(0,1565)
s = re.findall("[A-Z].*?[\.!?]", text, re.MULTILINE | re.DOTALL )[r].replace('\n', '').replace(' ', ' ').replace(' ', ' ')
t = 'Uncle Ted says:\n' + s
await ctx.send(t)
except:
embed = discord.Embed(title='ERROR: Could not connect. Please try again', color=0xff0000)
await ctx.send(embed=embed)
@bot.command()
async def info(ctx):
embed = discord.Embed(title='cleverbot', description='Cleverbot chatbot.', color=0xeee657)
# give info about you here
embed.add_field(name='Author', value='plasticuproject#3879')
# Shows the number of servers the bot is member of.
embed.add_field(name='Server count', value=f'{len(bot.guilds)}')
# give users a link to invite this bot to their server
embed.add_field(name='Invite', value='https://discordapp.com/oauth2/authorize?client_id=' + clientID + '&scope=bot')
await ctx.send(embed=embed)
bot.remove_command('help')
# return command help
@bot.command()
async def help(ctx):
embed = discord.Embed(title='cleverbot',
description='Cleverbot chatbot. List of commands are:', color=0xeee657)
embed.add_field(name='&chat', value='Have a chat with Cleverbot', inline=False)
embed.add_field(name='&info', value='Gives a little info about the bot', inline=False)
embed.add_field(name='&help', value='Gives this message', inline=False)
embed.add_field(name='&cve', value='Lookup CVEs from NIST NVD', inline=False)
embed.add_field(name='&password', value='Check estimatied cracking time for passwords', inline=False)
embed.add_field(name='&ted', value='Uncle Ted\'s greatest hits', inline=False)
await ctx.send(embed=embed)
bot.run(token)