From 683a73a2f03371a464cfcba8dbba87156618e70d Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Tue, 15 Dec 2020 19:31:58 -0500 Subject: [PATCH] first commit --- .build.yml | 15 +++++++++++++++ .gitignore | 1 + Dockerfile | 8 ++++++++ LICENSE | 8 ++++++++ README.md | 5 +++++ requirements.txt | 14 ++++++++++++++ tallbot.py | 41 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 .build.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 requirements.txt create mode 100755 tallbot.py diff --git a/.build.yml b/.build.yml new file mode 100644 index 0000000..bc16a4b --- /dev/null +++ b/.build.yml @@ -0,0 +1,15 @@ +image: archlinux +packages: + - docker +sources: + - https://git.sr.ht/~armaan/tall.bot +secrets: + - cfca6590-dec3-46f3-abf0-3bce5c907e4a +tasks: + - build: | + cd tall.bot + docker build -t armaanb/tall.bot:latest + docker login + docker push +artifacts: + - gen-shell/src/gen-shell diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67e8ef5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tall.bot diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb581a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.8 + +WORKDIR /src +COPY . . + +RUN pip install -r requirements.txt + +ENTRYPOINT python tallbot.py $TOKEN diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..086cc32 --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +tall.bot - a simple Discord Wikipedia bot +Copyright © 2020 Armaan Bhojwani + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d12e66f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# tall.bot +A simple discord Wikipedia bot + +## License +Copyright Armaan Bhojwani 2020, MIT license diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..520252e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +aiohttp==3.6.3 +async-timeout==3.0.1 +attrs==20.3.0 +beautifulsoup4==4.9.3 +certifi==2020.12.5 +chardet==3.0.4 +discord.py==1.5.1 +idna==2.10 +multidict==4.7.6 +requests==2.25.0 +soupsieve==2.1 +urllib3==1.26.2 +wikipedia==1.4.0 +yarl==1.5.1 diff --git a/tallbot.py b/tallbot.py new file mode 100755 index 0000000..a888a4e --- /dev/null +++ b/tallbot.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# tall.bot - a simple Discord Wikipedia bot +# Armaan Bhojwani 2020 + +import sys +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): + try: + output = "From Wikipedia: " + wikipedia.summary(search, sentences=sen) + except: + output = "There was an error" + + return output + +def keyword_check(inp): + x = inp.split() + x = " ".join(x[:2]) + if x in keywords: + return True + else: + return False + +class MyClient(discord.Client): + async def on_ready(self): + print('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)) + +client = MyClient() +client.run(sys.argv[1]) -- 2.39.2