想问一下discord里跑dnd的话,用什么骰娘比较好用呢
那么如何导出log呢?也就是果园的染色版本想问一下discord里跑dnd的话,用什么骰娘比较好用呢
一般都是用Avrae (https://avrae.io/),可支持D&D Beyond角色卡导入,也可以直接使用官方资源里的数据
那么如何导出log呢?也就是果园的染色版本
import json
import os
import re
def parse(a):
a = re.sub('\*\*(.*?)\*\*', '[b]\\1[/b]', a)
a = re.sub('\*(.*?)\*', '[i]\\1[/i]', a)
a = re.sub('\|\|(.*?)\|\|', '[color=white]\\1[/color]', a)
a = re.sub('`(.*?)`', '[tt]\\1[/tt]', a)
a = re.sub('~(.*?)~', '[s]\\1[/s]', a)
return a
def coloring(entry, c):
name_list = ["旁白", "诺瓦莉安", "米克", "伊甘", "巴伦德"]
color_list = ["black", "royalblue", "crimson", "seagreen", "#993399"]
sentence_list = []
for x in entry.split("\n"):
sentence_list.append("[color=" + color_list[c] + "]<" + name_list[c] + "> " + parse(x) + "[/color]")
return sentence_list
def auto_format(dict):
outputs = []
messages = dict["messages"]
for utterance in messages:
if int(utterance["author"]["id"]) == 替换为ID数字: #dm
colored = coloring(utterance["content"], 0)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #nuowalian
colored = coloring(utterance["content"], 1)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #mike
colored = coloring(utterance["content"], 2)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #yigan
colored = coloring(utterance["content"], 3)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #balunde
colored = coloring(utterance["content"], 4)
for sentence in colored:
outputs.append(sentence)
return outputs
path = "E:/ProcessedLog/log/"
for file in os.listdir(path):
if file.endswith(".json"):
f = open(path + file, 'r', encoding="utf8")
raw = json.load(f)
processed = auto_format(raw)
with open(file[:-5] + ".txt", 'w', encoding="utf8") as out_f:
for p in processed:
out_f.write(p + "\n")
f.close()
cd 你放log.py的路径
python log.py
或
python3 log.py(如果你以前安装过Python2)
非常感谢那么如何导出log呢?也就是果园的染色版本
我们DM以前问过这个问题,可以作为参考 (https://www.goddessfantasy.net/bbs/index.php?topic=124661)
简单来说要先使用DiscordChatExporter (https://github.com/Tyrrrz/DiscordChatExporter)导出频道聊天记录
如果导出txt格式的话可以使用关键词替换,导出csv或者json的话可以用程序来处理
上面的帖子里有对应的程序,不过我一开始没发现,所以自己也写了一个版本(用来处理json文件):代码: [选择]import json
import os
import re
def parse(a):
a = re.sub('\*\*(.*?)\*\*', '[b]\\1[/b]', a)
a = re.sub('\*(.*?)\*', '[i]\\1[/i]', a)
a = re.sub('\|\|(.*?)\|\|', '[color=white]\\1[/color]', a)
a = re.sub('`(.*?)`', '[tt]\\1[/tt]', a)
a = re.sub('~(.*?)~', '[s]\\1[/s]', a)
return a
def coloring(entry, c):
name_list = ["旁白", "诺瓦莉安", "米克", "伊甘", "巴伦德"]
color_list = ["black", "royalblue", "crimson", "seagreen", "#993399"]
sentence_list = []
for x in entry.split("\n"):
sentence_list.append("[color=" + color_list[c] + "]<" + name_list[c] + "> " + parse(x) + "[/color]")
return sentence_list
def auto_format(dict):
outputs = []
messages = dict["messages"]
for utterance in messages:
if int(utterance["author"]["id"]) == 替换为ID数字: #dm
colored = coloring(utterance["content"], 0)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #nuowalian
colored = coloring(utterance["content"], 1)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #mike
colored = coloring(utterance["content"], 2)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #yigan
colored = coloring(utterance["content"], 3)
for sentence in colored:
outputs.append(sentence)
if int(utterance["author"]["id"]) == 替换为ID数字: #balunde
colored = coloring(utterance["content"], 4)
for sentence in colored:
outputs.append(sentence)
return outputs
path = "E:/ProcessedLog/log/"
for file in os.listdir(path):
if file.endswith(".json"):
f = open(path + file, 'r', encoding="utf8")
raw = json.load(f)
processed = auto_format(raw)
with open(file[:-5] + ".txt", 'w', encoding="utf8") as out_f:
for p in processed:
out_f.write(p + "\n")
f.close()
考虑到未来可能还有人看到这个帖子,顺便贴上Windows环境下的运行流程:
- 直接使用安装包安装Python (https://www.python.org/downloads/)
- 安装DiscordChatExporter (https://github.com/Tyrrrz/DiscordChatExporter)
- 点击Download → GUI → Stable release
- 下载DiscordChatExporter.zip并根据提示安装
- 导出对应频道的json文件
- 复制上方代码粘贴到记事本中,保存时选择UTF-8,保存后修改文件后缀为.py
- 粘贴代码时记得修改对应的文件路径、颜色代码、角色名字和用户ID
- 用户ID可以用记事本打开刚才导出的json文件查看,是一串很长的数字,可以根据对应用户名确认
- 打开WindowsPowerShell(开始菜单里输入terminal)
- 输入以下指令
代码: [选择]cd 你放log.py的路径
python log.py
或
python3 log.py(如果你以前安装过Python2)
上面的代码可以在Windows/macOS/Linux系统下无差别运行,但DiscordChatExporter只有支持Window的GUI