From 10b514473f020225d8e2506044c9b9fc47e898a5 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Sat, 12 Nov 2022 14:59:39 -0800 Subject: [PATCH] catch absence of avatar --- pyproject.toml | 2 +- wiki_postbot/templates/wiki.py | 78 +++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b964ac1..913515d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wiki-postbot" -version = "0.1.1" +version = "0.1.2" description = "Add posts to the wiki!" authors = ["sneakers-the-rat "] license = "GPL-3.0" diff --git a/wiki_postbot/templates/wiki.py b/wiki_postbot/templates/wiki.py index d8b4fc2..abc1c02 100644 --- a/wiki_postbot/templates/wiki.py +++ b/wiki_postbot/templates/wiki.py @@ -5,6 +5,7 @@ Templates for representing different kinds of messages on mediawiki from wiki_postbot.formats.wiki import WikiPage from abc import abstractmethod from discord.message import Message +import warnings class WikiTemplate(WikiPage): @@ -18,10 +19,17 @@ class TemplateMessage(WikiTemplate): @classmethod 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 ( "{{Message\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"|Channel={msg.channel}\n" f"|Text={msg.content}\n" @@ -30,37 +38,37 @@ class TemplateMessage(WikiTemplate): ) - -template_message = TemplateMessage.from_source( - title="Template:Message", - source=""" -
-{{Message
-|Author=
-|Avatar=
-|Date Sent=
-|Channel=(Optional)
-|Text=
-|Link=
-}}
-
-
- - -{{#subobject:{{{Author}}}-{{{Date Sent}}} - |Message topic={{PAGENAME}} - |Has author={{{Author}}} - |Date sent={{{Date Sent}}} - |Has URL={{{Link}}} - |Contains text={{{Text}}} -}} -
-
{{{Author}}}#{{{Channel|}}}[{{{Link}}} {{{Date Sent}}}]
-
-{{{Text}}} -
-
-
-""" -) \ No newline at end of file +# +# template_message = TemplateMessage.from_source( +# title="Template:Message", +# source=""" +#
+# {{Message
+# |Author=
+# |Avatar=
+# |Date Sent=
+# |Channel=(Optional)
+# |Text=
+# |Link=
+# }}
+# 
+#
+# +# +# {{#subobject:{{{Author}}}-{{{Date Sent}}} +# |Message topic={{PAGENAME}} +# |Has author={{{Author}}} +# |Date sent={{{Date Sent}}} +# |Has URL={{{Link}}} +# |Contains text={{{Text}}} +# }} +#
+#
{{{Author}}}#{{{Channel|}}}[{{{Link}}} {{{Date Sent}}}]
+#
+# {{{Text}}} +#
+#
+#
+# """ +# ) \ No newline at end of file