]> git.armaanb.net Git - tall.bot.git/blob - tallbot.py
fixe search concatonation, improve usability
[tall.bot.git] / tallbot.py
1 #!/usr/bin/env python3
2 # tall.bot - a simple Discord Wikipedia bot
3 # Armaan Bhojwani 2020
4
5 import sys
6 import logging
7 import wikipedia
8 import discord
9
10 keywords = ["what is", "What is", "what was", "What was", "what were",
11             "What were", "who is", "Who is", "who was", "Who was", 
12             "who were", "Who were", "who are", "Who are"]
13
14 def wiki_sum(search, sen, pid):
15     search = " ".join(search)
16
17     try:
18         output = "<Wikipedia> " + wikipedia.summary(search, sentences=sen)
19         logging.info(str(pid) + " | " + search)
20     except Exception as e:
21         output = str(e)
22         logging.info(str(pid) + " | " + search + " | " + str(e))
23
24     return output
25
26 def keyword_check(inp):
27     x = inp.split()
28     x = " ".join(x[:2])
29     if x in keywords:
30         return True
31     else:
32         return False
33
34 class TallBot(discord.Client):
35     async def on_ready(self):
36         logging.debug('Logged in as ', self.user)
37
38     async def on_message(self, message):
39         if message.author == self.user:
40             return
41
42         if keyword_check(message.content):
43             await message.channel.send(wiki_sum(message.content.split()[2:],
44                                                 2,
45                                                 message.author))
46
47 client = TallBot()
48 client.run(sys.argv[1])