-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.3.0 - Merge pull request #130 from osu-cascades/dev
- Loading branch information
Showing
34 changed files
with
324 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v13.7 | ||
v14.13.1 |
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 @@ | ||
nodejs 14.13.1 |
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,17 @@ | ||
import Hacktoberfest from '@/commands/hacktoberfest'; | ||
|
||
import { message as mockMessage, MockedMessage } from '../mocks/discord'; | ||
|
||
let sendMock: MockedMessage; | ||
beforeEach(() => { | ||
sendMock = jest.fn(); | ||
mockMessage.channel.send = sendMock; | ||
}); | ||
|
||
describe('Hacktoberfest command', () => { | ||
test('hacktoberfest', () => { | ||
Hacktoberfest.execute([], mockMessage); | ||
const sentMessage = sendMock.mock.calls[0][0]; | ||
expect(sentMessage.includes('Hacktoberfest')).toEqual(true); | ||
}); | ||
}); |
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,21 @@ | ||
import Run from '@/commands/run'; | ||
import { message as mockMessage, MockedMessage } from '../mocks/discord'; | ||
|
||
let sendMock: MockedMessage; | ||
beforeEach(() => { | ||
sendMock = jest.fn(); | ||
mockMessage.channel.send = sendMock; | ||
mockMessage.reply = sendMock; | ||
}); | ||
|
||
test('Malformed message', () => { | ||
mockMessage.content = "Wow this is nowhere near the correct content"; | ||
Run.execute([], mockMessage); | ||
expect(sendMock).lastCalledWith("Sorry, I ran into some problems understanding your message. Here is the error stopping me.\nError: Unable to extract code from Wow this is nowhere near the correct content"); | ||
}); | ||
|
||
test('Unknown language', () => { | ||
mockMessage.content = "```invalidLanguage\nblahblahblah```"; | ||
Run.execute([], mockMessage); | ||
expect(sendMock).lastCalledWith("Unknown language: invalidLanguage") | ||
}); |
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,21 @@ | ||
import Rust from '@/runners/rust'; | ||
import axiosMock from '../__mocks__/axios'; | ||
|
||
jest.mock('axios'); | ||
|
||
test('valid code', async () => { | ||
const code = "testCode"; | ||
let mockResponse = Promise.resolve({ data: { success: true, stdout: "test", stderr: " Compiling playground v0.0.1 (/playground)\n Finished dev [unoptimized + debuginfo] target(s) in 0.43s\n Running `target/debug/playground`\n" } }); | ||
axiosMock.post.mockResolvedValueOnce(mockResponse); | ||
let result = await Rust.execute(code); | ||
expect(result).toEqual({ success: true, output: "test" }); | ||
}) | ||
|
||
test('invalid code', async () => { | ||
const code = "testCode"; | ||
const errorResult = "bad code"; | ||
let mockResponse = Promise.resolve({ data: { success: false, stdout: "", stderr: errorResult } }); | ||
axiosMock.post.mockResolvedValueOnce(mockResponse); | ||
let result = await Rust.execute(code); | ||
expect(result).toEqual({ success: false, output: errorResult }); | ||
}) |
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,31 @@ | ||
import Languages from '@/library/languages'; | ||
import IRunner from '@/library/interfaces/iRunner'; | ||
import { ILanguageRunners } from '@/library/languageLoader'; | ||
|
||
describe('Languages', () => { | ||
let mockLanguageRunner: IRunner; | ||
let languageRunners: ILanguageRunners; | ||
let languages: Languages; | ||
|
||
beforeEach(() => { | ||
mockLanguageRunner = { | ||
execute: jest.fn() | ||
}; | ||
|
||
languageRunners = { | ||
testLang: mockLanguageRunner, | ||
}; | ||
|
||
languages = new Languages(languageRunners); | ||
}); | ||
|
||
test('.names returns language names', () => { | ||
const languageNames = ['testLang']; | ||
expect(languages.names).toEqual(languageNames); | ||
}); | ||
|
||
test('Can fetch a command', () => { | ||
const testLang = languages.get('testLang'); | ||
expect(testLang).toBe(mockLanguageRunner); | ||
}); | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
import ICommand from '@/library/interfaces/iCommand'; | ||
import { Message } from 'discord.js'; | ||
|
||
// Hack for implementing with static properties/methods | ||
let Hacktoberfest: ICommand; | ||
export default Hacktoberfest = class { | ||
|
||
static get description(): string { | ||
return 'Lists information on how to participate in Hacktoberfest 2020'; | ||
} | ||
|
||
public static execute(args: string[], msg: Message) { | ||
const content = "Hacktoberfest has officially begun! Find out more information at\nhttps://hacktoberfest.digitalocean.com\nand stay tuned for opportunities and workshops from tech club members."; | ||
return msg.channel.send(content); | ||
} | ||
|
||
}; |
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,61 @@ | ||
import ICommand from '@/library/interfaces/iCommand'; | ||
import Languages from '@/library/languages'; | ||
import { Message } from 'discord.js'; | ||
|
||
const languages = new Languages(); | ||
|
||
// Hack for implementing with static properties/methods | ||
let Run: ICommand; | ||
export default Run = class { | ||
|
||
|
||
/* istanbul ignore next */ | ||
static get description(): string { | ||
return 'Executes provided code using a LanguageRunner'; | ||
} | ||
|
||
public static execute(args: string[], msg: Message) { | ||
|
||
let parseResponse; | ||
|
||
try { | ||
parseResponse = this.parseCode(msg.content); | ||
if (!languages.get(parseResponse.language)) { | ||
msg.channel.send(`Unknown language: ${parseResponse.language}`); | ||
return; | ||
} | ||
} catch (e) { | ||
msg.channel.send("Sorry, I ran into some problems understanding your message. Here is the error stopping me.\n" + e); | ||
return; | ||
} | ||
|
||
const codeRunnerResponse = languages.get(parseResponse.language).execute(parseResponse.code); | ||
|
||
codeRunnerResponse.then((response: { success: any; output: string; }) => { | ||
if (response.success) { | ||
msg.channel.send("```" + response.output + "```"); | ||
} else { | ||
msg.channel.send( | ||
"Unfortunately I was unable to run your code. Here is the error I received.\n```" + | ||
response.output + | ||
"```" | ||
); | ||
} | ||
}); | ||
|
||
} | ||
|
||
// Tries to pull language and source code out of message | ||
private static parseCode(messageText: string): { language: string, code: string } { | ||
const codeRegex = /(```(.[^\n]*))(\n(.*))(```)/s; | ||
const match = codeRegex.exec(messageText); | ||
|
||
// Group 2 = language, group 4 = code | ||
if (match && match[2] && match[4]) { | ||
return { language: match[2], code: match[4] }; | ||
} else { | ||
throw new Error(`Unable to extract code from ${messageText}`); | ||
} | ||
} | ||
|
||
}; |
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
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,10 @@ | ||
/** | ||
* An interface for all code runners to extend, representing the API that all | ||
* subclasses should implement. | ||
* | ||
* @class Runner | ||
*/ | ||
|
||
export default interface IRunner { | ||
execute(code: string): Promise<{success: boolean, output: string}>; | ||
} |
Oops, something went wrong.