Skip to content
Permalink
Browse files
Fix merge errors
  • Loading branch information
grantb3 committed Nov 28, 2018
2 parents b4a0fca + 7f62333 commit e98ac8c3537aecec26405040842d5654cc9509e8
Show file tree
Hide file tree
Showing 15 changed files with 1,266 additions and 1,068 deletions.
@@ -6,10 +6,17 @@
/._pycache_
/kopia
/TextExtracts
/seq2seq
/py-googletrans
/BOT
/botsfloor
/nlp


names.json

names.json
names.pck
brain.pck

### Linux ###
*~
@@ -1,31 +1,31 @@
import discord
import webbrowser
import nltk
import random
from discord.ext import commands
import asyncio

TOKEN = 'NTA3NjMyNDUwMzkwODUxNTg1.Drzsew.lVbUm7WKIPrV56q_9LegdqZuXZo'

client = commands.Bot(command_prefix = '?')

@client.event
async def on_ready():
print('"BOT ON DUTY"')

@client.command
async def test(ctx):
await ctx.send('I heard you! {0}'.format(ctx.author))

@client.event
async def message(message):

if message.author.id == client.user.id:
return

if message.content.lower().startswith ('!math'):




client.run(TOKEN)
import discord
import webbrowser
import nltk
import random
from discord.ext import commands
import asyncio

TOKEN = 'NTA3NjMyNDUwMzkwODUxNTg1.Drzsew.lVbUm7WKIPrV56q_9LegdqZuXZo'

client = commands.Bot(command_prefix = '?')

@client.event
async def on_ready():
print('"BOT ON DUTY"')

@client.command
async def test(ctx):
await ctx.send('I heard you! {0}'.format(ctx.author))

@client.event
async def message(message):

if message.author.id == client.user.id:
return

if message.content.lower().startswith ('!math'):




client.run(TOKEN)
@@ -1,9 +1,21 @@
# Discord Chatbot

Multi-purpose discord chatbot for module 4006CEM - Oct/Nov 2018
Semi-intelligent discord chatbot for module 4006CEM - Oct/Nov 2018

Usage: python3 connector.py

# Python 3.5 or larger must be installed due to asynchronous functions
You will

