added !inspire

This commit is contained in:
Sid 2021-12-18 18:36:06 +01:00 committed by GitHub
parent 4feb24898b
commit 924fc26bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View file

@ -17,3 +17,6 @@
>**merry christmas** >**merry christmas**
> Someone writes "merry christmas" and bot responds w/ legendary vine quote selected from an array > 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

23
main.py
View file

@ -1,19 +1,33 @@
import os import os
import discord import discord
import requests
import json
import random import random
client = discord.Client() client = discord.Client()
my_secret = os.environ['TOKEN'] my_secret = os.environ['TOKEN']
# arrays containing answers
xmasAnswers = ['Happy Chrismis!', 'Its Chrismin!', 'Merry Chrisis!', 'Merry Chrysler!'] xmasAnswers = ['Happy Chrismis!', 'Its Chrismin!', 'Merry Chrisis!', 'Merry Chrysler!']
coinflip = ['Heads', 'Not Sonic lol (Tails..)'] 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 # when bot is ready
@client.event # Register an event @client.event # Register an event
async def on_ready(): async def on_ready():
print('We have logged in as {0.user}'.format(client)) print('We have logged in as {0.user}'.format(client))
# bot senses a message & responds # bot senses a message & responds
@client.event @client.event
async def on_message(message): async def on_message(message):
@ -34,11 +48,11 @@ async def on_message(message):
elif message.content.lower().startswith("!help"): elif message.content.lower().startswith("!help"):
await message.channel.send(file=discord.File("commands.md")) 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"): elif message.content.lower().startswith("!coinflip"):
await message.channel.send(random.choice(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"): elif message.content.lower().startswith("!github"):
await message.channel.send('https://github.com/SindreKjelsrud') await message.channel.send('https://github.com/SindreKjelsrud')
@ -46,6 +60,11 @@ async def on_message(message):
elif "merry christmas" in message.content.lower(): elif "merry christmas" in message.content.lower():
await message.channel.send(random.choice(xmasAnswers) + ':santa:') 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 # run bot
client.run(my_secret) client.run(my_secret)