Remove commands
This commit is contained in:
parent
0a967c9a97
commit
c66a0674c0
1 changed files with 5 additions and 57 deletions
60
main.py
60
main.py
|
|
@ -80,9 +80,6 @@ def get_yurl(path):
|
||||||
|
|
||||||
|
|
||||||
class AngelBot(ClientXMPP):
|
class AngelBot(ClientXMPP):
|
||||||
commands = {}
|
|
||||||
muc_commands = {}
|
|
||||||
|
|
||||||
messages = defaultdict(
|
messages = defaultdict(
|
||||||
lambda: {
|
lambda: {
|
||||||
"messages": Lifo(100),
|
"messages": Lifo(100),
|
||||||
|
|
@ -183,26 +180,6 @@ class AngelBot(ClientXMPP):
|
||||||
uri = urlparse(u)
|
uri = urlparse(u)
|
||||||
await self.parse_uri(uri, sender, mtype)
|
await self.parse_uri(uri, sender, mtype)
|
||||||
|
|
||||||
def muc_word(self, func):
|
|
||||||
name = func.__name__
|
|
||||||
self.muc_commands[name] = func
|
|
||||||
return func
|
|
||||||
|
|
||||||
def muc_command(self, func):
|
|
||||||
name = self.prefix + func.__name__
|
|
||||||
self.muc_commands[name] = func
|
|
||||||
return func
|
|
||||||
|
|
||||||
def word(self, func):
|
|
||||||
name = func.__name__
|
|
||||||
self.commands[name] = func
|
|
||||||
return func
|
|
||||||
|
|
||||||
def command(self, func):
|
|
||||||
name = self.prefix + func.__name__
|
|
||||||
self.commands[name] = func
|
|
||||||
return func
|
|
||||||
|
|
||||||
def s(self, msg, sender, mtype):
|
def s(self, msg, sender, mtype):
|
||||||
try:
|
try:
|
||||||
text = msg["body"]
|
text = msg["body"]
|
||||||
|
|
@ -289,9 +266,11 @@ class AngelBot(ClientXMPP):
|
||||||
if msg["type"] in ("chat", "normal"):
|
if msg["type"] in ("chat", "normal"):
|
||||||
mtype = "chat"
|
mtype = "chat"
|
||||||
sender = msg["from"].bare
|
sender = msg["from"].bare
|
||||||
message = msg["body"]
|
|
||||||
|
|
||||||
ctx = message.strip().split()
|
edit = "urn:xmpp:message-correct:0" in str(msg)
|
||||||
|
if edit:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not msg["oob"]["url"]:
|
if not msg["oob"]["url"]:
|
||||||
if urls := self.get_urls(msg):
|
if urls := self.get_urls(msg):
|
||||||
|
|
@ -299,13 +278,6 @@ class AngelBot(ClientXMPP):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
edit = "urn:xmpp:message-correct:0" in str(msg)
|
|
||||||
|
|
||||||
cm = ctx.pop(0)
|
|
||||||
if cm in self.commands:
|
|
||||||
if not edit:
|
|
||||||
self.commands[cm](msg, ctx, sender)
|
|
||||||
else:
|
|
||||||
self.s(msg, sender, mtype)
|
self.s(msg, sender, mtype)
|
||||||
|
|
||||||
async def muc_message(self, msg):
|
async def muc_message(self, msg):
|
||||||
|
|
@ -330,30 +302,6 @@ class AngelBot(ClientXMPP):
|
||||||
else:
|
else:
|
||||||
self.s(msg, sender, mtype)
|
self.s(msg, sender, mtype)
|
||||||
|
|
||||||
@self.muc_word
|
|
||||||
def ping(msg, ctx, sender):
|
|
||||||
if ctx:
|
|
||||||
return
|
|
||||||
bot.send_message(
|
|
||||||
mto=sender, mbody=f"pong: {msg['mucnick']}", mtype="groupchat"
|
|
||||||
)
|
|
||||||
|
|
||||||
@self.word
|
|
||||||
def ping(msg, ctx, sender):
|
|
||||||
if ctx:
|
|
||||||
return
|
|
||||||
bot.send_message(
|
|
||||||
mto=sender,
|
|
||||||
mbody=f"pong: {msg.get_from().bare}",
|
|
||||||
mtype="chat",
|
|
||||||
)
|
|
||||||
|
|
||||||
@self.command
|
|
||||||
def join(msg, ctx, sender):
|
|
||||||
if sender == bot.owner:
|
|
||||||
for channel in ctx:
|
|
||||||
bot.plugin["xep_0045"].join_muc(channel, bot.nick)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue