Consolidate admin commands
This commit is contained in:
parent
108f27eb22
commit
462d0c879c
8 changed files with 47 additions and 23 deletions
|
@ -5,7 +5,7 @@ import User from "./objects/User";
|
|||
|
||||
// Commands
|
||||
import RankingCommand from "./commands/Ranking";
|
||||
import LockCommand from "./commands/Lock";
|
||||
import AdminCommand from "./commands/Admin";
|
||||
import MultiplayerCommands from "./commands/Multiplayer";
|
||||
import HelpCommand from "./commands/Help";
|
||||
import RollCommand from "./commands/Roll";
|
||||
|
@ -19,7 +19,7 @@ export default class Bot {
|
|||
|
||||
this.commands["help"] = new HelpCommand(shared, this.commands);
|
||||
this.commands["ranking"] = new RankingCommand(shared);
|
||||
this.commands["lock"] = new LockCommand(shared);
|
||||
this.commands["admin"] = new AdminCommand(shared);
|
||||
this.commands["mp"] = new MultiplayerCommands(shared);
|
||||
this.commands["roll"] = new RollCommand(shared);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ export default async function LoginProcess(req:IncomingMessage, res:ServerRespon
|
|||
}
|
||||
|
||||
// Retreive the newly created user
|
||||
newUser = shared.users.add(newClientToken, new User(userInfo.id, loginInfo.username, newClientToken, shared));
|
||||
newUser = shared.users.add(newClientToken, new User(userInfo.id, loginInfo.username, newClientToken, userInfo.tags, shared));
|
||||
// Set tourney client flag
|
||||
newUser.isTourneyUser = isTourneyClient;
|
||||
newUser.location = userLocation;
|
||||
|
|
35
server/commands/Admin.ts
Normal file
35
server/commands/Admin.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { enumHasFlag } from "../Util";
|
||||
import { Permissions } from "../enums/Permissions";
|
||||
import Channel from "../objects/Channel";
|
||||
import User from "../objects/User";
|
||||
import BaseCommand from "./BaseCommand";
|
||||
|
||||
export default class AdminCommand extends BaseCommand {
|
||||
public readonly adminOnly:boolean = true;
|
||||
public readonly helpDescription:string = "Locks/Unlocks a channel and limits conversation to mods and above.";
|
||||
|
||||
public exec(channel:Channel, sender:User, args:Array<string>) {
|
||||
if (!enumHasFlag(sender.permissions, Permissions.Admin) || !enumHasFlag(sender.permissions, Permissions.Peppy)) {
|
||||
channel.SendBotMessage("You don't have permission to execute that command.");
|
||||
return;
|
||||
}
|
||||
|
||||
const subCommand = args[0].toLowerCase();
|
||||
args.shift();
|
||||
|
||||
switch (subCommand) {
|
||||
case "lock":
|
||||
return adminLock(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function adminLock(channel:Channel) {
|
||||
if (channel.isSpecial) {
|
||||
channel.SendBotMessage("Multiplayer channels cannot be locked");
|
||||
return;
|
||||
}
|
||||
|
||||
channel.isLocked = !channel.isLocked;
|
||||
channel.SendBotMessage(`Channel is now ${channel.isLocked ? "locked" : "unlocked"}`);
|
||||
}
|
|
@ -5,7 +5,8 @@ import User from "../objects/User";
|
|||
|
||||
export default class BaseCommand implements ICommand {
|
||||
public shared:Shared;
|
||||
public readonly helpText:string = "No help page was found for that command";
|
||||
public readonly adminOnly:boolean = false;
|
||||
public readonly helpText = "No help page was found for that command";
|
||||
public readonly helpDescription:string = "Command has no description set";
|
||||
public readonly helpArguments:Array<string> = new Array<string>();
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import Channel from "../objects/Channel";
|
||||
import User from "../objects/User";
|
||||
import BaseCommand from "./BaseCommand";
|
||||
|
||||
export default class LockCommand extends BaseCommand {
|
||||
public readonly helpDescription:string = "Locks/Unlocks a channel and limits conversation to mods and above.";
|
||||
|
||||
public exec(channel:Channel, sender:User, args:Array<string>) {
|
||||
if (channel.isSpecial) {
|
||||
channel.SendBotMessage("Multiplayer channels cannot be locked");
|
||||
return;
|
||||
}
|
||||
|
||||
channel.isLocked = !channel.isLocked;
|
||||
channel.SendBotMessage(`Channel is now ${channel.isLocked ? "locked" : "unlocked"}`);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import User from "../objects/User";
|
|||
|
||||
export default interface ICommand {
|
||||
shared:Shared,
|
||||
adminOnly:boolean,
|
||||
helpText:string,
|
||||
helpDescription:string,
|
||||
exec: (channel:Channel, sender:User, args:Array<string>) => void
|
||||
|
|
|
@ -11,6 +11,7 @@ import LatLng from "./LatLng";
|
|||
import Bot from "../Bot";
|
||||
import { ConsoleHelper } from "../../ConsoleHelper";
|
||||
import UserInfoRepository from "../repos/UserInfoRepository";
|
||||
import { Permissions } from "../enums/Permissions";
|
||||
|
||||
export default class Shared {
|
||||
public readonly chatManager:ChatManager;
|
||||
|
@ -36,7 +37,7 @@ export default class Shared {
|
|||
|
||||
// Add the bot user
|
||||
this.users = new UserArray();
|
||||
const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", this));
|
||||
const botUser = this.users.add("bot", new User(3, "SillyBot", "bot", Permissions.None, this));
|
||||
botUser.location = new LatLng(50, -32);
|
||||
this.bot = new Bot(this, botUser);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import Shared from "../objects/Shared";
|
|||
import Slot from "./Slot";
|
||||
import Channel from "./Channel";
|
||||
import PresenceData from "../interfaces/PresenceData";
|
||||
import { Permissions } from "../enums/Permissions";
|
||||
|
||||
const rankingModes = [
|
||||
"pp_raw",
|
||||
|
@ -28,6 +29,7 @@ export default class User {
|
|||
public rankingMode:RankingModes = RankingModes.PP;
|
||||
public spectatorStream?:DataStream;
|
||||
public spectatingUser?:User;
|
||||
public permissions:Permissions;
|
||||
|
||||
// osu! data
|
||||
public playMode:number = 0;
|
||||
|
@ -65,10 +67,11 @@ export default class User {
|
|||
return user0.uuid === user1.uuid;
|
||||
}
|
||||
|
||||
public constructor(id:number, username:string, uuid:string, shared:Shared) {
|
||||
public constructor(id:number, username:string, uuid:string, permissions:Permissions, shared:Shared) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.uuid = uuid;
|
||||
this.permissions = permissions;
|
||||
|
||||
this.shared = shared;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue