Merge pull request 'Bot Accounts #98' (#114) from freamon/pyfedi:20 into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/114
This commit is contained in:
rimu 2024-03-21 08:37:27 +00:00
commit 40246fee1e
11 changed files with 42 additions and 5 deletions

View file

@ -195,7 +195,7 @@ def user_profile(actor):
if is_activitypub_request(): if is_activitypub_request():
server = current_app.config['SERVER_NAME'] server = current_app.config['SERVER_NAME']
actor_data = { "@context": default_context(), actor_data = { "@context": default_context(),
"type": "Person", "type": "Person" if not user.bot else "Service",
"id": f"https://{server}/u/{actor}", "id": f"https://{server}/u/{actor}",
"preferredUsername": actor, "preferredUsername": actor,
"name": user.title if user.title else user.user_name, "name": user.title if user.title else user.user_name,

View file

@ -488,7 +488,7 @@ def refresh_community_profile_task(community_id):
def actor_json_to_model(activity_json, address, server): def actor_json_to_model(activity_json, address, server):
if activity_json['type'] == 'Person': if activity_json['type'] == 'Person' or activity_json['type'] == 'Service':
try: try:
user = User(user_name=activity_json['preferredUsername'], user = User(user_name=activity_json['preferredUsername'],
title=activity_json['name'] if 'name' in activity_json else None, title=activity_json['name'] if 'name' in activity_json else None,
@ -508,6 +508,7 @@ def actor_json_to_model(activity_json, address, server):
ap_fetched_at=utcnow(), ap_fetched_at=utcnow(),
ap_domain=server, ap_domain=server,
public_key=activity_json['publicKey']['publicKeyPem'], public_key=activity_json['publicKey']['publicKeyPem'],
bot=True if activity_json['type'] == 'Service' else False,
instance_id=find_instance_id(server) instance_id=find_instance_id(server)
# language=community_json['language'][0]['identifier'] # todo: language # language=community_json['language'][0]['identifier'] # todo: language
) )

View file

@ -282,6 +282,14 @@ h1 {
} }
} }
.fe-bot-account {
position: relative;
top: 1px;
&:before {
content: "\e94d";
}
}
.fe-video { .fe-video {
position: relative; position: relative;
top: 2px; top: 2px;

View file

@ -305,6 +305,14 @@ h1 .fe-bell, h1 .fe-no-bell {
content: "\e986"; content: "\e986";
} }
.fe-bot-account {
position: relative;
top: 1px;
}
.fe-bot-account:before {
content: "\e94d";
}
.fe-video { .fe-video {
position: relative; position: relative;
top: 2px; top: 2px;

View file

@ -304,6 +304,14 @@ h1 .fe-bell, h1 .fe-no-bell {
content: "\e986"; content: "\e986";
} }
.fe-bot-account {
position: relative;
top: 1px;
}
.fe-bot-account:before {
content: "\e94d";
}
.fe-video { .fe-video {
position: relative; position: relative;
top: 2px; top: 2px;

View file

@ -11,6 +11,9 @@
{% if user.created_recently() %} {% if user.created_recently() %}
<span class="fe fe-new-account" title="New account"> </span> <span class="fe fe-new-account" title="New account"> </span>
{% endif %} {% endif %}
{% if user.bot %}
<span class="fe fe-bot-account" title="Bot account"> </span>
{% endif %}
{% if user.reputation < -10 %} {% if user.reputation < -10 %}
<span class="fe fe-warning red" title="Very low reputation. Beware."> </span> <span class="fe fe-warning red" title="Very low reputation. Beware."> </span>
<span class="fe fe-warning red" title="Very low reputation. Beware!"> </span> <span class="fe fe-warning red" title="Very low reputation. Beware!"> </span>

View file

@ -29,6 +29,9 @@
{% if comment['comment'].author.created_recently() %} {% if comment['comment'].author.created_recently() %}
<span class="fe fe-new-account small" title="New account"> </span> <span class="fe fe-new-account small" title="New account"> </span>
{% endif %} {% endif %}
{% if comment['comment'].author.bot %}
<span class="fe fe-bot-account small" title="Bot account"> </span>
{% endif %}
{% if comment['comment'].author.id != current_user.id %} {% if comment['comment'].author.id != current_user.id %}
{% if comment['comment'].author.reputation < -10 %} {% if comment['comment'].author.reputation < -10 %}
<span class="fe fe-warning red" title="Very low reputation. Beware."> </span> <span class="fe fe-warning red" title="Very low reputation. Beware."> </span>

View file

@ -90,6 +90,9 @@
{% if comment['comment'].author.created_recently() %} {% if comment['comment'].author.created_recently() %}
<span class="fe fe-new-account small" title="New account"> </span> <span class="fe fe-new-account small" title="New account"> </span>
{% endif %} {% endif %}
{% if comment['comment'].author.bot %}
<span class="fe fe-bot-account small" title="Bot account"> </span>
{% endif %}
{% if comment['comment'].author.id != current_user.id %} {% if comment['comment'].author.id != current_user.id %}
{% if comment['comment'].author.reputation < -10 %} {% if comment['comment'].author.reputation < -10 %}
<span class="fe fe-warning red" title="Very low reputation. Beware."> </span> <span class="fe fe-warning red" title="Very low reputation. Beware."> </span>

View file

@ -57,6 +57,9 @@
</div> </div>
{% endif %} {% endif %}
<p class="small">{{ _('Joined') }}: {{ moment(user.created).fromNow(refresh=True) }}<br /> <p class="small">{{ _('Joined') }}: {{ moment(user.created).fromNow(refresh=True) }}<br />
{% if user.bot %}
{{ _('Bot Account') }}<br />
{% endif %}
{{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{{ (user.attitude * 100) | round | int }}%</span></p> {{ _('Attitude') }}: <span title="{{ _('Ratio of upvotes cast to downvotes cast. Higher is more positive.') }}">{{ (user.attitude * 100) | round | int }}%</span></p>
{{ user.about_html|safe }} {{ user.about_html|safe }}
{% if posts %} {% if posts %}

View file

@ -149,7 +149,7 @@ def search_for_user(address: str):
if user_data.status_code == 200: if user_data.status_code == 200:
user_json = user_data.json() user_json = user_data.json()
user_data.close() user_data.close()
if user_json['type'] == 'Person': if user_json['type'] == 'Person' or user_json['type'] == 'Service':
user = actor_json_to_model(user_json, name, server) user = actor_json_to_model(user_json, name, server)
return user return user
return None return None

View file

@ -448,7 +448,7 @@ def banned_ip_addresses() -> List[str]:
def can_downvote(user, community: Community, site=None) -> bool: def can_downvote(user, community: Community, site=None) -> bool:
if user is None or community is None or user.banned: if user is None or community is None or user.banned or user.bot:
return False return False
if site is None: if site is None:
@ -473,7 +473,7 @@ def can_downvote(user, community: Community, site=None) -> bool:
def can_upvote(user, community: Community) -> bool: def can_upvote(user, community: Community) -> bool:
if user is None or community is None or user.banned: if user is None or community is None or user.banned or user.bot:
return False return False
if community.id in communities_banned_from(user.id): if community.id in communities_banned_from(user.id):