From d31cccf2fefb36b257893cfe8e88d6cd1215b51e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Jan 2023 13:07:45 +0000 Subject: [PATCH 1/4] Bump docker/metadata-action from 4.1.1 to 4.3.0 Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 4.1.1 to 4.3.0. - [Release notes](https://github.com/docker/metadata-action/releases) - [Commits](https://github.com/docker/metadata-action/compare/57396166ad8aefe6098280995947635806a0e6ea...507c2f2dc502c992ad446e3d7a5dfbe311567a96) --- updated-dependencies: - dependency-name: docker/metadata-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4b7764e..21a142e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -47,7 +47,7 @@ jobs: # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta - uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea + uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} flavor: latest=true From 6389df651e49dd46c437aa25f663bd0034dbc3e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 13:03:31 +0000 Subject: [PATCH 2/4] Bump docker/build-push-action from 3.2.0 to 4.0.0 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3.2.0 to 4.0.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/c56af957549030174b10d6867f20e78cfd7debc5...3b5e8027fcad23fda98b2e3ac259d8d67585f671) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4b7764e..e32c799 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -55,7 +55,7 @@ jobs: # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image - uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: context: . push: ${{ github.event_name != 'pull_request' }} From bd8f57457229f2cf951955f2627cf20a3482dd2e Mon Sep 17 00:00:00 2001 From: Aciid <703382+Aciid@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:38:38 +0200 Subject: [PATCH 3/4] Wikipedia module initial commit --- README.md | 8 +++++ modules/wikipedia.py | 75 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 modules/wikipedia.py diff --git a/README.md b/README.md index 6f70b73..df61bd1 100644 --- a/README.md +++ b/README.md @@ -708,6 +708,14 @@ including version, how many users are connected, and ping time. * !mumble - Show info about the configured mumble server - !mumble (set|setserver) [host] ([port]) - Set the configured mumble server +### Wikipedia + +Searches Wikipedia for a given query and returns the first result summary and link. + +#### Usage + +* !wikipedia [query] - Search Wikipedia for query + ## Bot setup * Create a Matrix user diff --git a/modules/wikipedia.py b/modules/wikipedia.py new file mode 100644 index 0000000..30879e2 --- /dev/null +++ b/modules/wikipedia.py @@ -0,0 +1,75 @@ +import re +import html + +import requests + +from modules.common.module import BotModule + +# This module searches wikipedia for query, returns page summary and link. +class MatrixModule(BotModule): + def __init__(self, name): + super().__init__(name) + self.api_url = 'https://en.wikipedia.org/w/api.php' + + async def matrix_message(self, bot, room, event): + args = event.body.split() + + if len(args) == 3 and args[1] == 'apikey': + bot.must_be_owner(event) + self.api_key = args[2] + bot.save_settings() + await bot.send_text(room, 'Api key set') + elif len(args) > 1: + query = event.body[len(args[0])+1:] + try: + response = requests.get(self.api_url, params={ + 'action': 'query', + 'prop': 'extracts', + 'exintro': True, + 'explaintext': True, + 'titles': query, + 'format': 'json', + 'formatversion': 2 + }) + + response.raise_for_status() + data = response.json() + if 'query' not in data or 'pages' not in data['query'] or len(data['query']['pages']) == 0: + await bot.send_text(room, 'No results found') + return + + page = data['query']['pages'][0] + + if 'extract' not in page: + await bot.send_text(room, 'No results found') + return + + # Remove all html tags + extract = re.sub('<[^<]+?>', '', page['extract']) + # Remove any multiple spaces + extract = re.sub(' +', ' ', extract) + # Remove any new lines + extract = re.sub('', '', extract) + # Remove any tabs + extract = re.sub('\t', '', extract) + + # Truncate to 500 chars + extract = extract[:500] + + # Add a link to the page + extract = extract + '\nhttps://en.wikipedia.org/?curid=' + str(page['pageid']) + + await bot.send_text(room, extract) + return + except Exception as exc: + await bot.send_text(room, str(exc)) + else: + await bot.send_text(room, 'Usage: !wikipedia ') + + def help(self): + return ('Wikipedia bot') + + def get_settings(self): + data = super().get_settings() + data["api_key"] = self.api_key + return data \ No newline at end of file From 9af7a4228b46808a1c134d26e7857dfeaa954677 Mon Sep 17 00:00:00 2001 From: Aciid <703382+Aciid@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:38:53 +0200 Subject: [PATCH 4/4] Wikipedia module initial commit --- modules/wikipedia.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/modules/wikipedia.py b/modules/wikipedia.py index 30879e2..e59be5a 100644 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -1,5 +1,4 @@ import re -import html import requests @@ -14,12 +13,7 @@ class MatrixModule(BotModule): async def matrix_message(self, bot, room, event): args = event.body.split() - if len(args) == 3 and args[1] == 'apikey': - bot.must_be_owner(event) - self.api_key = args[2] - bot.save_settings() - await bot.send_text(room, 'Api key set') - elif len(args) > 1: + if len(args) > 1: query = event.body[len(args[0])+1:] try: response = requests.get(self.api_url, params={ @@ -67,9 +61,4 @@ class MatrixModule(BotModule): await bot.send_text(room, 'Usage: !wikipedia ') def help(self): - return ('Wikipedia bot') - - def get_settings(self): - data = super().get_settings() - data["api_key"] = self.api_key - return data \ No newline at end of file + return ('Wikipedia bot') \ No newline at end of file