# Please state which modules/components needed to be installed before executing your program, thanks!
Libraries being used:
- requests (http://docs.python-requests.org/en/master/) by Kenneth Reitz for web requests
- bs4 (https://www.crummy.com/software/BeautifulSoup/) by Leonard Richardson for parsing HTML pages
- discord.py (https://github.com/Rapptz/discord.py/) by Rapptz used to connect to Discord.
- selenium (https://docs.seleniumhq.org/) by (originally) Jason Huggins used to scrap pages that use javascript calls for data (translate module)
- googletrans(https://pypi.org/project/googletrans/) by SuHun Han used as Google Translate API


If you get an error (error 'NoneType' object has no attribute 'group') when using googletrans follow these instructions:
Step 1. pip uninstall googletrans
Step 2. clone https://github.com/BoseCorp/py-googletrans.git
Step 3. ./py-googletrans
Step 4. setup.py install
@@ -4,23 +4,23 @@ Source: https://github.com/Rapptz/discord.py/
"""
import discord
import asyncio
import quote
import namestore
import wikipedia
import stackoverflow
import translate
import exchange
import conversate
import pickle
import os
import json
import translatesimple
import hangman
from tests import Test
import time

import weather_realtime

client = discord.Client()

#Returns help string
##################################################
# Benjamin Grant
# Returns help string
def commands():
commandList = "What can I do?\n"
commandList += "!test\n"
commandList += "!q\n"
commandList += "!wiki\n"
commandList += "!translate\n"
@@ -29,95 +29,105 @@ def commands():
commandList += "!hangman\n"
return commandList

#Creates files critical to bot functioning
def initialise_files():
print("Initialising critical files...")

names={"1":"test"}

brain={"GREETING":
["Hello!",
"How can I help you today %name%?",
"Hey %name%!",
"What a lovely surprise! Hello %name%."],
"STATE":
["I'm okay thanks.",
"Good, thank you for asking :)",
"All the better now I've spoken to you, %name%."],
"POSITIVE":
["Good",
"Great",
"Fantastic",
"Spiffing",
"Spectacular"
"Amazing"]
}

if not os.path.isfile("names.pck"):
print("names.pck not found. Please restart the bot, this will be automatically fixed!")
pickle.dump(names, open("names.pck", "wb+"))

if not os.path.isfile("brain.pck"):
print("brain.pck not found. Please restart the bot, this will be automatically fixed!")
pickle.dump(brain, open("brain.pck", "wb+"))

if not os.path.isfile("names.json"):
print("names.pck not found. Please restart the bot, this will be automatically fixed!")
json.dump(names, open("names.json", "w"))

print("Initialisation complete.")
##################################################


@client.event
#Called on login
# Called on login
async def on_ready():
print('[*] ' + client.user.name + ' ('+client.user.id+') logged in')

await client.change_presence(game=discord.Game(name="!help"))
print('[*] ' + client.user.name + ' ('+client.user.id+') logged in')

initialise_files()

await client.change_presence(game=discord.Game(name="Chat to me!"))


@client.event
#Called whenever it receives a message
# Called whenever it receives a message
async def on_message(message):

hello = ["hey", "hello", "hi", "yo", "sup", "wagwarn"]

##################################################
# Benjamin Grant
if message.author.id == client.user.id:
return

elif message.content.lower().split(" ")[0] in hello:

await client.send_message(message.channel, 'Hey!')

elif message.content.lower().startswith('my name is'):

tokenised = message.content.lower().split(" ")

if len(tokenised) <= 3:
await client.send_message(message.channel, 'Please provide a name.')
else:
#This for-loop rebuilds the required tokens into a name. This enables spaces in names
name=""
for i in range(len(tokenised)):
if i <= 2:
continue
name += tokenised[i] + " "

await namestore.set_name(message.author.id, name.strip())
await client.send_message(message.channel, 'Hello, ' + name.strip() + ".")

elif message.content.lower().startswith('what is my name'):
name = await namestore.get_name(message.author.id)
if name == None:
await client.send_message(message.channel, "I don't know your name. Try using `my name is <name>`")
else:
await client.send_message(message.channel, 'Your name is ' + name.strip() + ".")


elif message.content.lower().startswith('!quote') or message.content.lower().startswith('!q'):
editable = await client.send_message(message.channel, 'Searching for zesty quotes...')
genQ = await quote.generateQuote()
await client.edit_message(editable, genQ)

await conversate.processMessage(client, message) # Commands and functionality by Benjamin Grant may be found here

if message.content.lower().startswith('!help'):
await client.send_message(message.channel, commands())
##################################################

##################################################
# Konrad Czarniecki

# command is !wiki search_word
elif message.content.lower().startswith('!wiki'):
await wikipedia.wikipedia(client, message)

# command is !flow search_phrase_here. Then '!f na' for next answer, '!f nq' for next question
elif message.content.lower().startswith('!flow'):
await stackoverflow.stackoverflow(client, message)

# command is !translate from_language to target_language your_query e.g !translate english to french i hate selenium
elif message.content.lower().startswith('!translate'):
await translate.translate(client, message)
await translatesimple.translate(client, message)


elif message.content.lower().startswith('!hangman'):
await hangman.hangman(client, message)

elif message.content.lower().startswith('test yourself'):
await client.send_message(message.channel, "Running 3 tests...")

tests = Test()

await tests.testQuoteApi(client, message)
await tests.testCurrencyApi(client, message)
await tests.testNameStore(client, message)

del tests

await client.send_message(message.channel, "Tests complete")
##################################################

##################################################
# Kelvin Mock
elif message.content.lower().startswith('weather'):
await weather_realtime.weather(client,message)

elif message.content.lower().startswith('!help'):
await client.send_message(message.channel, commands())

#sorry bout that, this part is causing some errors with stackoverflow module
#elif message.content.lower().startswith('!'):
# await client.send_message(message.channel, "Unknown command! Use `!help` for a command/usage list.")
elif message.content.lower().startswith('web'):
await web.YouTubeBrowser(client,message)

elif message.content.lower().startswith('social'):
await
##################################################


#This token is linked to Ben's discord account/applications - sets bot account
client.run('NTA2NDAxMjcwMzAzNTU1NTg0.Drhmxg.w1m3iG58BbYZiRM_o17gd-kyBUE')

0 comments on commit e98ac8c

Please sign in to comment.