Skip to content
Permalink
Browse files
Pre-merge
  • Loading branch information
grantb3 committed Nov 19, 2018
1 parent 6eec404 commit 8ee4ca07a63e16b15661a940e68b13a0720dc911
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
@@ -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)
@@ -20,7 +20,6 @@ client = discord.Client()
#Returns help string
def commands():
commandList = "What can I do?\n"
commandList += "!test\n"
commandList += "!q\n"
commandList += "!wiki\n"
commandList += "!translate\n"
@@ -1,5 +1,6 @@
import random
import namestore
import datetime

# Replaces string variables such as %name%
async def replacePlaceholders(msg, user):
@@ -32,20 +33,19 @@ async def processMessage(client, message):
["Hello!",
"How can I help you today %name%?",
"Hey %name%!",
"What a lovely surprise! Hello %name%."
"What a lovely surprise! Hello %name%."]
]

state = [
["how are you",
state = [["how are you",
"how're you",
"are you okay",
"how do you feel",
"what's up",
"suh"],
["Hello!",
"How can I help you today %name%?",
"Hey %name%!",
"What a lovely surprise! Hello %name%."
["I'm okay thanks.",
"Good, thanks for asking :)",
"All the better now I've spoken to you, Ben",
"What a lovely surprise! Hello %name%."]
]

for greet in greeting[0]:
@@ -16,7 +16,7 @@ async def set_name(id, name):
with open("names.json", "w+") as f:
json.dump(names, f)

#Opens names.json, checks if the user has a name and returns None if not
#Opens names.json, checks if the user has a name and returns None if not. IMPORTANT TO CHECK FOR NONE, DO NOT ASSUME NAME EXISTS
async def get_name(id):
with open("names.json") as f:
names = json.load(f)
@@ -3,40 +3,38 @@ import asyncio

class TestQuoteFunctionality(unittest.TestCase):


@classmethod
def setUpClass(self):
import quote
import time

# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines
# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines. Only function names modified
loop = asyncio.get_event_loop()

tasks = [asyncio.ensure_future(quote.generateQuote())]

done, _ = loop.run_until_complete(asyncio.wait(tasks))

self.quote = tasks[0].result()


#Test if quote is empty
def test_length(self):
self.assertNotEqual(len(self.quote), 0)

#Test if HTML entities or unicode remain
def test_html(self):
self.assertNotIn("&#", self.quote)
self.assertNotIn("\\u", self.quote)


class TestCurrencyFunctionality(unittest.TestCase):


@classmethod
def setUpClass(self):
import exchange
import time

# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines
# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines. Only function names modified
loop = asyncio.get_event_loop()

tasks = [asyncio.ensure_future(exchange.convertCurrency("USD", "GBP", 320874239)),
@@ -50,25 +48,27 @@ class TestCurrencyFunctionality(unittest.TestCase):
self.usdeur = tasks[1].result()
self.jpygbp = tasks[2].result()
self.neg = tasks[3].result()


#Test if any convert to < 0
def test_zero(self):
assert self.gbpusd >= 0, "Less than zero"
assert self.usdeur >= 0, "Less than zero"
assert self.jpygbp >= 0, "Less than zero"

#Test how negative input is handled (*hint*, it isn't) //TODO
def test_negative(self):
self.assertEqual(-5, self.neg)


class TestNameStorage(unittest.TestCase):


@classmethod
def setUpClass(self):
import namestore
import time

# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines
# Code by dano at https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks to get return values from coroutines. Only function names modified
loop = asyncio.get_event_loop()

tasks = [asyncio.ensure_future(namestore.set_name(12345, "Mike")),
@@ -96,7 +96,8 @@ class TestNameStorage(unittest.TestCase):
self.num = tasks[4].result()
self.fgn = tasks[5].result()



#Test if process of dumping and retrieval inteferes with true values
def test_names(self):
self.assertEqual(self.mike, "Mike")
self.assertEqual(self.amp, "&&&&&")

0 comments on commit 8ee4ca0

Please sign in to comment.