Some small fixes

Signed-off-by: jolheiser <john.olheiser@gmail.com>
roll
jolheiser 2022-02-14 22:21:02 -06:00
parent 66cf464f3d
commit 24fd3d6e45
Signed by untrusted user: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
4 changed files with 37 additions and 21 deletions

View File

@ -314,7 +314,7 @@ class PluginAPI(View):
warning.save() warning.save()
json['message'] = "Warning issued." json['message'] = "Warning issued."
link = mcm_utils.full_reverse('note_info', warning.id) link = mcm_utils.full_reverse('note_info', warning.id)
msg = mcm_utils.build_warning(warning, link) msg = mcm_utils.build_note(warning, link)
mcm_api.discord_mcm(embed=msg) mcm_api.discord_mcm(embed=msg)
except Exception as ex: except Exception as ex:
json['status'] = False json['status'] = False

29
discord.py 100644
View File

@ -0,0 +1,29 @@
from enum import Enum
from datetime import datetime
from typing import Union
class TimestampStyle(Enum):
SHORT_TIME = "t"
"""16:20"""
LONG_TIME = "T"
"""16:20:30"""
SHORT_DATE = "d"
"""20/04/2021"""
LONG_DATE = "D"
"""20 April 2021"""
SHORT_DATETIME = "f"
"""20 April 2021 16:20"""
LONG_DATETIME = "F"
"""Tuesday, 20 April 2021 16:20"""
RELATIVE = "R"
"""2 months ago"""
def format_timestamp(unix: Union[int, datetime], style: TimestampStyle = TimestampStyle.SHORT_DATETIME) -> str:
t = 0
if isinstance(unix, int):
t = unix
elif isinstance(unix, datetime):
t = unix.timestamp()
return f"<t:{t}:{style}>"

View File

@ -13,4 +13,4 @@ class TimezoneMiddleware(MiddlewareMixin):
try: try:
timezone.activate(pytz.timezone(request.user.usersettings.default_timezone)) timezone.activate(pytz.timezone(request.user.usersettings.default_timezone))
except: except:
timezone.deactivate() timezone.deactivate()

View File

@ -30,7 +30,7 @@ def build_application(application):
embed = discord.Embed(colour=discord.Colour(0x417505)) embed = discord.Embed(colour=discord.Colour(0x417505))
embed.title = "Application" embed.title = "Application"
embed.set_thumbnail( embed.set_thumbnail(
url="https://minotar.net/helm/{0}/100.png".format(application.username)) url=f"https://minotar.net/helm/{application.username}/100.png")
embed.add_field(name="Application ID", value=application.id) embed.add_field(name="Application ID", value=application.id)
embed.add_field(name="Username", value=application.username.replace("_", "\\_")) embed.add_field(name="Username", value=application.username.replace("_", "\\_"))
embed.add_field(name="Age", value=application.age) embed.add_field(name="Age", value=application.age)
@ -43,7 +43,7 @@ def build_application(application):
embed.add_field(name="Read the Rules", value=application.read_rules) embed.add_field(name="Read the Rules", value=application.read_rules)
embed.timestamp = application.date embed.timestamp = application.date
embed.add_field(name="Status", value=application.status) embed.add_field(name="Status", value=application.status)
embed.add_field(name="Link", value=full_reverse('application_info', application.id)) embed.add_field(name="Link", value=full_reverse('application_info', application.id), inline=False)
return embed return embed
@ -57,19 +57,7 @@ def build_ticket(ticket, link):
if ticket.x and ticket.y and ticket.z and ticket.world: if ticket.x and ticket.y and ticket.z and ticket.world:
embed.add_field(name="Location", value=ticket.location) embed.add_field(name="Location", value=ticket.location)
embed.add_field(name="Message", value=ticket.message) embed.add_field(name="Message", value=ticket.message)
embed.add_field(name="Link", value=link) embed.add_field(name="Link", value=link, inline=False)
return embed
def build_warning(warning, link):
embed = discord.Embed(colour=discord.Colour(0x417505))
embed.title = "Warning"
embed.set_thumbnail(url=full_static("favicon.png"))
embed.timestamp = warning.date
embed.add_field(name="Player", value=warning.player.username.replace("_", "\\_"))
embed.add_field(name="Importance", value=warning.importance_display)
embed.add_field(name="Message", value=warning.message)
embed.add_field(name="Link", value=link)
return embed return embed
@ -78,16 +66,15 @@ def build_note(note, link):
embed.title = "Note" embed.title = "Note"
embed.set_thumbnail(url=full_static("favicon.png")) embed.set_thumbnail(url=full_static("favicon.png"))
embed.timestamp = note.date embed.timestamp = note.date
embed.add_field(name="Date", value=note.date_display)
embed.add_field(name="Player", value=note.player.username.replace("_", "\\_")) embed.add_field(name="Player", value=note.player.username.replace("_", "\\_"))
embed.add_field(name="Importance", value=note.importance_display) embed.add_field(name="Importance", value=note.importance_display)
embed.add_field(name="Message", value=note.message) embed.add_field(name="Message", value=note.message)
embed.add_field(name="Link", value=link) embed.add_field(name="Link", value=link, inline=False)
return embed return embed
def validate_username(username): def validate_username(username):
response = requests.get("https://api.mojang.com/users/profiles/minecraft/{}".format(username)) response = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{username}")
if response.status_code == 200: if response.status_code == 200:
return True return True
return False return False
@ -137,4 +124,4 @@ class Captcha:
def add_error(self, error): def add_error(self, error):
if error not in self.errors: if error not in self.errors:
self.errors.append(error) self.errors.append(error)