catch absence of avatar
This commit is contained in:
parent
7498969d2e
commit
10b514473f
2 changed files with 44 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "wiki-postbot"
|
name = "wiki-postbot"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
description = "Add posts to the wiki!"
|
description = "Add posts to the wiki!"
|
||||||
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
|
@ -5,6 +5,7 @@ Templates for representing different kinds of messages on mediawiki
|
||||||
from wiki_postbot.formats.wiki import WikiPage
|
from wiki_postbot.formats.wiki import WikiPage
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from discord.message import Message
|
from discord.message import Message
|
||||||
|
import warnings
|
||||||
|
|
||||||
class WikiTemplate(WikiPage):
|
class WikiTemplate(WikiPage):
|
||||||
|
|
||||||
|
@ -18,10 +19,17 @@ class TemplateMessage(WikiTemplate):
|
||||||
|
|
||||||
@classmethod
|
@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
|
||||||
|
except Exception as e:
|
||||||
|
warnings.warn("No avatar found!")
|
||||||
|
avatar = ""
|
||||||
|
|
||||||
return (
|
return (
|
||||||
"{{Message\n"
|
"{{Message\n"
|
||||||
f"|Author={msg.author.name}\n"
|
f"|Author={msg.author.name}\n"
|
||||||
f"|Avatar={msg.author.avatar.url}\n"
|
f"|Avatar={avatar}\n"
|
||||||
f"|Date Sent={msg.created_at.strftime('%y-%m-%d %H:%M:%S')}\n"
|
f"|Date Sent={msg.created_at.strftime('%y-%m-%d %H:%M:%S')}\n"
|
||||||
f"|Channel={msg.channel}\n"
|
f"|Channel={msg.channel}\n"
|
||||||
f"|Text={msg.content}\n"
|
f"|Text={msg.content}\n"
|
||||||
|
@ -30,37 +38,37 @@ class TemplateMessage(WikiTemplate):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
template_message = TemplateMessage.from_source(
|
# template_message = TemplateMessage.from_source(
|
||||||
title="Template:Message",
|
# title="Template:Message",
|
||||||
source="""<noinclude>
|
# source="""<noinclude>
|
||||||
<pre>
|
# <pre>
|
||||||
{{Message
|
# {{Message
|
||||||
|Author=
|
# |Author=
|
||||||
|Avatar=
|
# |Avatar=
|
||||||
|Date Sent=
|
# |Date Sent=
|
||||||
|Channel=(Optional)
|
# |Channel=(Optional)
|
||||||
|Text=
|
# |Text=
|
||||||
|Link=
|
# |Link=
|
||||||
}}
|
# }}
|
||||||
</pre>
|
# </pre>
|
||||||
</noinclude>
|
# </noinclude>
|
||||||
<includeonly>
|
# <includeonly>
|
||||||
|
#
|
||||||
{{#subobject:{{{Author}}}-{{{Date Sent}}}
|
# {{#subobject:{{{Author}}}-{{{Date Sent}}}
|
||||||
|Message topic={{PAGENAME}}
|
# |Message topic={{PAGENAME}}
|
||||||
|Has author={{{Author}}}
|
# |Has author={{{Author}}}
|
||||||
|Date sent={{{Date Sent}}}
|
# |Date sent={{{Date Sent}}}
|
||||||
|Has URL={{{Link}}}
|
# |Has URL={{{Link}}}
|
||||||
|Contains text={{{Text}}}
|
# |Contains text={{{Text}}}
|
||||||
}}
|
# }}
|
||||||
<div style="border: 1px solid black; border-radius: 5px;padding:5px"
|
# <div style="border: 1px solid black; border-radius: 5px;padding:5px"
|
||||||
>
|
# >
|
||||||
<div style="display:flex; flex-direction:row; align-items:center; border-bottom:1px solid black; gap:10px; padding-bottom:5px;"><img src={{{Avatar|}}} style="width:30px;border-radius:10px"/><span style="font-weight:bold;">{{{Author}}}</span><span><nowiki>#</nowiki>{{{Channel|}}}</span><span style="font-style:italic;color:#999999">[{{{Link}}} {{{Date Sent}}}]</span></div>
|
# <div style="display:flex; flex-direction:row; align-items:center; border-bottom:1px solid black; gap:10px; padding-bottom:5px;"><img src={{{Avatar|}}} style="width:30px;border-radius:10px"/><span style="font-weight:bold;">{{{Author}}}</span><span><nowiki>#</nowiki>{{{Channel|}}}</span><span style="font-style:italic;color:#999999">[{{{Link}}} {{{Date Sent}}}]</span></div>
|
||||||
<div>
|
# <div>
|
||||||
{{{Text}}}
|
# {{{Text}}}
|
||||||
</div>
|
# </div>
|
||||||
</div>
|
# </div>
|
||||||
</includeonly>
|
# </includeonly>
|
||||||
"""
|
# """
|
||||||
)
|
# )
|
Loading…
Reference in a new issue