add /quote, /popfirst and /poplast
This commit is contained in:
parent
d63a9bee81
commit
f7858607e1
|
@ -74,6 +74,24 @@ async def message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
print("Changed topic to:", new_topic)
|
||||
channel.save()
|
||||
|
||||
sep = '┃'
|
||||
|
||||
current_topic = []
|
||||
if channel.topic is not None and len(channel.topic.strip()) != 0:
|
||||
current_topic = channel.topic.split(sep)
|
||||
|
||||
async def append(args):
|
||||
if len(args) > config.MAX_LENGTH:
|
||||
await update.message.reply_text("this won't fit in the topic")
|
||||
return
|
||||
|
||||
|
||||
current_topic.insert(0, args)
|
||||
while len(sep.join(current_topic)) > config.MAX_LENGTH:
|
||||
current_topic.pop()
|
||||
|
||||
await topic_update(sep.join(current_topic))
|
||||
|
||||
if cmd == '/topic':
|
||||
if args == '':
|
||||
if channel.topic is not None:
|
||||
|
@ -82,23 +100,34 @@ async def message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
await topic_update(args)
|
||||
|
||||
if cmd == '/append':
|
||||
sep = '┃'
|
||||
if len(args) > config.MAX_LENGTH:
|
||||
await update.message.reply_text("this won't fit in the topic")
|
||||
await append(args)
|
||||
return
|
||||
|
||||
|
||||
if cmd == '/quote':
|
||||
m = update.message.reply_to_message
|
||||
if m is None:
|
||||
await update.message.reply_text("reply to a message with the command to quote it")
|
||||
return
|
||||
|
||||
current_topic = []
|
||||
if channel.topic is not None and len(channel.topic.strip()) != 0:
|
||||
current_topic = channel.topic.split(sep)
|
||||
|
||||
current_topic.insert(0, args)
|
||||
while len(sep.join(current_topic)) > config.MAX_LENGTH:
|
||||
current_topic.pop()
|
||||
|
||||
await topic_update(sep.join(current_topic))
|
||||
attribution = f' ~@{m.from_user.username}' if m.from_user.username is not None else ''
|
||||
quote = f'"{m.text}"{attribution}'
|
||||
await append(quote)
|
||||
return
|
||||
|
||||
if cmd == '/popfirst':
|
||||
if len(current_topic) <= 1:
|
||||
await update.message.reply_text("can't pop the last existing item")
|
||||
return
|
||||
current_topic.pop(0)
|
||||
await topic_update(sep.join(current_topic))
|
||||
|
||||
if cmd == '/poplast':
|
||||
if len(current_topic) <= 1:
|
||||
await update.message.reply_text("can't pop the last existing item")
|
||||
return
|
||||
current_topic.pop()
|
||||
await topic_update(sep.join(current_topic))
|
||||
|
||||
|
||||
print(update, type(update))
|
||||
|
|
Loading…
Reference in a new issue