Skip to content
Snippets Groups Projects
Commit 60cccccd authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Not async

parent 189fdb27
Branches step_test_cto
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ class RT(Plugin):
def get_config_class(cls) -> Type[BaseProxyConfig]:
return Config
def is_valid_id(self, id: str) -> bool:
def valid_id(self, id: str) -> bool:
return True if self.regex_id.match(id) else False
def filter_dict(self, raw: dict, keys: Set) -> dict:
......@@ -59,14 +59,11 @@ class RT(Plugin):
def html_link(self, id: str) -> str:
return f'<a href="{self.display}?id={id}">rt#{id}</a>'
async def can_manage(self, evt: MessageEvent) -> bool:
def can_manage(self, evt: MessageEvent) -> bool:
if evt.sender in self.whitelist:
return True
return False
async def _username(self, evt: MessageEvent) -> str:
return evt.sender[1:].split(':')[0]
async def _member_mxids(self, room_id: RoomID) -> Dict[UserID, str]:
room_members = await self.client.get_joined_members(room_id)
member_mxids = {}
......@@ -149,7 +146,7 @@ class RT(Plugin):
@rt.subcommand('properties', aliases=('p', 'prop'), help='Show all ticket properties.')
@command.argument('id', 'ticket id', parser=str)
async def properties(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
properties_dict = await self._properties(id)
......@@ -159,7 +156,7 @@ class RT(Plugin):
@rt.subcommand('resolve', aliases=('r', 'res'), help='Mark the ticket as resolved.')
@command.argument('id', 'ticket id', parser=str)
async def resolve(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
await self._edit(id, {'Status': 'resolved'})
......@@ -168,7 +165,7 @@ class RT(Plugin):
@rt.subcommand('open', aliases=('o', 'op'), help='Mark the ticket as open.')
@command.argument('id', 'ticket id', parser=str)
async def open(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
await self._edit(id, {'Status': 'open'})
......@@ -177,7 +174,7 @@ class RT(Plugin):
@rt.subcommand('stall', aliases=('st', 'sta'), help='Mark the ticket as stalled.')
@command.argument('id', 'ticket id', parser=str)
async def stall(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
await self._edit(id, {'Status': 'stalled'})
......@@ -186,7 +183,7 @@ class RT(Plugin):
@rt.subcommand('delete', aliases=('d', 'del'), help='Mark the ticket as deleted.')
@command.argument('id', 'ticket id', parser=str)
async def delete(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
await self._edit(id, {'Status': 'deleted'})
......@@ -194,7 +191,7 @@ class RT(Plugin):
@rt.subcommand('autoresolve', help='Ask the bot to automatically answer and resolve tickets.')
async def autoresolve(self, evt: MessageEvent) -> None:
if not await self.can_manage(evt):
if not self.can_manage(evt):
return
await evt.mark_read()
await evt.react('😂🤣🦄🌈')
......@@ -203,7 +200,7 @@ class RT(Plugin):
@command.argument('id', 'ticket id', parser=str)
@command.argument('comment', 'comment text', pass_raw=True)
async def comment(self, evt: MessageEvent, id: str, comment: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
await self._comment(id, comment)
......@@ -212,7 +209,7 @@ class RT(Plugin):
@rt.subcommand('history', aliases=('h', 'hist'), help='Get a list of all history entries.')
@command.argument('id', 'ticket id', parser=str)
async def history(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
history_dict = await self._history(id)
......@@ -223,7 +220,7 @@ class RT(Plugin):
@command.argument('id', 'ticket id', parser=str)
@command.argument('entryid', 'history entry id', parser=str)
async def entry(self, evt: MessageEvent, id: str, entryid: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
entry_dict = await self._entry(id, entryid)
......@@ -233,7 +230,7 @@ class RT(Plugin):
@rt.subcommand('last', aliases=('l', 'la'), help='Gets the last entry.')
@command.argument('id', 'ticket id', parser=str)
async def last(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
history = await self._history(id)
......@@ -246,7 +243,7 @@ class RT(Plugin):
@rt.subcommand('show', aliases=('s', 'sh'), help='Show all information about the ticket.')
@command.argument('id', 'ticket id', parser=str)
async def show(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
prop_dict = await self._properties(id)
......@@ -265,12 +262,11 @@ class RT(Plugin):
@rt.subcommand('take', aliases=('t', 'ta', 'steal'), help='Take or steal the ticket.')
@command.argument('id', 'ticket id', parser=str)
async def take(self, evt: MessageEvent, id: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
username = await self._username(evt)
displayname = await self._displayname(evt.room_id, evt.sender)
await self._edit(id, {'Owner': username})
await self._edit(id, {'Owner': evt.sender[1:].split(':')[0]})
content = TextMessageEventContent(
msgtype=MessageType.NOTICE, format=Format.HTML,
body=f'{displayname} took rt#{id} 👍️',
......@@ -282,7 +278,7 @@ class RT(Plugin):
@command.argument('id', 'ticket id', parser=str)
@command.argument('user', 'matrix user', parser=str)
async def give(self, evt: MessageEvent, id: str, user: str) -> None:
if not await self.can_manage(evt) or not self.is_valid_id(id):
if not self.can_manage(evt) or not self.valid_id(id):
return
await evt.mark_read()
member_mxids = await self._member_mxids(evt.room_id)
......
  • Sven Mäder :speech_balloon: @maedersv

    mentioned in commit 68941a11

    By maedersv on 2020-04-24T11:45:46

    · Imported

    mentioned in commit 68941a11

    By maedersv on 2020-04-24T11:45:46

    Edited by Ghost User
    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment