Mixin 机器人如何获得自己的用户列表
Mixin 机器人如何获得使用过本机器人的所有用户呢?
并没有直接的API方法获得。需要开发者在用户和机器人交互时获得用户信息,并进行保存和管理。
参考 Mixin 机器人如何获得用户ID和会话ID,获得用户ID和会话ID后,保存到内存、文件或数据库。
Mixin 机器人如何获得使用过本机器人的所有用户呢?
并没有直接的API方法获得。需要开发者在用户和机器人交互时获得用户信息,并进行保存和管理。
参考 Mixin 机器人如何获得用户ID和会话ID,获得用户ID和会话ID后,保存到内存、文件或数据库。
若需要给每个用户逐一发送消息(群发消息),就是发送消息到每个会话ID (Conversation ID)。而这份会话ID列表需要自己提前准备好,参考 Mixin 机器人如何获得用户ID和会话ID,然后自行存储和管理。
Mixin 的会话 ID 形式相同,但生成方法分两种:
1. 用户和用户之间的单人会话,可以通过计算两个用户的 user_id 获得。计算方法参考代码。
2. 多人群组的会话ID是随机生成的。
使用的库: PyNaCl
安装依赖: pip install PyNaCl
from nacl.signing import SigningKey
from nacl.public import PrivateKey
def generate_curve25519_keypair():
# 生成私钥
private_key = PrivateKey.generate()
# 从私钥生成公钥
public_key = private_key.public_key
# 将私钥和公钥导出为字节形式,便于存储或传输
private_key_bytes = private_key.encode()
public_key_bytes = public_key.encode()
# 打印密钥
print(" ----- Curve25519 key pair -----")
print("Private Key (hex):", private_key_bytes.hex())
print("Public Key (hex):", public_key_bytes.hex())
# 适用于 JWT 签名
def generate_ed25519_keypair():
# 生成私钥
private_key = SigningKey.generate()
# 从私钥生成公钥
public_key = private_key.verify_key
# 将私钥和公钥导出为字节形式,便于存储或传输
private_key_bytes = private_key.encode()
public_key_bytes = public_key.encode()
# 打印密钥
print(" ----- Ed25519 key pair -----")
print("Private Key (hex):", private_key_bytes.hex())
print("Public Key (hex):", public_key_bytes.hex())
if __name__ == "__main__":
generate_curve25519_keypair()
generate_ed25519_keypair()
本文章引用自: https://www.educative.io/edpresso/installing-pip3-in-ubuntu ,版权归原作者所有。
pip3 is the official package installer for Python 3. It can be used to install packages from the Python Package Index.
It is always a good idea to update before trying to install a new package. Run the command below:
sudo apt update
If Python 3 has already been installed on the system, execute the command below to install pip3:
可以使用 t
(target) 选项来指定安装的位置。
举例:
pip install -r requirements.txt -t /path/to/directory
安装到当前路径:
pip install -r requirements.txt -t .
参考
基础概念可参考阮一峰写的 Systemd 定时器教程
[Service]
区块用来 Service 的配置,只有 Service 类型的 Unit 才有这个区块。它的主要字段如下。
Type
:定义启动时的进程行为。它有以下几种值。Type=simple
:默认值,执行ExecStart
指定的命令,启动主进程Type=forking
:以 fork 方式从父进程创建子进程,创建后父进程会立即退出Type=oneshot
:一次性进程,Systemd 会等当前服务退出,再继续往下执行Type=dbus
:当前服务通过D-Bus启动Type=notify
:当前服务启动完毕,会通知Systemd
,再继续往下执行Type=idle
:若有其他任务执行完毕,当前服务才会运行ExecStart
:启动当前服务的命令ExecStartPre
:启动当前服务之前执行的命令ExecStartPost
:启动当前服务之后执行的命令ExecReload
:重启当前服务时执行的命令ExecStop
:停止当前服务时执行的命令ExecStopPost
:停止当其服务之后执行的命令RestartSec
:自动重启当前服务间隔的秒数Restart
:定义何种情况 Systemd 会自动重启当前服务,可能的值包括always
(总是重启)、on-success
、on-failure
、on-abnormal
、on-abort
、on-watchdog
TimeoutSec
:定义 Systemd 停止当前服务之前等待的秒数Environment
:指定环境变量
Unit 配置文件的完整字段清单,请参考官方文档。
如何显示?
import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
中文翻译:
可以使用 cp
复制,或 sync
同步,或者 mv
移动
https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html
下载文件 aws s3 cp <S3Uri> <LocalPath>
上传文件 aws s3 cp <LocalPath> <S3Uri>
S3Uri 格式:
s3://bucket-name/object-key-or-prefix
记录或下载 Access Key ID 和 Secret Access Key。
Generate random characters
Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 5);
Math.random()
,生成随机数,例如:0.09751664076957856
.toString(36)
,转换成36进制后的字符串。输出类似:“0.3idqid3cvvy”
.replace(/[^a-z]+/g, '')
,仅保留小写自负。输出类似:“idqidcvvy”
.slice(0, 5)
, 截取前5个字符。输出类似:"idqid"