Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redis command and pub/sub event (#75)
* Add redis command and pub/sub event * Fix minor redis event issues * Allow multiple subbed channels, command arg list input * Avoid list object hacking
- Loading branch information
Showing
6 changed files
with
590 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
src/main/java/com/denizenscript/denizencore/events/core/RedisPubSubMessageScriptEvent.java
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,78 @@ | ||
package com.denizenscript.denizencore.events.core; | ||
|
||
import com.denizenscript.denizencore.DenizenCore; | ||
import com.denizenscript.denizencore.events.ScriptEvent; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
|
||
public class RedisPubSubMessageScriptEvent extends ScriptEvent { | ||
|
||
// <--[event] | ||
// @Events | ||
// redis pubsub message | ||
// | ||
// @Switch channel:<channel> to only fire on events advanced-matching the given channel. | ||
// | ||
// @Group Core | ||
// | ||
// @Triggers when a subscribed redis connection receives a published message, see <@link command Redis>. | ||
// | ||
// @Context | ||
// <context.redis_id> returns the connection id that saw this message. | ||
// <context.pattern> returns the redis pattern that matched the channel. | ||
// <context.channel> returns the actual channel matched. | ||
// <context.message> returns the published message. | ||
// | ||
// --> | ||
|
||
public static RedisPubSubMessageScriptEvent instance; | ||
|
||
public String redisID; | ||
public String pattern; | ||
public String channel; | ||
public String message; | ||
|
||
public RedisPubSubMessageScriptEvent() { | ||
instance = this; | ||
registerCouldMatcher("redis pubsub message"); | ||
registerSwitches("channel"); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return DenizenCore.implementation.getEmptyScriptEntryData(); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!runGenericSwitchCheck(path, "channel", channel)) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RedisPubSubMessage"; | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
switch (name) { | ||
case "redis_id": return new ElementTag(redisID); | ||
case "pattern": return new ElementTag(pattern); | ||
case "channel": return new ElementTag(channel); | ||
case "message": return new ElementTag(message); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
public void handle(String redisID, String pattern, String channel, String message) { | ||
this.redisID = redisID; | ||
this.pattern = pattern; | ||
this.channel = channel; | ||
this.message = message; | ||
fire(); | ||
} | ||
} |
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.