Skip to content

Refactor #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 58 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2532ff7
remove prototype Subscriber Alerts
Orciument Jan 28, 2025
5a73bd5
remove donationGoal prototype
Orciument Jan 28, 2025
f5b659f
remove years old testing code
Orciument Jan 28, 2025
92988e5
remove Twitch4JHandler, move object translation into from method on C…
Orciument Jan 28, 2025
ffe8806
makeshift startup script
Orciument Jan 28, 2025
c741d18
change command and template registration, add central Registrar
Orciument Jan 29, 2025
9a8cc97
move WatchtimeUpdateService initialization
Orciument Jan 29, 2025
62e3d03
remove registration from botinput, add ui customizations for health r…
Orciument Jan 29, 2025
172052a
remove InputManager, remove @Input
Orciument Jan 29, 2025
344d742
add stub for resetableCaches in Registrar
Orciument Jan 29, 2025
262bbae
add Command builder Pattern in the Registrar
Orciument Jan 30, 2025
c167b80
add ascii fuzzing test, rename ArgumentValueNullException
Orciument Feb 1, 2025
f02c26d
impl tests in TemplateLexerTest, add token string fuzzing
Orciument Feb 1, 2025
44cd541
remove dead code
Orciument Feb 1, 2025
8f8b10a
adds error for malformed for loop head,
Orciument Feb 1, 2025
519c0c6
wip higher-order-function to improve TwitchApi connector
Orciument Feb 1, 2025
bb3f69a
adds syntax checking to VarStatement field access expressions, change…
Orciument Feb 1, 2025
fd0ddbd
rework string template Exception hierarchy, and adjust non-test code
Orciument Feb 1, 2025
1d3b7af
start fixing test code for Exception changes
Orciument Feb 1, 2025
e4573a4
fix no .equals for VarStatement, remove dead UnsupportedComparandType…
Orciument Feb 1, 2025
65315a0
add builder methods for TemplateToken, fix parsers returning null tok…
Orciument Feb 2, 2025
84f93cd
with to using Class.getCanonicalName() to get package information
Orciument Feb 2, 2025
68711e2
add template if comparator null tests
Orciument Feb 2, 2025
eb20611
use record pattern, change to string builder to reduce reallocations
Orciument Feb 2, 2025
45cab61
fully parse loop directive in parsing step, fix missing_percent test,…
Orciument Feb 2, 2025
e918453
fixed if_parser exception with malformed number
Orciument Feb 2, 2025
eca4536
run test scripts on pull requests
Orciument Feb 2, 2025
6bc6550
fix pipeline
Orciument Feb 2, 2025
cff08d2
upgrade package.json
Orciument Feb 2, 2025
2e6dceb
added error messages
Orciument Feb 3, 2025
391eab2
remove dead code
Orciument Feb 3, 2025
9ff8cd5
change getName of java Class
Orciument Feb 3, 2025
cbf9e84
fix bug of incorrect UnexpectedEndOfInput when if/for statement was n…
Orciument Feb 3, 2025
3789227
add end-to-end compile and interpret tests
Orciument Feb 3, 2025
cd23c35
remove next because it is now redundant since peak was removed
Orciument Feb 3, 2025
34f6383
rename to parseStatement to make more consistent and reduce ambiguity…
Orciument Feb 3, 2025
36146d8
fixed test assert
Orciument Feb 3, 2025
a771052
replace assert with jupiter asserts
Orciument Feb 3, 2025
20d71aa
remove outdated todos
Orciument Feb 4, 2025
ef36a69
extract autowired values from TipeeeInput to make it more testable
Orciument Feb 4, 2025
fce22fa
make tipeeeInput throw exceptions on startup
Orciument Feb 4, 2025
bc5ba71
test tipeee info url parsing and info url format
Orciument Feb 5, 2025
d80305a
make TipeeeEventHandler testable, add Donations table
Orciument Feb 5, 2025
c6ed2f3
introduce twitch api interface, and noop api impl
Orciument Feb 6, 2025
21475c2
try automatic reconnect on twitch api failure
Orciument Feb 6, 2025
b5d8274
extract config from Twitch4JInput
Orciument Feb 6, 2025
e871516
add TipeeeConnectionTest to test authentication procedure with live t…
Orciument Feb 6, 2025
7186296
remove some @Component annotations
Orciument Feb 6, 2025
88f9ae1
fix brocken cooldowns
Orciument Feb 6, 2025
bcfd94c
ignore singular % or $ not followed by {
Orciument Feb 7, 2025
5f5bf24
fix pipeline
Orciument Feb 7, 2025
e2dc831
fix pipeline
Orciument Feb 7, 2025
d058898
fix pipeline
Orciument Feb 7, 2025
90fa083
add logging and exceptions to twitch ChatMessage conversion
Orciument Feb 7, 2025
d464d5a
move oauth
Orciument Feb 7, 2025
83b44ee
move tipeee and twitch
Orciument Feb 7, 2025
db5c7be
move out of system dir
Orciument Feb 7, 2025
650e587
lowercase twitch and tipeee
Orciument Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Java CI
name: Build on Push

on: [push, pull_request]
on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on: pull_request

jobs:
build:
runs-on: ubuntu-latest

services:
db:
image: mariadb:11.1.2
env:
MYSQL_DATABASE: 'talium'
MYSQL_USER: 'taliumBot'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
ports:
- "4770:3306"

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots clean compile
working-directory: bot
env:
JAVA_TOOL_OPTIONS: --enable-preview
- name: Run all Tests
run: mvn test
working-directory: bot
env:
JAVA_TOOL_OPTIONS: --enable-preview
tipeeeApikey: ${{ secrets.tipeeeApikey }}
DOCKER_PASS: ${{ secrets.tipeeeChannel }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package talium.system;
package talium;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package talium.system;
package talium;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand All @@ -10,6 +10,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = {Exception.class})
public String generalException(Exception e) {
logger.error(e.getMessage(), e);
return "An Exception occurred!";
}
}
40 changes: 24 additions & 16 deletions bot/main/talium/system/Out.java → bot/main/talium/Out.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package talium.system;
package talium;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import talium.inputs.Twitch4J.Twitch4JInput;
import talium.inputs.Twitch4J.TwitchApi;
import talium.system.stringTemplates.Template;
import talium.system.stringTemplates.TemplateService;
import talium.system.templateParser.exeptions.ArgumentValueNullException;
import talium.system.templateParser.exeptions.UnIterableArgumentException;
import talium.system.templateParser.exeptions.UnsupportedComparandType;
import talium.system.templateParser.exeptions.UnsupportedComparisonOperator;
import talium.system.templateParser.TemplateParser;
import talium.twitch4J.TwitchAPINoop;
import talium.twitch4J.TwitchApi;
import talium.stringTemplates.Template;
import talium.stringTemplates.TemplateService;
import talium.templateParser.exeptions.*;
import talium.templateParser.TemplateParser;
import talium.templateParser.statements.Statement;

