]> git.armaanb.net Git - tall.bot.git/blob - tallbot.py
371c048bc9162cc6aa1423d8fd1382680d0a4d62
[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 logging
6 import sys
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     try:
17         logging.info(str(pid) + " | " + search)
18         return "<Wikipedia> " + wikipedia.summary(search,
19                                                   sentences=sen,
20                                                   auto_suggest=False)
21     except Exception as e:
22         logging.debug(str(pid) + " | " + search + " | " + str(e))
23         return str(e)
24
25 def keyword_check(inp):
26     x = inp.split()
27     x = " ".join(x[:2])
28     if x in keywords:
29         return True
30     else:
31         return False
32
33 class TallBot(discord.Client):
34     async def on_ready(self):
35         logging.debug('Logged in as ', self.user)
36
37     async def on_message(self, message):
38         if message.author == self.user:
39             return
40
41         if keyword_check(message.content):
42             await message.channel.send(wiki_sum(message.content.split()[2:],
43                                                 2,
44                                                 message.author))
45
46 TallBot().run(sys.argv[1])