mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 13:56:57 +01:00
add admin powers
This commit is contained in:
16
bot/commands/addadmin.ts
Normal file
16
bot/commands/addadmin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Command, sendMessage } from ".";
|
||||
import { addAdmin } from "../lib/admins";
|
||||
import parseCommandArgs from "../lib/parseCommandArgs";
|
||||
import { User } from "../user";
|
||||
import { unbannableUsers } from "..";
|
||||
|
||||
export default new Command('addadmin', ['addadmin'], [], async msg => {
|
||||
if (!unbannableUsers.includes(msg.chatterId)) return;
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; };
|
||||
const data = await addAdmin(target.id);
|
||||
if (data === 1) await sendMessage(`${target.displayName} is now an admin`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} is already an admin`, msg.messageId);
|
||||
}, false);
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Command, sendMessage } from ".";
|
||||
import { unbannableUsers } from "..";
|
||||
import { getUserRecord } from "../db/dbUser";
|
||||
import items, { changeItemCount } from "../items";
|
||||
import { isAdmin } from "../lib/admins";
|
||||
import parseCommandArgs from "../lib/parseCommandArgs";
|
||||
import { User } from "../user";
|
||||
|
||||
export default new Command('admingive', ['admingive'], [], async msg => {
|
||||
if (!unbannableUsers.includes(msg.chatterId)) { await sendMessage('nah', msg.messageId); return; };
|
||||
if (!await isAdmin(msg.chatterId)) return;
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a user', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
|
||||
13
bot/commands/getadmins.ts
Normal file
13
bot/commands/getadmins.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Command, sendMessage } from ".";
|
||||
import { getAdmins } from "../lib/admins";
|
||||
import { User } from "../user";
|
||||
|
||||
export default new Command('getadmins', ['getadmins'], [], async msg => {
|
||||
const admins = await getAdmins()
|
||||
const adminnames: string[] = [];
|
||||
for (const id of admins) {
|
||||
const admin = await User.initUserId(id);
|
||||
adminnames.push(admin?.displayName!);
|
||||
};
|
||||
await sendMessage(`Current admins: ${adminnames.join(', ')}`, msg.messageId);
|
||||
}, false);
|
||||
17
bot/commands/removeadmin.ts
Normal file
17
bot/commands/removeadmin.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Command, sendMessage } from ".";
|
||||
import { unbannableUsers } from "..";
|
||||
import { removeAdmin } from "../lib/admins";
|
||||
import parseCommandArgs from "../lib/parseCommandArgs";
|
||||
import { User } from "../user";
|
||||
|
||||
export default new Command('removeadmin', ['removeadmin'], [], async msg => {
|
||||
if (!unbannableUsers.includes(msg.chatterId)) return;
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage('Please specify a target', msg.messageId); return; };
|
||||
const target = await User.initUsername(args[0].toLowerCase());
|
||||
if (!target) { await sendMessage(`Chatter ${args[0]} doesn't exist`, msg.messageId); return; };
|
||||
if (unbannableUsers.includes(target.id)) { await sendMessage(`Can't remove admin ${target.displayName} as they are managed by the bot program`, msg.messageId); return; };
|
||||
const data = await removeAdmin(target.id);
|
||||
if (data === 1) await sendMessage(`${target.displayName} is no longer an admin`, msg.messageId);
|
||||
else await sendMessage(`${target.displayName} isn't an admin`, msg.messageId);
|
||||
}, false);
|
||||
Reference in New Issue
Block a user