import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;

import static talium.system.templateParser.TemplateInterpreter.populate;
import static talium.templateParser.TemplateInterpreter.populate;

@Component
public class Out {
Expand All @@ -30,8 +30,11 @@ public void setTemplateService(TemplateService templateService) {

public static class Twitch {

@NonNull
public static TwitchApi api = new TwitchAPINoop();

public static void sendRawMessage(String message) {
TwitchApi.sendMessage(message);
api.sendMessage(message);
}

public static String sendNamedTemplate(String id, HashMap<String, Object> baseValues) throws NoSuchElementException {
Expand All @@ -47,16 +50,21 @@ public static String sendNamedTemplate(String id, HashMap<String, Object> baseVa

public static String sendRawTemplate(String template, HashMap<String, Object> values) {
String message;
List<Statement> parsed;
try {
parsed = new TemplateParser(template).parse();
} catch (ParsingException e) {
// TODO display exceptions, but this should not throw exceptions, since a parsing check should be done on save, so it should still work here
throw new RuntimeException(e);
}
try {
var parsed = new TemplateParser(template).parse();
message = populate(parsed, values);
} catch (UnsupportedComparisonOperator | NoSuchFieldException | ArgumentValueNullException |
IllegalAccessException | UnIterableArgumentException | UnsupportedComparandType e) {
} catch (InterpretationException e) {
//TODO handle exceptions
// the exceptions should be displayed in the console and in the webconsole with a fairly high priority
throw new RuntimeException(e);
}
TwitchApi.sendMessage(message);
api.sendMessage(message);
return message;
}
}
Expand Down
141 changes: 141 additions & 0 deletions bot/main/talium/Registrar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package talium;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import talium.twitch4J.TwitchUserPermission;
import talium.inputSystem.HealthManager;
import talium.stringTemplates.Template;
import talium.stringTemplates.TemplateService;
import talium.twitchCommands.cooldown.ChatCooldown;
import talium.twitchCommands.cooldown.CooldownType;
import talium.twitchCommands.triggerEngine.RuntimeTrigger;
import talium.twitchCommands.triggerEngine.TriggerCallback;
import talium.twitchCommands.triggerEngine.TriggerEngine;
import talium.twitchCommands.triggerEngine.TriggerProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/// Used as a central place to register actions and resources with parts of the bot
@Component
public class Registrar {

static TemplateService templateService;

@Autowired
public Registrar(TemplateService templateService) {
Registrar.templateService = templateService;
}

/// Register Custom HealthUI titel and description
public static void registerHealthDescription(String self, String title, String description) {
HealthManager.addCustomization(self, title, description);
}

/// Register Custom HealthUI titel and description
public static void registerHealthDescription(Class<?> self, String title, String description) {
HealthManager.addCustomization(self.getCanonicalName(), title, description);
}

public interface ResetableCache {
void rebuild();
}

/// Register a function to reset/rebuild a application cache from the panel ui
public static void registerResetableChache(String name, String description, ResetableCache cache) {
//TODO register cache, show in ui, act on reset HTTP post
}

/// Register an autogenerated command with the bot
public static class Command {
//set all defaults
String id;
List<Pattern> patterns = new ArrayList<>();
TwitchUserPermission permission = TwitchUserPermission.EVERYONE;
ChatCooldown userCooldown = new ChatCooldown(CooldownType.MESSAGES, 0);
ChatCooldown globalCooldown = new ChatCooldown(CooldownType.MESSAGES, 0);

public Command(String id) {
checkId(id);
this.id = id;
}

public Command(String id, String pattern) {
checkId(id);
this.id = id;
}

private static void checkId(String id) {
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("Command id cannot be null or empty");
}
if (id.startsWith("userCommand.")) {
throw new IllegalArgumentException("Autogenerated command is not allowed to have the prefix \"userCommand.\" cause: '"+ id);
}
}

public Command id(String id) {
this.id = id;
return this;
}

public Command patterns(List<String> patterns) {
for (String pattern : patterns) {
this.patterns.add(Pattern.compile(pattern));
}
return this;
}

public Command pattern(String pattern) {
this.patterns.add(Pattern.compile(pattern));
return this;
}

public Command permission(TwitchUserPermission permission) {
this.permission = permission;
return this;
}

public Command userCooldown(ChatCooldown userCooldown) {
this.userCooldown = userCooldown;
return this;
}

public Command globalCooldown(ChatCooldown globalCooldown) {
this.globalCooldown = globalCooldown;
return this;
}

/// Registers an automatically generated command with a callback
public void registerActionCommand(TriggerCallback callback) {
TriggerProvider.addCommandRegistration(new RuntimeTrigger(id, patterns, permission, userCooldown,globalCooldown, callback));
}

/// Registers an automatically generated command without a callback, but with a template
public void registerTextCommand(String template) {
registerTextCommand(template, null);
}

/// Registers an automatically generated command without a callback, but with a template
public void registerTextCommand(String template, String messageColor) {
templateService.saveIfAbsent(new Template(id, template, messageColor));
TriggerProvider.addCommandRegistration(new RuntimeTrigger(id, patterns, permission, userCooldown,globalCooldown, TriggerEngine.TEXT_COMMAND_CALLBACK));
}
}

/// Registers a template with the context variables (captured environment)
public static void registerTemplate(Template template) {
templateService.saveIfAbsent(template);
}

/// Registers a template with the context variables (captured environment)
public static void registerTemplate(String templateId, String template, String messageColor) {
templateService.saveIfAbsent(new Template(templateId, template, messageColor));
}

/// Registers a template with the context variables (captured environment)
public static void registerTemplate(String templateId, String template) {
templateService.saveIfAbsent(new Template(templateId, template, null));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package talium.system;
package talium;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -35,7 +35,7 @@ public StopWatch(TYPE type) {
endMessage = "Finished Bot shutdown";
}
}
if (startMessage.length() > 0)
if (!startMessage.isEmpty())
logger.info("{}...", startMessage.trim());
}

Expand Down
Loading