Skip to content
Permalink
Browse files
Merge pull request #27 from czarniek/ben
Final merge for Ben
  • Loading branch information
grantb3 committed Nov 27, 2018
2 parents 6b30abd + 95bf33a commit c12a20416d6fdfb66003c8c706fb350ea56ba78f
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 127 deletions.
@@ -15,7 +15,8 @@


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)
@@ -4,82 +4,97 @@ Source: https://github.com/Rapptz/discord.py/
"""
import discord
import asyncio
import quote
import namestore
import wikipedia
import stackoverflow
import conversate
import pickle
import os
import json
import translatesimple
import exchange
import hangman
import time

client = discord.Client()


##################################################
# 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"
commandList += "!flow\n"
commandList += "!name\n"
commandList += "!hangman\n"
return commandList
commandList = "What can I do?\n"
commandList += "!q\n"
commandList += "!wiki\n"
commandList += "!translate\n"
commandList += "!flow\n"
commandList += "!name\n"
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
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
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)


return

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

@@ -99,14 +114,7 @@ async def on_message(message):
await hangman.hangman(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.")



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

0 comments on commit c12a204

Please sign in to comment.