mirror of
https://github.com/gissleh/irc.git
synced 2026-10-15 19:32:52 +00:00
Renamed Event.Kill to Event.PreventDefault
This commit is contained in:
@@ -548,7 +548,7 @@ func (client *Client) handleEventLoop() {
|
|||||||
emit(event, client)
|
emit(event, client)
|
||||||
|
|
||||||
// Turn an unhandled input into a raw command.
|
// Turn an unhandled input into a raw command.
|
||||||
if event.kind == "input" && !event.Killed() {
|
if event.kind == "input" && !event.preventedDefault {
|
||||||
client.SendQueued(strings.ToUpper(event.verb) + " " + event.Text)
|
client.SendQueued(strings.ToUpper(event.verb) + " " + event.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ type Event struct {
|
|||||||
Text string
|
Text string
|
||||||
Tags map[string]string
|
Tags map[string]string
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
killed bool
|
preventedDefault bool
|
||||||
hidden bool
|
hidden bool
|
||||||
|
|
||||||
targets []Target
|
targets []Target
|
||||||
targetIds map[Target]string
|
targetIds map[Target]string
|
||||||
@@ -89,18 +89,13 @@ func (event *Event) Context() context.Context {
|
|||||||
return event.ctx
|
return event.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill stops propagation of the event. The context will be killed once
|
// PreventDefault stops propagation of the event. The context will be killed once
|
||||||
// the current event handler returns.
|
// the current event handler returns.
|
||||||
//
|
//
|
||||||
// A use case for this is to prevent the default input handler from firing
|
// A use case for this is to prevent the default input handler from firing
|
||||||
// on an already prcoessed input event.
|
// on an already prcoessed input event.
|
||||||
func (event *Event) Kill() {
|
func (event *Event) PreventDefault() {
|
||||||
event.killed = true
|
event.preventedDefault = true
|
||||||
}
|
|
||||||
|
|
||||||
// Killed returns true if Kill has been called.
|
|
||||||
func (event *Event) Killed() bool {
|
|
||||||
return event.killed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide will not stop propagation, but it will allow output handlers to know not to
|
// Hide will not stop propagation, but it will allow output handlers to know not to
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ func emit(event *Event, client *Client) {
|
|||||||
eventHandler.mutex.RLock()
|
eventHandler.mutex.RLock()
|
||||||
for _, handler := range eventHandler.handlers {
|
for _, handler := range eventHandler.handlers {
|
||||||
handler(event, client)
|
handler(event, client)
|
||||||
if event.killed {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
eventHandler.mutex.RUnlock()
|
eventHandler.mutex.RUnlock()
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -12,7 +12,7 @@ func Input(event *irc.Event, client *irc.Client) {
|
|||||||
// /msg sends an action to a target specified before the message.
|
// /msg sends an action to a target specified before the message.
|
||||||
case "input.msg":
|
case "input.msg":
|
||||||
{
|
{
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
|
|
||||||
targetName, text := ircutil.ParseArgAndText(event.Text)
|
targetName, text := ircutil.ParseArgAndText(event.Text)
|
||||||
if targetName == "" || text == "" {
|
if targetName == "" || text == "" {
|
||||||
@@ -30,7 +30,7 @@ func Input(event *irc.Event, client *irc.Client) {
|
|||||||
// /text (or text without a command) sends a message to the target.
|
// /text (or text without a command) sends a message to the target.
|
||||||
case "input.text":
|
case "input.text":
|
||||||
{
|
{
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
|
|
||||||
if event.Text == "" {
|
if event.Text == "" {
|
||||||
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /text <text...>"))
|
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /text <text...>"))
|
||||||
@@ -53,7 +53,7 @@ func Input(event *irc.Event, client *irc.Client) {
|
|||||||
// /me and /action sends a CTCP ACTION.
|
// /me and /action sends a CTCP ACTION.
|
||||||
case "input.me", "input.action":
|
case "input.me", "input.action":
|
||||||
{
|
{
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
|
|
||||||
if event.Text == "" {
|
if event.Text == "" {
|
||||||
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /me <text...>"))
|
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /me <text...>"))
|
||||||
@@ -76,7 +76,7 @@ func Input(event *irc.Event, client *irc.Client) {
|
|||||||
// /describe sends an action to a target specified before the message, like /msg.
|
// /describe sends an action to a target specified before the message, like /msg.
|
||||||
case "input.describe":
|
case "input.describe":
|
||||||
{
|
{
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
|
|
||||||
targetName, text := ircutil.ParseArgAndText(event.Text)
|
targetName, text := ircutil.ParseArgAndText(event.Text)
|
||||||
if targetName == "" || text == "" {
|
if targetName == "" || text == "" {
|
||||||
@@ -94,7 +94,7 @@ func Input(event *irc.Event, client *irc.Client) {
|
|||||||
// /m is a shorthand for /mode that targets the current channel
|
// /m is a shorthand for /mode that targets the current channel
|
||||||
case "input.m":
|
case "input.m":
|
||||||
{
|
{
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
|
|
||||||
if event.Text == "" {
|
if event.Text == "" {
|
||||||
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /m <text...>"))
|
client.EmitNonBlocking(irc.NewErrorEvent("input", "Usage: /m <text...>"))
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func MRoleplay(event *irc.Event, client *irc.Client) {
|
|||||||
client.SendQueuedf("%s %s %s :%s", npcCommand, channel.Name(), nick, cut)
|
client.SendQueuedf("%s %s %s :%s", npcCommand, channel.Name(), nick, cut)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
}
|
}
|
||||||
case "input.scenec":
|
case "input.scenec":
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ func MRoleplay(event *irc.Event, client *irc.Client) {
|
|||||||
client.SendQueuedf("SCENE %s :%s", channel.Name(), cut)
|
client.SendQueuedf("SCENE %s :%s", channel.Name(), cut)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Kill()
|
event.PreventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user