From 8151385bb89b8084e6540552cc23f90734d8b68e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sven=20M=C3=A4der?= <maeder@phys.ethz.ch>
Date: Thu, 13 Feb 2020 20:41:26 +0100
Subject: [PATCH] Fix quoting

---
 rt.py | 132 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 66 insertions(+), 66 deletions(-)

diff --git a/rt.py b/rt.py
index 3ae62bc..d793040 100755
--- a/rt.py
+++ b/rt.py
@@ -8,13 +8,13 @@ from maubot.handlers import command
 
 class Config(BaseProxyConfig):
     def do_update(self, helper: ConfigUpdateHelper) -> None:
-        helper.copy("prefix")
-        helper.copy("url")
-        helper.copy("user")
-        helper.copy("pass")
-        helper.copy("whitelist")
-        helper.copy("filter_properties")
-        helper.copy("filter_entry")
+        helper.copy('prefix')
+        helper.copy('url')
+        helper.copy('user')
+        helper.copy('pass')
+        helper.copy('whitelist')
+        helper.copy('filter_properties')
+        helper.copy('filter_entry')
 
 
 class RT(Plugin):
@@ -22,7 +22,7 @@ class RT(Plugin):
     whitelist: Set[UserID]
     api: str
     login: dict
-    headers = {"User-agent": "maubot-rt"}
+    headers = {'User-agent': 'maubot-rt'}
     regex_number = re.compile(r'[0-9]+')
     regex_properties = re.compile(r'([a-zA-z]+): (.+)')
     regex_history = re.compile(r'([0-9]+): (.+)')
@@ -33,14 +33,14 @@ class RT(Plugin):
 
     def on_external_config_update(self) -> None:
         self.config.load_and_update()
-        self.prefix = self.config["prefix"]
-        self.whitelist = set(self.config["whitelist"])
+        self.prefix = self.config['prefix']
+        self.whitelist = set(self.config['whitelist'])
         self.url = self.config['url']
         self.api = '{}/REST/1.0/'.format(self.url)
         self.display = '{}/Ticket/Display.html'.format(self.url)
         self.login = {'user': self.config['user'], 'pass': self.config['pass']}
-        self.filter_properties = set(self.config["filter_properties"])
-        self.filter_entry = set(self.config["filter_entry"])
+        self.filter_properties = set(self.config['filter_properties'])
+        self.filter_entry = set(self.config['filter_entry'])
 
     @classmethod
     def get_config_class(cls) -> Type[BaseProxyConfig]:
@@ -71,12 +71,12 @@ class RT(Plugin):
         return {k: v for k, v in raw.items() if k in keys}
 
     async def get_markdown_link(self, number: str) -> str:
-        link = "{}/Ticket/Display.html?id={}".format(self.config['url'], number)
-        markdown = "[rt#{}]({})".format(number, link)
+        link = '{}/Ticket/Display.html?id={}'.format(self.config['url'], number)
+        markdown = '[rt#{}]({})'.format(number, link)
         return markdown
 
     async def get_html_link(self, number: str) -> str:
-        link = "{}/Ticket/Display.html?id={}".format(self.config['url'], number)
+        link = '{}/Ticket/Display.html?id={}'.format(self.config['url'], number)
         html = '<a href="{}">rt#{}</a>'.format(link, number)
         return html
 
@@ -94,7 +94,7 @@ class RT(Plugin):
 
     async def _edit(self, number: str, properties: dict) -> None:
         api_edit = '{}ticket/{}/edit'.format(self.api, number)
-        content = {'content': '\n'.join(["{}: {}".format(k, v) for k, v in properties.items()])}
+        content = {'content': '\n'.join(['{}: {}'.format(k, v) for k, v in properties.items()])}
         data = {**self.login, **content}
         await self.http.post(api_edit, data=data, headers=self.headers)
 
@@ -124,7 +124,7 @@ class RT(Plugin):
             entry['Content'] = block
         return entry
 
