-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (47 loc) · 1.61 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import discord
import requests
import random
import json
from replit import db
client = discord.Client()
def get_random_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)
keywords = ["courage","dreams","fear","freedom","future","happiness","inspiration","leadership","life","love","past","success","work"]
if "zen" not in db.keys():
db["zen"] = True
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if db["zen"]:
if msg.startswith('$random'):
quote = get_random_quote()
await message.channel.send(quote)
if msg.startswith('$quote '):
keyword = msg.split("$quote ",1)[1]
if keyword in keywords:
link = "https://zenquotes.io/api/quotes/" + keyword
response = requests.get(link)
json_data = json.loads(response.text)
rand = random.randint(0, len(json_data))
quote = json_data[rand]['q'] + " -" + json_data[rand]['a']
await message.channel.send(quote)
if msg.startswith("$keywords"):
await message.channel.send(keywords)
if msg.startswith("$zen"):
value = msg.split("$zen ",1)[1]
if value.lower() == "on":
db["zen"] = True
await message.channel.send("Zen Bot is on.")
elif value.lower() == "off":
db["zen"] = False
await message.channel.send("Zen Bot is off.")
client.run(os.getenv('ZEN_TOKEN'))