feat: Added customizable /help response for outsiders
This commit is contained in:
parent
1ca0c65adc
commit
6c5e5210d0
|
@ -6,7 +6,14 @@ import deltachat
|
||||||
from deltachat import account_hookimpl
|
from deltachat import account_hookimpl
|
||||||
from deltachat.capi import lib as dclib
|
from deltachat.capi import lib as dclib
|
||||||
|
|
||||||
from .commands import help_message, set_display_name, set_avatar, start_chat
|
from .commands import (
|
||||||
|
crew_help,
|
||||||
|
set_display_name,
|
||||||
|
set_avatar,
|
||||||
|
start_chat,
|
||||||
|
outside_help,
|
||||||
|
set_outside_help,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SetupPlugin:
|
class SetupPlugin:
|
||||||
|
@ -74,7 +81,7 @@ class RelayPlugin:
|
||||||
)
|
)
|
||||||
arguments = message.text.split(" ")
|
arguments = message.text.split(" ")
|
||||||
if arguments[0] == "/help":
|
if arguments[0] == "/help":
|
||||||
self.reply(message.chat, help_message(), quote=message)
|
self.reply(message.chat, crew_help(), quote=message)
|
||||||
if arguments[0] == "/set_name":
|
if arguments[0] == "/set_name":
|
||||||
self.reply(
|
self.reply(
|
||||||
message.chat,
|
message.chat,
|
||||||
|
@ -95,6 +102,18 @@ class RelayPlugin:
|
||||||
for msg in outside_chat.get_messages():
|
for msg in outside_chat.get_messages():
|
||||||
self.forward_to_relay_group(msg, started_by_crew=True)
|
self.forward_to_relay_group(msg, started_by_crew=True)
|
||||||
self.reply(message.chat, result, quote=message)
|
self.reply(message.chat, result, quote=message)
|
||||||
|
if arguments[0] == "/set_outside_help":
|
||||||
|
try:
|
||||||
|
help_message = message.text.split("/set_outside_help ")[1]
|
||||||
|
except IndexError:
|
||||||
|
set_outside_help(self.kvstore, "")
|
||||||
|
return self.reply(message.chat, "Removed help message for outsiders", quote=message)
|
||||||
|
set_outside_help(self.kvstore, help_message)
|
||||||
|
self.reply(
|
||||||
|
message.chat,
|
||||||
|
f"Set help message for outsiders to {help_message}",
|
||||||
|
quote=message,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logging.debug("Ignoring message, just the crew chatting")
|
logging.debug("Ignoring message, just the crew chatting")
|
||||||
|
|
||||||
|
@ -112,6 +131,22 @@ class RelayPlugin:
|
||||||
logging.debug("Ignoring message, just the crew chatting")
|
logging.debug("Ignoring message, just the crew chatting")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if message.text.startswith("/help"):
|
||||||
|
logging.info("Outsider %s asked for help", message.get_sender_contact().addr)
|
||||||
|
help_message = outside_help(self.kvstore)
|
||||||
|
if help_message == False:
|
||||||
|
help_message = f"I forward messages to the {self.account.get_config('displayname')} team."
|
||||||
|
if help_message == "":
|
||||||
|
logging.debug(
|
||||||
|
"Help message empty, forwarding message to relay group"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logging.info(
|
||||||
|
"Sending help text to %s: %s",
|
||||||
|
message.get_sender_contact().addr,
|
||||||
|
help_message,
|
||||||
|
)
|
||||||
|
return self.reply(message.chat, help_message, quote=message)
|
||||||
logging.debug("Forwarding message to relay group")
|
logging.debug("Forwarding message to relay group")
|
||||||
self.forward_to_relay_group(message)
|
self.forward_to_relay_group(message)
|
||||||
|
|
||||||
|
@ -132,6 +167,7 @@ class RelayPlugin:
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
""":TODO don't forward if message is the explanation message"""
|
||||||
outside_chat.send_msg(message)
|
outside_chat.send_msg(message)
|
||||||
|
|
||||||
def forward_to_relay_group(self, message: deltachat.Message, started_by_crew=False):
|
def forward_to_relay_group(self, message: deltachat.Message, started_by_crew=False):
|
||||||
|
|
|
@ -1,24 +1,44 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import deltachat
|
import deltachat
|
||||||
|
import pickledb
|
||||||
from deltachat.capi import lib as dclib
|
from deltachat.capi import lib as dclib
|
||||||
from deltachat.message import _view_type_mapping
|
from deltachat.message import _view_type_mapping
|
||||||
|
|
||||||
|
|
||||||
def help_message() -> str:
|
def crew_help() -> str:
|
||||||
"""Get the help message
|
"""Get the help message for the crew chat
|
||||||
|
|
||||||
:return: the help message
|
:return: the help message
|
||||||
"""
|
"""
|
||||||
help_text = """
|
help_text = """
|
||||||
Start a chat:\t/start_chat alice@example.org,bob@example.org Chat_Title Hello friends!
|
Start a chat:\t/start_chat alice@example.org,bob@example.org Chat_Title Hello friends!
|
||||||
Change the bot's name:\t/set_name <name>
|
Change the bot's name:\t/set_name Name
|
||||||
Change the bot's avatar:\t/set_avatar (attach image)
|
Change the bot's avatar:\t/set_avatar <attach image>
|
||||||
Show this help text:\t\t/help
|
Show this help text:\t\t/help
|
||||||
|
Change the help message for outsiders:\t/set_outside_help Hello outsider
|
||||||
"""
|
"""
|
||||||
return help_text
|
return help_text
|
||||||
|
|
||||||
|
|
||||||
|
def outside_help(kvstore: pickledb.PickleDB) -> str:
|
||||||
|
"""Get the help message for outsiders
|
||||||
|
|
||||||
|
:param kvstore: the pickledDB key-value-store
|
||||||
|
:return: the help message
|
||||||
|
"""
|
||||||
|
return kvstore.get("outside_help_message")
|
||||||
|
|
||||||
|
|
||||||
|
def set_outside_help(kvstore: pickledb.PickleDB, help_message: str):
|
||||||
|
"""Set the help message for outsiders
|
||||||
|
|
||||||
|
:param kvstore: the pickeDB key-value-store
|
||||||
|
"""
|
||||||
|
logging.debug("Setting outside_help_message to %s", help_message)
|
||||||
|
kvstore.set("outside_help_message", help_message)
|
||||||
|
|
||||||
|
|
||||||
def set_display_name(account: deltachat.Account, display_name: str) -> str:
|
def set_display_name(account: deltachat.Account, display_name: str) -> str:
|
||||||
"""Set the display name of the bot.
|
"""Set the display name of the bot.
|
||||||
|
|
||||||
|
@ -81,7 +101,7 @@ def start_chat(
|
||||||
return chat, "Chat successfully created."
|
return chat, "Chat successfully created."
|
||||||
else:
|
else:
|
||||||
logging.error("Can't send message. sent_id: %s, msg.id: %s", sent_id, msg.id)
|
logging.error("Can't send message. sent_id: %s, msg.id: %s", sent_id, msg.id)
|
||||||
return chat, "Something went wrong...\n\n" + help_message()
|
return chat, "Something went wrong...\n\n" + crew_help()
|
||||||
|
|
||||||
|
|
||||||
def get_message_view_type(message: deltachat.Message) -> str:
|
def get_message_view_type(message: deltachat.Message) -> str:
|
||||||
|
|
Loading…
Reference in a new issue