-    @command.passive("((^| )([rR][tT]#?))([0-9]+)", multiple=True)
+    @command.passive('((^| )([rR][tT]#?))([0-9]+)', multiple=True)
     async def handler(self, evt: MessageEvent, subs: List[Tuple[str, str]]) -> None:
         await evt.mark_read()
         msg_lines = []
@@ -136,7 +136,7 @@ class RT(Plugin):
                 content = await response.text()
             ticket = dict(self.regex_properties.findall(content))
             markdown_link = await self.get_markdown_link(number)
-            markdown = "{} is **{}** in **{}** from {}  \n{}".format(
+            markdown = '{} is **{}** in **{}** from {}  \n{}'.format(
                 markdown_link,
                 ticket['Status'],
                 ticket['Queue'],
@@ -146,27 +146,27 @@ class RT(Plugin):
             msg_lines.append(markdown)
 
         if msg_lines:
-            await evt.respond("\n".join(msg_lines))
+            await evt.respond('\n'.join(msg_lines))
 
     @command.new(name=lambda self: self.prefix,
-                 help="Manage RT tickets", require_subcommand=True)
+                 help='Manage RT tickets', require_subcommand=True)
     async def rt(self) -> None:
         pass
 
-    @rt.subcommand("properties", aliases=("p", "prop"), help="Show all ticket properties.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('properties', aliases=('p', 'prop'), help='Show all ticket properties.')
+    @command.argument('number', 'ticket number', parser=str)
     async def properties(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
         await evt.mark_read()
         properties_dict = await self._properties(number)
-        properties_list = ["{}: {}".format(k, v) for k, v in properties_dict.items()]
+        properties_list = ['{}: {}'.format(k, v) for k, v in properties_dict.items()]
         markdown_link = await self.get_markdown_link(number)
         markdown = '{} properties:  \n{}'.format(markdown_link, '  \n'.join(properties_list))
         await evt.respond(markdown)
 
-    @rt.subcommand("resolve", aliases=("r", "res"), help="Mark the ticket as resolved.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('resolve', aliases=('r', 'res'), help='Mark the ticket as resolved.')
+    @command.argument('number', 'ticket number', parser=str)
     async def resolve(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -175,8 +175,8 @@ class RT(Plugin):
         markdown_link = await self.get_markdown_link(number)
         await evt.respond('{} resolved 😃'.format(markdown_link))
 
-    @rt.subcommand("open", aliases=("o", "op"), help="Mark the ticket as open.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('open', aliases=('o', 'op'), help='Mark the ticket as open.')
+    @command.argument('number', 'ticket number', parser=str)
     async def open(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -185,8 +185,8 @@ class RT(Plugin):
         markdown_link = await self.get_markdown_link(number)
         await evt.respond('{} opened 😐️'.format(markdown_link))
 
-    @rt.subcommand("stall", aliases=("st", "sta"), help="Mark the ticket as stalled.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('stall', aliases=('st', 'sta'), help='Mark the ticket as stalled.')
+    @command.argument('number', 'ticket number', parser=str)
     async def stall(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -195,8 +195,8 @@ class RT(Plugin):
         markdown_link = await self.get_markdown_link(number)
         await evt.respond('{} stalled 😴'.format(markdown_link))
 
-    @rt.subcommand("delete", aliases=("d", "del"), help="Mark the ticket as deleted.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('delete', aliases=('d', 'del'), help='Mark the ticket as deleted.')
+    @command.argument('number', 'ticket number', parser=str)
     async def delete(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -205,16 +205,16 @@ class RT(Plugin):
         markdown_link = await self.get_markdown_link(number)
         await evt.respond('{} deleted 🤬'.format(markdown_link))
 
-    @rt.subcommand("autoresolve", help="Enable automatic ticket resolve mode.")
+    @rt.subcommand('autoresolve', help='Enable automatic ticket resolve mode.')
     async def autoresolve(self, evt: MessageEvent) -> None:
         if not await self.can_manage(evt):
             return
         await evt.mark_read()
         await evt.react('😂🤣🦄🌈')
 
-    @rt.subcommand("comment", aliases=("c", "com"), help="Add a comment.")
-    @command.argument("number", "ticket number", parser=str)
-    @command.argument("comment", "comment text", pass_raw=True)
+    @rt.subcommand('comment', aliases=('c', 'com'), help='Add a comment.')
+    @command.argument('number', 'ticket number', parser=str)
+    @command.argument('comment', 'comment text', pass_raw=True)
     async def comment(self, evt: MessageEvent, number: str, comment: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -223,34 +223,34 @@ class RT(Plugin):
         markdown_link = await self.get_markdown_link(number)
         await evt.respond('{} comment added 🤓'.format(markdown_link))
 
-    @rt.subcommand("history", aliases=("h", "hist"), help="Get a list of all history entries.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('history', aliases=('h', 'hist'), help='Get a list of all history entries.')
+    @command.argument('number', 'ticket number', parser=str)
     async def history(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
         await evt.mark_read()
         history_dict = await self._history(number)
-        history_list = ["{}: {}".format(k, v) for k, v in history_dict.items()]
+        history_list = ['{}: {}'.format(k, v) for k, v in history_dict.items()]
         markdown_link = await self.get_markdown_link(number)
         markdown = '{} history entries:  \n{}'.format(markdown_link, '  \n'.join(history_list))
         await evt.respond(markdown)
 
-    @rt.subcommand("entry", aliases=("e", "ent"), help="Gets a single history entry.")
-    @command.argument("number", "ticket number", parser=str)
-    @command.argument("entry", "history entry number", parser=str)
+    @rt.subcommand('entry', aliases=('e', 'ent'), help='Gets a single history entry.')
+    @command.argument('number', 'ticket number', parser=str)
+    @command.argument('entry', 'history entry number', parser=str)
     async def entry(self, evt: MessageEvent, number: str, entry: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
         await evt.mark_read()
         entry_dict = await self._entry(number, entry)
-        entry_list = ["{}: {}".format(k, v) for k, v in entry_dict.items()]
+        entry_list = ['{}: {}'.format(k, v) for k, v in entry_dict.items()]
         markdown_link = await self.get_markdown_link(number)
         markdown = '{} history entry {}:  \n{}'.format(markdown_link, entry,
                                                        '  \n'.join(entry_list))
         await evt.respond(markdown)
 
-    @rt.subcommand("last", aliases=("l", "la"), help="Gets the last correspondence entry.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('last', aliases=('l', 'la'), help='Gets the last correspondence entry.')
+    @command.argument('number', 'ticket number', parser=str)
     async def last(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -259,30 +259,30 @@ class RT(Plugin):
         correspondences = {k: v for k, v in history_dict.items() if 'Corr' in v or 'Tick' in v}
         entry = max(correspondences, key=int)
         entry_dict = await self._entry(number, entry)
-        entry_list = ["{}: {}".format(k, v) for k, v in entry_dict.items()]
+        entry_list = ['{}: {}'.format(k, v) for k, v in entry_dict.items()]
         markdown_link = await self.get_markdown_link(number)
         markdown = '{} history entry {}:  \n{}'.format(markdown_link, entry,
                                                        '  \n'.join(entry_list))
         await evt.respond(markdown)
 
-    @rt.subcommand("show", aliases=("s", "sh"), help="Show all information about the ticket.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('show', aliases=('s', 'sh'), help='Show all information about the ticket.')
+    @command.argument('number', 'ticket number', parser=str)
     async def show(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
         await evt.mark_read()
         prop_dict = await self._properties(number)
-        prop_list = ["{}: {}".format(k, v) for k, v in prop_dict.items()]
+        prop_list = ['{}: {}'.format(k, v) for k, v in prop_dict.items()]
         link = await self.get_markdown_link(number)
         await evt.respond('{} properties:  \n{}'.format(link, '  \n'.join(prop_list)))
         history_dict = await self._history(number)
         for entry in history_dict.keys():
             entry_dict = await self._entry(number, entry)
-            entry_list = ["{}: {}".format(k, v) for k, v in entry_dict.items()]
+            entry_list = ['{}: {}'.format(k, v) for k, v in entry_dict.items()]
             await evt.respond('history entry {}:  \n{}'.format(entry, '  \n'.join(entry_list)))
 
-    @rt.subcommand("steal", aliases=("st", "ste"), help="Steal the ticket.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('steal', aliases=('st', 'ste'), help='Steal the ticket.')
+    @command.argument('number', 'ticket number', parser=str)
     async def steal(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -293,13 +293,13 @@ class RT(Plugin):
         html_link = await self.get_html_link(number)
         content = TextMessageEventContent(
             msgtype=MessageType.NOTICE, format=Format.HTML,
-            body=f"{displayname} has stolen rt#{number} 😈",
-            formatted_body=f"<a href='https://matrix.to/#/{evt.sender}'>{evt.sender}</a> "
-            f"has stolen {html_link} 😈")
+            body=f'{displayname} has stolen rt#{number} 😈',
+            formatted_body=f'<a href="https://matrix.to/#/{evt.sender}">{evt.sender}</a> '
+            f'has stolen {html_link} 😈')
         await evt.respond(content)
 
-    @rt.subcommand("take", aliases=("t", "ta"), help="Take the ticket.")
-    @command.argument("number", "ticket number", parser=str)
+    @rt.subcommand('take', aliases=('t', 'ta'), help='Take the ticket.')
+    @command.argument('number', 'ticket number', parser=str)
     async def take(self, evt: MessageEvent, number: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
@@ -310,21 +310,21 @@ class RT(Plugin):
         html_link = await self.get_html_link(number)
         content = TextMessageEventContent(
             msgtype=MessageType.NOTICE, format=Format.HTML,
-            body=f"{displayname} took rt#{number} 👍️",
-            formatted_body=f"<a href='https://matrix.to/#/{evt.sender}'>{evt.sender}</a> "
-            f"took {html_link} 👍️")
+            body=f'{displayname} took rt#{number} 👍️',
+            formatted_body=f'<a href="https://matrix.to/#/{evt.sender}">{evt.sender}</a> '
+            f'took {html_link} 👍️')
         await evt.respond(content)
 
-    @rt.subcommand("give", aliases=("g", "gi", "assign"), help="Give the ticket to somebody.")
-    @command.argument("number", "ticket number", parser=str)
-    @command.argument("user", "matrix user", parser=str)
+    @rt.subcommand('give', aliases=('g', 'gi', 'assign'), help='Give the ticket to somebody.')
+    @command.argument('number', 'ticket number', parser=str)
+    @command.argument('user', 'matrix user', parser=str)
     async def give(self, evt: MessageEvent, number: str, user: str) -> None:
         if not await self.can_manage(evt) or not self.is_valid_number(number):
             return
         await evt.mark_read()
         members = await self.get_member_names(evt.room_id)
         if user not in members.keys():
-            await evt.respond(f"hmm... **{user}** is not the in room 🤔")
+            await evt.respond(f'hmm... **{user}** is not the in room 🤔')
             return
         displayname = await self._get_displayname(evt.room_id, evt.sender)
         target_mxid = members[user]
@@ -333,7 +333,7 @@ class RT(Plugin):
         html_link = await self.get_html_link(number)
         content = TextMessageEventContent(
             msgtype=MessageType.NOTICE, format=Format.HTML,
-            body=f"{displayname} assigned rt#{number} to {user} 😜",
-            formatted_body=f"<a href='https://matrix.to/#/{evt.sender}'>{evt.sender}</a> assigned "
-            f"{html_link} to <a href='https://matrix.to/#/{target_mxid}'>{target_mxid}</a> 😜")
+            body=f'{displayname} assigned rt#{number} to {user} 😜',
+            formatted_body=f'<a href="https://matrix.to/#/{evt.sender}">{evt.sender}</a> assigned '
+            f'{html_link} to <a href="https://matrix.to/#/{target_mxid}">{target_mxid}</a> 😜')
         await evt.respond(content)
-- 
GitLab