-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Source Command Repo Link and fix typo (#17) * Fixed repo link * Fixed typo * Fix production error handler (#19) * Add twitch integration only in production (#21) * Removed docsdex submodule (#22) * Fix Error handler for slash commands (#23) * Fix production error handler * Make @NyCodeGHG happy * Fix detekt issues * Replace work around in favour of Kord release * Respond with Embed on unkown tag (#25) * Removed docsdex submodule * Fix embed * Remove unused method * Variables in Tags (#26) * Added calculation parser * Added check task to ci * Added calc command * Added pow functionality * Fixed formatting * Added tag variables * Added http variable * Add tag with variable creation only by bot owners * Added floating number support * Fixed calc command * Fixed exception handling * Fix formatting Co-authored-by: NyCode <[email protected]>
- Loading branch information
1 parent
80e11dc
commit 7a6f863
Showing
38 changed files
with
1,158 additions
and
60 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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
grammar Calculation; | ||
|
||
root: expression; | ||
|
||
expression: '(' expression ')' #Parentheses | ||
| left=expression operator='^' right=expression #Squared | ||
| left=expression operator='*' right=expression #Multiply | ||
| left=expression operator='/' right=expression #Divide | ||
| left=expression operator='+' right=expression #Plus | ||
| left=expression operator='-' right=expression #Minus | ||
| NUMBER #Number | ||
; | ||
|
||
NUMBER: [0-9]+('.'[0-9]+)?; | ||
WHITESPACE: [ \t\r\n]+ -> skip; |
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
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/de/nycode/bankobot/command/MathExpressionArgument.kt
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,54 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2021 BankoBot Contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package de.nycode.bankobot.command | ||
|
||
import de.nycode.bankobot.variables.parsers.InvalidExpressionException | ||
import de.nycode.bankobot.variables.parsers.calc.CalcExpression | ||
import dev.kord.core.event.message.MessageCreateEvent | ||
import dev.kord.x.commands.argument.Argument | ||
import dev.kord.x.commands.argument.result.ArgumentResult | ||
|
||
val MathExpressionArgument: Argument<CalcExpression, MessageCreateEvent> = | ||
InternalMathExpressionArgument() | ||
|
||
internal class InternalMathExpressionArgument(override val name: String = "expression") : | ||
Argument<CalcExpression, MessageCreateEvent> { | ||
override suspend fun parse( | ||
text: String, | ||
fromIndex: Int, | ||
context: MessageCreateEvent | ||
): ArgumentResult<CalcExpression> { | ||
val expression = CalcExpression(text.substring(fromIndex)) | ||
return try { | ||
expression.getResult() | ||
ArgumentResult.Success(expression, text.length - fromIndex) | ||
} catch (exception: InvalidExpressionException) { | ||
ArgumentResult.Failure(exception.message ?: "Unknown error", exception.position) | ||
} catch (exception: Exception) { | ||
ArgumentResult.Failure(exception.message ?: "Unknown error", 0) | ||
} | ||
} | ||
} |
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.