Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import os
- import logging
- import re
- import pathlib
- from google_images_download import google_images_download
- TOKEN = 'XXXXX'
- client = discord.Client()
- @client.event
- async def on_message(message):
- #don't do anything if it is us
- if message.author == client.user:
- return
- if re.match('!mugabe\squote', message.content):
- #TODO: We need to integrate with the mugabe api
- reply = "This should be a robert mugabe quote"
- await client.send_message(message.channel, reply)
- elif re.match('!mugabe\simage', message.content):
- await get_mugabe_pic(message)
- elif re.match('!mugabe\shelp', message.content):
- await help_message(message)
- elif re.match('!mugabe\sabout', message.content):
- await about(message)
- else:
- await invalid_command(message)
- @client.event
- async def on_ready():
- print('Logged in:', client.user.name, client.user.id)
- async def help_message(message):
- help_message = """
- ```
- *!mugabe quote* - I will find a Robert Mugabe Quote
- *!mugabe image* - I will find a Picture of Robert Mugabe
- *!mugabe help* - I will help you how to use me :D
- *!mugabe about* - About Mugabe bot
- ```
- """
- await client.send_message(message.channel, help_message)
- async def about(message):
- about_msg = """
- This is a joke mugabe bot so Mr. Jesus could learn how to write discord bots.
- """
- await client.send_message(message.channel, about_msg)
- async def invalid_command(message):
- invalid_command_msg = "Sorry I didn't understand that. Type `!mugabe help` to show what I respond to."
- await client.send_message(message.channel, invalid_command_msg)
- async def get_mugabe_pic(message):
- #for now assume anything after the
- searchterm = re.sub('^!mugabe\simage\s', '', message.content)
- response = google_images_download.googleimagesdownload()
- arguments = {
- 'keywords': "robert mugabe",
- 'limit': 20,
- 'print_urls' : True
- }
- #if we don't have a search term then
- if searchterm.strip():
- arguments['keywords'] = "robert mugabe {}".format(searchterm)
- paths = response.download(arguments)
- images = paths[list(paths.keys())[0]]
- if len(images) is not 0:
- with open(images[0], 'rb') as pic:
- await client.send_file(message.channel, pic)
- if __name__ == '__main__':
- client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement