summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <code@armaanb.net>2020-12-19 15:53:09 -0500
committerArmaan Bhojwani <code@armaanb.net>2020-12-19 15:53:09 -0500
commit23ed273a82dcca74600f02f0263aa60cab4a84cc (patch)
tree2565e24eb526ffe6bf8b22ebd002ccdfa6ea6eae
parent1a63360df4ae08d437a36ddfa519ed9d8e8b8d5e (diff)
downloadtall.bot-23ed273a82dcca74600f02f0263aa60cab4a84cc.tar.gz
add detection for words like "the" in the query
-rwxr-xr-xtallbot.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/tallbot.py b/tallbot.py
index 371c048..e097ba7 100755
--- a/tallbot.py
+++ b/tallbot.py
@@ -4,17 +4,13 @@
import logging
import sys
+import time
import wikipedia
import discord
-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, pid):
- search = " ".join(search)
try:
- logging.info(str(pid) + " | " + search)
+ logging.info(str(pid) + " | " + str(int(time.time())) + " | " + search)
return "<Wikipedia> " + wikipedia.summary(search,
sentences=sen,
auto_suggest=False)
@@ -22,25 +18,35 @@ def wiki_sum(search, sen, pid):
logging.debug(str(pid) + " | " + search + " | " + str(e))
return str(e)
-def keyword_check(inp):
+def create_query(inp):
+ key1 = ["What", "what", "who", "Who"]
+ key2 = ["is", "are", "were", "was"]
+ key3 = ["a", "an", "the"]
+
x = inp.split()
- x = " ".join(x[:2])
- if x in keywords:
- return True
+ if x[0] in key1 and x[1] in key2:
+ x = x[2:]
+ if x[0] in key3:
+ x = x[1:]
else:
return False
+ return " ".join(x)
+
class TallBot(discord.Client):
async def on_ready(self):
- logging.debug('Logged in as ', self.user)
+ logging.info('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,
- message.author))
+ key = create_query(message.content)
+ if key:
+ await message.channel.send(wiki_sum(key, 2, message.author))
+
+def main():
+ TallBot().run(sys.argv[1])
-TallBot().run(sys.argv[1])
+if __name__ == "__main__":
+ main()