changing spaces to tabs

This commit is contained in:
Cadence Ember 2023-08-21 21:04:41 +12:00
parent c22f434c1f
commit c8021cadec
9 changed files with 154 additions and 120 deletions

View file

@ -18,10 +18,10 @@ passthrough.discord = discord
;(async () => {
await discord.cloud.connect()
console.log("Discord gateway started")
console.log("Discord gateway started")
const f = event => onPacket(discord, event, () => discord.cloud.off("event", f))
discord.cloud.on("event", f)
const f = event => onPacket(discord, event, () => discord.cloud.off("event", f))
discord.cloud.on("event", f)
})()
const expectedGuilds = new Set()
@ -30,29 +30,29 @@ const prepared = db.prepare("UPDATE channel_room SET name = ? WHERE channel_id =
/** @param {DiscordClient} discord */
function onPacket(discord, event, unsubscribe) {
if (event.t === "READY") {
for (const obj of event.d.guilds) {
expectedGuilds.add(obj.id)
}
if (event.t === "READY") {
for (const obj of event.d.guilds) {
expectedGuilds.add(obj.id)
}
} else if (event.t === "GUILD_CREATE") {
expectedGuilds.delete(event.d.id)
} else if (event.t === "GUILD_CREATE") {
expectedGuilds.delete(event.d.id)
// Store the channel.
for (const channel of event.d.channels || []) {
prepared.run(channel.name, channel.id)
}
// Store the channel.
for (const channel of event.d.channels || []) {
prepared.run(channel.name, channel.id)
}
// Checked them all?
if (expectedGuilds.size === 0) {
discord.cloud.disconnect()
unsubscribe()
// Checked them all?
if (expectedGuilds.size === 0) {
discord.cloud.disconnect()
unsubscribe()
// I don't know why node keeps running.
setTimeout(() => {
console.log("Stopping now.")
process.exit()
}, 1500).unref()
}
}
// I don't know why node keeps running.
setTimeout(() => {
console.log("Stopping now.")
process.exit()
}, 1500).unref()
}
}
}

View file

@ -18,13 +18,13 @@ const rows = db.prepare("SELECT event_id, room_id, event_type FROM event_message
const preparedUpdate = db.prepare("UPDATE event_message SET event_type = ?, event_subtype = ? WHERE event_id = ?")
;(async () => {
for (const row of rows) {
if (row.event_type == null) {
const event = await api.getEvent(row.room_id, row.event_id)
const type = event.type
const subtype = event.content.msgtype || null
preparedUpdate.run(type, subtype, row.event_id)
console.log(`Updated ${row.event_id} -> ${type} + ${subtype}`)
}
}
for (const row of rows) {
if (row.event_type == null) {
const event = await api.getEvent(row.room_id, row.event_id)
const type = event.type
const subtype = event.content.msgtype || null
preparedUpdate.run(type, subtype, row.event_id)
console.log(`Updated ${row.event_id} -> ${type} + ${subtype}`)
}
}
})()