我可以在涉及的电报聊天本身上存储漫游器状态数据吗? [英] Can I store bot state data on the involved telegram chat itself?

查看:143
本文介绍了我可以在涉及的电报聊天本身上存储漫游器状态数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个组中存储有关该机器人的对话的一些数据(即该机器人管理一种基于文本的聊天室,我想保存该组是哪个世界"和舞台")当时),所以我想知道您是否可以在聊天本身中存储少量数据(而不是将其保存在机器人服务器端*,这似乎是

I'm trying to store a bit of data regarding the bot's conversation within a group (i.e. the bot manages kind of a text-based chat scape room and I want to save which "world" and "stage" the group is in at the time), and so I was wondering whether you can just store this little amount of data within the chat itself (instead of saving it on the bot server side*, which seems quite a lot of work for something that should be so simple).

因此,按照这种python zen的哲学,我试图找到一种存储这对值的KISS方法,也许在电报聊天本身中,这样我就不需要在服务器端管理任何重要的数据库了.以便对聊天消息来自何方进行分类.

So following this python zen philosophy, I'm trying to find a KISS way of storing that couple of values, maybe within the telegram chat itself, so that I don't need to manage any serious database on the server side in order to classify which chat things came from.

*我在Flask Web应用程序中使用带有Webhook的Telepot.

*I'm using telepot with webhook in a Flask web app.

推荐答案

所以...我只是想分享一下我发现了一种非常荒谬但非常有效的方法(只要您不需要存储私有数据,而且条件是只有漫游器(而不是玩家)可以弄乱聊天的描述).

So... I just wanted to share that I found a deeply ridiculous but quite effective way of doing it (as long as you don't need to store private data in there, and with the condition that only the bot -and not the players- can mess with the chat's description).

机器人可以通过命令bot.getChat("@group_id").setChatDescription("@group_id","New desc")检查并更改聊天的描述,因此您实际上可以在其中保存包含所需所有值的字符串,并在以后检索它们.

Bots can check and change the chat's description via the commands bot.getChat("@group_id") and .setChatDescription("@group_id","New desc") so you actually can save there a string that contains all the values you need, and retrieve them later.

在公开的情况下,我可以将当​​前游戏级别保存在描述中,例如"Level: 4",并可以通过以下方式随时对其进行检索:

In the case exposed, I could save the current game level in the description, like "Level: 4", and retrieve it at any time by:

desc = bot.getChat("@my_game_chat")["description"]
level = desc[7:]

在这种情况下,它也可以为玩家提供线索.

And in this case it works as a clue for the player too.

使用类似的方法,您可以同时在其中保存不同的内容,甚至可能只是将其放置为一串没有标签的数字而使它模糊不清"01-21-5493"

Using a similar approach you could save different stuff there at the same time, even maybe obscuring it a bit by just putting it as a string of numbers with no labels "01-21-5493"

desc = bot.getChat("@my_game_chat")["description"]
world, stage, score = desc.split('-')

如果您使用固定宽度的数字,甚至可以在不相关的地方扔一些随机数字,以免混淆任何可能的八卦.

Also if you work with fixed width numbers, you could even throw in there some random numbers in irrelevant places so as to confuse any possible gossip.

PS:bot.getChat()返回这样的结构(这就是我们需要["description"]的原因):

PS: bot.getChat() returns a structure like this (that's why we need ["description"]):

{
'id': -2424242424242, 
'title': 'Channel Name', 
'username': 'channelusername', 
'type': 'channel', 
'description': 'Pernils i tal'
}

这篇关于我可以在涉及的电报聊天本身上存储漫游器状态数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