mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-10-23 01:21:16 +00:00
Fix command processing for recent refactorings
This commit is contained in:
1 parent
05ab8f60c6
commit
49468c5aab
4 files changed
+15
-15
No files matched your search
@@ -27,29 +27,29 @@ import { execUnwatchCommand, execWatchCommand } from "./WatchUnwatchCommand";
|
||||
|
||||
export const COMMAND_PREFIX = "!mjolnir";
|
||||
|
||||
export function handleCommand(roomId: string, event: any, mjolnir: Mjolnir) {
|
||||
export async function handleCommand(roomId: string, event: any, mjolnir: Mjolnir) {
|
||||
const cmd = event['content']['body'];
|
||||
const parts = cmd.trim().split(' ');
|
||||
|
||||
try {
|
||||
if (parts.length === 1 || parts[1] === 'status') {
|
||||
return execStatusCommand(roomId, event, mjolnir);
|
||||
return await execStatusCommand(roomId, event, mjolnir);
|
||||
} else if (parts[1] === 'ban' && parts.length > 4) {
|
||||
return execBanCommand(roomId, event, mjolnir, parts);
|
||||
return await execBanCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'unban' && parts.length > 4) {
|
||||
return execUnbanCommand(roomId, event, mjolnir, parts);
|
||||
return await execUnbanCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'rules') {
|
||||
return execDumpRulesCommand(roomId, event, mjolnir);
|
||||
return await execDumpRulesCommand(roomId, event, mjolnir);
|
||||
} else if (parts[1] === 'sync') {
|
||||
return execSyncCommand(roomId, event, mjolnir);
|
||||
return await execSyncCommand(roomId, event, mjolnir);
|
||||
} else if (parts[1] === 'verify') {
|
||||
return execPermissionCheckCommand(roomId, event, mjolnir);
|
||||
return await execPermissionCheckCommand(roomId, event, mjolnir);
|
||||
} else if (parts.length >= 5 && parts[1] === 'list' && parts[2] === 'create') {
|
||||
return execCreateListCommand(roomId, event, mjolnir, parts);
|
||||
return await execCreateListCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'watch' && parts.length > 1) {
|
||||
return execWatchCommand(roomId, event, mjolnir, parts);
|
||||
return await execWatchCommand(roomId, event, mjolnir, parts);
|
||||
} else if (parts[1] === 'unwatch' && parts.length > 1) {
|
||||
return execUnwatchCommand(roomId, event, mjolnir, parts);
|
||||
return await execUnwatchCommand(roomId, event, mjolnir, parts);
|
||||
} else {
|
||||
// Help menu
|
||||
const menu = "" +
|
||||
@@ -66,7 +66,7 @@ export function handleCommand(roomId: string, event: any, mjolnir: Mjolnir) {
|
||||
const text = `Mjolnir help:\n${menu}`;
|
||||
const reply = RichReply.createFor(roomId, event, text, html);
|
||||
reply["msgtype"] = "m.notice";
|
||||
return mjolnir.client.sendMessage(roomId, reply);
|
||||
return await mjolnir.client.sendMessage(roomId, reply);
|
||||
}
|
||||
} catch (e) {
|
||||
LogService.error("CommandHandler", e);
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function execDumpRulesCommand(roomId: string, event: any, mjolnir:
|
||||
let text = "Rules currently in use:\n";
|
||||
|
||||
let hasLists = false;
|
||||
for (const list of mjolnir.banLists) {
|
||||
for (const list of mjolnir.lists) {
|
||||
hasLists = true;
|
||||
let hasRules = false;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export async function execStatusCommand(roomId: string, event: any, mjolnir: Mjo
|
||||
// Append list information
|
||||
html += "<b>Subscribed ban lists:</b><br><ul>";
|
||||
text += "Subscribed ban lists:\n";
|
||||
for (const list of mjolnir.banLists) {
|
||||
for (const list of mjolnir.lists) {
|
||||
const ruleInfo = `rules: ${list.serverRules.length} servers, ${list.userRules.length} users, ${list.roomRules.length} rooms`;
|
||||
html += `<li><a href="${list.roomRef}">${list.roomId}</a> (${ruleInfo})</li>`;
|
||||
text += `* ${list.roomRef} (${ruleInfo})\n`;
|
||||
|
||||
@@ -59,7 +59,7 @@ export async function execBanCommand(roomId: string, event: any, mjolnir: Mjolni
|
||||
};
|
||||
const stateKey = `rule:${bits.glob}`;
|
||||
|
||||
const list = mjolnir.banLists.find(b => b.listShortcode === bits.listShortcode);
|
||||
const list = mjolnir.lists.find(b => b.listShortcode === bits.listShortcode);
|
||||
if (!list) {
|
||||
const replyText = "No ban list with that shortcode was found.";
|
||||
const reply = RichReply.createFor(roomId, event, replyText, replyText);
|
||||
@@ -84,7 +84,7 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol
|
||||
const ruleContent = {}; // empty == clear/unban
|
||||
const stateKey = `rule:${bits.glob}`;
|
||||
|
||||
const list = mjolnir.banLists.find(b => b.listShortcode === bits.listShortcode);
|
||||
const list = mjolnir.lists.find(b => b.listShortcode === bits.listShortcode);
|
||||
if (!list) {
|
||||
const replyText = "No ban list with that shortcode was found.";
|
||||
const reply = RichReply.createFor(roomId, event, replyText, replyText);
|
||||
|
||||
Reference in new issue
Block a user