-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from aNickzz/rc/0.7.0
rc/0.7.0
- Loading branch information
Showing
56 changed files
with
3,675 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "dashbot", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"main": "index.js", | ||
"author": "Nicholas Sorokin <[email protected]>", | ||
"license": "Apache-2.0", | ||
|
@@ -26,8 +26,11 @@ | |
"greenlock-express": "^4.0.3", | ||
"haiku-random": "^1.0.0", | ||
"luxon": "^1.24.1", | ||
"mineflayer": "^2.23.0", | ||
"node-fetch": "^2.6.0", | ||
"tail": "^2.0.3", | ||
"throttle-debounce": "^2.2.1", | ||
"typed-emitter": "^1.2.0", | ||
"typescript": "^3.7.5", | ||
"winston": "^3.2.1" | ||
}, | ||
|
@@ -41,6 +44,7 @@ | |
"@types/mocha": "^7.0.2", | ||
"@types/node-fetch": "^2.5.4", | ||
"@types/tail": "^2.0.0", | ||
"@types/throttle-debounce": "^2.1.0", | ||
"@types/ws": "^7.2.3", | ||
"@typescript-eslint/eslint-plugin": "^2.18.0", | ||
"@typescript-eslint/parser": "^2.18.0", | ||
|
@@ -55,5 +59,8 @@ | |
"prettier": "^1.19.1", | ||
"source-map-support": "^0.5.16", | ||
"ts-node": "^8.6.2" | ||
}, | ||
"resolutions": { | ||
"vec3": "0.1.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
import Message from './ChatServer/Message'; | ||
|
||
export default interface Command { | ||
run( | ||
message: Message | null, | ||
name: string, | ||
...args: string[] | ||
): Promise<void>; | ||
export default abstract class Command { | ||
abstract readonly name: string; | ||
readonly alias: string[] | null = null; | ||
abstract readonly description: string; | ||
|
||
getUsage(): string { | ||
return `${this.name}${ | ||
this.alias !== null ? ` (${this.alias.join(', ')})` : `` | ||
}:\n${this.description}`; | ||
} | ||
abstract run(message: Message, ...args: string[]): Promise<void>; | ||
} | ||
|
||
export class CommandSet { | ||
readonly commands: Command[] = []; | ||
|
||
add(command: Command) { | ||
this.commands.push(command); | ||
} | ||
|
||
async run(message: Message, commandName: string, args: string[]) { | ||
for (const command of this.commands) { | ||
if ( | ||
command.name === commandName || | ||
command.alias?.includes(commandName) | ||
) { | ||
await command.run(message, ...args); | ||
return; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import winston from 'winston'; | ||
import ChatServer from '../ChatServer/ChatServer'; | ||
import Message from '../ChatServer/Message'; | ||
import Command from '../Command'; | ||
import DashBot from '../DashBot'; | ||
|
||
export default class LoginCommand extends Command { | ||
readonly name = 'login'; | ||
readonly description = 'Logs dashbot in to a server'; | ||
|
||
constructor(private bot: DashBot) { | ||
super(); | ||
} | ||
|
||
async run(message: Message, serverId?: string) { | ||
const servers = this.bot.servers.filter(server => !server.isConnected); | ||
if (servers.length === 0) { | ||
await message.channel.sendText('No servers to login to.'); | ||
return; | ||
} | ||
|
||
let server: ChatServer | null = null; | ||
if (!serverId) { | ||
if (servers.length > 1) { | ||
await message.channel.sendText('Which server?'); | ||
return; | ||
} | ||
|
||
server = servers[0]; | ||
} else { | ||
server = | ||
servers.filter(server => server.id === serverId).shift() ?? | ||
null; | ||
|
||
if (!server) { | ||
await message.channel.sendText("Couldn't find that server"); | ||
return; | ||
} | ||
} | ||
message.channel.sendText('Connecting to server...'); | ||
try { | ||
//TODO: this is weird, shouldn't need both of these calls | ||
await server.connect(); | ||
await server.awaitConnected(); | ||
|
||
await message.channel.sendText('Connected!'); | ||
} catch (e) { | ||
winston.error("Couldn't log in to server on request"); | ||
await message.channel.sendText("Couldn't connect! :("); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import winston from 'winston'; | ||
import ChatServer from '../ChatServer/ChatServer'; | ||
import Message from '../ChatServer/Message'; | ||
import Command from '../Command'; | ||
import DashBot from '../DashBot'; | ||
|
||
export default class LogoutCommand extends Command { | ||
readonly name = 'logout'; | ||
readonly description = | ||
'Logs out of the given server (or the current one if no server was specified)'; | ||
|
||
constructor(private bot: DashBot) { | ||
super(); | ||
} | ||
|
||
async run(message: Message, serverId?: string) { | ||
const servers = this.bot.servers.filter(server => server.isConnected); | ||
|
||
if (servers.length === 1) { | ||
await message.channel.sendText( | ||
"Not logging out, this is the only server I'm connected to" | ||
); | ||
return; | ||
} | ||
|
||
let server: ChatServer | null = null; | ||
if (!serverId) { | ||
server = message.channel.server; | ||
} else { | ||
server = | ||
servers.filter(server => server.id === serverId).shift() ?? | ||
null; | ||
|
||
if (!server) { | ||
await message.channel.sendText("Couldn't find that server"); | ||
return; | ||
} | ||
} | ||
|
||
message.channel.sendText('Disconnecting'); | ||
try { | ||
await server.disconnect(); | ||
|
||
if (message.channel.server.isConnected) { | ||
await message.channel.sendText('Connected!'); | ||
} | ||
} catch (e) { | ||
winston.error("Couldn't log in to server on request"); | ||
|
||
if (message.channel.server.isConnected) { | ||
await message.channel.sendText("Couldn't disconnect! :("); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.