mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-26 04:51:08 -05:00
Matrix2051: quick hack to trigger commands from edited messages
This commit is contained in:
parent
799b7c7b71
commit
77f57a7d93
@ -50,7 +50,7 @@ def configure(advanced):
|
|||||||
Matrix2051 = conf.registerPlugin('Matrix2051')
|
Matrix2051 = conf.registerPlugin('Matrix2051')
|
||||||
# This is where your configuration variables (if any) should go. For example:
|
# This is where your configuration variables (if any) should go. For example:
|
||||||
conf.registerNetworkValue(Matrix2051, 'enabled',
|
conf.registerNetworkValue(Matrix2051, 'enabled',
|
||||||
registry.Boolean(False, _("""Whether to enable DM room rerouting on this network.""")))
|
registry.Boolean(False, _("""Whether to enable Matrix2051 tweaks on this network.""")))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2022, James Lu <james@overdrivenetworks.com>
|
# Copyright (c) 2022-2023, James Lu <james@overdrivenetworks.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -89,14 +89,26 @@ class Matrix2051(callbacks.Plugin):
|
|||||||
self.log.debug("Matrix2051: dropping replayed %s from before initial connect (%s < %s)",
|
self.log.debug("Matrix2051: dropping replayed %s from before initial connect (%s < %s)",
|
||||||
msg.command, msg.time, irc.startedAt)
|
msg.command, msg.time, irc.startedAt)
|
||||||
return
|
return
|
||||||
|
target = msg.args[0]
|
||||||
|
text = msg.args[-1]
|
||||||
if room_map := getattr(irc.state, '_dmroom_map', None):
|
if room_map := getattr(irc.state, '_dmroom_map', None):
|
||||||
account = msg.server_tags.get('account')
|
account = msg.server_tags.get('account')
|
||||||
dmroom = room_map.get(account)
|
dmroom = room_map.get(account)
|
||||||
if account and dmroom == msg.args[0]:
|
if account and dmroom == msg.args[0]:
|
||||||
self.log.debug("Matrix2051: rewriting incoming %s from %s -> %s",
|
self.log.debug("Matrix2051: rewriting incoming %s from %s -> %s",
|
||||||
msg.command, dmroom, account)
|
msg.command, dmroom, account)
|
||||||
new_msg = ircmsgs.IrcMsg(args=(irc.nick, *msg.args[1:]), msg=msg)
|
target = irc.nick
|
||||||
return new_msg
|
new_msg = ircmsgs.IrcMsg(args=(target, text), msg=msg)
|
||||||
|
|
||||||
|
# Allow edited messages (with default Matrix fallback prefix) to trigger commands
|
||||||
|
# However, keep the message text as is for other plugins by not rewriting it permanently
|
||||||
|
if text.startswith('* '):
|
||||||
|
self.log.debug("Matrix2051: stripping edit prefix from message from %s", msg.nick)
|
||||||
|
if not callbacks.addressed(irc, new_msg):
|
||||||
|
maybe_command_msg = ircmsgs.IrcMsg(args=(target, text[2:]), msg=msg)
|
||||||
|
payload = callbacks.addressed(irc, maybe_command_msg)
|
||||||
|
new_msg.tag('addressed', payload)
|
||||||
|
return new_msg
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user