Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
Added yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
code-rgb authored Oct 19, 2020
1 parent ac5aeae commit f02e606
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions userge/plugins/tools/json.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.

import re
import json
import yaml
from userge import userge, Message


Expand All @@ -15,3 +11,20 @@
async def jsonify(message: Message):
msg = str(message.reply_to_message) if message.reply_to_message else str(message)
await message.edit_or_send_as_file(text=msg, filename="json.txt", caption="Too Large")


@userge.on_cmd("yaml", about={
'header': "message object to yaml",
'usage': "reply {tr}yaml to any message"})
async def yamlify(message: Message):
"""get yaml"""
msg = str(message.reply_to_message) if message.reply_to_message else str(message)
yaml_ify = yaml.dump(json.loads(msg), allow_unicode=True)
regex = r"(\s+|)(?:- _:|_:)[\s]"
result = re.sub(regex, " ", yaml_ify, re.MULTILINE)
if result:
await message.edit_or_send_as_file(
text=f"```{result[1:]}```",
filename="yaml.txt",
caption="Too Large"
)

1 comment on commit f02e606

@vercel
Copy link

@vercel vercel bot commented on f02e606 Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.