summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <code@armaanb.net>2020-12-16 12:18:45 -0500
committerArmaan Bhojwani <code@armaanb.net>2020-12-16 12:18:45 -0500
commitd470b39c98fa558e8485f8189050abb52d34a905 (patch)
treece39bd80570035847f43c039971de9c3e202bdb7
parent05c778d3a80992e794725552032e7cc9931370f6 (diff)
downloadtall.bot-d470b39c98fa558e8485f8189050abb52d34a905.tar.gz
fixe search concatonation, improve usability
-rwxr-xr-xtallbot.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/tallbot.py b/tallbot.py
index a888a4e..b27e3ba 100755
--- a/tallbot.py
+++ b/tallbot.py
@@ -3,6 +3,7 @@
# Armaan Bhojwani 2020
import sys
+import logging
import wikipedia
import discord
@@ -10,11 +11,15 @@ keywords = ["what is", "What is", "what was", "What was", "what were",
"What were", "who is", "Who is", "who was", "Who was",
"who were", "Who were", "who are", "Who are"]
-def wiki_sum(search, sen):
+def wiki_sum(search, sen, pid):
+ search = " ".join(search)
+
try:
- output = "From Wikipedia: " + wikipedia.summary(search, sentences=sen)
- except:
- output = "There was an error"
+ output = "<Wikipedia> " + wikipedia.summary(search, sentences=sen)
+ logging.info(str(pid) + " | " + search)
+ except Exception as e:
+ output = str(e)
+ logging.info(str(pid) + " | " + search + " | " + str(e))
return output
@@ -26,16 +31,18 @@ def keyword_check(inp):
else:
return False
-class MyClient(discord.Client):
+class TallBot(discord.Client):
async def on_ready(self):
- print('Logged in as', self.user)
+ logging.debug('Logged in as ', self.user)
async def on_message(self, message):
if message.author == self.user:
return
if keyword_check(message.content):
- await message.channel.send(wiki_sum(message.content.split()[2:], 2))
+ await message.channel.send(wiki_sum(message.content.split()[2:],
+ 2,
+ message.author))
-client = MyClient()
+client = TallBot()
client.run(sys.argv[1])