Skip to content
Merged

bot #100

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Projects/Encourage bot/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Encourage-Bot
This bot bring joyness to your life
15 changes: 15 additions & 0 deletions Projects/Encourage bot/keep_alive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask
from threading import Thread

app = Flask('')

@app.route('/')
def home():
return "Hello. I am alive!"

def run():
app.run(host='0.0.0.0',port=8080)

def keep_alive():
t = Thread(target=run)
t.start()
95 changes: 95 additions & 0 deletions Projects/Encourage bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import discord
import os
import requests
import json
import random
from replit import db
from keep_alive import keep_alive

client = discord.Client()

sad_words = ["sad", "depressed", "unhappy", "angry", "miserable", "depressing"]

starter_encouragements = [
"Cheer up!",
"Hang in there.",
"You are a great person / bot!"
]

if "responding" not in db.keys():
db["responding"] = True

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)

def update_encouragements(encouraging_message):
if "encouragements" in db.keys():
encouragements = db["encouragements"]
encouragements.append(encouraging_message)
db["encouragements"] = encouragements
else:
db["encouragements"] = [encouraging_message]

def delete_encouragment(index):
encouragements = db["encouragements"]
if len(encouragements) > index:
del encouragements[index]
db["encouragements"] = encouragements

@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 msg.startswith('$inspire'):
quote = get_quote()
await message.channel.send(quote)

if db["responding"]:
options = starter_encouragements
if "encouragements" in db.keys():
options = options + db["encouragements"]

if any(word in msg for word in sad_words):
await message.channel.send(random.choice(options))

if msg.startswith("$new"):
encouraging_message = msg.split("$new ",1)[1]
update_encouragements(encouraging_message)
await message.channel.send("New encouraging message added.")

if msg.startswith("$del"):
encouragements = []
if "encouragements" in db.keys():
index = int(msg.split("$del",1)[1])
delete_encouragment(index)
encouragements = db["encouragements"]
await message.channel.send(encouragements)

if msg.startswith("$list"):
encouragements = []
if "encouragements" in db.keys():
encouragements = db["encouragements"]
await message.channel.send(encouragements)

if msg.startswith("$responding"):
value = msg.split("$responding ",1)[1]

if value.lower() == "true":
db["responding"] = True
await message.channel.send("Responding is on.")
else:
db["responding"] = False
await message.channel.send("Responding is off.")

keep_alive()
client.run(os.getenv('TOKEN'))