Finish moving from SQL to New Funny ORM
This commit is contained in:
		
							parent
							
								
									4e1e590c3a
								
							
						
					
					
						commit
						79bd0254f0
					
				
					 19 changed files with 87 additions and 87 deletions
				
			
		| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
const assert = require("assert")
 | 
			
		||||
 | 
			
		||||
const passthrough = require("../../passthrough")
 | 
			
		||||
const { discord, sync, db } = passthrough
 | 
			
		||||
const {discord, sync, db, select} = passthrough
 | 
			
		||||
/** @type {import("./message-to-event")} */
 | 
			
		||||
const messageToEvent = sync.require("../converters/message-to-event")
 | 
			
		||||
/** @type {import("../actions/register-user")} */
 | 
			
		||||
| 
						 | 
				
			
			@ -21,17 +21,15 @@ const createRoom = sync.require("../actions/create-room")
 | 
			
		|||
async function editToChanges(message, guild, api) {
 | 
			
		||||
	// Figure out what events we will be replacing
 | 
			
		||||
 | 
			
		||||
	const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(message.channel_id)
 | 
			
		||||
	/** @type {string?} */
 | 
			
		||||
	let senderMxid = db.prepare("SELECT mxid FROM sim WHERE discord_id = ?").pluck().get(message.author.id) || null
 | 
			
		||||
	const roomID = select("channel_room", "room_id", "WHERE channel_id = ?").pluck().get(message.channel_id)
 | 
			
		||||
	let senderMxid = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(message.author.id) || null
 | 
			
		||||
	if (senderMxid) {
 | 
			
		||||
		const senderIsInRoom = db.prepare("SELECT * FROM sim_member WHERE room_id = ? and mxid = ?").get(roomID, senderMxid)
 | 
			
		||||
		const senderIsInRoom = select("sim_member", "mxid", "WHERE room_id = ? AND mxid = ?").get(roomID, senderMxid)
 | 
			
		||||
		if (!senderIsInRoom) {
 | 
			
		||||
			senderMxid = null // just send as ooye bot
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	/** @type {{event_id: string, event_type: string, event_subtype: string?, part: number}[]} */
 | 
			
		||||
   const oldEventRows = db.prepare("SELECT event_id, event_type, event_subtype, part FROM event_message WHERE message_id = ?").all(message.id)
 | 
			
		||||
	const oldEventRows = select("event_message", ["event_id", "event_type", "event_subtype", "part"], "WHERE message_id = ?").all(message.id)
 | 
			
		||||
 | 
			
		||||
	// Figure out what we will be replacing them with
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ const assert = require("assert").strict
 | 
			
		|||
const {PNG} = require("pngjs")
 | 
			
		||||
 | 
			
		||||
const passthrough = require("../../passthrough")
 | 
			
		||||
const { sync, db, discord } = passthrough
 | 
			
		||||
const {sync, db, discord, select} = passthrough
 | 
			
		||||
/** @type {import("../../matrix/file")} */
 | 
			
		||||
const file = sync.require("../../matrix/file")
 | 
			
		||||
//** @type {import("../../matrix/mreq")} */
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +38,7 @@ const Rlottie = (async () => {
 | 
			
		|||
 * @returns {Promise<{mxc: string, info: typeof INFO}>}
 | 
			
		||||
 */
 | 
			
		||||
async function convert(stickerItem) {
 | 
			
		||||
	const existingMxc = db.prepare("SELECT mxc FROM lottie WHERE id = ?").pluck().get(stickerItem.id)
 | 
			
		||||
	const existingMxc = select("lottie", "mxc", "WHERE id = ?").pluck().get(stickerItem.id)
 | 
			
		||||
	if (existingMxc) return {mxc: existingMxc, info: INFO}
 | 
			
		||||
	const r = await Rlottie
 | 
			
		||||
	const res = await fetch(file.DISCORD_IMAGES_BASE + file.sticker(stickerItem))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
// @ts-check
 | 
			
		||||
 | 
			
		||||
const assert = require("assert")
 | 
			
		||||
const assert = require("assert").strict
 | 
			
		||||
 | 
			
		||||
const passthrough = require("../../passthrough")
 | 
			
		||||
const { discord, sync, db } = passthrough
 | 
			
		||||
const {discord, sync, db, select} = passthrough
 | 
			
		||||
/** @type {import("../../matrix/read-registration")} */
 | 
			
		||||
const reg = sync.require("../../matrix/read-registration.js")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17,8 +17,7 @@ const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex))
 | 
			
		|||
 * @param {{api: import("../../matrix/api")}} di simple-as-nails dependency injection for the matrix API
 | 
			
		||||
 */
 | 
			
		||||
async function threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thread, di) {
 | 
			
		||||
	/** @type {string?} */
 | 
			
		||||
	const branchedFromEventID = db.prepare("SELECT event_id FROM event_message WHERE message_id = ?").pluck().get(thread.id)
 | 
			
		||||
	const branchedFromEventID = select("event_message", "event_id", "WHERE message_id = ?").pluck().get(thread.id)
 | 
			
		||||
	/** @type {{"m.mentions"?: any, "m.in_reply_to"?: any}} */
 | 
			
		||||
	const context = {}
 | 
			
		||||
	if (branchedFromEventID) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
const assert = require("assert")
 | 
			
		||||
 | 
			
		||||
const passthrough = require("../../passthrough")
 | 
			
		||||
const { sync, db } = passthrough
 | 
			
		||||
const {select} = passthrough
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Downcased and stripped username. Can only include a basic set of characters.
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,7 @@ function userToSimName(user) {
 | 
			
		|||
	assert.notEqual(user.discriminator, "0000", "cannot create user for a webhook")
 | 
			
		||||
 | 
			
		||||
	// 1. Is sim user already registered?
 | 
			
		||||
	const existing = db.prepare("SELECT sim_name FROM sim WHERE discord_id = ?").pluck().get(user.id)
 | 
			
		||||
	const existing = select("sim", "sim_name", "WHERE discord_id = ?").pluck().get(user.id)
 | 
			
		||||
	if (existing) return existing
 | 
			
		||||
 | 
			
		||||
	// 2. Register based on username (could be new or old format)
 | 
			
		||||
| 
						 | 
				
			
			@ -64,8 +64,7 @@ function userToSimName(user) {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	// Check for conflicts with already registered sims
 | 
			
		||||
	/** @type {string[]} */
 | 
			
		||||
	const matches = db.prepare("SELECT sim_name FROM sim WHERE sim_name LIKE ? ESCAPE '@'").pluck().all(downcased + "%")
 | 
			
		||||
	const matches = select("sim", "sim_name", "WHERE sim_name LIKE ? ESCAPE '@'").pluck().all(downcased + "%")
 | 
			
		||||
	// Keep generating until we get a suggestion that doesn't conflict
 | 
			
		||||
	for (const suggestion of generateLocalpartAlternatives(preferences)) {
 | 
			
		||||
		if (!matches.includes(suggestion)) return suggestion
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue