Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatbot_mycodes/myconnector.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
117 lines (87 sloc)
4 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Library 'discord.py' by Rapptz used to connect to Discord. | |
Source: https://github.com/Rapptz/discord.py/ | |
""" | |
import discord | |
import asyncio | |
import quote | |
import namestore | |
import wikipedia | |
import stackoverflow | |
import translate | |
import exchange | |
import hangman | |
import time | |
import weather_realtime | |
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" | |
commandList += "!flow\n" | |
commandList += "!name\n" | |
commandList += "!hangman\n" | |
commandList += "weather\n" | |
return commandList | |
@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")) | |
@client.event | |
# Called whenever it receives a message | |
async def on_message(message): | |
hello = ["hey", "hello", "hi", "yo", "sup", "wagwarn"] | |
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) | |
################################################## | |
# 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 translatesimple.translate(client, message) | |
elif message.content.lower().startswith('!hangman'): | |
await hangman.hangman(client, message) | |
################################################## | |
elif message.content.lower().startswith('!help'): | |
await client.send_message(message.channel, commands()) | |
elif message.content.lower().startswith('weather'): | |
await weather_realtime.weather(client,message) | |
# 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 mockk's discord account/applications - sets bot account | |
client.run('NTA3MTUwNDA3NjM0NTE4MDE3.Dtx6SA.VCa8D43Kdlbq0pETGjopiZgULiA') |