4 #include "xchat-plugin.h"
6 static xchat_plugin
*ph
; /* plugin handle */
7 static GSList
*timer_list
= NULL
;
11 "Usage: TIMER [-refnum <num>] [-repeat <num>] <seconds> <command>\n" \
12 " TIMER [-quiet] -delete <num>"
17 xchat_context
*context
;
22 unsigned int forever
:1;
26 timer_del (timer
*tim
)
28 timer_list
= g_slist_remove (timer_list
, tim
);
30 xchat_unhook (ph
, tim
->hook
);
35 timer_del_ref (int ref
, int quiet
)
48 xchat_printf (ph
, "Timer %d deleted.\n", ref
);
54 xchat_print (ph
, "No such ref number found.\n");
58 timeout_cb (timer
*tim
)
60 if (xchat_set_context (ph
, tim
->context
))
62 xchat_command (ph
, tim
->command
);
77 timer_add (int ref
, float timeout
, int repeat
, char *command
)
95 tim
= malloc (sizeof (timer
));
98 tim
->timeout
= timeout
;
99 tim
->command
= strdup (command
);
100 tim
->context
= xchat_get_context (ph
);
101 tim
->forever
= FALSE
;
106 tim
->hook
= xchat_hook_timer (ph
, timeout
* 1000.0, (void *)timeout_cb
, tim
);
107 timer_list
= g_slist_append (timer_list
, tim
);
111 timer_showlist (void)
116 if (timer_list
== NULL
)
118 xchat_print (ph
, "No timers installed.\n");
119 xchat_print (ph
, HELP
);
122 /* 00000 00000000 0000000 abc */
123 xchat_print (ph
, "\026 Ref# Seconds Repeat Command \026\n");
128 xchat_printf (ph
, "%5d %8.1f %7d %s\n", tim
->ref
, tim
->timeout
,
129 tim
->repeat
, tim
->command
);
135 timer_cb (char *word
[], char *word_eol
[], void *userdata
)
147 return XCHAT_EAT_XCHAT
;
150 if (strcasecmp (word
[2], "-quiet") == 0)
156 if (strcasecmp (word
[2 + offset
], "-delete") == 0)
158 timer_del_ref (atoi (word
[3 + offset
]), quiet
);
159 return XCHAT_EAT_XCHAT
;
162 if (strcasecmp (word
[2 + offset
], "-refnum") == 0)
164 ref
= atoi (word
[3 + offset
]);
168 if (strcasecmp (word
[2 + offset
], "-repeat") == 0)
170 repeat
= atoi (word
[3 + offset
]);
174 timeout
= atof (word
[2 + offset
]);
175 command
= word_eol
[3 + offset
];
177 if (timeout
< 0.1 || !command
[0])
178 xchat_print (ph
, HELP
);
180 timer_add (ref
, timeout
, repeat
, command
);
182 return XCHAT_EAT_XCHAT
;
191 (xchat_plugin
*plugin_handle
, char **plugin_name
,
192 char **plugin_desc
, char **plugin_version
, char *arg
)
194 /* we need to save this for use with any xchat_* functions */
197 *plugin_name
= "Timer";
198 *plugin_desc
= "IrcII style /TIMER command";
199 *plugin_version
= "";
201 xchat_hook_command (ph
, "TIMER", XCHAT_PRI_NORM
, timer_cb
, HELP
, 0);
203 return 1; /* return 1 for success */