]> git.armaanb.net Git - tall.bot.git/blobdiff - tallbot.py
login before pulling image
[tall.bot.git] / tallbot.py
index a888a4ee16760fa6156d32bdead675bde2fabaed..371c048bc9162cc6aa1423d8fd1382680d0a4d62 100755 (executable)
@@ -2,6 +2,7 @@
 # tall.bot - a simple Discord Wikipedia bot
 # Armaan Bhojwani 2020
 
+import logging
 import sys
 import wikipedia
 import discord
@@ -10,13 +11,16 @@ 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"
-
-    return output
+        logging.info(str(pid) + " | " + search)
+        return "<Wikipedia> " + wikipedia.summary(search,
+                                                  sentences=sen,
+                                                  auto_suggest=False)
+    except Exception as e:
+        logging.debug(str(pid) + " | " + search + " | " + str(e))
+        return str(e)
 
 def keyword_check(inp):
     x = inp.split()
@@ -26,16 +30,17 @@ 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.run(sys.argv[1])
+TallBot().run(sys.argv[1])