]> git.armaanb.net Git - tall.bot.git/blob - tallbot.py
first commit
[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 wikipedia
7 import discord
8
9 keywords = ["what is", "What is", "what was", "What was", "what were",
10             "What were", "who is", "Who is", "who was", "Who was", 
11             "who were", "Who were", "who are", "Who are"]
12
13 def wiki_sum(search, sen):
14     try:
15         output = "From Wikipedia: " + wikipedia.summary(search, sentences=sen)
16     except:
17         output = "There was an error"
18
19     return output
20
21 def keyword_check(inp):
22     x = inp.split()
23     x = " ".join(x[:2])
24     if x in keywords:
25         return True
26     else:
27         return False
28
29 class MyClient(discord.Client):
30     async def on_ready(self):
31         print('Logged in as', self.user)
32
33     async def on_message(self, message):
34         if message.author == self.user:
35             return
36
37         if keyword_check(message.content):
38             await message.channel.send(wiki_sum(message.content.split()[2:], 2))
39
40 client = MyClient()
41 client.run(sys.argv[1])