Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active January 30, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohemohe/2cd98c1452b4cefb2ab86009419c73e5 to your computer and use it in GitHub Desktop.
Save mohemohe/2cd98c1452b4cefb2ab86009419c73e5 to your computer and use it in GitHub Desktop.
kokorobot hubot -> lxbot マイグレ
function pad(n) {
return ("00" + n).slice(-2);
}
use lxbot;
db.brain.find({}).toArray().forEach(doc => {
let key = doc.key;
let value = doc.value;
// 社会
if (key.startsWith("kokoroio_socialquest")) {
key = key.replace(/kokoroio_socialquest/g, "lxbot_socialquest");
if (key.endsWith("_rebirth_auto")) {
key = key.replace(/_rebirth_auto/g, "_auto");
}
if (key.endsWith("_enable")) {
value = value == 1;
}
if (key.endsWith("_auto")) {
value = value == 1;
}
if (key.endsWith("_hp")) {
value = parseInt(value, 10);
}
if (key.endsWith("_last")) {
const date = new Date(value);
value = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDay())}T00:00:00Z`;
}
}
// ikku
if (key.startsWith("kokoroio_ikku")) {
key = key.replace(/kokoroio_ikku/g, "lxbot_ikku");
value = value == 1;
}
// mstdn
if (key == "kokoroio_mstdn") {
key = "lxbot_mstdn_rooms";
Object.keys(value).forEach(key => {
value[key] = 1;
})
}
if (key.startsWith("kokoroio_mstdn_")) {
key = key.replace(/kokoroio_mstdn_/g, "lxbot_mastodon_");
}
db.store.updateOne({ key }, { $set: { key, value } }, { upsert: true });
});
db.brain.drop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment