Compare commits
No commits in common. "main" and "slack" have entirely different histories.
5 changed files with 26 additions and 70 deletions
23
README.md
23
README.md
|
@ -1,27 +1,8 @@
|
|||
# wiki-postbot
|
||||
|
||||
Bot to crosspost from chat clients and microblogs using an extended wikilink syntax to the (media)wiki.
|
||||
|
||||
eg. say `Hey what up i'm [[wikilinkin]]` in slack, and embed that message with a backlink on the `wikilinkin` page.
|
||||
|
||||
Sorry for the extremely crappy docs and code structure y'all, this was supposed to be an internal tool for like 5 different projects, so i have done nothing yet to make it readable or reusable. the best way to understand this package for now would probably be to work backwards from the script entrypoints (see https://git.jon-e.net/jonny/wiki-postbot/src/branch/main/pyproject.toml#L11 ).
|
||||
|
||||
> this is not a model directed project, since it hasn't been intended to outlive the immediate circumstances each time, but it ends up doing so anyway.
|
||||
>
|
||||
> discord entrypoint is this: https://git.jon-e.net/jonny/wiki-postbot/src/branch/main/wiki_postbot/clients/discord.py
|
||||
>
|
||||
> main thing it does is transcribe messages onto wiki pages, this is the parser for those:
|
||||
> https://git.jon-e.net/jonny/wiki-postbot/src/branch/main/wiki_postbot/patterns/wikilink.py
|
||||
>
|
||||
> it was designed to have a little microsyntax for selecting n-back post ranges and handling semantic wikilinks contextually but i haven't been able to implement that on the client side yet.
|
||||
>
|
||||
> wiki interface is here: https://git.jon-e.net/jonny/wiki-postbot/src/branch/main/wiki_postbot/interfaces/mediawiki.py
|
||||
>
|
||||
> specifically incoming from discord here: https://git.jon-e.net/jonny/wiki-postbot/src/commit/b4fd7c2080f2c3f2af6f215705083368ceef18d8/wiki_postbot/interfaces/mediawiki.py#L164
|
||||
>
|
||||
> so ideally that would, yno, have a data model that it juices things into, so i'm going to work those scraps into an n-to-m bridger that i was experimenting with a lil service version of here: https://git.jon-e.net/jonny/chatbridge
|
||||
> - https://neuromatch.social/@jonny/111476292383009212
|
||||
Bot to add tweets using an extended wikilink syntax to the wiki
|
||||
|
||||
Starting with twitter, but then will add masto
|
||||
|
||||
# Mediawiki
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
# 0.1.3
|
||||
|
||||
- Add overwrite option to append_text in wiki interface
|
||||
|
||||
# 0.1.4
|
||||
|
||||
- Like 0.1.3 but actually doing it right
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "wiki-postbot"
|
||||
version = "0.1.4"
|
||||
version = "0.1.3"
|
||||
description = "Add posts to the wiki!"
|
||||
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -13,19 +13,11 @@ from wiki_postbot.actions import Result
|
|||
from wiki_postbot.logger import init_logger
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
from discord.message import Message, Embed
|
||||
import pdb
|
||||
|
||||
if TYPE_CHECKING:
|
||||
try:
|
||||
from wiki_postbot.clients.slack import SlackMessage
|
||||
except ImportError:
|
||||
SlackMessage = None
|
||||
try:
|
||||
from discord.message import Message, Embed
|
||||
except ImportError:
|
||||
Message = None
|
||||
Embed = None
|
||||
from wiki_postbot.clients.slack import SlackMessage
|
||||
|
||||
# creds = Mediawiki_Creds.from_json('mediawiki_creds.json')
|
||||
|
||||
|
@ -95,6 +87,10 @@ class Wiki:
|
|||
return WikiPage.from_source(title=content['parse']['title'], source=content['parse']['wikitext'])
|
||||
|
||||
def insert_text(self, page, section, text, overwrite:bool=False):
|
||||
if overwrite:
|
||||
operation_key = 'text'
|
||||
else:
|
||||
operation_key = 'appendtext'
|
||||
|
||||
# TODO: Move finding section IDs into the page class!
|
||||
page_text = self.get_page(page)
|
||||
|
@ -121,30 +117,17 @@ class Wiki:
|
|||
|
||||
if matching_section >= 0:
|
||||
print(f'found matching section {matching_section}')
|
||||
if overwrite:
|
||||
page_text.content.sections[matching_section].contents = text
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"text": page_text.content.string,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
else:
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"section":str(matching_section),
|
||||
"appendtext":text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"section":str(matching_section),
|
||||
operation_key:text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
else:
|
||||
self.logger.debug('making new section')
|
||||
result = self.sess.post(
|
||||
|
@ -154,14 +137,14 @@ class Wiki:
|
|||
"title":page,
|
||||
"section":"new",
|
||||
"sectiontitle":section,
|
||||
"appendtext":text,
|
||||
operation_key:text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
def handle_discord(self, msg:'Message') -> Result:
|
||||
def handle_discord(self, msg:Message) -> Result:
|
||||
"""
|
||||
Not being precious about this, just implementing
|
||||
and will worry about generality later!
|
||||
|
|
|
@ -4,20 +4,16 @@ Templates for representing different kinds of messages on mediawiki
|
|||
from typing import TYPE_CHECKING
|
||||
from wiki_postbot.formats.wiki import WikiPage
|
||||
from abc import abstractmethod
|
||||
|
||||
from discord.message import Message
|
||||
import warnings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from wiki_postbot.clients.slack import SlackMessage
|
||||
try:
|
||||
from discord.message import Message
|
||||
except ImportError:
|
||||
Message = None
|
||||
|
||||
class WikiTemplate(WikiPage):
|
||||
|
||||
@abstractmethod
|
||||
def format_discord(self, msg:'Message') -> str:
|
||||
def format_discord(self, msg:Message) -> str:
|
||||
"""
|
||||
Format a discord message into a template string
|
||||
"""
|
||||
|
@ -25,7 +21,7 @@ class WikiTemplate(WikiPage):
|
|||
class TemplateMessage(WikiTemplate):
|
||||
|
||||
@classmethod
|
||||
def format_discord(self, msg:'Message') -> str:
|
||||
def format_discord(self, msg:Message) -> str:
|
||||
# try/catch the avatar URL
|
||||
try:
|
||||
avatar = msg.author.avatar.url
|
||||
|
|
Loading…
Reference in a new issue