-
Notifications
You must be signed in to change notification settings - Fork 1
/
boop-bot.py
70 lines (54 loc) · 1.54 KB
/
boop-bot.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
67
68
69
70
"""
Test version of Discord chatbot.
Contributions: Ewan Klein
Rosalyn Pearson
Helen Williams
Andrew
Yousef
May 2021
"""
import json
import os
import random
import discord
from dotenv import load_dotenv # required for running locally
load_dotenv()
with open("exchanges.json", "r") as f:
exchanges = json.load(f)
TOKEN = os.getenv('TOKEN')
client = discord.Client()
def new_topic():
"""
Start talking about a random topic.
"""
topics = ["wasps", "ice cream", "school", "Fortnite",
"burgers", "hotels", "getting a suntan"]
choice = random.choice(topics) # choose a topic at random
phrases = [f"So what do you think about {choice}?",
f"Anyway, I really like {choice}!", f"That's really interesing but what about {choice}???"]
phrase = choice = random.choice(phrases)
return phrase
def respond(user_input):
"""
Generate a response to the user input.
"""
user_input.lower()
words = user_input.split()
response = new_topic()
for word in words:
if word in exchanges:
responses = exchanges[word]
response = random.choice(responses)
break
return response
@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
user_input = message.content
response = respond(user_input)
await message.reply(response)
client.run(TOKEN)