From 924fc26bdf4a5659a7ae80d0c42a52f81ea41fd1 Mon Sep 17 00:00:00 2001 From: Sid <93219711+SindreKjelsrud@users.noreply.github.com> Date: Sat, 18 Dec 2021 18:36:06 +0100 Subject: [PATCH] added !inspire --- commands.md | 5 ++++- main.py | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/commands.md b/commands.md index 0f3d3dc..4cb359e 100644 --- a/commands.md +++ b/commands.md @@ -16,4 +16,7 @@ > Heads or Tails! >**merry christmas** -> Someone writes "merry christmas" and bot responds w/ legendary vine quote selected from an array \ No newline at end of file +> Someone writes "merry christmas" and bot responds w/ legendary vine quote selected from an array + +>**!inspire** +> Bot inspires user with a quote from zenquotes.io \ No newline at end of file diff --git a/main.py b/main.py index bdaf20c..35c9b55 100644 --- a/main.py +++ b/main.py @@ -1,19 +1,33 @@ import os import discord +import requests +import json import random client = discord.Client() my_secret = os.environ['TOKEN'] + +# arrays containing answers xmasAnswers = ['Happy Chrismis!', 'Its Chrismin!', 'Merry Chrisis!', 'Merry Chrysler!'] coinflip = ['Heads', 'Not Sonic lol (Tails..)'] + +# gets a quote from zenquotes.io +def get_quote(): + response = requests.get('https://zenquotes.io/api/random') + json_data = json.loads(response.text) + quote = json_data[0]['q'] + ' -' + json_data[0]['a'] + return(quote) + + # when bot is ready @client.event # Register an event async def on_ready(): print('We have logged in as {0.user}'.format(client)) + # bot senses a message & responds @client.event async def on_message(message): @@ -30,15 +44,15 @@ async def on_message(message): await message.channel.send(f'Pong :ping_pong: (Bot latency: **{round(client.latency * 1000)}ms**)') await message.channel.send(file=discord.File('resources/pingpong.gif')) - # user sends "!help", bot sends commands file + # user sends "!help", bot sends commandsfile elif message.content.lower().startswith("!help"): await message.channel.send(file=discord.File("commands.md")) - # user sends "!coinflip", bot sends commands file + # user sends "!coinflip", bot returns result elif message.content.lower().startswith("!coinflip"): await message.channel.send(random.choice(coinflip)) - # user sends "!github", bot sends commands file + # user sends "!github", bot responds w/ my GitHub profile elif message.content.lower().startswith("!github"): await message.channel.send('https://github.com/SindreKjelsrud') @@ -46,6 +60,11 @@ async def on_message(message): elif "merry christmas" in message.content.lower(): await message.channel.send(random.choice(xmasAnswers) + ':santa:') + # user sends "!inspire", bot inspires user + elif message.content.lower().startswith("!inspire"): + quote = get_quote() + await message.channel.send(quote) + # run bot client.run(my_secret) \ No newline at end of file