mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-29 07:08:50 +00:00
Provision with Draupnir in mxid instead of mjolnir.
This commit is contained in:
@@ -210,7 +210,9 @@ export class MjolnirAppService {
|
||||
reg.setHomeserverToken(AppServiceRegistration.generateToken());
|
||||
reg.setAppServiceToken(AppServiceRegistration.generateToken());
|
||||
reg.setSenderLocalpart('draupnir-moderation');
|
||||
// This is maintained for backwards compatibility with mjolnir4all.
|
||||
reg.addRegexPattern("users", "@mjolnir_.*", true);
|
||||
reg.addRegexPattern("users", "@draupnir_.*", true);
|
||||
reg.setRateLimited(false);
|
||||
callback(reg);
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ export class MjolnirManager {
|
||||
}
|
||||
const provisionedMjolnirs = await this.dataStore.lookupByOwner(requestingUserId);
|
||||
if (provisionedMjolnirs.length === 0) {
|
||||
const mjolnirLocalPart = `mjolnir_${randomUUID()}`;
|
||||
const mjolnirLocalPart = `draupnir_${randomUUID()}`;
|
||||
const mjIntent = await this.makeMatrixIntent(mjolnirLocalPart);
|
||||
|
||||
const managementRoomId = await mjIntent.matrixClient.createRoom({
|
||||
preset: 'private_chat',
|
||||
invite: [requestingUserId],
|
||||
name: `${requestingUserId}'s mjolnir`,
|
||||
name: `${requestingUserId}'s Draupnir`,
|
||||
power_level_content_override: {
|
||||
users: {
|
||||
[requestingUserId]: 100,
|
||||
@@ -158,7 +158,7 @@ export class MjolnirManager {
|
||||
|
||||
return [mjIntent.userId, managementRoomId];
|
||||
} else {
|
||||
throw new Error(`User: ${requestingUserId} has already provisioned ${provisionedMjolnirs.length} mjolnirs.`);
|
||||
throw new Error(`User: ${requestingUserId} has already provisioned ${provisionedMjolnirs.length} Draupnirs.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import { PostgresStore, SchemaUpdateFunction } from "matrix-appservice-bridge";
|
||||
import { DataStore, MjolnirRecord } from "../datastore";
|
||||
|
||||
function getSchema(): SchemaUpdateFunction[] {
|
||||
const nSchema = 1;
|
||||
const nSchema = 2;
|
||||
const schema = [];
|
||||
for (let schemaID = 1; schemaID < nSchema + 1; schemaID++) {
|
||||
schema.push(require(`./schema/v${schemaID}`).runSchema);
|
||||
@@ -41,7 +41,7 @@ export class PgDataStore extends PostgresStore implements DataStore {
|
||||
}
|
||||
|
||||
public async list(): Promise<MjolnirRecord[]> {
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM mjolnir`;
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM draupnir`;
|
||||
if (!result.count) {
|
||||
return [];
|
||||
}
|
||||
@@ -50,18 +50,18 @@ export class PgDataStore extends PostgresStore implements DataStore {
|
||||
}
|
||||
|
||||
public async store(mjolnirRecord: MjolnirRecord): Promise<void> {
|
||||
await this.sql`INSERT INTO mjolnir (local_part, owner, management_room)
|
||||
await this.sql`INSERT INTO draupnir (local_part, owner, management_room)
|
||||
VALUES (${mjolnirRecord.local_part}, ${mjolnirRecord.owner}, ${mjolnirRecord.management_room})`;
|
||||
}
|
||||
|
||||
public async lookupByOwner(owner: string): Promise<MjolnirRecord[]> {
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM mjolnir
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM draupnir
|
||||
WHERE owner = ${owner}`;
|
||||
return result.flat() as MjolnirRecord[];
|
||||
}
|
||||
|
||||
public async lookupByLocalPart(localPart: string): Promise<MjolnirRecord[]> {
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM mjolnir
|
||||
const result = await this.sql`SELECT local_part, owner, management_room FROM draupnir
|
||||
WHERE local_part = ${localPart}`;
|
||||
return result.flat() as MjolnirRecord[];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
import postgres from 'postgres';
|
||||
|
||||
export async function runSchema(sql: postgres.Sql) {
|
||||
await sql.begin(s => [
|
||||
s`ALTER TABLE IF EXISTS mjolnir RENAME TO draupnir;`
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user