Skip to content

Commit

Permalink
Add got-chanlist event bind type
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg committed Nov 3, 2023
1 parent 322bddb commit 1e49969
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/sphinx_source/using/tcl-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,7 @@ The following is a list of bind types and how they work. Below each bind type is
disconnect-server - called when we disconnect from our IRC server
fail-server - called when an IRC server fails to respond
hidden-host - called after the bot's host is hidden by the server
got-chanlist - called after Eggdrop receives the channel userlist from the server

Note that Tcl scripts can trigger arbitrary events, including ones that are not pre-defined or used by Eggdrop.

Expand Down
1 change: 1 addition & 0 deletions src/mod/irc.mod/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ static int got315(char *from, char *msg)
sync_members(chan);
chan->status |= CHAN_ACTIVE;
chan->status &= ~CHAN_PEND;
check_tcl_event_arg("got-chanlist", chname);
if (!ismember(chan, botname)) { /* Am I on the channel now? */
putlog(LOG_MISC | LOG_JOIN, chan->dname, "Oops, I'm not really on %s.",
chan->dname);
Expand Down
3 changes: 3 additions & 0 deletions src/mod/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ typedef void (*chanout_butfunc)(int, int, const char *, ...) ATTRIBUTE_FORMAT(pr
#define USERENTRY_ACCOUNT (*(struct user_entry_type *)(global[316]))
#define get_user_by_account ((struct userrec * (*)(char *))global[317])
#define delaccount_by_handle ((int(*)(char *,char *))global[318])
#define check_tcl_event_arg ((void (*) (const char *,const char *))global[319])
/*320 - 323 */




Expand Down
4 changes: 3 additions & 1 deletion src/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ Function global_table[] = {
/* 316 - 319 */
(Function) & USERENTRY_ACCOUNT, /* struct user_entry_type * */
(Function) get_user_by_account,
(Function) delhost_by_handle
(Function) delhost_by_handle,
(Function) check_tcl_event_arg
/* 320 - 323 */
};

void init_modules(void)
Expand Down
26 changes: 25 additions & 1 deletion src/tclhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static int builtin_cron STDVAR;
static int builtin_char STDVAR;
static int builtin_chpt STDVAR;
static int builtin_chjn STDVAR;
static int builtin_evnt STDVAR;
static int builtin_idxchar STDVAR;
static int builtin_charidx STDVAR;
static int builtin_chat STDVAR;
Expand Down Expand Up @@ -235,7 +236,7 @@ void init_bind(void)
H_bcst = add_bind_table("bcst", HT_STACKABLE, builtin_chat);
H_away = add_bind_table("away", HT_STACKABLE, builtin_chat);
H_act = add_bind_table("act", HT_STACKABLE, builtin_chat);
H_event = add_bind_table("evnt", HT_STACKABLE, builtin_char);
H_event = add_bind_table("evnt", HT_STACKABLE, builtin_evnt);
H_die = add_bind_table("die", HT_STACKABLE, builtin_char);
H_log = add_bind_table("log", HT_STACKABLE, builtin_log);
#ifdef TLS
Expand Down Expand Up @@ -593,6 +594,21 @@ static int builtin_chjn STDVAR
return TCL_OK;
}

static int builtin_evnt STDVAR
{
Function F = (Function) cd;

BADARGS(2, 3, " event ?arg?");

CHECKVALIDITY(builtin_evnt);
if (argc==2) {
F(argv[1]);
} else {
F(argv[1], argv[2]);
}
return TCL_OK;
}

static int builtin_idxchar STDVAR
{
Function F = (Function) cd;
Expand Down Expand Up @@ -1212,6 +1228,14 @@ void check_tcl_event(const char *event)
MATCH_EXACT | BIND_STACKABLE);
}

void check_tcl_event_arg(const char *event, const char *arg)
{
Tcl_SetVar(interp, "_event1", (char *) event, TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "_event2", (char *) arg, TCL_GLOBAL_ONLY);
check_tcl_bind(H_event, event, 0, " $::_event1 $::_event2",
MATCH_EXACT | BIND_STACKABLE);
}

int check_tcl_signal(const char *event)
{
int x;
Expand Down
1 change: 1 addition & 0 deletions src/tclhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void check_tcl_nkch(const char *, const char *);
void check_tcl_away(const char *, int, const char *);
void check_tcl_chatactbcst(const char *, int, const char *, tcl_bind_list_t *);
void check_tcl_event(const char *);
void check_tcl_event_arg(const char *, const char *);
int check_tcl_signal(const char *);
void check_tcl_die(char *);
void check_tcl_log(int, char *, char *);
Expand Down
8 changes: 6 additions & 2 deletions src/tclmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,13 @@ static int tcl_reloadhelp STDVAR

static int tcl_callevent STDVAR
{
BADARGS(2, 2, " event");
BADARGS(2, 3, " event ?arg?");

check_tcl_event(argv[1]);
if (argc == 2) {
check_tcl_event(argv[1]);
} else {
check_tcl_event_arg(argv[1], argv[2]);
}
return TCL_OK;
}

Expand Down

0 comments on commit 1e49969

Please sign in to comment.