mirror of https://gitlab.com/bashrc2/epicyon
Add option for use of discord within profile fields
parent
7c00870679
commit
09e0dc5e9b
|
@ -81,6 +81,8 @@ from pgp import set_pgp_fingerprint
|
|||
from pgp import get_pgp_fingerprint
|
||||
from pronouns import get_pronouns
|
||||
from pronouns import set_pronouns
|
||||
from discord import get_discord
|
||||
from discord import set_discord
|
||||
from youtube import get_youtube
|
||||
from youtube import set_youtube
|
||||
from pixelfed import get_pixelfed
|
||||
|
@ -2005,6 +2007,23 @@ def _profile_post_youtube(actor_json: {}, fields: {},
|
|||
return actor_changed
|
||||
|
||||
|
||||
def _profile_post_discord(actor_json: {}, fields: {},
|
||||
actor_changed: bool) -> bool:
|
||||
""" HTTP POST change discord channel address
|
||||
"""
|
||||
current_discord = get_discord(actor_json)
|
||||
if fields.get('discordChannel'):
|
||||
if fields['discordChannel'] != current_discord:
|
||||
set_discord(actor_json,
|
||||
fields['discordChannel'])
|
||||
actor_changed = True
|
||||
else:
|
||||
if current_discord:
|
||||
set_discord(actor_json, '')
|
||||
actor_changed = True
|
||||
return actor_changed
|
||||
|
||||
|
||||
def _profile_post_pixelfed(actor_json: {}, fields: {},
|
||||
actor_changed: bool) -> bool:
|
||||
""" HTTP POST change pixelfed channel address
|
||||
|
@ -2910,6 +2929,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
|
|||
_profile_post_pixelfed(actor_json, fields,
|
||||
actor_changed)
|
||||
|
||||
actor_changed = \
|
||||
_profile_post_discord(actor_json, fields,
|
||||
actor_changed)
|
||||
|
||||
actor_changed = \
|
||||
_profile_post_youtube(actor_json, fields,
|
||||
actor_changed)
|
||||
|
|
|
@ -45,6 +45,7 @@ from donate import get_donation_url
|
|||
from donate import get_website
|
||||
from donate import get_gemini_link
|
||||
from pronouns import get_pronouns
|
||||
from discord import get_discord
|
||||
from youtube import get_youtube
|
||||
from pixelfed import get_pixelfed
|
||||
from peertube import get_peertube
|
||||
|
@ -660,6 +661,7 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
pgp_fingerprint = None
|
||||
pronouns = None
|
||||
pixelfed = None
|
||||
discord = None
|
||||
youtube = None
|
||||
peertube = None
|
||||
xmpp_address = None
|
||||
|
@ -692,6 +694,7 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
gemini_link = get_gemini_link(actor_json)
|
||||
pronouns = get_pronouns(actor_json)
|
||||
pixelfed = get_pixelfed(actor_json)
|
||||
discord = get_discord(actor_json)
|
||||
youtube = get_youtube(actor_json)
|
||||
peertube = get_peertube(actor_json)
|
||||
xmpp_address = get_xmpp_address(actor_json)
|
||||
|
@ -767,7 +770,8 @@ def show_person_options(self, calling_domain: str, path: str,
|
|||
self.server.blocked_cache,
|
||||
repo_url,
|
||||
self.server.sites_unavailable,
|
||||
youtube, peertube, pixelfed)
|
||||
youtube, peertube, pixelfed,
|
||||
discord)
|
||||
if msg:
|
||||
msg = msg.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
__filename__ = "discord.py"
|
||||
__author__ = "Bob Mottram"
|
||||
__license__ = "AGPL3+"
|
||||
__version__ = "1.5.0"
|
||||
__maintainer__ = "Bob Mottram"
|
||||
__email__ = "bob@libreserver.org"
|
||||
__status__ = "Production"
|
||||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
from utils import get_attachment_property_value
|
||||
from utils import remove_html
|
||||
from utils import string_contains
|
||||
|
||||
discord_fieldnames = ['discord']
|
||||
|
||||
|
||||
def get_discord(actor_json: {}) -> str:
|
||||
"""Returns discord for the given actor
|
||||
"""
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
if not isinstance(actor_json['attachment'], list):
|
||||
return ''
|
||||
for property_value in actor_json['attachment']:
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name'].lower()
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name'].lower()
|
||||
if not name_value:
|
||||
continue
|
||||
if not string_contains(name_value, discord_fieldnames):
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
prop_value_name, _ = \
|
||||
get_attachment_property_value(property_value)
|
||||
if not prop_value_name:
|
||||
continue
|
||||
if not property_value['type'].endswith('PropertyValue'):
|
||||
continue
|
||||
discord_text = property_value[prop_value_name]
|
||||
return remove_html(discord_text)
|
||||
return ''
|
||||
|
||||
|
||||
def set_discord(actor_json: {}, discord: str) -> None:
|
||||
"""Sets discord for the given actor
|
||||
"""
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
property_found = None
|
||||
for property_value in actor_json['attachment']:
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name'].lower()
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name'].lower()
|
||||
if not name_value:
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
if not string_contains(name_value, discord_fieldnames):
|
||||
continue
|
||||
property_found = property_value
|
||||
break
|
||||
|
||||
if property_found:
|
||||
actor_json['attachment'].remove(property_found)
|
||||
|
||||
for property_value in actor_json['attachment']:
|
||||
name_value = None
|
||||
if property_value.get('name'):
|
||||
name_value = property_value['name']
|
||||
elif property_value.get('schema:name'):
|
||||
name_value = property_value['schema:name']
|
||||
if not name_value:
|
||||
continue
|
||||
if not property_value.get('type'):
|
||||
continue
|
||||
name_value = name_value.lower()
|
||||
if not string_contains(name_value, discord_fieldnames):
|
||||
continue
|
||||
if not property_value['type'].endswith('PropertyValue'):
|
||||
continue
|
||||
prop_value_name, _ = \
|
||||
get_attachment_property_value(property_value)
|
||||
if not prop_value_name:
|
||||
continue
|
||||
property_value[prop_value_name] = remove_html(discord)
|
||||
return
|
||||
|
||||
new_discord = {
|
||||
"type": "PropertyValue",
|
||||
"name": "Discord",
|
||||
"value": remove_html(discord)
|
||||
}
|
||||
actor_json['attachment'].append(new_discord)
|
9
pgp.py
9
pgp.py
|
@ -28,6 +28,7 @@ from auth import create_basic_auth_header
|
|||
from session import post_json
|
||||
from pronouns import get_pronouns
|
||||
from pixelfed import get_pixelfed
|
||||
from discord import get_discord
|
||||
from youtube import get_youtube
|
||||
from peertube import get_peertube
|
||||
from xmpp import get_xmpp_address
|
||||
|
@ -746,6 +747,9 @@ def actor_to_vcard(actor: {}, domain: str) -> str:
|
|||
blog_address = get_blog_address(actor)
|
||||
if blog_address:
|
||||
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Blog:' + blog_address + '\n'
|
||||
discord = get_discord(actor)
|
||||
if discord:
|
||||
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Discord:' + discord + '\n'
|
||||
pixelfed = get_pixelfed(actor)
|
||||
if pixelfed:
|
||||
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Pixelfed:' + pixelfed + '\n'
|
||||
|
@ -832,6 +836,11 @@ def actor_to_vcard_xml(actor: {}, domain: str) -> str:
|
|||
vcard_str += ' <url>' + \
|
||||
'<parameters><type><text>pixelfed</text></type></parameters>' + \
|
||||
'<uri>' + pixelfed + '</uri></url>\n'
|
||||
discord = get_discord(actor)
|
||||
if discord:
|
||||
vcard_str += ' <url>' + \
|
||||
'<parameters><type><text>discord</text></type></parameters>' + \
|
||||
'<uri>' + discord + '</uri></url>\n'
|
||||
youtube = get_youtube(actor)
|
||||
if youtube:
|
||||
vcard_str += ' <url>' + \
|
||||
|
|
|
@ -172,7 +172,8 @@ def html_person_options(default_timeline: str,
|
|||
repo_url: str,
|
||||
sites_unavailable: [],
|
||||
youtube: str, peertube: str,
|
||||
pixelfed: str) -> str:
|
||||
pixelfed: str,
|
||||
discord: str) -> str:
|
||||
"""Show options for a person: view/follow/block/report
|
||||
"""
|
||||
options_link_str = ''
|
||||
|
@ -442,6 +443,11 @@ def html_person_options(default_timeline: str,
|
|||
' <p class="imText">Pixelfed' + \
|
||||
': <a href="' + remove_html(pixelfed) + '">' + \
|
||||
pixelfed + '</a></p>\n'
|
||||
if discord:
|
||||
options_str += \
|
||||
' <p class="imText">Discord' + \
|
||||
': <a href="' + remove_html(discord) + '">' + \
|
||||
discord + '</a></p>\n'
|
||||
if youtube:
|
||||
options_str += \
|
||||
' <p class="imText">YouTube' + \
|
||||
|
|
|
@ -68,6 +68,7 @@ from donate import get_website
|
|||
from donate import get_gemini_link
|
||||
from pronouns import get_pronouns
|
||||
from pixelfed import get_pixelfed
|
||||
from discord import get_discord
|
||||
from youtube import get_youtube
|
||||
from peertube import get_peertube
|
||||
from xmpp import get_xmpp_address
|
||||
|
@ -329,6 +330,7 @@ def html_profile_after_search(authorized: bool,
|
|||
display_name += '🔒'
|
||||
|
||||
pronouns = get_pronouns(profile_json)
|
||||
discord = get_discord(profile_json)
|
||||
youtube = get_youtube(profile_json)
|
||||
peertube = get_peertube(profile_json)
|
||||
pixelfed = get_pixelfed(profile_json)
|
||||
|
@ -456,7 +458,8 @@ def html_profile_after_search(authorized: bool,
|
|||
authorized,
|
||||
person_url, no_of_books,
|
||||
birth_date,
|
||||
youtube, peertube, pixelfed)
|
||||
youtube, peertube, pixelfed,
|
||||
discord)
|
||||
|
||||
domain_full = get_full_domain(domain, port)
|
||||
|
||||
|
@ -826,7 +829,8 @@ def _get_profile_header_after_search(base_dir: str,
|
|||
birth_date: str,
|
||||
youtube: str,
|
||||
peertube: str,
|
||||
pixelfed: str) -> str:
|
||||
pixelfed: str,
|
||||
discord: str) -> str:
|
||||
"""The header of a searched for handle, containing background
|
||||
image and avatar
|
||||
"""
|
||||
|
@ -948,6 +952,9 @@ def _get_profile_header_after_search(base_dir: str,
|
|||
if pixelfed:
|
||||
html_str += ' <p>Pixelfed: <a href="' + pixelfed + '">' + \
|
||||
pixelfed + '</a></p>\n'
|
||||
if discord:
|
||||
html_str += ' <p>Discord: <a href="' + discord + '">' + \
|
||||
discord + '</a></p>\n'
|
||||
if repo_url:
|
||||
html_str += ' <p>💻 <a href="' + repo_url + '">' + \
|
||||
repo_url + '</a></p>\n'
|
||||
|
@ -1115,6 +1122,7 @@ def html_profile(signing_priv_key_pem: str,
|
|||
email_address = get_email_address(profile_json)
|
||||
pronouns = get_pronouns(profile_json)
|
||||
pixelfed = get_pixelfed(profile_json)
|
||||
discord = get_discord(profile_json)
|
||||
youtube = get_youtube(profile_json)
|
||||
peertube = get_peertube(profile_json)
|
||||
xmpp_address = get_xmpp_address(profile_json)
|
||||
|
@ -1125,8 +1133,8 @@ def html_profile(signing_priv_key_pem: str,
|
|||
cwtch_address = get_cwtch_address(profile_json)
|
||||
verified_site_checkmark = '✔'
|
||||
premium = is_premium_account(base_dir, nickname, domain)
|
||||
if donate_url or website_url or repo_url or pronouns or youtube or \
|
||||
peertube or pixelfed or xmpp_address or matrix_address or \
|
||||
if donate_url or website_url or repo_url or pronouns or discord or \
|
||||
youtube or peertube or pixelfed or xmpp_address or matrix_address or \
|
||||
ssb_address or tox_address or briar_address or cwtch_address or \
|
||||
pgp_pub_key or enigma_pub_key or pgp_fingerprint or email_address:
|
||||
donate_section = '<div class="container">\n'
|
||||
|
@ -1196,6 +1204,10 @@ def html_profile(signing_priv_key_pem: str,
|
|||
donate_section += \
|
||||
'<p>Pixelfed: <a href="' + \
|
||||
pixelfed + '" tabindex="1">' + pixelfed + '</a></p>\n'
|
||||
if discord:
|
||||
donate_section += \
|
||||
'<p>Discord: <a href="' + \
|
||||
discord + '" tabindex="1">' + discord + '</a></p>\n'
|
||||
if youtube:
|
||||
donate_section += \
|
||||
'<p>YouTube: <a href="' + \
|
||||
|
@ -2751,7 +2763,8 @@ def _html_edit_profile_contact_info(email_address: str,
|
|||
translate: {},
|
||||
youtube: str,
|
||||
peertube: str,
|
||||
pixelfed: str) -> str:
|
||||
pixelfed: str,
|
||||
discord: str) -> str:
|
||||
"""Contact Information section of edit profile screen
|
||||
"""
|
||||
edit_profile_form = begin_edit_section(translate['Contact Details'])
|
||||
|
@ -2773,6 +2786,8 @@ def _html_edit_profile_contact_info(email_address: str,
|
|||
peertube)
|
||||
edit_profile_form += edit_text_field('Pixelfed', 'pixelfedChannel',
|
||||
pixelfed)
|
||||
edit_profile_form += edit_text_field('Discord', 'discordChannel',
|
||||
discord)
|
||||
edit_profile_form += end_edit_section()
|
||||
return edit_profile_form
|
||||
|
||||
|
@ -3220,7 +3235,7 @@ def html_edit_profile(server, translate: {},
|
|||
email_address = featured_hashtags = pgp_pub_key = enigma_pub_key = ''
|
||||
pgp_fingerprint = pronouns = peertube = youtube = pixelfed = ''
|
||||
ssb_address = blog_address = matrix_address = tox_address = ''
|
||||
cwtch_address = briar_address = xmpp_address = ''
|
||||
cwtch_address = briar_address = xmpp_address = discord = ''
|
||||
manually_approves_followers = reject_spam_actors = ''
|
||||
|
||||
actor_json = load_json(actor_filename)
|
||||
|
@ -3233,6 +3248,7 @@ def html_edit_profile(server, translate: {},
|
|||
gemini_link = get_gemini_link(actor_json)
|
||||
pronouns = get_pronouns(actor_json)
|
||||
pixelfed = get_pixelfed(actor_json)
|
||||
discord = get_discord(actor_json)
|
||||
youtube = get_youtube(actor_json)
|
||||
peertube = get_peertube(actor_json)
|
||||
xmpp_address = get_xmpp_address(actor_json)
|
||||
|
@ -3454,7 +3470,8 @@ def html_edit_profile(server, translate: {},
|
|||
ssb_address, tox_address,
|
||||
briar_address,
|
||||
cwtch_address, translate,
|
||||
youtube, peertube, pixelfed)
|
||||
youtube, peertube, pixelfed,
|
||||
discord)
|
||||
|
||||
# notification settings
|
||||
edit_profile_form += \
|
||||
|
|
Loading…
Reference in New Issue