4 #include "xchat-plugin.h"
7 #define strcasecmp stricmp
10 static xchat_plugin
*ph
; /* plugin handle */
11 static GSList
*timer_list
= NULL
;
15 "Usage: TIMER [-refnum <num>] [-repeat <num>] <seconds> <command>\n" \
16 " TIMER [-quiet] -delete <num>"
21 xchat_context
*context
;
26 unsigned int forever
:1;
30 timer_del (timer
*tim
)
32 timer_list
= g_slist_remove (timer_list
, tim
);
34 xchat_unhook (ph
, tim
->hook
);
39 timer_del_ref (int ref
, int quiet
)
52 xchat_printf (ph
, "Timer %d deleted.\n", ref
);
58 xchat_print (ph
, "No such ref number found.\n");
62 timeout_cb (timer
*tim
)
64 if (xchat_set_context (ph
, tim
->context
))
66 xchat_command (ph
, tim
->command
);
81 timer_add (int ref
, float timeout
, int repeat
, char *command
)
99 tim
= malloc (sizeof (timer
));
101 tim
->repeat
= repeat
;
102 tim
->timeout
= timeout
;
103 tim
->command
= strdup (command
);
104 tim
->context
= xchat_get_context (ph
);
105 tim
->forever
= FALSE
;
110 tim
->hook
= xchat_hook_timer (ph
, timeout
* 1000.0, (void *)timeout_cb
, tim
);
111 timer_list
= g_slist_append (timer_list
, tim
);
115 timer_showlist (void)
120 if (timer_list
== NULL
)
122 xchat_print (ph
, "No timers installed.\n");
123 xchat_print (ph
, HELP
);
126 /* 00000 00000000 0000000 abc */
127 xchat_print (ph
, "\026 Ref# Seconds Repeat Command \026\n");
132 xchat_printf (ph
, "%5d %8.1f %7d %s\n", tim
->ref
, tim
->timeout
,
133 tim
->repeat
, tim
->command
);
139 timer_cb (char *word
[], char *word_eol
[], void *userdata
)
151 return XCHAT_EAT_XCHAT
;
154 if (strcasecmp (word
[2], "-quiet") == 0)
160 if (strcasecmp (word
[2 + offset
], "-delete") == 0)
162 timer_del_ref (atoi (word
[3 + offset
]), quiet
);
163 return XCHAT_EAT_XCHAT
;
166 if (strcasecmp (word
[2 + offset
], "-refnum") == 0)
168 ref
= atoi (word
[3 + offset
]);
172 if (strcasecmp (word
[2 + offset
], "-repeat") == 0)
174 repeat
= atoi (word
[3 + offset
]);
178 timeout
= atof (word
[2 + offset
]);
179 command
= word_eol
[3 + offset
];
181 if (timeout
< 0.1 || !command
[0])
182 xchat_print (ph
, HELP
);
184 timer_add (ref
, timeout
, repeat
, command
);
186 return XCHAT_EAT_XCHAT
;
195 (xchat_plugin
*plugin_handle
, char **plugin_name
,
196 char **plugin_desc
, char **plugin_version
, char *arg
)
198 /* we need to save this for use with any xchat_* functions */
201 *plugin_name
= "Timer";
202 *plugin_desc
= "IrcII style /TIMER command";
203 *plugin_version
= "";
205 xchat_hook_command (ph
, "TIMER", XCHAT_PRI_NORM
, timer_cb
, HELP
, 0);
207 return 1; /* return 1 for success */